[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Dynamic trailing stop - ploting vs backtesting giving different values



PureBytes Links

Trading Reference Links

Hi all.

I'm trying to plot the trailing stop used by the ApplyStop() function 
but had no success so far. Consider this simple system:

---------------------snip-------------------

SetOption("InitialEquity", 100000);

BuyPrice = SellPrice = Open;
SetTradeDelays(1, 1, 1, 1);

Buy = Cross(Signal(), MACD());
Sell = Cross(MA(C, 200), C);

TS = 4 * ATR(20);
ApplyStop(stopTypeTrailing, stopModePoint, TS, 1, TRUE);

#include "Formulas/Basic Charts/Price.afl";

Plot(High - TS, "Trailing Stop", colorRed, styleDots | styleNoLine);

---------------------snip-------------------

For example, when I run this system on DJI from 2003 to 2007, I get a 
trade started on 2006-08-14 with entry price equals to 11089.10. This 
trade ends by triggering the backtester trailing stop in 2007-02-27 with 
exit price at 12148.50.

However, the trailing stop plot never reach the 12148.50 value exactly. 
Actually, the highest value of the trailing stop plot since trade start 
is 12237.11 (at 2007-02-20), which is higher than backtester exit price!

Another example:

Entry: 2004-09-21 @ 10204.50
Exit (trail): 2005-03-29 @ 10373.50
If following plot: trailing stop reached 9732.29 in 2004-10-04, which 
would cause the trade to be stopped much earlier in 2004-10-25.

(Note: I'm using Yahoo free EOD data -- if you use another feed then 
your numbers may be different.)

This is frustating because I developed and optimized a system that 
perform somewhat well in the backtester, but I can't apply it in real 
life because I don't know how to move the stops in my broker to match 
the values used by AB.

So... what's wrong in my code? How to plot the ACTUAL price that 
ApplyStop(stotTypeTrailing, stopModePoint...) consider when exiting trades?

Thanks in advance.

-- 
Flávio

------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/