I would like the backtest report to list what the total position size for a 
particular trade is.  I use a dynamic position size.  I have tried to modify my 
Custom Backtest code without success.  Prior to trying this, my custom code was 
set up to process entry signals first then scalein followed by exit signals.  
When I try to add in the code for the custom metric, it just does not work.  
Here is my latest attempt:

SetCustomBacktestProc(""); 
if( Status("action") == actionPortfolio ) 
{ 
 bo = GetBacktesterObject(); 
 bo.PreProcess(); 
 for( bar = 0; bar < BarCount; bar++ ) 
 {
  eqty = bo.Equity();
  //Handle ENTRY signals then Exit signals
  for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) ) 
  { 
   if( sig.IsEntry() && sig.Price != -1 ) 
   {  
    bo.EnterTrade( bar, sig.symbol, sig.IsLong(), sig.Price, 
    sig.PosSize, sig.PosScore );  
   }
   if (sig.Type == 5)   //  If signal type is scale-in
   {
    trade = bo.FindOpenPos(sig.Symbol);   //  Check for open position in stock
    if (trade)  
    {
    bo.ScaleTrade(bar, trade.Symbol, sig.IsLong(), sig.Price, 
    sig.PosSize, sig.PosScore ); 
    }
   }
  for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
    {                                   //  Loop through all closed trades
        Entry = trade.GetEntryValue();          //  Get trade entry in dollars  
     
        trade.AddCustomMetric("PosSize", Entry/eqty);   //  Calculate the 
position size of this trade
    }                                   //  End of for loop over all trades
   if (sig.IsExit() && sig.Price != -1 ) 
   { 
    bo.ExitTrade(bar,sig.symbol,sig.Price);  
   }
  }
  bo.UpdateStats(bar, 0); 
  bo.UpdateStats(bar, 1); 
  bo.UpdateStats(bar, 2); 
 } 
 bo.PostProcess(); 
}

I tried adding in bo.Backtest(True) and bo.ListTrades() but no matter where I 
put it, it would not run properly.

Any suggestions?

Thanks,

John

Reply via email to