#property copyright "© 2008-2011 BJF Trading Group" #property link "www.iticsoftware.com" #define major 3 #define minor 1 #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Silver #property indicator_style1 STYLE_SOLID #property indicator_width1 1 extern string _tmp1_ = " --- Common ---"; //Set 4, 5 or 0 //4: set 4 if your broker provides 4-digit quotes for EURUSD pair and 2-digit quotes for USDJPY pair //5: set 5 if your broker provides 5-digit quotes for EURUSD pair and 3-digit quotes for USDJPY pair //0: auto detect extern int AccDigits = 0; extern bool UseOpenBar = false; extern string _tmp2_ = " --- Spearman ---"; extern int Spear_RangeN = 7; extern string _tmp3_ = " --- Divergence peaks ---"; extern int Chart_LeftTop_BarsL = 3; extern int Chart_LeftTop_BarsR = 2; extern int Chart_RightTop_BarsL = 2; extern int Chart_RightTop_BarsR = 1; extern int Ind_LeftTop_BarsL = 2; extern int Ind_LeftTop_BarsR = 2; extern int Ind_RightTop_BarsL = 15; extern int Ind_RightTop_BarsR = 3; extern int LeftTops_MaxBarsDiff = 10; extern int RightTops_MaxBarsDiff = 5; extern string _tmp4_ = " --- Levels ---"; extern double BullishDiv_ResetAbove = 1.1; extern double BearishDiv_ResetBelow = -1.1; extern string _tmp5_ = " --- Filters ---"; extern int MaxBars = 2000; extern int DivWidth_MinBars = 30; extern int DivWidth_MaxBars = 150; extern int DivHeight_MinPips = 1; extern int DivHeight_MaxPips = 1000; extern string _tmp6_ = " --- Graphic ---"; extern color clBullishDiv = DeepSkyBlue; extern color clBearishDiv = OrangeRed; extern int Chart_BullishDiv_ArrowCode1 = 233; extern int Chart_BullishDiv_ArrowCode2 = 32; extern int Chart_BearishDiv_ArrowCode1 = 234; extern int Chart_BearishDiv_ArrowCode2 = 32; //M1;M5;M15;M30;H1;H4;D1;W1;MN1 extern string Chart_Arrow_shift_all_TF = "5;5;10;10;15;20;70;200;300"; extern string Chart_Line_shift_all_TF = "0;0;0;0;0;0;0;0;0"; extern int Chart_Line_style = STYLE_DOT; extern int Chart_Line_width = 1; extern int Ind_Line_style = STYLE_SOLID; extern int Ind_Line_width = 1; extern string _tmp7_ = " --- Alerts ---"; extern bool PopupOn = true; extern bool MailOn = false; extern bool SoundOn = true; extern string BullishDivSound = "alert.wav"; extern string BearishDivSound = "alert.wav"; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double ExtMapBuffer1[]; double R2[]; double multiply; int PriceInt[]; int SortInt[]; double chart_right_fr[], chart_left_fr[]; double ind_right_fr[], ind_left_fr[]; int Chart_Arrow_shift[]; int Chart_Line_shift[]; string prefix; string short_name; datetime LastSigTime = 0; double kIT = 0.236; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void init() { IndicatorBuffers(5); SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, ExtMapBuffer1); ArrayResize(R2, Spear_RangeN); ArrayResize(PriceInt, Spear_RangeN ); ArrayResize(SortInt, Spear_RangeN ); multiply = MathPow(10, Digits); SetIndexBuffer(1, chart_right_fr); SetIndexBuffer(2, chart_left_fr); SetIndexBuffer(3, ind_right_fr); SetIndexBuffer(4, ind_left_fr); SetIndexEmptyValue(1, 0.0); SetIndexEmptyValue(2, 0.0); SetIndexEmptyValue(3, 0.0); SetIndexEmptyValue(4, 0.0); short_name = "BJF Spearman Div("+Spear_RangeN +")"; IndicatorShortName(short_name); IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1); SetLevelValue(0, BullishDiv_ResetAbove); SetLevelValue(1, BearishDiv_ResetBelow); prefix = WindowExpertName(); clear(); split_i(Chart_Arrow_shift, Chart_Arrow_shift_all_TF, ";"); split_i(Chart_Line_shift, Chart_Line_shift_all_TF, ";"); } void deinit() { clear(); } double fInd(int ind) { return (ExtMapBuffer1[ind]); } double PointEx() { if (AccDigits == 0) { if (Digits == 2 || Digits == 4) return (Point); if (Digits == 3 || Digits == 5) return (10.0*Point); return (Point); } if (AccDigits == 4) { return (Point); } if (AccDigits == 5) { return (10.0*Point); } return (Point); } void start() { Spearman(); int win_ind = WindowFind(short_name); if (win_ind == -1) win_ind = 1; //----- int counted_bars = IndicatorCounted(); if (counted_bars > 0) counted_bars--; int limit = Bars-counted_bars; if (limit > 1) clear(); //----- int i, j, k; double w; string obj_name; int chart_fr_i, ind_fr_i; int chart_fr_j, ind_fr_j; datetime time1, time2; double price1, price2; int x1, x2; double y1, y2, a, b, f; int shift = 0; if (!UseOpenBar) { shift = 1; } clear(); for (i=0; i < Bars; i++) { chart_right_fr[i] = 0.0; chart_left_fr[i] = 0.0; ind_right_fr[i] = 0.0; ind_left_fr[i] = 0.0; } //----- limit = MaxBars; for (i=0; i < limit; i++) { chart_right_fr[i] = chart_is_fr(MODE_UPPER, Chart_RightTop_BarsL, Chart_RightTop_BarsR, i); chart_left_fr[i] = chart_is_fr(MODE_UPPER, Chart_LeftTop_BarsL, Chart_LeftTop_BarsR, i); ind_right_fr[i] = ind_is_fr(MODE_UPPER, Ind_RightTop_BarsL, Ind_RightTop_BarsR, i); ind_left_fr[i] = ind_is_fr(MODE_UPPER, Ind_LeftTop_BarsL, Ind_LeftTop_BarsR, i); } //----- for (i=0; i < limit; i++) { chart_fr_i = i + Chart_RightTop_BarsR + shift; ind_fr_i = i + Ind_RightTop_BarsR + shift; if (chart_right_fr[chart_fr_i] == 0 && ind_right_fr[ind_fr_i] == 0) continue; for (k=0; k < RightTops_MaxBarsDiff; k++) { if (chart_right_fr[chart_fr_i] != 0) { ind_fr_i = chart_fr_i + k; if (ind_right_fr[ind_fr_i] != 0 && ind_fr_i - Ind_RightTop_BarsR - shift >= i) { break; } } if (ind_right_fr[ind_fr_i] != 0) { chart_fr_i = ind_fr_i + k; if (chart_right_fr[chart_fr_i] != 0 && chart_fr_i - Chart_RightTop_BarsR - shift >= i) { break; } } } if (chart_right_fr[chart_fr_i] == 0 || ind_right_fr[ind_fr_i] == 0) continue; //----- int j0 = MathMax(chart_fr_i, ind_fr_i) + 1; for (j=j0; j < limit; j++) { chart_fr_j = j; ind_fr_j = j; if (chart_fr_j - Chart_LeftTop_BarsR - shift < i + 1) continue; if (ind_fr_j - Ind_LeftTop_BarsR - shift < i + 1) continue; if (chart_left_fr[chart_fr_j] == 0 && ind_left_fr[ind_fr_j] == 0) continue; for (k=0; k < LeftTops_MaxBarsDiff; k++) { if (chart_left_fr[chart_fr_j] != 0) { ind_fr_j = chart_fr_j + k; if (ind_left_fr[ind_fr_j] != 0 && ind_fr_j - Ind_LeftTop_BarsR - shift >= i + 1) { break; } } if (ind_left_fr[ind_fr_j] != 0) { chart_fr_j = ind_fr_j + k; if (chart_left_fr[chart_fr_j] != 0 && chart_fr_j - Chart_LeftTop_BarsR - shift >= i + 1) { break; } } } if (chart_fr_j-chart_fr_i > DivWidth_MaxBars) break; if (chart_left_fr[chart_fr_j] == 0 || ind_left_fr[ind_fr_j] == 0) continue; //----- if (chart_left_fr[chart_fr_j] > chart_right_fr[chart_fr_i]) break; if (ind_left_fr[ind_fr_j] < ind_right_fr[ind_fr_i]) continue; if (chart_fr_j-chart_fr_i < DivWidth_MinBars) continue; if (ind_fr_j-ind_fr_i < DivWidth_MinBars) continue; w = MathAbs(chart_left_fr[chart_fr_j] - chart_right_fr[chart_fr_i]); if (w < DivHeight_MinPips*PointEx()) continue; if (w > DivHeight_MaxPips*PointEx()) continue; //----- int Chart_bar = -1; for (k = chart_fr_i+1; k < chart_fr_j; k++) { if (High[k] > High[chart_fr_i] + 1*PointEx()) { Chart_bar = k; break; } } if (Chart_bar >= 0) break; //----- x1 = ind_fr_j; y1 = fInd(x1); x2 = ind_fr_i; y2 = fInd(x2); a = (y2-y1)/(x2-x1); b = y1 - a*x1; int Ind_bar = -1; for (k = ind_fr_i; k < ind_fr_j; k++) { double Ind_val = fInd(k); if (Ind_val > ind_left_fr[ind_fr_j]) { Ind_bar = k; break; } f = a*k + b; if (fInd(k) > f + kIT*MathAbs(y2-y1)) { Ind_bar = k; break; } if (Ind_val < BearishDiv_ResetBelow) { Ind_bar = k; break; } } if (Ind_bar >= 0) break; //----- obj_name = prefix + "_chart_ua1_" + Time[i]; time1 = Time[i]; price1 = High[i] + 1.3*Chart_Arrow_shift[ITF(Period())]*PointEx(); if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_ARROW, 0, time1, price1); } else { ObjectMove(obj_name, 0, time1, price1); } ObjectSet(obj_name, OBJPROP_WIDTH, 1); ObjectSet(obj_name, OBJPROP_COLOR, clBearishDiv); ObjectSet(obj_name, OBJPROP_ARROWCODE, Chart_BearishDiv_ArrowCode1); //----- obj_name = prefix + "_chart_ua2_" + Time[chart_fr_j]; time1 = Time[chart_fr_j]; price1 = High[chart_fr_j] + 1.3*Chart_Arrow_shift[ITF(Period())]*PointEx(); if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_ARROW, 0, time1, price1); } else { ObjectMove(obj_name, 0, time1, price1); } ObjectSet(obj_name, OBJPROP_WIDTH, 1); ObjectSet(obj_name, OBJPROP_COLOR, clBearishDiv); ObjectSet(obj_name, OBJPROP_ARROWCODE, Chart_BearishDiv_ArrowCode2); //----- obj_name = prefix + "_chart_ul_" + Time[chart_fr_j] + "_" + Time[chart_fr_i]; time1 = Time[chart_fr_j]; price1 = High[chart_fr_j] + Chart_Line_shift[ITF(Period())]*PointEx(); time2 = Time[chart_fr_i]; price2 = High[chart_fr_i] + Chart_Line_shift[ITF(Period())]*PointEx(); if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_TREND, 0, time1, price1, time2, price2); } else { ObjectMove(obj_name, 0, time1, price1); ObjectMove(obj_name, 1, time2, price2); } ObjectSet(obj_name, OBJPROP_RAY, false); ObjectSet(obj_name, OBJPROP_COLOR, clBearishDiv); ObjectSet(obj_name, OBJPROP_STYLE, Chart_Line_style); ObjectSet(obj_name, OBJPROP_WIDTH, Chart_Line_width); //----- obj_name = prefix + "_ind_ul_" + Time[ind_fr_j] + "_" + Time[ind_fr_i]; time1 = Time[ind_fr_j]; price1 = ind_left_fr[ind_fr_j]; time2 = Time[ind_fr_i]; price2 = ind_right_fr[ind_fr_i]; if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_TREND, win_ind, time1, price1, time2, price2); } else { ObjectMove(obj_name, 0, time1, price1); ObjectMove(obj_name, 1, time2, price2); } ObjectSet(obj_name, OBJPROP_RAY, false); ObjectSet(obj_name, OBJPROP_COLOR, clBearishDiv); ObjectSet(obj_name, OBJPROP_STYLE, Ind_Line_style); ObjectSet(obj_name, OBJPROP_WIDTH, Ind_Line_width); } } //----- for (i=0; i < Bars; i++) { chart_right_fr[i] = 0.0; chart_left_fr[i] = 0.0; ind_right_fr[i] = 0.0; ind_left_fr[i] = 0.0; } limit = MaxBars; for (i=0; i < limit; i++) { chart_right_fr[i] = chart_is_fr(MODE_LOWER, Chart_RightTop_BarsL, Chart_RightTop_BarsR, i); chart_left_fr[i] = chart_is_fr(MODE_LOWER, Chart_LeftTop_BarsL, Chart_LeftTop_BarsR, i); ind_right_fr[i] = ind_is_fr(MODE_LOWER, Ind_RightTop_BarsL, Ind_RightTop_BarsR, i); ind_left_fr[i] = ind_is_fr(MODE_LOWER, Ind_LeftTop_BarsL, Ind_LeftTop_BarsR, i); } for (i=0; i < limit; i++) { chart_fr_i = i + Chart_RightTop_BarsR + shift; ind_fr_i = i + Ind_RightTop_BarsR + shift; if (chart_right_fr[chart_fr_i] == 0 && ind_right_fr[ind_fr_i] == 0) continue; for (k=0; k < RightTops_MaxBarsDiff; k++) { if (chart_right_fr[chart_fr_i] != 0) { ind_fr_i = chart_fr_i + k; if (ind_right_fr[ind_fr_i] != 0 && ind_fr_i - Ind_RightTop_BarsR - shift >= i) { break; } } if (ind_right_fr[ind_fr_i] != 0) { chart_fr_i = ind_fr_i + k; if (chart_right_fr[chart_fr_i] != 0 && chart_fr_i - Chart_RightTop_BarsR - shift >= i) { break; } } } if (chart_right_fr[chart_fr_i] == 0 || ind_right_fr[ind_fr_i] == 0) continue; //----- j0 = MathMax(chart_fr_i, ind_fr_i) + 1; for (j=j0; j < limit; j++) { chart_fr_j = j; ind_fr_j = j; if (chart_fr_j - Chart_LeftTop_BarsR - shift < i + 1) continue; if (ind_fr_j - Ind_LeftTop_BarsR - shift < i + 1) continue; if (chart_left_fr[chart_fr_j] == 0 && ind_left_fr[ind_fr_j] == 0) continue; for (k=0; k < LeftTops_MaxBarsDiff; k++) { if (chart_left_fr[chart_fr_j] != 0) { ind_fr_j = chart_fr_j + k; if (ind_left_fr[ind_fr_j] != 0 && ind_fr_j - Ind_LeftTop_BarsR - shift >= i + 1) { break; } } if (ind_left_fr[ind_fr_j] != 0) { chart_fr_j = ind_fr_j + k; if (chart_left_fr[chart_fr_j] != 0 && chart_fr_j - Chart_LeftTop_BarsR - shift >= i + 1) { break; } } } if (chart_fr_j-chart_fr_i > DivWidth_MaxBars) break; if (chart_left_fr[chart_fr_j] == 0 || ind_left_fr[ind_fr_j] == 0) continue; //----- if (chart_left_fr[chart_fr_j] < chart_right_fr[chart_fr_i]) break; if (ind_left_fr[ind_fr_j] > ind_right_fr[ind_fr_i]) continue; if (chart_fr_j-chart_fr_i < DivWidth_MinBars) continue; if (ind_fr_j-ind_fr_i < DivWidth_MinBars) continue; w = MathAbs(chart_left_fr[chart_fr_j] - chart_right_fr[chart_fr_i]); if (w < DivHeight_MinPips*PointEx()) continue; if (w > DivHeight_MaxPips*PointEx()) continue; //----- Chart_bar = -1; for (k = chart_fr_i+1; k < chart_fr_j; k++) { if (Low[k] < Low[chart_fr_i] - 1*PointEx()) { Chart_bar = k; break; } } if (Chart_bar >= 0) break; //----- x1 = ind_fr_j; y1 = fInd(x1); x2 = ind_fr_i; y2 = fInd(x2); a = (y2-y1)/(x2-x1); b = y1 - a*x1; Ind_bar = -1; for (k = ind_fr_i; k < ind_fr_j; k++) { Ind_val = fInd(k); if (Ind_val < ind_left_fr[ind_fr_j]) { Ind_bar = k; break; } f = a*k + b; if (fInd(k) < f - kIT*MathAbs(y2-y1)) { Ind_bar = k; break; } if (Ind_val > BullishDiv_ResetAbove) { Ind_bar = k; break; } } if (Ind_bar >= 0) break; //----- obj_name = prefix + "_chart_la1_" + Time[i]; time1 = Time[i]; price1 = Low[i] - 1.0*Chart_Arrow_shift[ITF(Period())]*PointEx(); if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_ARROW, 0, time1, price1); } else { ObjectMove(obj_name, 0, time1, price1); } ObjectSet(obj_name, OBJPROP_WIDTH, 1); ObjectSet(obj_name, OBJPROP_COLOR, clBullishDiv); ObjectSet(obj_name, OBJPROP_ARROWCODE, Chart_BullishDiv_ArrowCode1); //----- obj_name = prefix + "_chart_la2_" + Time[chart_fr_j]; time1 = Time[chart_fr_j]; price1 = Low[chart_fr_j] - 1.0*Chart_Arrow_shift[ITF(Period())]*PointEx(); if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_ARROW, 0, time1, price1); } else { ObjectMove(obj_name, 0, time1, price1); } ObjectSet(obj_name, OBJPROP_WIDTH, 1); ObjectSet(obj_name, OBJPROP_COLOR, clBullishDiv); ObjectSet(obj_name, OBJPROP_ARROWCODE, Chart_BullishDiv_ArrowCode2); //----- obj_name = prefix + "_chart_ll_" + Time[chart_fr_j] + "_" + Time[chart_fr_i]; time1 = Time[chart_fr_j]; price1 = Low[chart_fr_j] - Chart_Line_shift[ITF(Period())]*PointEx(); time2 = Time[chart_fr_i]; price2 = Low[chart_fr_i] - Chart_Line_shift[ITF(Period())]*PointEx(); if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_TREND, 0, time1, price1, time2, price2); } else { ObjectMove(obj_name, 0, time1, price1); ObjectMove(obj_name, 1, time2, price2); } ObjectSet(obj_name, OBJPROP_RAY, false); ObjectSet(obj_name, OBJPROP_COLOR, clBullishDiv); ObjectSet(obj_name, OBJPROP_STYLE, Chart_Line_style); ObjectSet(obj_name, OBJPROP_WIDTH, Chart_Line_width); //----- obj_name = prefix + "_ind_ll_" + Time[ind_fr_j] + "_" + Time[ind_fr_i]; time1 = Time[ind_fr_j]; price1 = ind_left_fr[ind_fr_j]; time2 = Time[ind_fr_i]; price2 = ind_right_fr[ind_fr_i]; if (ObjectFind(obj_name) == -1) { ObjectCreate(obj_name, OBJ_TREND, win_ind, time1, price1, time2, price2); } else { ObjectMove(obj_name, 0, time1, price1); ObjectMove(obj_name, 1, time2, price2); } ObjectSet(obj_name, OBJPROP_RAY, false); ObjectSet(obj_name, OBJPROP_COLOR, clBullishDiv); ObjectSet(obj_name, OBJPROP_STYLE, Ind_Line_style); ObjectSet(obj_name, OBJPROP_WIDTH, Ind_Line_width); } } //----- if (Time[1] != LastSigTime) { obj_name = prefix + "_chart_la1_" + Time[0]; bool LongSig = (ObjectFind(obj_name) != -1); obj_name = prefix + "_chart_ua1_" + Time[0]; bool ShortSig = (ObjectFind(obj_name) != -1); if (LongSig || ShortSig) { LastSigTime = Time[1]; } //----------------------- // Sound Alert //----------------------- if (SoundOn) { if (LongSig) PlaySound(BearishDivSound); if (ShortSig) PlaySound(BullishDivSound); } //----------------------- // Popup Alert //----------------------- string msg; if (PopupOn) { if (LongSig) { msg = WindowExpertName() + " " + Symbol() + " " + TF2Str(Period()) + ": BEARISH divergence at " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); Alert(msg); } if (ShortSig) { msg = WindowExpertName() + " " + Symbol() + " " + TF2Str(Period()) + ": BULLISH divergence at " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); Alert(msg); } } //----------------------- // Mail Alert //----------------------- if (MailOn) { if (LongSig) { msg = Symbol() + " " + TF2Str(Period()) + ": BEARISH divergence at " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); SendMail(WindowExpertName(), msg); } if (ShortSig) { msg = Symbol() + " " + TF2Str(Period()) + ": BEARISH divergence at " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); SendMail(WindowExpertName(), msg); } } } //if (LastSigTime != Time[1]) } int Spearman() { int counted_bars = IndicatorCounted(); //---- int i, k, limit; if(counted_bars == 0) limit = Bars - Spear_RangeN ; if(counted_bars > 0) limit = Bars - counted_bars; for(i = limit; i >= 0; i--) { for(k = 0; k < Spear_RangeN ; k++) PriceInt[k] = Close[i+k]*multiply; RankPrices(PriceInt); ExtMapBuffer1[i] = SpearmanRankCorrelation(R2,Spear_RangeN ); } //---- return(0); } //+------------------------------------------------------------------+ //| calculate RSP function | //+------------------------------------------------------------------+ double SpearmanRankCorrelation(double Ranks[], int N) { //---- double res,z2; int i; for(i = 0; i < N; i++) { z2 += MathPow(Ranks[i] - i - 1, 2); } res = 1 - 6*z2 / (MathPow(N,3) - N); //---- return(res); } //+------------------------------------------------------------------+ //| Ranking array of prices function | //+------------------------------------------------------------------+ void RankPrices(int InitialArray[]) { //int Spear_SortDir = MODE_DESCEND; int Spear_SortDir = MODE_ASCEND; //---- int i, k, m, dublicat, counter, etalon; double dcounter, averageRank; double TrueRanks[]; ArrayResize(TrueRanks, Spear_RangeN); ArrayCopy(SortInt, InitialArray); for(i = 0; i < Spear_RangeN; i++) TrueRanks[i] = i + 1; ArraySort(SortInt, 0, 0, Spear_SortDir); for(i = 0; i < Spear_RangeN-1; i++) { if(SortInt[i] != SortInt[i+1]) continue; dublicat = SortInt[i]; k = i + 1; counter = 1; averageRank = i + 1; while(k < Spear_RangeN) { if(SortInt[k] == dublicat) { counter++; averageRank += k + 1; k++; } else break; } dcounter = counter; averageRank = averageRank / dcounter; for(m = i; m < k; m++) TrueRanks[m] = averageRank; i = k; } for(i = 0; i < Spear_RangeN; i++) { etalon = InitialArray[i]; k = 0; while(k < Spear_RangeN) { if(etalon == SortInt[k]) { R2[i] = TrueRanks[k]; break; } k++; } } //---- return; } void clear() { int total = ObjectsTotal(); for (int i=total-1; i >= 0; i--) { string name = ObjectName(i); if (StringFind(name, prefix) == 0) ObjectDelete(name); } } double chart_is_fr(int mode, int left_period, int right_period, int shift) { int l = 0; int r = 0; if (mode == MODE_UPPER) { for (int i=1; i <= left_period; i++) { if (shift+i >= Bars) break; if (High[shift+i] <= High[shift]) l++; } for (i=1; i <= right_period; i++) { if (shift-i < 0) break; if (High[shift-i] < High[shift]) r++; } if (l == left_period && r == right_period) return (High[shift]); } if (mode == MODE_LOWER) { for (i=1; i <= left_period; i++) { if (shift+i >= Bars) break; if (Low[shift+i] >= Low[shift]) l++; } for (i=1; i <= right_period; i++) { if (shift-i < 0) break; if (Low[shift-i] > Low[shift]) r++; } if (l == left_period && r == right_period) return (Low[shift]); } return (0); } double ind_is_fr(int mode, int left_period, int right_period, int shift) { int l = 0; int r = 0; double Ind_val, Ind_val_l, Ind_val_r; Ind_val = fInd(shift); if (mode == MODE_UPPER) { for (int i=1; i <= left_period; i++) { if (shift+i >= Bars) break; Ind_val_l = fInd(shift+i); if (Ind_val_l <= Ind_val) l++; } for (i=1; i <= right_period; i++) { if (shift-i < 0) break; Ind_val_r = fInd(shift-i); if (Ind_val_r < Ind_val) r++; } if (l == left_period && r == right_period) return (Ind_val); } if (mode == MODE_LOWER) { for (i=1; i <= left_period; i++) { if (shift+i >= Bars) break; Ind_val_l = fInd(shift+i); if (Ind_val_l >= Ind_val) l++; } for (i=1; i <= right_period; i++) { if (shift-i < 0) break; Ind_val_r = fInd(shift-i); if (Ind_val_r > Ind_val) r++; } if (l == left_period && r == right_period) return (Ind_val); } return (0); } void split_i(int& arr[], string str, string sym) { ArrayResize(arr, 0); string item; int pos, size; int len = StringLen(str); for (int i=0; i < len;) { pos = StringFind(str, sym, i); if (pos == -1) pos = len; item = StringSubstr(str, i, pos-i); item = StringTrimLeft(item); item = StringTrimRight(item); size = ArraySize(arr); ArrayResize(arr, size+1); arr[size] = StrToInteger(item); i = pos+1; } } int ITF(int period) { if (period == PERIOD_M1) return (0); if (period == PERIOD_M5) return (1); if (period == PERIOD_M15) return (2); if (period == PERIOD_M30) return (3); if (period == PERIOD_H1) return (4); if (period == PERIOD_H4) return (5); if (period == PERIOD_D1) return (6); if (period == PERIOD_W1) return (7); if (period == PERIOD_MN1) return (8); return (4); } string TF2Str(int period) { switch (period) { case PERIOD_M1: return("M1"); case PERIOD_M5: return("M5"); case PERIOD_M15: return("M15"); case PERIOD_M30: return("M30"); case PERIOD_H1: return("H1"); case PERIOD_H4: return("H4"); case PERIOD_D1: return("D1"); case PERIOD_W1: return("W1"); case PERIOD_MN1: return("MN1"); } return (Period()); }