Hans_Indicator_x62_Cloud_System_Alert

Author: Copyright © 2014, Shimodax
Miscellaneous
It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
Hans_Indicator_x62_Cloud_System_Alert
ÿþ//+------------------------------------------------------------------+ 

//|                        Hans_Indicator_x62_Cloud_System_Alert.mq5 | 

//|                                       Copyright © 2014, Shimodax | 

//|   http://www.strategybuilderfx.com/forums/showthread.php?t=15439 | 

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

/* Introduction:



   Draw ranges for "Simple Combined Breakout System for EUR/USD and GBP/USD" thread

   (see http://www.strategybuilderfx.com/forums/showthread.php?t=15439)



   LocalTimeZone: TimeZone for which MT5 shows your local time, 

                  e.g. 1 or 2 for Europe (GMT+1 or GMT+2 (daylight 

                  savings time).  Use zero for no adjustment.

                  

                  The MetaQuotes demo server uses GMT +2.   

   Enjoy  :-)

   

   Markus



*/

#property copyright "Copyright © 2014, Shimodax"

#property link "http://www.strategybuilderfx.com/forums/showthread.php?t=15439"

#property description "=48:0B>@ @0AH8@ONI8EAO :>@84>@>2 2@5<5==KE 7>= A B@84F0BLN >4=8< :>@84>@><,  A D>=>2K< F25B>2K< 70?>;=5=85<, A@54=59 ;8=859 :>@84>@0,"

#property description "A >:@0H820=85< A25G5: ?@8 2KE>45 87 AD>@<8@>20==>3> G5BK@QEG0A>2>3> :>@84>@0."

#property description "!D>@<8@>20==K9 :>@84>@ @025= G5BK@Q< G0A0<, @0AH8@5=8O :>@84>@0 - H5AB=04F0BL G0A>2."

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

#property version   "1.02"

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

#property indicator_chart_window  

//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2 74

#property indicator_buffers 74

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

#property indicator_plots   68

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

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

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

#define LINES_TOTAL         32    // >=AB0=B0 4;O :>;8G5AB20 ?0@ ;8=89 8=48:0B>@0 4;O C@>2=59 

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

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

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

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

//---- >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 C'232,255,247'

#property indicator_color1 C'232,255,247'

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

#property indicator_label1  "Upper Hans_Indicator_x22 cloud"

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

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

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

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

#property indicator_type2   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B C'255,240,255'

#property indicator_color2 C'255,240,255'

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

#property indicator_label2  "Lower Hans_Indicator_x22 cloud"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 3       |

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

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

#property indicator_type3   DRAW_LINE

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

#property indicator_color3 clrBlue

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style3  STYLE_SOLID

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

#property indicator_width3  1

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

#property indicator_label3  "Upper Hans_Indicator 1"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 4       |

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

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

#property indicator_type4   DRAW_LINE

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

#property indicator_color4 clrMagenta

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style4  STYLE_SOLID

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

#property indicator_width4  1

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

#property indicator_label4  "Lower Hans_Indicator 1"

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

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

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

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

#property indicator_type5   DRAW_LINE

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

#property indicator_color5 clrLime

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style5  STYLE_SOLID

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

#property indicator_width5 3

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

#property indicator_label5  "Upper Hans_Indicator 2"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 6       |

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

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

#property indicator_type6   DRAW_LINE

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

#property indicator_color6 clrRed

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style6  STYLE_SOLID

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

#property indicator_width6  3

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

#property indicator_label6  "Lower Hans_Indicator 2"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 7       |

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

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

#property indicator_type7   DRAW_LINE

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

#property indicator_color7 clrGreen

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style7  STYLE_SOLID

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

#property indicator_width7 3

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

#property indicator_label7  "Upper Hans_Indicator 3"

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

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

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

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

#property indicator_type8   DRAW_LINE

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

#property indicator_color8 clrIndigo

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style8  STYLE_SOLID

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

#property indicator_width8  3

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

#property indicator_label8  "Lower Hans_Indicator 3"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 9       |

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

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

#property indicator_type9   DRAW_LINE

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

#property indicator_color9 clrGreen

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

#property indicator_style9  STYLE_DASH

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

#property indicator_width9 1

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

#property indicator_label9  "Upper Hans_Indicator 4"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 10      |

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

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

#property indicator_type10   DRAW_LINE

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

#property indicator_color10 clrIndigo

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

#property indicator_style10  STYLE_DASH

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

#property indicator_width10  1

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

#property indicator_label10  "Lower Hans_Indicator 4"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 11      |

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

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

#property indicator_type11   DRAW_LINE

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

#property indicator_color11 clrGreen

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

#property indicator_style11  STYLE_DASHDOTDOT

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

#property indicator_width11 1

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

#property indicator_label11  "Upper Hans_Indicator 5"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 12      |

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

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

#property indicator_type12   DRAW_LINE

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

#property indicator_color12 clrIndigo

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

#property indicator_style12  STYLE_DASHDOTDOT

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

#property indicator_width12  1

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

#property indicator_label12  "Lower Hans_Indicator 5"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 13      |

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

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

#property indicator_type13   DRAW_LINE

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

#property indicator_color13 clrGreen

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style13  STYLE_SOLID

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

#property indicator_width13  1

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

#property indicator_label13  "Upper Hans_Indicator 6"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 14      |

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

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

#property indicator_type14   DRAW_LINE

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

#property indicator_color14 clrIndigo

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style14  STYLE_SOLID

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

#property indicator_width14  1

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

#property indicator_label14  "Lower Hans_Indicator 6"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 67      |

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

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

#property indicator_type67   DRAW_LINE

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

#property indicator_color67 clrSlateGray

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style67  STYLE_SOLID

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

#property indicator_width67 2

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

#property indicator_label67  "Middle Hans_Indicator"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 A25G    |

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

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

#property indicator_type68   DRAW_COLOR_CANDLES

#property indicator_color68   clrDeepSkyBlue,clrBlue,clrGray,clrPurple,clrMagenta

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

#property indicator_label68  "Hans_Indicator Open;Hans_Indicator High;Hans_Indicator Low;Hans_Indicator Close"

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

//|  %+  " + "            |

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

input uint LocalTimeZone=0;         // G0A =0G0;0 >BAGQB0 8AE>4=>3> :>@84>@0

input uint DestTimeZone=4;          // A4283 :>@84>@0 2;52> 2 10@0E

input uint PipsForEntryStep=50;     // H03 @0AH8@5=8O 3@0=8F :064>3> AD>@<8@>20==>3> :>@84>@0 2 ?C=:B0E

input int  Shift=0;                 // !4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 

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

input uint  Slip=0;             // !<5I5=85 :>>@48=0B=>9 A5B:8 ?> 25@B8:0;8 =0 PipsForEntryStep >B A5@548=K :0=0;0

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

//---- >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 UpUpBuffer[],UpDnBuffer[],DnUpBuffer[],DnDnBuffer[],MiddleBuffer[];

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

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

int  min_rates_total;

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

//|  0AA82K ?5@5<5==KE 4;O A>740=8O 8=48:0B>@=KE 1CD5@>2            |

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

class CIndicatorsBuffers

  {

public: double    ZoneUpper[];

public: double    ZoneLower[];

  };

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

//| !>740=85 8=48:0B>@=KE 1CD5@>2                                    |

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

CIndicatorsBuffers Ind[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

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

   min_rates_total=100;

//---- >1JO2;5=85 <0AA82>2 4;O AB8;59 8=48:0B>@=KE ;8=89

   ENUM_LINE_STYLE line_style[];

   color line_color[];

   int line_width[];

   ENUM_DRAW_TYPE plot_type[];

//----  0A?@545;5=85 ?0<OB8 ?>4 <0AA82K ?5@5<5==KE

   int size=10;

   ArrayResize(line_style,size);

   ArrayResize(line_color,size);

   ArrayResize(line_width,size);

   ArrayResize(plot_type,size);

   ArrayResize(Ind,LINES_TOTAL);

//---- ?>;CG5=85 A2>9AB2 8=48:0B>@=KE ;8=89

   for(int plot=4; plot<14; plot++)

     {

      plot_type[plot-4]=ENUM_DRAW_TYPE(PlotIndexGetInteger(plot,PLOT_DRAW_TYPE));

      line_style[plot-4]=ENUM_LINE_STYLE(PlotIndexGetInteger(plot,PLOT_LINE_STYLE));

      line_width[plot-4]=PlotIndexGetInteger(plot,PLOT_LINE_WIDTH);

      line_color[plot-4]=color(PlotIndexGetInteger(plot,PLOT_LINE_COLOR));

     }



//---- 8=8F80;870F8O A2>9AB2 8=48:0B>@=KE ;8=89   

   for(int step=0; step<5; step++) for(int count=0; count<10; count++)

     {

      int number=14+10*step+count;

      PlotIndexSetInteger(number,PLOT_DRAW_TYPE,plot_type[count]);

      PlotIndexSetInteger(number,PLOT_LINE_STYLE,line_style[count]);

      PlotIndexSetInteger(number,PLOT_LINE_WIDTH,line_width[count]);

      PlotIndexSetInteger(number,PLOT_LINE_COLOR,line_color[count]);

     }

   for(int count=0; count<2; count++)

     {

      int number=64+count;

      PlotIndexSetInteger(number,PLOT_DRAW_TYPE,plot_type[count]);

      PlotIndexSetInteger(number,PLOT_LINE_STYLE,line_style[count]);

      PlotIndexSetInteger(number,PLOT_LINE_WIDTH,line_width[count]);

      PlotIndexSetInteger(number,PLOT_LINE_COLOR,line_color[count]);

     }

   for(int count=0; count<LINES_TOTAL-6; count++)

     {

      PlotIndexSetString(14+2*count,PLOT_LABEL,"Upper Hans_Indicator "+string(7+count));

      PlotIndexSetString(15+2*count,PLOT_LABEL,"Lower Hans_Indicator "+string(7+count));

     }

//---- =8F80;870F8O 8=48:0B>@=KE 1CD5@>2 

   IndBufferInit(0,UpUpBuffer);

   IndBufferInit(1,UpDnBuffer);

//----

   IndBufferInit(2,DnUpBuffer);

   IndBufferInit(3,DnDnBuffer);

//----

   for(int numb=0; numb<LINES_TOTAL; numb++)

     {

      IndBufferInit(4+2*numb,Ind[numb].ZoneUpper);

      IndBufferInit(5+2*numb,Ind[numb].ZoneLower);

     }

//----

   IndBufferInit(4+2*LINES_TOTAL,MiddleBuffer);

//----

   IndBufferInit(5+2*(LINES_TOTAL),ExtOpenBuffer);

   IndBufferInit(6+2*(LINES_TOTAL),ExtHighBuffer);

   IndBufferInit(7+2*(LINES_TOTAL),ExtLowBuffer);

   IndBufferInit(8+2*(LINES_TOTAL),ExtCloseBuffer);

   IndBufferInit(9+2*(LINES_TOTAL),ExtColorBuffer);



//---- =8F80;870F8O 8=48:0B>@>2  

//for(int count=0; count<2; count++) IndCldInit(count,min_rates_total,Shift);

   for(int count=0; count<2; count++) IndInit(count,EMPTY_VALUE,min_rates_total,Shift);

   for(int count=2; count<2*LINES_TOTAL+6; count++) IndInit(count,NULL,min_rates_total,Shift);



//--- 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,"Hans_Indicator_x22_Cloud_System("+string(LocalTimeZone)+","+string(DestTimeZone)+","+string(PipsForEntryStep)+","+string(Shift)+")");

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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 7025@H5=85 8=8F80;870F88

   return(INIT_SUCCEEDED);

  }

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

//| =8F80;870F8O 8=48:0B>@=>3> 1CD5@0                               |

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

void IndBufferInit(int BuffNumber,double &Buffer[])

  {

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

   SetIndexBuffer(BuffNumber,Buffer,INDICATOR_DATA);

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

   ArraySetAsSeries(Buffer,true);

//----

  }

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

//| =8F80;870F8O 8=48:0B>@0                                         |

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

void IndCldInit(int PlotNumber,int Draw_Begin,int nShift)

  {

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

   PlotIndexSetInteger(PlotNumber,PLOT_DRAW_BEGIN,Draw_Begin);

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

   PlotIndexSetInteger(PlotNumber,PLOT_SHIFT,nShift);

//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

   PlotIndexSetInteger(PlotNumber,PLOT_SHOW_DATA,false);

//----

  }

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

//| =8F80;870F8O 8=48:0B>@0                                         |

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

void IndInit(int PlotNumber,double Empty_Value,int Draw_Begin,int nShift)

  {

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

   PlotIndexSetInteger(PlotNumber,PLOT_DRAW_BEGIN,Draw_Begin);

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

   PlotIndexSetDouble(PlotNumber,PLOT_EMPTY_VALUE,Empty_Value);

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

   PlotIndexSetInteger(PlotNumber,PLOT_SHIFT,nShift);

//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

   PlotIndexSetInteger(PlotNumber,PLOT_SHOW_DATA,false);

//----

  }

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

//| 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[],

                const double &Low[],

                const double &Close[],

                const long &Tick_Volume[],

                const long &Volume[],

                const int &Spread[]

                )

  {

//---- ?@>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

   int limit;



//---- @0AG5B AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AG5B0 10@>2

   if(prev_calculated>rates_total || prev_calculated<=0)// ?@>25@:0 =0 ?5@2K9 AB0@B @0AG5B0 8=48:0B>@0

     {

      limit=rates_total-min_rates_total-1; // AB0@B>2K9 =><5@ 4;O @0AG5B0 2A5E 10@>2

     }

   else limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AG5B0 =>2KE 10@>2

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

   ArraySetAsSeries(Time,true);

   ArraySetAsSeries(Open,true);

   ArraySetAsSeries(High,true);

   ArraySetAsSeries(Low,true);

   ArraySetAsSeries(Close,true);



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

   BreakoutRanges(0,limit,LocalTimeZone,DestTimeZone,rates_total,Time,Open,High,Low,Close);

//---     

   BuySignal("Hans_Indicator_x22_Cloud_System_Alert",ExtColorBuffer,rates_total,prev_calculated,Close,Spread);

   SellSignal("Hans_Indicator_x22_Cloud_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]<2 && ColorArrow[index1]>1) 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]<3) 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));

//----

  }

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

//| Compute index of first/last bar of yesterday and today           |

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

int BreakoutRanges(int offset,int &lastbar,int tzlocal,int tzdest,const int rates_total_,const datetime &Time_[],

                   const double &Open_[],const double &High_[],const double &Low_[],const double &Close_[])

  {

//----

   int i,j,k,

   tzdiff=tzlocal-tzdest,

   tzdiffsec=tzdiff*3600,

   tidxstart[2]={ 0,0},

   tidxend[2]={ 0,0 };

   double thigh[2]={ 0.0,0.0 },

   tlow[2]={ DBL_MAX };

   string tfrom[3]={ "04:00","08:00",/*rest of day: */ "12:00"},

   tto[3]={ "08:00","12:00",/*rest of day: */ "24:00" },

   tday;

   bool inperiod=-1;

   datetime timet;



//

// search back for the beginning of the day

//

   tday=TimeToString(Time_[lastbar]-tzdiffsec,TIME_DATE);

   for(; lastbar<rates_total_-1; lastbar++)

     {

      if(TimeToString(Time_[lastbar]-tzdiffsec,TIME_DATE)!=tday)

        {

         lastbar--;

         break;

        }

     }



//

// find the high/low for the two periods and carry them forward through the day

//

   tday="XXX";

   for(i=lastbar; i>=offset; i--)

     {



      timet=Time_[i]-tzdiffsec;   // time of this bar



      string timestr=TimeToString(timet,TIME_MINUTES),// current time HH:MM

      thisday=TimeToString(timet,TIME_DATE);       // current date



                                                   //

      // for all three periods (first period, second period, rest of day)

      //

      for(j=0; j<2; j++)

        {

         if(tfrom[j]<=timestr && timestr<tto[j])

           {   // Bar[i] in this period

            if(inperiod!=j)

              { // entered new period, so last one is completed



               if(j>0)

                 {      // now draw high/low back over the recently completed period

                  for(k=tidxstart[j-1]; k>=tidxend[j-1]; k--)

                    {

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

                     ExtColorBuffer[k]=2;

                     if(j-1==0)

                       {

                        Ind[0].ZoneUpper[k]= thigh[j-1];

                        Ind[0].ZoneLower[k]= tlow[j-1];

                        MiddleBuffer[k]=(Ind[0].ZoneUpper[k]+Ind[0].ZoneLower[k])/2;



                        if(Close_[k]>Ind[0].ZoneUpper[k])

                          {

                           ExtOpenBuffer[k]=Open_[k];

                           ExtHighBuffer[k]=High_[k];

                           ExtLowBuffer[k]=Low_[k];

                           ExtCloseBuffer[k]=Close_[k];

                           if(Close_[k]>=Open_[k]) ExtColorBuffer[k]=0;

                           else ExtColorBuffer[k]=1;

                          }

                        if(Close_[k]<Ind[0].ZoneLower[k])

                          {

                           ExtOpenBuffer[k]=Open_[k];

                           ExtHighBuffer[k]=High_[k];

                           ExtLowBuffer[k]=Low_[k];

                           ExtCloseBuffer[k]=Close_[k];

                           if(Close_[k]<=Open_[k]) ExtColorBuffer[k]=4;

                           else ExtColorBuffer[k]=3;

                          }

                       }



                     if(j-1==1)

                       {

                        Ind[1].ZoneUpper[k]= thigh[j-1];

                        Ind[1].ZoneLower[k]= tlow[j-1];

                        MiddleBuffer[k]=(Ind[1].ZoneUpper[k]+Ind[1].ZoneLower[k])/2;

                        if(Close_[k]>Ind[1].ZoneUpper[k])

                          {

                           ExtOpenBuffer[k]=Open_[k];

                           ExtHighBuffer[k]=High_[k];

                           ExtLowBuffer[k]=Low_[k];

                           ExtCloseBuffer[k]=Close_[k];

                           if(Close_[k]>=Open_[k]) ExtColorBuffer[k]=0;

                           else ExtColorBuffer[k]=1;

                          }

                        if(Close_[k]<Ind[1].ZoneLower[k])

                          {

                           ExtOpenBuffer[k]=Open_[k];

                           ExtHighBuffer[k]=High_[k];

                           ExtLowBuffer[k]=Low_[k];

                           ExtCloseBuffer[k]=Close_[k];

                           if(Close_[k]<=Open_[k]) ExtColorBuffer[k]=4;

                           else ExtColorBuffer[k]=3;

                          }

                       }

                    }

                 }



               inperiod=j;   // remember current period

              }



            if(inperiod==2) // inperiod==2 (end of day) is just to check completion of zone 2

               break;



            // for the current period find idxstart, idxend and compute high/low

            if(tidxstart[j]==0)

              {

               tidxstart[j]=i;

               tday=thisday;

              }



            tidxend[j]=i;



            thigh[j]=MathMax(thigh[j],High_[i]);

            tlow[j]=MathMin(tlow[j],Low_[i]);

           }

        }



      // 

      // carry forward the periods for which we have definite high/lows

      //

      if(inperiod>=1 && tday==thisday)

        { // first time period completed



         for(int numb=1; numb<LINES_TOTAL; numb++)

           {

            Ind[numb].ZoneUpper[i]=thigh[0]+numb*PipsForEntryStep*_Point;

            Ind[numb].ZoneLower[i]=tlow[0]-numb*PipsForEntryStep*_Point;

           }



         Ind[0].ZoneUpper[i]=Ind[1].ZoneUpper[i];

         Ind[0].ZoneLower[i]=Ind[1].ZoneLower[i];



         for(int numb=1; numb<LINES_TOTAL; numb++)

           {

            Ind[numb].ZoneUpper[i]+=Slip*PipsForEntryStep*_Point;

            Ind[numb].ZoneLower[i]-=Slip*PipsForEntryStep*_Point;

           }



         MiddleBuffer[i]=UpDnBuffer[i]=DnUpBuffer[i]=(Ind[0].ZoneUpper[i]+Ind[0].ZoneLower[i])/2;

         UpUpBuffer[i]=Ind[LINES_TOTAL-1].ZoneUpper[i];

         DnDnBuffer[i]=Ind[LINES_TOTAL-1].ZoneLower[i];

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

         ExtColorBuffer[i]=2;

         if(Close_[i]>Ind[0].ZoneUpper[i])

           {

            ExtOpenBuffer[i]=Open_[i];

            ExtHighBuffer[i]=High_[i];

            ExtLowBuffer[i]=Low_[i];

            ExtCloseBuffer[i]=Close_[i];

            if(Close_[i]>=Open_[i]) ExtColorBuffer[i]=0;

            else ExtColorBuffer[i]=1;

           }

         if(Close_[i]<Ind[0].ZoneLower[i])

           {

            ExtOpenBuffer[i]=Open_[i];

            ExtHighBuffer[i]=High_[i];

            ExtLowBuffer[i]=Low_[i];

            ExtCloseBuffer[i]=Close_[i];

            if(Close_[i]<=Open_[i]) ExtColorBuffer[i]=4;

            else ExtColorBuffer[i]=3;

           }

        }

      else

        {   // none yet to carry forward (zero to clear old values, e.g. from switching timeframe)         

         for(int numb=0; numb<LINES_TOTAL; numb++)

           {

            Ind[numb].ZoneUpper[i]=NULL;

            Ind[numb].ZoneLower[i]=NULL;

           }

         MiddleBuffer[i]=UpDnBuffer[i]=DnUpBuffer[i]=UpUpBuffer[i]=DnDnBuffer[i]=NULL;

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

         ExtColorBuffer[i]=2;

        }



      //

      // at the beginning of a new day reset everything

      //

      if(tday!="XXX" && tday!=thisday)

        {

         //Print("#",i,"new day ",thisday,"/",tday);



         tday="XXX";



         inperiod=-1;



         for(j=0; j<2; j++)

           {

            tidxstart[j]=0;

            tidxend[j]=0;



            thigh[j]=0;

            tlow[j]=99999;

           }

        }

     }

//----

   return (0);

  }

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

Comments