Good afternoon to all, after having exhaustively searched this forum as well as the broader web for clues I come kindly requesting your assistance.
I currently have a custom trade metric which outputs data to the trade list report.
trade.AddCustomMetric("LoB", loB);
trade.AddCustomMetric("HiB", hiB);
My goal is to get the sum of trade list data and output the values to the custom backtest report.
bo.AddCustomMetric( "LoBT", loBT);
bo.AddCustomMetric( "HiBT", hiBT);
Full code is listed below. Any assistance will be much appreciated.
SetCustomBacktestProc("");
function processTrade( trade )
{
SetForeign( trade.Symbol );
if ( trade.IsLong() )
{
loB = (trade.BarsInTrade - Lookup( LLVBars( Low, trade.BarsInTrade + 1), trade.ExitDateTime ))/trade.BarsInTrade;
hiB = (trade.BarsInTrade - Lookup( HHVBars( High, trade.BarsInTrade + 1), trade.ExitDateTime ))/trade.BarsInTrade;
}
else
{
loB = (trade.BarsInTrade - Lookup( HHVBars( High, trade.BarsInTrade + 1), trade.ExitDateTime ))/trade.BarsInTrade;
hiB = (trade.BarsInTrade - Lookup( LLVBars( Low, trade.BarsInTrade + 1 ), trade.ExitDateTime ))/trade.BarsInTrade;
}
RestorePriceArrays();
trade.AddCustomMetric("LoB", loB);
trade.AddCustomMetric("HiB", hiB);
}
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(1);
loBT = hiBT = 0;
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
if ( trade.IsLong() )
{
loB = ((trade.BarsInTrade - Lookup( LLVBars( Low, trade.BarsInTrade + 1), trade.ExitDateTime ))/trade.BarsInTrade);
hiB = (trade.BarsInTrade - Lookup( HHVBars( High, trade.BarsInTrade + 1), trade.ExitDateTime ))/trade.BarsInTrade;
}
else
{
loB = (trade.BarsInTrade - Lookup( HHVBars( High, trade.BarsInTrade + 1), trade.ExitDateTime ))/trade.BarsInTrade;
hiB = (trade.BarsInTrade - Lookup( LLVBars( Low, trade.BarsInTrade + 1 ), trade.ExitDateTime ))/trade.BarsInTrade;
}
loBT += loB;
hiBT += hiB;
processTrade( trade );
}
for ( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() )
{
processTrade( trade );
}
bo.AddCustomMetric( "LoBT", loBT);
bo.AddCustomMetric( "HiBT", hiBT);
bo.ListTrades( );
}
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
StopLevel = Param("trailing stop %", 3, 0.1, 10, 0.1 );
ApplyStop(stopTypeLoss, stopModePercent, StopLevel, 2, True, 0, 0, -1 );
Buy = Cross( MA(C, 10), MA(C,100) );
Short = Cross( MA(C,100), MA(C,10) );
Sell = Cover = 0;
BuyPrice = SellPrice = ShortPrice = CoverPrice = Close;