Getting Current Drawdown in Custom Backtester

I'm trying to change the position sizing based on the current drawdown. I've been able to get other variables fine but having problems with this one. It doesn't seem to be a stat so I'm calculating it myself using the EquityArray function but I don't seem to be getting any data back. Is there something wrong with my approach or is there a better way? Thank you.


if( Status("action") == actionPortfolio )
	bo = GetBacktesterObject();
	for( bar = 0; bar < BarCount; bar++ ){
		eqa = bo.EquityArray();		
		drawDownPct = -100*(eqa/Highest(eqa) - 1);		
		currentDrawDown = LastValue(drawDownPct);
		for( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) ){		
			if(currentDrawDown > 20) sig.PosSize = -10;						
		bo.ProcessTradeSignals( bar );
	bo.AddCustomMetric("DD", currentDrawDown);

It looks like the solution for this was discussed already in this thread.

1 Like