i-AnyRangeCldTail_System_Alert

Author: Copyright © 2006, Ким Игорь В. aka KimIV
Miscellaneous
It issuies visual alerts to the screenIt sends emails
2 Views
0 Downloads
0 Favorites
i-AnyRangeCldTail_System_Alert
ÿþ//+----------------------------------------------------------------------------+

//|                                        i-AnyRangeCldTail_System_Alert.mq5  |

//|                                  Copyright © 2006, 8< 3>@L . aka KimIV  |

//|                                                       http://www.kimiv.ru  |

//+----------------------------------------------------------------------------+

//---- 02B>@AB2> 8=48:0B>@0

#property copyright "Copyright © 2006, 8< 3>@L . aka KimIV"

#property link      "http://www.kimiv.ru"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.10"

//---- >?8A0=85 8=48:0B>@0

#property description "=48:0B>@ 480?07>=>2 ?@>872>;L=KE 2@5<5==KE 8=B5@20;>2"

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

//---- 4;O @0AGQB0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20=> B@8=04F0BL 1CD5@>2

#property indicator_buffers 13

//---- 8A?>;L7>20=> A5<L 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   7

//+----------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 >1;0:0 1                 |

//+----------------------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 2 2845 >1;0:0

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B Lavender

#property indicator_color1 clrLavender

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label1  "i-AnyRange"

//+----------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 25@E=59 ;8=88            |

//+----------------------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 2 2 2845 ;8=88

#property indicator_type2   DRAW_LINE

//---- 2 :0G5AB25 F25B0 1KG59 ;8=88 8=48:0B>@0 8A?>;L7>20= A8=89 F25B

#property indicator_color2  clrBlue

//---- ;8=8O 8=48:0B>@0 2 - =5?@5@K2=0O :@820O

#property indicator_style1  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 2 @02=0 3

#property indicator_width2  3

//---- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0

#property indicator_label2  "Upper Zone"

//+----------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 =86=59 ;8=88             |

//+----------------------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 3 2 2845 ;8=88

#property indicator_type3   DRAW_LINE

//---- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= :@0A=K9 F25B

#property indicator_color3  clrRed

//---- ;8=8O 8=48:0B>@0 3 - =5?@5@K2=0O :@820O

#property indicator_style3  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 3 @02=0 3

#property indicator_width3  3

//---- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label3  "Lower Zone"

//+----------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 >1;0:0 2                 |

//+----------------------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 2 2845 >1;0:0

#property indicator_type4   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B LavenderBlush

#property indicator_color4 clrLavenderBlush

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label4  "i-AnyRange tail"

//+----------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 25@E=59 ;8=88            |

//+----------------------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 5 2 2845 ;8=88

#property indicator_type5   DRAW_LINE

//---- 2 :0G5AB25 F25B0 1KG59 ;8=88 8=48:0B>@0 8A?>;L7>20= A8=89 F25B

#property indicator_color5  clrBlue

//---- ;8=8O 8=48:0B>@0 5 - HB@8E-?C=:B8@

#property indicator_style5  STYLE_DASHDOTDOT

//---- B>;I8=0 ;8=88 8=48:0B>@0 5 @02=0 1

#property indicator_width5  1

//---- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0

#property indicator_label5  "Upper Zone  tail"

//+----------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 =86=59 ;8=88             |

//+----------------------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 6 2 2845 ;8=88

#property indicator_type6   DRAW_LINE

//---- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= :@0A=K9 F25B

#property indicator_color6  clrRed

//---- ;8=8O 8=48:0B>@0 6 - HB@8E-?C=:B8@

#property indicator_style6  STYLE_DASHDOTDOT

//---- B>;I8=0 ;8=88 8=48:0B>@0 6 @02=0 1

#property indicator_width6  1

//---- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label6  "Lower Zone  tail"

//+--------------------------------------------+

//| 0@0<5B@K >B@8A>2:8 A25G59                 |

//+--------------------------------------------+

//---- 2 :0G5AB25 8=48:0B>@0 8A?>;L7>20=K F25B=K5 A25G8

#property indicator_type7   DRAW_COLOR_CANDLES

#property indicator_color7   clrDeepPink,clrPurple,clrTeal,clrDarkTurquoise

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label7  "i-AnyRange_Open;i-AnyRange_High;i-AnyRange_Low;i-AnyRange_Close"

//+----------------------------------------------+

//|  >1JO2;5=85 :>=AB0=B                         |

//+----------------------------------------------+

#define RESET 0 // :>=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AGQB 8=48:0B>@0

//+----------------------------------------------+

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

//+----------------------------------------------+

input string Time1 = "02:00";   // @5<5==0O B>G:0 1

input string Time2 = "07:00";   // @5<5==0O B>G:0 2

input uint   nDays = 8;         // >;8G5AB2> 4=59 >1AGQB0 (0-2A5)

input int    Shift=0;           // A4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E

input uint NumberofBar=1;       // ><5@ 10@0 4;O ?>40G8 A83=0;0

input bool SoundON=true;        //  07@5H5=85 0;5@B0

input uint NumberofAlerts=2;    // >;8G5AB2> 0;5@B>2

input bool EMailON=false;       //  07@5H5=85 ?>GB>2>9 >B?@02:8 A83=0;0

input bool PushON=false;        //  07@5H5=85 >B?@02:8 A83=0;0 =0 <>18;L=K9

//+----------------------------------------------+

//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double Up0Buffer[],Dn0Buffer[],Up1Buffer[],Dn1Buffer[];

double Up2Buffer[],Dn2Buffer[],Up3Buffer[],Dn3Buffer[];

double ExtOpenBuffer[],ExtHighBuffer[],ExtLowBuffer[],ExtCloseBuffer[],ExtColorBuffer[];



//---- 1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

int min_rates_total,Max;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+  

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

   min_rates_total=int(24*60*60*nDays/PeriodSeconds()+1);

   Max=int(nDays*1440*60/PeriodSeconds());



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(0,Up0Buffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 1 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 1 =0 min_rates_total

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

//PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Up0Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(1,Dn0Buffer,INDICATOR_DATA);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Dn0Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(2,Up1Buffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 1 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 1 =0 min_rates_total

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Up1Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(3,Dn1Buffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 2 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 2 =0 min_rates_total

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Dn1Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(4,Up2Buffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 1 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(3,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 1 =0 min_rates_total

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

//PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Up2Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(5,Dn2Buffer,INDICATOR_DATA);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Dn2Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(6,Up3Buffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 1 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(4,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 1 =0 min_rates_total

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Up3Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(7,Dn3Buffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 2 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(5,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 2 =0 min_rates_total

   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(Dn3Buffer,true);



//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

   SetIndexBuffer(8,ExtOpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(9,ExtHighBuffer,INDICATOR_DATA);

   SetIndexBuffer(10,ExtLowBuffer,INDICATOR_DATA);

   SetIndexBuffer(11,ExtCloseBuffer,INDICATOR_DATA);

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 F25B>2>9, 8=45:A=K9 1CD5@   

   SetIndexBuffer(12,ExtColorBuffer,INDICATOR_COLOR_INDEX);

//---- CAB0=>2:0 ?>78F88, A :>B>@>9 =0G8=05BAO ;8=89 :0=0;0

   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,min_rates_total);

//---- 70?@5B =0 >B@8A>2:C 8=48:0B>@>< ?CABKE 7=0G5=89

   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,NULL);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 ?> 3>@87>=B0;8

   PlotIndexSetInteger(6,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 ?> 3>@87>=B0;8

   PlotIndexSetInteger(6,PLOT_SHIFT,Shift);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(ExtOpenBuffer,true);

   ArraySetAsSeries(ExtHighBuffer,true);

   ArraySetAsSeries(ExtLowBuffer,true);

   ArraySetAsSeries(ExtCloseBuffer,true);

   ArraySetAsSeries(ExtColorBuffer,true);



//---- 8=8F80;870F88 ?5@5<5==>9 4;O :>@>B:>3> 8<5=8 8=48:0B>@0

   string shortname;

   StringConcatenate(shortname,"i-AnyRangeCldTail_System(",Time1,", ",Time2,", ",nDays,")");

//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//----

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//----

   Comment("");

//----   

  }

//+------------------------------------------------------------------+

//| iBarShift() function                                             |

//+------------------------------------------------------------------+

int iBarShift(string symbol,ENUM_TIMEFRAMES timeframe,datetime time)



// iBarShift(symbol, timeframe, time)

//+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+

  {

//----+

   if(time<0) return(-1);



   datetime Arr[],time1;



   time1=(datetime) SeriesInfoInteger(symbol,timeframe,SERIES_LASTBAR_DATE);

   if(time>=time1) return(0);



   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)

     {

      int size=ArraySize(Arr);

      return(size-1);

     }

   else return(-1);

//----+

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(

                const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                const datetime &time[],

                const double &open[],

                const double& high[],     // F5=>2>9 <0AA82 <0:A8<C<>2 F5=K 4;O @0AGQB0 8=48:0B>@0

                const double& low[],      // F5=>2>9 <0AA82 <8=8<C<>2 F5=K  4;O @0AGQB0 8=48:0B>@0

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[]

                )

  {

//---- ?@>25@:0 ?5@8>40 3@0D8:0

   if(Period()>PERIOD_H1)

     {

      Comment("=48:0B>@C i-AnyRange =C65= "$ <;04H5 H4!");

      return(RESET);

     }

   else Comment("");



//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(rates_total<min_rates_total) return(RESET);



//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE 

   double up=NULL,dn=NULL;

   int    bar,limit,kd=0,nb1=0,nb2=0,nd=0,rates_10;

   string sdt;



   rates_10=rates_total-10;



//---- @0AGQB AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AGQB0 10@>2

   if(nDays==0) limit=rates_10;

   else limit=Max;

   limit=MathMin(rates_10,limit);



//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@>2

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,rates_total-limit);

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,rates_total-limit);

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,rates_total-limit);

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,rates_total-limit);

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,rates_total-limit);

   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,rates_total-limit);

   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,rates_total-limit);



//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E :0: 2 B09<A5@8OE  

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

   ArraySetAsSeries(time,true);



//---- >A=>2=>9 F8:; >1=C;5=8O 8=48:0B>@>2 1, 2, 3

   for(bar=0; bar<limit && !IsStopped(); bar++)

     {

      Up0Buffer[bar]=NULL;

      Dn0Buffer[bar]=NULL;

      Up1Buffer[bar]=EMPTY_VALUE;

      Dn1Buffer[bar]=EMPTY_VALUE;

     }



//---- >A=>2=>9 F8:; @0AGQB0 8=48:0B>@>2 1, 2, 3

   for(bar=0; bar<limit && !IsStopped(); bar++)

     {

      Up1Buffer[bar]=EMPTY_VALUE;

      Dn1Buffer[bar]=EMPTY_VALUE;

      MqlDateTime tm;

      TimeToStruct(time[bar],tm);



      if(nd!=tm.day)

        {

         nd=tm.day;

         kd++;

         if(kd>int(nDays) && nDays) break;



         sdt=TimeToString(time[bar],TIME_DATE);



         nb1=iBarShift(NULL, 0, StringToTime(sdt+" "+Time1));

         nb2=iBarShift(NULL, 0, StringToTime(sdt+" "+Time2));



         if(nb1>nb2+1)

           {

            up=high[ArrayMaximum(high,nb2+1,nb1-nb2)];

            dn=low[ArrayMinimum(low,nb2+1,nb1-nb2)];

           }



         if(nb2>nb1+1)

           {

            up=high[ArrayMaximum(high,nb1+1,nb2-nb1)];

            dn=low[ArrayMinimum(low,nb1+1,nb2-nb1)];

           }

        }

      if((nb1>=bar && bar>nb2) || (nb2>=bar && bar>nb1))

        {

         Up1Buffer[bar]=up;

         Dn1Buffer[bar]=dn;

         Up0Buffer[bar]=up;

         Dn0Buffer[bar]=dn;

        }

      else

        {

         Up1Buffer[bar]=EMPTY_VALUE;

         Dn1Buffer[bar]=EMPTY_VALUE;

        }

     }



//---- >A=>2=>9 F8:; >1=C;5=8O >1;0:0 1

   for(bar=0; bar<limit && !IsStopped(); bar++)

     {

      if(Up1Buffer[bar]==EMPTY_VALUE && Dn1Buffer[bar]==EMPTY_VALUE)

        {

         Up0Buffer[bar]=NULL;

         Dn0Buffer[bar]=NULL;

        }

     }



//----

   up=dn=EMPTY_VALUE;

//---- >A=>2=>9 F8:; @0AGQB0 8=48:0B>@>2 4, 5, 6

   for(bar=limit-1; bar>=0 && !IsStopped(); bar--)

     {

      Up2Buffer[bar]=NULL;

      Dn2Buffer[bar]=NULL;

      Up3Buffer[bar]=EMPTY_VALUE;

      Dn3Buffer[bar]=EMPTY_VALUE;



      if(Up0Buffer[bar])

        {

         up=Up0Buffer[bar];

         dn=Dn0Buffer[bar];

        }

      else

        {

         Up2Buffer[bar]=Up3Buffer[bar]=up;

         Dn2Buffer[bar]=Dn3Buffer[bar]=dn;

         int bar1=bar+1;

         if(Up0Buffer[bar1])

           {

            Up2Buffer[bar1]=Up3Buffer[bar1]=up;

            Dn2Buffer[bar1]=Dn3Buffer[bar1]=dn;

           }

        }

     }

//---- >A=>2=>9 F8:; @0AGQB0 8=48:0B>@>2 7

   for(bar=limit-1; bar>=0 && !IsStopped(); bar--)

     {

      ExtOpenBuffer[bar]=ExtCloseBuffer[bar]=ExtHighBuffer[bar]=ExtLowBuffer[bar]=NULL;

      ExtColorBuffer[bar]=4;

      //----

      if(Up2Buffer[bar] && close[bar]>Up2Buffer[bar])

        {

         ExtOpenBuffer[bar]=open[bar];

         ExtCloseBuffer[bar]=close[bar];

         ExtHighBuffer[bar]=high[bar];

         ExtLowBuffer[bar]=low[bar];

         if(close[bar]>=open[bar]) ExtColorBuffer[bar]=3;

         else ExtColorBuffer[bar]=2;

        }

      //----

      if(Dn2Buffer[bar] && close[bar]<Dn2Buffer[bar])

        {

         ExtOpenBuffer[bar]=open[bar];

         ExtCloseBuffer[bar]=close[bar];

         ExtHighBuffer[bar]=high[bar];

         ExtLowBuffer[bar]=low[bar];

         if(close[bar]<=open[bar]) ExtColorBuffer[bar]=0;

         else ExtColorBuffer[bar]=1;

        }

     }

//---     

   BuySignal("i-AnyRangeCldTail_System_Alert",ExtColorBuffer,rates_total,prev_calculated,close,spread);

   SellSignal("i-AnyRangeCldTail_System_Alert",ExtColorBuffer,rates_total,prev_calculated,close,spread);

//---    

   return(rates_total);

  }

//+------------------------------------------------------------------+

//| Buy signal function                                              |

//+------------------------------------------------------------------+

void BuySignal(string SignalSirname,      // B5:AB 8<5=8 8=48:0B>@0 4;O ?>GB>2KE 8 ?CH-A83=0;>2

               double &ColorArrow[],      // F25B>2>9 8=48:0B>@=K9  1CD5@ A A83=0;0<8 4;O ?>:C?:8

               const int Rates_total,     // B5:CI55 :>;8G5AB2> 10@>2

               const int Prev_calculated, // :>;8G5AB2> 10@>2 =0 ?@54K4CI5< B8:5

               const double &Close[],     // F5=0 70:@KB8O

               const int &Spread[])       // A?@54

  {

//---

   static uint counter=0;

   if(Rates_total!=Prev_calculated) counter=0;



   bool BuySignal=false;

   bool SeriesTest=ArrayGetAsSeries(ColorArrow);

   int index,index1;

   if(SeriesTest)

     {

      index=int(NumberofBar);

      index1=index+1;

     }

   else

     {

      index=Rates_total-int(NumberofBar)-1;

      index1=index-1;

     }

   if(ColorArrow[index]!=4 && ColorArrow[index]>1 && (ColorArrow[index1]<2 || ColorArrow[index1]==4)) BuySignal=true;

   if(BuySignal && counter<=NumberofAlerts)

     {

      counter++;

      MqlDateTime tm;

      TimeToStruct(TimeCurrent(),tm);

      string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min);

      SeriesTest=ArrayGetAsSeries(Close);

      if(SeriesTest) index=int(NumberofBar);

      else index=Rates_total-int(NumberofBar)-1;

      double Ask=Close[index];

      double Bid=Close[index];

      SeriesTest=ArrayGetAsSeries(Spread);

      if(SeriesTest) index=int(NumberofBar);

      else index=Rates_total-int(NumberofBar)-1;

      Bid+=Spread[index]*_Point;

      string sAsk=DoubleToString(Ask,_Digits);

      string sBid=DoubleToString(Bid,_Digits);

      string sPeriod=GetStringTimeframe(ChartPeriod());

      if(SoundON) Alert("BUY signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);

      if(EMailON) SendMail(SignalSirname+": BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);

      if(PushON) SendNotification(SignalSirname+": BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);

     }



//---

  }

//+------------------------------------------------------------------+

//| Sell signal function                                             |

//+------------------------------------------------------------------+

void SellSignal(string SignalSirname,      // B5:AB 8<5=8 8=48:0B>@0 4;O ?>GB>2KE 8 ?CH-A83=0;>2

                double &ColorArrow[],      // F25B>2>9 8=48:0B>@=K9  1CD5@ A A83=0;0<8 4;O ?@>4068

                const int Rates_total,     // B5:CI55 :>;8G5AB2> 10@>2

                const int Prev_calculated, // :>;8G5AB2> 10@>2 =0 ?@54K4CI5< B8:5

                const double &Close[],     // F5=0 70:@KB8O

                const int &Spread[])       // A?@54

  {

//---

   static uint counter=0;

   if(Rates_total!=Prev_calculated) counter=0;



   bool SellSignal=false;

   bool SeriesTest=ArrayGetAsSeries(ColorArrow);

   int index,index1;

   if(SeriesTest)

     {

      index=int(NumberofBar);

      index1=index+1;

     }

   else

     {

      index=Rates_total-int(NumberofBar)-1;

      index1=index-1;

     }

   if(ColorArrow[index]<2 && ColorArrow[index1]>1) SellSignal=true;

   if(SellSignal && counter<=NumberofAlerts)

     {

      counter++;

      MqlDateTime tm;

      TimeToStruct(TimeCurrent(),tm);

      string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min);

      SeriesTest=ArrayGetAsSeries(Close);

      if(SeriesTest) index=int(NumberofBar);

      else index=Rates_total-int(NumberofBar)-1;

      double Ask=Close[index];

      double Bid=Close[index];

      SeriesTest=ArrayGetAsSeries(Spread);

      if(SeriesTest) index=int(NumberofBar);

      else index=Rates_total-int(NumberofBar)-1;

      Bid+=Spread[index]*_Point;

      string sAsk=DoubleToString(Ask,_Digits);

      string sBid=DoubleToString(Bid,_Digits);

      string sPeriod=GetStringTimeframe(ChartPeriod());

      if(SoundON) Alert("SELL signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);

      if(EMailON) SendMail(SignalSirname+": SELL signal alert","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);

      if(PushON) SendNotification(SignalSirname+": SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);

     }

//---

  }

//+------------------------------------------------------------------+

//|  >;CG5=85 B09<D@59<0 2 2845 AB@>:8                              |

//+------------------------------------------------------------------+

string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)

  {

//----

   return(StringSubstr(EnumToString(timeframe),7,-1));

//----

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---