Boa_ZigZag_v1

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

//|                                                   Boa_ZigZag.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" 

//---- >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=> 420 1CD5@0

#property indicator_buffers 2

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

#property indicator_plots   1

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

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

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

//---- 2 :0G5AB25 8=48:0B>@0 8A?>;L7>20= 783703 A5:F8O<8

#property indicator_type1   DRAW_COLOR_SECTION

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

#property indicator_label1  "Boa_ZigZag"

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

#property indicator_color1 clrMediumOrchid,clrLimeGreen

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

#property indicator_style1  STYLE_SOLID

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

#property indicator_width1  3

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

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

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

input uint Length=6;

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

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

//---- 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,IndBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

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

   ArraySetAsSeries(IndBuffer,true);

   ArraySetAsSeries(ColorIndBuffer,true);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- #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(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;   

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



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

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

     {

      IndBuffer[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) IndBuffer[zd]=BL;

         if (Swing==-1) IndBuffer[zu]=BH;

         BH=high[bar];

         BL=low [bar];

        }

      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;

     }



//---- B>@>9 1>;LH>9 F8:; @0A:@0A:8 8=48:0B>@0

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

     {

      if(!IndBuffer[bar]) ColorIndBuffer[bar]=ColorIndBuffer[bar+1];



      if(IndBuffer[bar] && IndBuffer[bar]>high[bar+1]) ColorIndBuffer[bar]=1;

      if(IndBuffer[bar] && IndBuffer[bar]<low[bar+1]) ColorIndBuffer[bar]=0;

     }

//----     

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