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?
 
PLZFrosty:

Hello everyone

Is there anyone that can direct me pages where I can read up on how to code to identify swings? It's easy for me to identify them, but the method I'm using visually is not consistent enough to translate it to the PC. I have broken my brain these past couple of days trying to figure something out and started to search online for methods, but I only get ready made stuff. I've tried reverse engineering a couple to understand the reasoning behind how it works, but it is a real struggle (still a newbie at coding). Any help will be appreciated, whether through explaining or directing me to places where I can learn. I'll continue searching in the meantime.

Thanks

Zigzag indicator you can use Data Swing high low from chart