Australian (ASX) Stock Market Forum

Reply to thread

I finally got around to playing with the ZigZag indicator to end this matter once and for all.


I used GB's percentage of .00001.


Below is a snip of BHP. The Orange line is the Vanilla zigzag, The Green is zigzag with modified future data. In general the signals are delayed by a day when future data is modified.


I wrote the current bar to all future bars and calculated the current zig, in my code it's nullify_condition=1. The horizontal sections in the green are where zigzag is using future data and doesn't know where the turning point is, so it's horizontal and not sloping. In some cases it's up to 6 days away before the turning point is detected and always with a lag. So even with such a low percentage it can still make a significant impact.



[ATTACH=full]149167[/ATTACH]


And here is the code i used It could prove usefull to others one day.


[CODE]//*************************************************************

// Run an optimize on nullify_condition.

//    All 4 tests should show exact same results. If they don't, then there is a leak.

//    At the end, do a quick check to see if buy, sell signals have been messed with.

//

//    NOTE = This is just a quick helper. It does NOT prove there are problems, or prove your formula is safe.

//

//

//*************************************************************



_TRACE("Starting Test ");


futureLeakTest = True;    // use this to turn off the inner loop.


nullify_condition = Optimize("Future Null",1,1,4,1);    

                        // 1 = Future quotes == Current Close

                        // 2 = Future quotes == 0 (Zero)

                        // 3 = Future quotes == NULL

                        // 4 = Future quotes == unchanged.              


Buy = Sell = 0;


pr = .00001;

zzHiLo_test = Zig( c, pr ); // create an Original array to test against.


cc = Close;    // cache the close

for( i = 0; i < BarCount-1; i++ )

{

    C = cc; // Set the C back to the original.  

   

    //==============================================================================================

    if (futureLeakTest) // Inner loop

        for( t = i+1; t < BarCount; t++ )     // Loop through all future values From tomorrow onwards

        {                                    // Note we ONLY modify future values, which shouldn't be known or used.

            switch (nullify_condition)

            {          

            case 1:

                C[t] = C[t-1];    // Make future values non changing. ie, copy the last value. Usually the most stable.          

                break;

            case 2:

                C[t] = 0;        // Sometimes we want it to be zero, although this will upset calculations. This might be what you want

                break;

            case 3:

                C[t] = NULL;    // Sometimes just NULL it.  NOTE .. NULL and 0 are different in Amibroker, however most of the time produce the same results !!!

                break;

            case 4:

                break;            // C remains unchanged ie, do nothing. Will be the same as if

            }

        }      

// Put your base arrays, or other formula for looping here to be calculated and tested for future leaks.


    zz = Zig( C, pr ); // <== Note this is a modified Close array which Modifies future data.

    zzHiLo[i] = zz[i];

}


C = cc;


// zzHiLo = Zig( c, pr ); <= Doing in the loop now to modify future data

pk = zzHiLo>Ref(zzHiLo,-1) AND zzHiLo>Ref(zzHiLo,1); //<==== testing tomorrows Zig(close,pr)

tr = zzHiLo<Ref(zzHiLo,-1) AND zzHiLo<Ref(zzHiLo,1); //<==== testing tomorrows Zig(close,pr)

SetTradeDelays(1,1,0,0);

BuyPrice=SellPrice=C;

Buy = tr;

Sell = pk;


Filter = 1;

AddColumn(C,"C",1.6,IIf(C==C,colorBlack,colorRed));

AddColumn(zzHiLo_test,"ZZ1",1.6,IIf(zzHiLo_test==C,colorBlack,colorRed));

AddColumn(zzHiLo,"ZZ2",1.6,IIf(C==zzHiLo,colorBlack,colorRed));

AddColumn(zzHiLo - zzHiLo_test,"Delta ZZ",1.6,IIf(zzHiLo_test==zzHiLo,colorBlack,colorRed));


Plot(zzHiLo,"",colorgreen,styleLine);

Plot(zzHiLo_test,"",colororange,styleLine);


_TRACE("Completed test");


[/CODE]


Top