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

[amibroker] Code help for foward looking execution in backtesting



PureBytes Links

Trading Reference Links

This code I have written is forward looking. I believe
the backtester is waiting until the end of a bar is
completed to determine if the close is above/below the
entry/stop. I would like for it to execute at the
market. I used BuyPrice, ShortPrice, SellPrice, and
CoverPrice to try and get the correct execution price,
but the problem is occurring when the high/low of a
bar exceeds a stop but then reverses and closes on the
other side. The backtester does not execute on this
bar, because the close does not meet the criteria. I'm
sure there is a simple way to correct this, but I
could not find it. Simplified code is:

EntryBars = Param("Entry Bars", 15, 1, 30, 1);
ExitBars = Param("Exit Bars", 5, 1, 30, 1);

BuyUpper = HHV(Ref(H,-1),EntryBars);
SellLower = LLV(Ref(L,-1),EntryBars);

StopUpper = HHV(Ref(H,-1),ExitBars);
StopLower = LLV(Ref(L,-1),ExitBars);


Buy = Cross (Close, BuyUpper);
Short = Cross (SellLower, Close);

Sell = Cross (StopLower, Close);
Cover = Cross (Close, StopUpper);

BuyPrice = Max (BuyUpper, Low);
ShortPrice = Min (SellLower, High);
SellPrice = Min (StopLower, High);
CoverPrice = Max (StopUpper, Low);  

It is my understanding that in real time, Close would
act as Last, but that is not happening in the
backtest. Any ideas on how to fix this problem or
could someone kindly point me to a documented
solution?
TIA,
James


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com