How to code to identify swings? - page 2

 
for(int i = 0, j = 0; i < counted_bars && j < 5; i++)
{
        double z = iCustom(Symbol(), PERIOD_CURRENT, "ZigZag.ex4", 12, 5, 3, 0, i);
        if(z != 0.0 && z != EMPTY_VALUE)
        {
                val[j] = z;
                val_time[j] = iTime(Symbol(), PERIOD_CURRENT, i);
                j++;
        }
Comment(DoubleToStr(val[0], 4) + "    " +DoubleToStr(val[1], 4));
}
I have found an article about how to put the ZigZag indicator into your code, but I am running into a strange phenomenon. Because I'm still new to coding to MQL I regularly run into strange bugs so I am using the Comment function to help me debug my program. Since my program did not do what I expected I went on a search to find where it loses itself. If I put the Comment here as shown, the values it is supposed to be are shown, but if I put it outside of the for loop, it is all zeros. Since the variable val is a global variable and the values are being written to it, should it not retain the values outside of the for loop unless something else is writing over it? I have checked, this is the only place so far where it is being used and there is also only this one Comment that I move around. I greyed out all the other places (/* some code */). Am I missing something?