I am trying to get more granular data in the backtest reports to give myself a bit more insight into my trading systems. I'm simply trying to count trades per year and determine win ratio. I'm not sure if my attempt at the code below is correct or not but at the moment I'm getting this:
Error 16: too many arguments with window pointing to this line:
exitdate = datenum( trade.ExitDateTime )
I've searched the forums and read through the CBT manual but I'm out of ideas. Any help is much appreciated!
SetCustomBacktestProc("");
if(Status("action") == actionPortfolio)
{
bo = GetBacktesterObject();
bo.backtest();
if(BarCount > 252) // only execute if more than 1 year
{
//counting total wins, losses and trades per year
for ( Years = 2000; 2020; Years++)
{
//Reset counters
YrTrades = 0;
YrWin = 0;
YrLoss = 0;
// iterate through closed trades first
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
PL = trade.Getprofit();
exitdate = datenum( trade.ExitDateTime );
if( Years == exitdate)
{
yearTrades++;
if (PL >= 0)
YrWin_++;
else
YrLoss++;
}
VarSet("Year-"+Years, YrTrades);
VarSet("Year-"+Years, YrWin);
VarSet("Year-"+Years, YrLoss);
bo.AddCustomMetric( "Year-"+Years, LastValue(YrTrades) );
bo.AddCustomMetric( "Year-"+Years, LastValue(YrWin) );
bo.AddCustomMetric( "Year-"+Years, LastValue(YrLoss) );
}
}
}
}