# Help with zigzag EA

```Hi, i am writing an ea based on the zigzag indicator. I dont understand what happens here but for some reason, sometimes price is zero and date = 1970, I do check the buffer if its empty to zero

//+------------------------------------------------------------------+
//| searching for candle lows & highs that == peakPrice |
//| and get their opening time |
//+------------------------------------------------------------------+
for(int i = 1; i < rates_total_M15 && peakCount < peaksLookBack; i++)
{
peakPrice = buffer15Min[i];

if(peakPrice != 0 && peakPrice != EMPTY_VALUE)
{
zzPeaks[peakCount] = peakPrice;
for(int ii = 0; ii < rates_total_M15 ; ii++)
{
if(zzPeaks[peakCount] == cl[ii] || zzPeaks[peakCount] == ch[ii])
{
allTime[peakCount] = tym[ii];
}
}
17:52
// for(int a = 0; a <= breakCandle; i++)
double shouderDiffAbove = zzPeaks[peakCount-5] + ((zzPeaks[peakCount-1] - zzPeaks[peakCount-2]) * shoulderDiffernce)/100;
double shouderDiffBelow = zzPeaks[peakCount-5] - ((zzPeaks[peakCount-1] - zzPeaks[peakCount-2]) * shoulderDiffernce)/100;
double shouderDiffB = zzPeaks[peakCount-5] + ((zzPeaks[peakCount-1] - zzPeaks[peakCount-2]) * shoulderDiffernce)/100;

int leftSholder = Bars(_Symbol,H1,allTime[peakCount-2],allTime[peakCount]);
int rihtSholderdiff = (Bars(_Symbol,H1,allTime[peakCount-2],allTime[peakCount])) * shoulderSpace/100;
int rihtSholder = Bars(_Symbol,H1,allTime[peakCount-4],allTime[peakCount-6]);

double neckPeaks = zzPeaks[peakCount-2] * necklinePeaks/100;

if(zzPeaks[peakCount-1] < zzPeaks[peakCount-3] && zzPeaks[peakCount-5] < zzPeaks[peakCount-3] &&
zzPeaks[peakCount] < zzPeaks[peakCount-2] && zzPeaks[peakCount-1] > zzPeaks[peakCount-2] &&
/*rihtSholder <= leftSholder+rihtSholderdiff && rihtSholder >= leftSholder-rihtSholderdiff &&*/
// zzPeaks[peakCount-4] < zzPeaks[peakCount-5] && co[1] > zzPeaks[peakCount-4] && zzPeaks[peakCount-6] <= zzPeaks[peakCount-4] && zzPeaks[peakCount-2] < zzPeaks[peakCount-5] &&
// zzPeaks[peakCount-4] <= zzPeaks[peakCount-2]+neckPeaks && zzPeaks[peakCount-4] >= zzPeaks[peakCount-2]- neckPeaks

)
{
createTrend("HSneck"+hSCount,allTime[peakCount-6],zzPeaks[peakCount-2], allTime[peakCount],zzPeaks[peakCount-4],clNeckline);
Comment(neckPeaks);

createText("a"+hSCount, allTime[peakCount], zzPeaks[peakCount], "0");
createText("b"+hSCount, allTime[peakCount-1], zzPeaks[peakCount-1], "1");
createText("c"+hSCount, allTime[peakCount-2], zzPeaks[peakCount-2], "2");
createText("x"+hSCount, allTime[peakCount-3], zzPeaks[peakCount-3], "3");
createText("z"+hSCount, allTime[peakCount-4], zzPeaks[peakCount-4], "4");
createText("a"+hSCount, allTime[peakCount-5], zzPeaks[peakCount-5], "5");
createText("d"+hSCount, allTime[peakCount-6], zzPeaks[peakCount-6], "6");

sellStrategy = co[0];
hSCount++;

}

peakCount++;
}

}```
Files:
d.PNG  85 kb
Reason: