False ZIGZAG/flipping

 

Can anyone explain this problem? I have been puzzled for some time as to why on stratiegy tester and demo accounts zigzag suddenly decides to flip (current zig gets previous zig values and previous zig values get current zig values) and a while latter flip back again. This does not happen when print statements are introduced to the zigzag indicator to try and track the cause. Happens with both standard and custom zigzag code.

 
You realized the current values of ZigZag changes all the time as the indicator redraws?
 
blogzr3 wrote >>
You realized the current values of ZigZag changes all the time as the indicator redraws?

Yes I realise that it changes as it goes. But this is not that. The code in my EA saves the value of CurrentZig in the variable LastZig then waits for a new trend line to be drawn in the opposite direction.

That is when a new Current Zag appears and a new value is assigned to CurrentZig. This works fine - but a short period later the CurrentZig value flips back to its previous level for a period of time when it then flops back to the correct Level. The high and low levels of the ZigZag temporarily switch over then back again! This has been messing up my EA so I decided to use print statements within ZigZag to see exactly why its doing it. However, I assume because the prints slow down the ZigZag and/or the EA this behaviour no longer happens. A few prints within the EA do show the flipflop action on ZigZag values. The flip can occurr in the same or next period (1 hour) or several hundred ticks later as can the flop.

i = 0;
n = 0;
while(n < 2)
{
if(CurrentZig > 0) CurrentZag = CurrentZig;
CurrentZig = iCustom(Symbol(), 0, ZigZag, 0, i);
if (CurrentZig > 0) n += 1;
i++;
}

Then some code to save CurrentZig only on the first tick of the EA

if (TickCount == 0) LastZig = CurrentZig;


if (CurrentZig != LastZig)
{
Print(CurrentZig," ",LastZig);

LastZig = CurrentZig;

 
BigAl:

Yes I realise that it changes as it goes. But this is not that. The code in my EA saves the value of CurrentZig in the variable LastZig then waits for a new trend line to be drawn in the opposite direction.

You can get noise on a bar opening, especially if the indicators are using Close[0] which is sometimes spikey on backtesting. If you can use bar1 until Vol[0] is > 1 or so, you might get more stability. However the backtester in MT4 has issues with timeframes on High and Low, so that can make ZigZag foul as well.
Reason: