Maximum drawdown is a standard metric that is simply available directly without need to calculate it by hand. It is included in the standard backtest report and it is included in built-in statistics object in custom backtester (see http://www.amibroker.com/guide/a_custombacktest.html)
// 'bo' variable holds Backtester object retrieved earlier
// should be called after backtest inside CBT formula
stats = bo.GetPerformanceStats( 0 );
mdd = stats.GetValue("MaxSystemDrawdown"); // or MaxSystemDrawdownPercent
If you need it as array for charting equity/drawdown chart, then maximum drawdown formula is known and included in Underwater Equity.afl included in standard installation. It works on ~~~EQUITY ticker that is portfolio level equity.

// Underwater Equity chart
// (C)2009 AmiBroker.com
// Should be used only on ~~~EQUITY or ~~~OSEQUITY symbol
EQ = C;
MaxEQ = Highest( EQ );
DD = 100 * ( Eq - MaxEQ ) / MaxEq;
MaxDD = Lowest( DD );
Title = StrFormat("Drawdown = %.2g%%, Max. drawdown %.2g%%", DD, LastValue( MaxDD ) );
SetGradientFill( GetChartBkColor(), colorBlue, 0 );
Plot( DD, "Drawdown ", colorBlue, styleGradient | styleLine );
Plot( MaxDD, "Max DD", colorRed, styleNoLabel );
SetChartOptions( 2, 0, chartGridPercent );
if( Name() != "~~~EQUITY" AND Name() != "~~~OSEQUITY" ) Title = "Warning: wrong ticker! This chart should be used on ~~~EQUITY or ~~~OSEQUITY only";
In custom backtester, drawdown can be calculated out of bo.Equity or bo.EquityArray pretty much the same way, but not using HHV/LLV array functions but using looping.
Just update your maximo/minimo variables inside the loop
// INSIDE YOUR custom backtester code
maximo = minimo = bo.Equity;
for( bar = 0; bar < BarCount; bar++ )
{
maximo = Max( bo.Equity, maximo );
minimo = Min( bo.Equity, minimo );
incorrect_maxdd = maximo - minimo; // your INCORRECT mdd formula
....
As @mradtke noted the way you calculate MDD is incorrect because you are not taking into account sequence of events. For proper drawdown you should be tracking maximum of equity, then calculate current drawdown (maximo - bo.Equity) and then track maximum of current drawdown.
So your code should actually be looking like this:
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject(); // Get backtester object
bo.PreProcess(); // Do pre-processing (always required)
// snippet INSIDE YOUR custom backtester code
// maxeq and maxdd are scalars, not arrays!
maxeq = bo.Equity;
maxdd = 0;
for (i = 0; i < BarCount; i++) // Loop through all bars
{
maxeq = Max( bo.Equity, maxeq );
curdd = maxeq - bo.Equity;
maxdd = Max( curdd, maxdd );
for (sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
{
// do your custom signal processing
}
bo.ProcessTradeSignals( i ); // Process trades at bar (always required)
}
bo.PostProcess(); // Do post-processing (always required)
}