Blog · Risk
How to calculate drawdown in MT5, and which number to alert on
The four drawdown measures in MT5 explained with formulas and MQL5 code: balance vs equity, daily loss, static drawdown and per-EA attribution by magic number.
"Drawdown" is one word for at least four different numbers, and MT5 reports them in different places with different formulas. An alert built on the wrong one fires late or not at all. This guide defines each measure, shows how to compute it from account data (per account and per EA), and explains which one your alerts should use.
The four drawdowns
| Measure | Formula | Answers |
|---|---|---|
| Balance drawdown | (peak balance − current balance) ÷ peak balance | How much have closed trades given back? |
| Equity drawdown | (peak equity − current equity) ÷ peak equity | How much would I have lost if everything closed now? |
| Daily loss | (day-start reference − current equity) ÷ reference base | How close am I to a daily limit? |
| Static / absolute drawdown | (initial deposit − lowest equity) ÷ initial deposit | How far below my starting capital did I go? |
The MT5 strategy tester reports "Balance Drawdown Maximal", "Equity Drawdown Maximal" and their "Relative" versions. Maximal is the largest drop in money; Relative is the largest drop in percent. They can come from different moments of the test, which is why the two lines rarely match.
Why balance drawdown lies for some strategies
Balance only moves when a trade closes. A grid or averaging EA can hold a floating loss of 15% while its balance curve is a smooth staircase upward. Anything that keeps losers open, including swing systems with wide stops, must be judged on equity. For a strategy with one position and a hard stop, the two measures stay close and either works.
Computing it live in MQL5
You need a running peak that survives restarts. Store it in a terminal global variable so a VPS reboot does not reset your high-water mark to today's equity:
double EquityDrawdownPct()
{
string key = "peak_eq_" + IntegerToString((int)AccountInfoInteger(ACCOUNT_LOGIN));
double eq = AccountInfoDouble(ACCOUNT_EQUITY);
double peak = GlobalVariableCheck(key) ? GlobalVariableGet(key) : eq;
if(eq > peak) { peak = eq; GlobalVariableSet(key, peak); }
return (peak > 0.0) ? 100.0 * (peak - eq) / peak : 0.0;
}
Remember that deposits and withdrawals move equity without being profit or loss. Adjust the peak by the same amount when a balance operation appears in history (DEAL_TYPE_BALANCE), or a withdrawal will look like a crash.
Drawdown per EA, not per account
With several experts on one account, the account figure tells you something is wrong but not what. Attribute by magic number: sum the floating profit of open positions with that magic, add the closed profit of its deals since the last peak, and track a separate high-water mark per magic.
double FloatingByMagic(long magic)
{
double sum = 0.0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
if(PositionGetTicket(i) > 0 && PositionGetInteger(POSITION_MAGIC) == magic)
sum += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
return sum;
}
Per-EA curves are also what let you retire a strategy on evidence instead of on a feeling.
Which number should trigger an alert?
- Prop firm daily limit: daily loss on equity, against the firm's day-start reference. Nothing else matches their calculation.
- Prop firm overall limit: equity against the firm's floor (static or trailing, as your programme defines it).
- Personal account risk: equity drawdown from peak, with thresholds taken from the backtest: alert at the historical maximum, act at 1.5 times it.
- Strategy health: per-magic equity drawdown compared with that strategy's own tested maximum.
Sampling and storage
Sample equity on a timer, once a minute at most for swing systems and every few seconds for scalpers around news. Keep the series, not just the current value: a breach that lasted forty seconds is invisible in end-of-day numbers, and it is exactly the one a prop firm will quote back to you. Sending the samples to an external, read-only store means the record survives a terminal crash and cannot be edited after the fact.
Frequently asked questions
What is the difference between balance and equity drawdown?
Balance drawdown only counts closed trades. Equity drawdown includes floating profit and loss, so it shows the real exposure of strategies that hold losing positions open, such as grids.
What do Maximal and Relative drawdown mean in the MT5 tester?
Maximal is the largest drop measured in money; Relative is the largest drop measured in percent. They can occur at different moments, so the two figures often differ.
How do I calculate drawdown for one EA on a shared account?
Attribute by magic number: sum floating profit of open positions with that magic, add the closed profit of its deals since the last peak, and keep a separate high-water mark per magic.
Which drawdown should a prop firm alert use?
Daily loss computed on equity against the firm's day-start reference, because that is how the firm calculates it.