Author: Copyright 2020, SEM Software Corp., ZigzagX
0 Views
0 Downloads
0 Favorites
ZigzagX
ÿþ//+------------------------------------------------------------------+

//|                                                      ProjectName |

//|                                      Copyright 2020, CompanyName |

//|                                       http://www.companyname.net |

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

#property copyright "Copyright 2020, SEM Software Corp., ZigzagX"

#property link "https://www.mql5.com"

#property version "1.00"

//--- indicator settings

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots  2







#property indicator_label1 "H"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrRed

#property indicator_width1 1



#property indicator_label2 "L"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrDeepSkyBlue, clrMediumBlue

#property indicator_width2 1







//--- input parameters



input int _X=1; //1,2,4,8,16 (Zigzag 12*X,5*X,3*X)



double HBuffer[];

//double _H=0.0;

double LBuffer[];

//double _L=0.0;





int ZigZag_handle;

//double ZigZag[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {



   ZigZag_handle=iCustom(_Symbol,_Period,"Examples\\ZigzagColor",12*_X,5*_X,3*_X);

//--- 5A;8 =5 C40;>AL A>740BL EM=4;

   if(ZigZag_handle==INVALID_HANDLE)

     {

      //--- A>>1I8< > =5C40G5 8 2K2545< =><5@ >H81:8

      PrintFormat("5 C40;>AL A>740BL EM=4; 8=48:0B>@0 ZigZag 4;O ?0@K %s/%s, :>4 >H81:8 %d",_Symbol,EnumToString(PERIOD_CURRENT),GetLastError());       //--- @01>B0 8=48:0B>@0 7025@H05BAO 4>A@>G=>

      return(INIT_FAILED);

     };

//--- indicator buffers mapping

   SetIndexBuffer(0,HBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,LBuffer,INDICATOR_DATA);

//SetIndexBuffer(2,ZigZag,INDICATOR_CALCULATIONS);



   PlotIndexSetInteger(0,PLOT_ARROW,139+_intNomer(_X));

   PlotIndexSetInteger(1,PLOT_ARROW,139+_intNomer(_X));



   PlotIndexSetInteger(0,PLOT_SHIFT,_intNomer(_X)-1);

   PlotIndexSetInteger(1,PLOT_SHIFT,_intNomer(_X)-1);



   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,_intNomer(_X)*(2));

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,_intNomer(_X)*(-2));



   PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);

   PlotIndexSetInteger(1,PLOT_SHOW_DATA,false);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//--- name for DataWindow and indicator subwindow label

//IndicatorSetString(INDICATOR_SHORTNAME,"ZigZag("+(string)ExtDepth+","+(string)ExtDeviation+","+(string)ExtBackstep+")");





//

//--- set drawing line empty value

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);





   return(INIT_SUCCEEDED);

  }

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

//|                                                                  |

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

int _intNomer(int fromIndex)

  {

   int g_nPeriod[]= {1,2,4,8,16};

   int res=ArraySize(g_nPeriod);

   for(int i=0; i<res; i++)

     {

      if(_X==g_nPeriod[i])

         res=i+1;

     }

   return(res);

  }

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

//|                                                                  |

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

//double _alfa(int y)

//  {

//

//   return(_Point*_intNomer(_X));

//  }

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

//| Detrended Price Oscillator                                       |

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

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[])

  {



   int _limit=(rates_total-prev_calculated)-1;

   if(_limit<1)

     {

      _limit=100;

     };

   if(!ZZ_FromBuffer(HBuffer,LBuffer,ZigZag_handle,_limit))

      return(0);









//--- OnCalculate done. Return new prev_calculated.

   return(rates_total);

  }

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

//|                                                                  |

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

bool ZZ_FromBuffer(double &ZH_buffer[],double &ZL_buffer[],int ind_handle,int _count)

  {

//--- A1@>A8< :>4 >H81:8

   ResetLastError();

//--- 70?>;=O5< G0ABL <0AA820  7=0G5=8O<8 87 8=48:0B>@=>3> 1CD5@0 ?>4 8=45:A>< 0

   if(CopyBuffer(ind_handle,0,0,_count,ZH_buffer)<0)

     {

      //--- 5A;8 :>?8@>20=85 =5 C40;>AL, A>>1I8< :>4 >H81:8

      PrintFormat("5 C40;>AL A:>?8@>20BL 40==K5 87 8=48:0B>@0 ZZ, :>4 >H81:8 %d",GetLastError());

      //--- 7025@H8< A =C;52K< @57C;LB0B>< - MB> >7=0G05B, GB> 8=48:0B>@ 1C45B AG8B0BLAO =5@0AAG8B0==K<

      return(false);

     };



   if(CopyBuffer(ind_handle,1,0,_count,ZL_buffer)<0)

     {

      //--- 5A;8 :>?8@>20=85 =5 C40;>AL, A>>1I8< :>4 >H81:8

      PrintFormat("5 C40;>AL A:>?8@>20BL 40==K5 87 8=48:0B>@0 ZZ, :>4 >H81:8 %d",GetLastError());

      //--- 7025@H8< A =C;52K< @57C;LB0B>< - MB> >7=0G05B, GB> 8=48:0B>@ 1C45B AG8B0BLAO =5@0AAG8B0==K<

      return(false);

     }

//--- 2A5 ?>;CG8;>AL

   return(true);

  }

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

Comments