PureBytes Links
Trading Reference Links
|
Hello,
I am trying to add an initial stop column to the "trade list" reprt
of the backtester. I am able to add extra columns of e.g. Close, Low,
etc arrays with trade.AddCustomMetric (code I am using is shown
below - taken from the previous message). I would like to add columns
that include other AFL functions, e.g. 3*ATR(15) for an initial stop.
Does anyone know how this can be done?
With thanks,
Pavel.
function FindValueAtDateTime( array, dt, Value )
{
found = -1;
for( i = 0; i < BarCount AND found == -1; i++ )
{
if( dt[ i ] == Value ) found = i; }
result = Null;
if( found != -1 ) result = array[ found ];
return result;
}
SetCustomBacktestProc("");
dt = DateTime();
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(1); // run default backtest procedure
// iterate through closed trades and add some info
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
() )
{
//Lookup Close at trade entry
foi = Foreign( trade.symbol, "C" );
temp = findvalueatdatetime( foi, dt, trade.Entrydatetime );
trade.AddCustomMetric("Close", temp, 2);
//Lookup Low at trade entry
foi = Foreign( trade.symbol, "L" );
temp = findvalueatdatetime( foi, dt, trade.Entrydatetime );
trade.AddCustomMetric("Low", temp, 2);
}
bo.ListTrades();
}
--- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@xxx> wrote:
>
> It's not quite that easy. I had fits with this until Tomasz,
incredible
> support guy that he is, helped me out.
>
>
>
> The problem isn't too difficult when you want a built-in metric, but
> when you want something different, for example, the actual price or
the
> Industry group there are a couple of tricks. Take special note of
the
> function preceding the SetCustomBacktestProc("") and this statement:
>
> SetForeign(trade.Symbol);
>
>
>
> Also note that there are two identical sections, one for closed
trades
> and one for open trades.
>
>
>
> I suggest anyone interested in adding stats columns to the back-
tester
> copy and modify this code (inserted before your Buy/Sell/Short/Cover
> statements) :
>
>
>
> /********************* CUSTOM BACKTEST PROCEDURE
********************/
>
> function FindValueAtDateTime( array, dt, Value )
>
> {
>
> found = -1;
>
> for( i = 0; i < BarCount AND found == -1; i++ )
>
> {
>
> if( dt[ i ] == Value ) found = i - 1; //Coded by Tomasz = i,
but
> I want the value from the day BEFORE the signal
>
> }
>
> result = Null;
>
> if( found != -1 ) result = array[ found ];
>
> return result;
>
> }
>
>
>
> SetCustomBacktestProc("");
>
> dt = DateTime();
>
>
>
> if( Status("action") == actionPortfolio )
>
> {
>
> bo = GetBacktesterObject();
>
> bo.Backtest(1); // run default backtest procedure
>
>
>
> // iterate through closed trades and add some info
>
> for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
() )
>
> {
>
> SetForeign(trade.Symbol);
>
> trade.AddCustomMetric("Industry",IndustryID(1) ); //Want to
see
> IndustryID by trade
>
> trade.AddCustomMetric("PScore",trade.Score,0);
>
> //Lookup actual price at trade entry
>
> foi = Foreign( trade.Symbol, "I" );
>
> temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime );
>
> // _TRACE( "Temp=" + temp );
>
> trade.AddCustomMetric("Actual OI", temp/100 );
>
> //Lookup Volume at trade entty
>
> foi = Foreign( trade.Symbol, "V" );
>
> temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime );
>
> trade.AddCustomMetric("Volume", temp, 0 );
>
>
>
> }
>
> // iterate through open trades and add same info
>
> for( trade = bo.GetFirstOpenPos(); trade; trade =
> bo.GetNextOpenPos() )
>
> {
>
> SetForeign(trade.Symbol);
>
> trade.AddCustomMetric("Industry",IndustryID(1)); //Want to
see
> IndustryID by trade
>
> trade.AddCustomMetric("PScore",trade.Score,0);
>
> //Lookup actual price at trade entry
>
> foi = Foreign( trade.Symbol, "I" );
>
> temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime );
>
> // _TRACE( "Temp=" + temp );
>
> trade.AddCustomMetric("Actual OI", temp );
>
> //Lookup Volume at trade entty
>
> foi = Foreign( trade.Symbol, "V" );
>
> temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime );
>
> trade.AddCustomMetric("Volume", temp, 0 );
>
>
>
> }
>
> bo.ListTrades();
>
> }
>
>
>
>
>
> /********************** END C.B.T. PROCEDURE
************************/
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/
|