Boa_ZigZag_channel

Author: Copyright © 2005, MetaQuotes Software Corp.
2 Views
0 Downloads
0 Favorites
Boa_ZigZag_channel
ÿþ//+------------------------------------------------------------------+

//|                                           Boa_ZigZag_channel.mq5 |

//|                      Copyright © 2005, MetaQuotes Software Corp. |

//|                                                mandorr@gmail.com |

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

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

#property copyright "Copyright © 2005, MetaQuotes Software Corp."

//---- AAK;:0 =0 A09B 02B>@0

#property link      "mandorr@gmail.com"

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

#property version   "1.00"

#property description "070EA:89 C402 2 2845 :0=0;0" 

//---- >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=> 2>A5<L 1CD5@>2

#property indicator_buffers 8

//---- 8A?>;L7>20=> 2A53> ?OBL 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   5

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

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

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

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

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color1  clrLavender

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

#property indicator_label1  "Boa_ZigZag_channel Cloud"

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

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

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

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

#property indicator_type2   DRAW_COLOR_LINE

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

#property indicator_color2  clrLimeGreen,clrMediumOrchid

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

#property indicator_width2  2

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

#property indicator_label2  "Up Boa_ZigZag_channel"

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

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

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

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

#property indicator_type3   DRAW_COLOR_LINE

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

#property indicator_color3  clrLimeGreen,clrMediumOrchid

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

#property indicator_width3  2

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

#property indicator_label3 "Down Boa_ZigZag_channel"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 4 2 2845 A8<2>;0

#property indicator_type4   DRAW_ARROW

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

#property indicator_color4  clrBlue

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

#property indicator_width4  2

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

#property indicator_label4  "Up Boa_ZigZag_Arrows"

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

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

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

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

#property indicator_type5   DRAW_ARROW

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

#property indicator_color5  clrMagenta

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

#property indicator_width5  2

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

#property indicator_label5 "Down Boa_ZigZag_Arrows"

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

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

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

input uint Length=6;

input uint  UpLable=159;//;5910 25@E=53> D@0:B0;0

input uint  DnLable=159;//;5910 =86=53> D@0:B0;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 UpBuffer[],DnBuffer[];

double UpperBuffer[],LowerBuffer[];

double ColorUpperBuffer[],ColorLowerBuffer[];

double ZigzagPeakBuffer[],ZigzagLawnBuffer[];

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

int min_rates_total;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

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

   min_rates_total=int(Length)+1;

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

   SetIndexBuffer(0,UpBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,DnBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,UpperBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,ColorUpperBuffer,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(4,LowerBuffer,INDICATOR_DATA);

   SetIndexBuffer(5,ColorLowerBuffer,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(6,ZigzagPeakBuffer,INDICATOR_DATA);

   SetIndexBuffer(7,ZigzagLawnBuffer,INDICATOR_DATA);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,NULL);

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

   ArraySetAsSeries(UpBuffer,true);

   ArraySetAsSeries(DnBuffer,true);

   ArraySetAsSeries(UpperBuffer,true);

   ArraySetAsSeries(LowerBuffer,true);

   ArraySetAsSeries(ColorUpperBuffer,true);

   ArraySetAsSeries(ColorLowerBuffer,true);

   ArraySetAsSeries(ZigzagLawnBuffer,true);

   ArraySetAsSeries(ZigzagPeakBuffer,true);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);

//---- A8<2>;K 4;O 8=48:0B>@0

   PlotIndexSetInteger(3,PLOT_ARROW,DnLable);

   PlotIndexSetInteger(4,PLOT_ARROW,UpLable);

//---- #AB0=>2:0 D>@<0B0 B>G=>AB8 >B>1@065=8O 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 8<O 4;O >:>= 40==KE 8 ;M910 4;O AC1J>:>= 

   string shortname;

   StringConcatenate(shortname,"Boa_ZigZag_channel(Length=",Length,")");

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//----   

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                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(0);



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

   int limit,climit,bar;

   double HH,LL,BH,BL;

   double LastLawn_prev,LastLawn,LastPeak_prev,LastPeak;

   int zu,zd,Swing,Swing_n;

//----



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

   climit=limit; // AB0@B>2K9 =><5@ 4;O @0A:@0A:8 8=48:0B>@0



   Swing=0;

   Swing_n=0;

   zu=limit;

   zd=limit;

   BH=high[limit];

   BL=low[limit];



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

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);



   LastPeak_prev=LastPeak=high[ArrayMaximum(high,limit,Length)];

   LastLawn_prev=LastLawn=low[ArrayMinimum(low,limit,Length)];



//---- 5@2K9 1>;LH>9 F8:; @0AGQB0 8=48:0B>@0

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

     {

      ZigzagLawnBuffer[bar]=NULL;

      ZigzagPeakBuffer[bar]=NULL;



      HH=high[ArrayMaximum(high,bar+1,Length)];

      LL=low[ArrayMinimum(low,bar+1,Length)];

      if(low[bar]<LL && high[bar]>HH)

        {

         Swing=2;

         if(Swing_n== 1) zu=bar+1;

         if(Swing_n==-1) zd=bar+1;

        }

      else

        {

         if(low [bar]<LL) Swing=-1;

         if(high[bar]>HH) Swing= 1;

        }

      if(Swing!=Swing_n && Swing_n!=0)

        {

         if(Swing==2) {Swing=-Swing_n; BH=high[bar]; BL=low[bar];}

         if(Swing==+1)

           {

            ZigzagLawnBuffer[zd]=BL;

            LastLawn_prev=LastLawn;

            LastLawn=BL;

            DnBuffer[zd]=LowerBuffer[zd]=BL;

            if(LastLawn_prev>LastLawn) ColorLowerBuffer[zd]=1;

            else if(LastLawn_prev<LastLawn) ColorLowerBuffer[zd]=0;

            else ColorLowerBuffer[zd]=ColorLowerBuffer[zd+1];

           }

         if(Swing==-1)

           {

            ZigzagPeakBuffer[zu]=BH;

            LastPeak_prev=LastPeak;

            LastPeak=BH;

            UpBuffer[zu]=UpperBuffer[zu]=BH;

            if(LastPeak_prev>LastPeak) ColorUpperBuffer[zu]=1;

            else if(LastPeak_prev<LastPeak) ColorUpperBuffer[zu]=0;

            else ColorUpperBuffer[zu]=ColorUpperBuffer[zu+1];

           }

         BH=high[bar];

         BL=low [bar];

        }



      if(ZigzagPeakBuffer[zu])

         for(int index=zu-1; index>=bar && !IsStopped(); index--)

           {

            UpBuffer[index]=UpBuffer[index+1];

            UpperBuffer[index]=UpperBuffer[index+1];

            ColorUpperBuffer[index]=ColorUpperBuffer[index+1];

           }

      else

        {

         UpBuffer[bar]=UpperBuffer[bar]=LastPeak;

         ColorUpperBuffer[bar]=ColorUpperBuffer[bar+1];

        }

      if(ZigzagLawnBuffer[zd])

         for(int index=zd-1; index>=bar && !IsStopped(); index--)

           {

            DnBuffer[index]=DnBuffer[index+1];

            LowerBuffer[index]=LowerBuffer[index+1];

            ColorLowerBuffer[index]=ColorLowerBuffer[index+1];

           }

      else

        {

         DnBuffer[bar]=LowerBuffer[bar]=LowerBuffer[bar+1];

         ColorLowerBuffer[bar]=ColorLowerBuffer[bar+1];

        }



      if(!ZigzagPeakBuffer[zu] && !ZigzagLawnBuffer[zd])

        {

         DnBuffer[bar]=LowerBuffer[bar]=LastLawn;

         ColorLowerBuffer[bar]=ColorLowerBuffer[bar+1];

         //----

         UpBuffer[bar]=UpperBuffer[bar]=LastPeak;

         ColorUpperBuffer[bar]=ColorUpperBuffer[bar+1];

        }



      if(Swing== 1) {if(high[bar]>=BH) {BH=high[bar]; zu=bar;}}

      if(Swing==-1) {if(low [bar]<=BL) {BL=low [bar]; zd=bar;}}

      Swing_n=Swing;

     }

//----     

   return(rates_total);

  }

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

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 ---