Thanks Tomasz. Yes I've found that thread. I still have problems with the 'Amount' variable for the ZIG. Should not this be a percentage ? Anyway I have got my 'Expected Lag' in Bars. Thanks again ...
Regards, Ton. ----- Original Message ----- From: Tomasz Janeczko To: amibroker@yahoogroups.com Sent: Tuesday, April 27, 2010 11:43 AM Subject: Re: [amibroker] Re: How to backtest or plot a script, which uses SelectedValue or LastValue? Hello, This has been answered already in my previous response in this thread: http://finance.groups.yahoo.com/group/amibroker/message/148933 (It was back in 2003 http://www.amibroker.com/members/traders/11-2003.html when the formula was provided in the Traders' Tips section that: a) shows how to use Zig/Peak/Trough SAFELY in backtest b) provides actual code that marks points where you know when Peak/Trough is true The 'expected lag' is dynamic and is given by distance between peak/trough and the signal in ZZT variable. ZZT variable crosses zero when peak / trough is guaranteed. Such signals are backtest-safe. Once again the formula: array = Close; amount = Param("Amount", 15.5, 1, 50, 0.5 ); zz0 = Zig( array, amount ); zz1 = Ref( zz0, -1 ); zz2 = Ref( zz0, -2 ); tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1); pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1); PU = tr + 0.01 * abs(tr)*amount; PD = pk - 0.01 * abs(pk)*amount; ZZT = IIf( array >= PU AND zz0 > zz1, 1, IIf( array <= PD AND zz0 < zz1, -1, 0 ) ); ZZT = ValueWhen( ZZT != 0, ZZT ); // plot price bar chart Plot( Close, "Price", colorBlack, styleBar ); // plot Zigzag and zigzag trend Plot( ZZT, "ZigZagTrend", colorRed, styleOwnScale ); Plot( zz0, "ZigZag line", colorBlue, styleThick ); // Plot the ribbon ribboncol= IIf( ZZT > 0, colorGreen, colorRed ); Plot( 2, "ZZT Ribbon", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 ); GraphXSpace = 10; Buy = Cover = Cross( ZZT, 0 ); Sell = Short = Cross( 0, ZZT ); // plot arrows PlotShapes( Buy + 2 * Sell, ribboncol, 0, IIf( Buy, L, H ), -30 ); PlotShapes( Buy + 2 * Sell, ribboncol, 0, IIf( Buy, L, H ), -30 ); Best regards, Tomasz Janeczko amibroker.com On 2010-04-27 08:41, Ton Sieverding wrote: Tomasz how do I calculate this 'Expected Lag' in Bars? So how do I know when the Peak/Through is true ? Regards, Ton. ----- Original Message ----- From: Tomasz Janeczko To: amibroker@yahoogroups.com Sent: Tuesday, April 27, 2010 12:59 AM Subject: Re: [amibroker] Re: How to backtest or plot a script, which uses SelectedValue or LastValue? Hello, > The script never looks after the BAR, but, of course, it does look after the peak if the peak is in the past. This is *exactly* looking into the future. You can only claim a peak when you look several bars AFTER the peak - that is looking into the future in purest form. You don't know that the PEAK occurred until many bars AFTER the fact. You can call it "expected lag" and I am calling it "looking into the future", both having same net effect - the result is useless for profitable trading, as useless as knowing what kind of market cycle we had one year ago. You can not profit from the information that is several bars (days) old. For me this ends this purely academic discussion. Best regards, Tomasz Janeczko amibroker.com On 2010-04-26 23:43, jhnlmn wrote: > > Hi, > > >> You admit that you are complete novice, yet you make definitive statements ... >> > Sure. This is because I wrote a script, which generates exactly the same output as Peak/Trough in WL. > So, I know for sure that this script does not use a Zigzag (WL simply does not have this indicator) > and it does not look into the future, that is when I call TroughBars[bar] I do know that it does not > use any bars with indexes> bar. So, it does not look into the future, but have some lag, > which is expected. Please, correct me if I am wrong. > > >> (i.e. you must look at bars that occur AFTER THE PEAK) and find out that the price moved in opposite >> > Sure, but I never look AFTER THE BAR when I call TroughBars[bar]. Therefore, my script does not look into the future. That is, it will generate exactly the same answer no matter whether bar is the last in the series or some time later when bar will be in the middle of historical data. > > >> Finding "that reversal happens" is where looking into the future occurs. >> > No. The script never looks after the BAR, but, of course, it does look after the peak if the peak is in the past. > > > >> *IS* actually zig-zag algorithm and that peak and trough functions are _products_ of zig-zag algorithm. >> > This may be true, but it is not really important. It does not matter how a particular trading program chose to name each function. It is more important what exactly the function does, in particular whether it does look into the future, that is when I call TroughBars[bar] will it look after the bar or not? And here, if I understood you correctly, AB is profoundly different from WL because in WL TroughBars[bar] does NOT touch any data after bar, but AB does. > > >> You can not simply remove SelectedValue from such formula because it relied on manual input >> > Of course. I stated this in my original question. > > >> In order to remove SelectedValue you would need to come up first with >> conditions that say when to start and when to end the trendline because it is not always obvious. >> > I already did that in my post > http://finance.groups.yahoo.com/group/amibroker/message/148924 > I, as well as other users, found it very difficult to understand AB array-based language, > so it is very likely that I made some mistake in my rewritten scripts. > So, I would appreciate if somebody with experience will comment on it. > > Thank you > John > > > > > > > ------------------------------------ > > **** IMPORTANT PLEASE READ **** > This group is for the discussion between users only. > This is *NOT* technical support channel. > > TO GET TECHNICAL SUPPORT send an e-mail directly to > SUPPORT {at} amibroker.com > > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at > http://www.amibroker.com/feedback/ > (submissions sent via other channels won't be considered) > > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: > http://www.amibroker.com/devlog/ > > Yahoo! Groups Links > > > > >