Can not use Zigzag in my custom indicator

 

I'm trying to create an indicator that uses zigzag as it's base and adds some extra features on top of that. but the zigzag lines don't show up correctly. 

here's my code: 

//+------------------------------------------------------------------+
//|                                                      custome.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot lines
#property indicator_label1  "lineZ"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrAqua
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         linesBuffer[];
int            ZigZagHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,linesBuffer,INDICATOR_DATA);

   ZigZagHandle=iCustom(NULL,0,"Zigzag",12,5,3,3,0);

   Print(IntegerToString(ZigZagHandle)+" is the Zigzag Handle");

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//--- Copy the output of zigzag 
   int copy=CopyBuffer(ZigZagHandle,0,0,rates_total,linesBuffer);

   if(copy<=0)
     {
      Print("Failed to initialize the Zigzag indicator");
     }
     
     ArrayPrint(linesBuffer);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


What am I doing wrong here?

Thank you in advance

 
htondkar:

I'm trying to create an indicator that uses zigzag as it's base and adds some extra features on top of that. but the zigzag lines don't show up correctly. 

here's my code: 

What am I doing wrong here?

Thank you in advance

Insert this line (highlighted) so that zeros are ignored:

   SetIndexBuffer(0,linesBuffer,INDICATOR_DATA);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   ZigZagHandle=iCustom(NULL,0,"Zigzag",12,5,3,3,0);

Reason: