I am having trouble getting my code to output to me the length of the
drawdown from portfolio equity high to the next equity high. 
Everytime I run the backtest, the report always list MaxDDdays = 0. 
Any help would be appreciated.

Thanks,

John

//Entry signals before sell signals
//Calculate length of drawdown
SetCustomBacktestProc(""); 
if( Status("action") == actionPortfolio ) 
{ 
 bo = GetBacktesterObject(); 
 Eqty = bo.Equity(); 
 Cash = bo.Cash(); 
 MaxEqty = bo.InitialEquity();
 DDdays = 0;
 MaxDDdays = 0;
 bo.PreProcess(); 
 for( bar = 0; bar < BarCount; bar++ ) 
 { 
  //Handle ENTRY signals 
  for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) ) 
  { 
   if( sig.IsEntry() && sig.Price != -1 ) 
   { 
    //determine if cash is less than 10% of equity, if so, do not
enter trade
    if( Cash<Eqty*0.1 )
     { 
      sig.Price = -1; 
     } 
    else 
    { 
     bo.EnterTrade( bar, sig.symbol, sig.IsLong(), sig.Price, 
     sig.PosSize, sig.PosScore ); 
    } 
    //calculate the length of the drawdown from portfolio equity high
to next portfolio equity high
    if (Eqty<MaxEqty) //IS today less than MaxEqty?
    {
     DDdays = DDdays+1;
     if (DDdays>MaxDDdays) //Is this a new max for length of drawdown?
     {
      MaxDDdays = DDdays; //reset to a new MaxDDdays
     }
    }
    else
    {
     MaxEqty = Eqty; //Since today is a new equity high, increase the
MaxEqty to todays equity
     DDdays = 0;
    }   
   }
  }
  bo.UpdateStats(bar, 0); 
  bo.UpdateStats(bar, 1); 
  //handle EXIT signals 
  for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) ) 
  { 
   if (sig.IsExit() && sig.Price != -1 ) 
   { 
    bo.ExitTrade(bar,sig.symbol,sig.Price); 
   } 
  } 
  //update stats after closing trades 
  bo.UpdateStats(bar, 2); 
 } 
 bo.PostProcess(); 
 bo.addcustommetric("MaxDDdays",MaxDDdays);
}


Reply via email to