PureBytes Links
Trading Reference Links
|
Hello,
How can you access AFL function values that work on price arrays in a
low level backtest??
I am attempting to handle multiple signals using Custom Backtester.
In version 4.76.0 Tomasz introduced the "Handle" property.
In this simple example I want to use "Handle" to exit if share has
dropped 2xATR(30) from BuyPrice.
(note: 2xATR(30) is calculated on the 'Buy' day)
The middle line of code is obviously incorrect, but HOW should it be
written?
for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
{
if(pos.GetPrice(bar,"C") < pos.GetEntryValue() -
2*ATR(30).[bar-pos.BarsInTrade])
bo.ExitTrade(......);
}
Any ideas on how this can be done would be appreciated.
Complete code is listed below:
/* Backtest is carried out on multiple symbols*/
Buy = Cross(C,Ref(HHV(H,20),-1);
BuyPrice = Open;
Sell = 0;
SellPrice = 0;
if( Status("action") == actionPortfolio )
{
// actual backtest routine(low-level)
bo = GetBacktesterObject();
bo.PreProcess();
for( i = 1; i < BarCount; i++ )
{
// first update backtest stats and handle stops
bo.UpdateStats( i, 0 );
for( sig = bo.GetFirstSignal(i);sig; sig = bo.GetNextSignal(i) )
{
if (sig.IsLong() AND sig.Price != -1)
{
bo.RawTextOutput("Bar " + i + " Symbol: " + sig.Symbol);
bo.EnterTrade(i, sig.Symbol, True, sig.Price,-10);
for(pos=bo.GetFirstOpenPos();pos;pos = bo.GetNextOpenPos() )
{
bo.RawTextOutput("Open Pos Found For: " + pos.Symbol);
/* --- Now Process Exit ---*/
/* --- This won't work ---*/
/* --- Have we closed 2xATR(30) below entry price? */
if(pos.GetPrice(i,"C") < pos.GetEntryValue() -
2*ATR(30).[i-pos.BarsInTrade])
bo.ExitTrade( i+1, OpenPos.Handle, OpenPos.GetPrice( i+1, "O" ) );
}
}
bo.UpdateStats( i, 2 );
}
bo.PostProcess();
}
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/
|