Page 1 of 1

Free Tool: Real-Time Equity Drawdown Calculator for MT4 & MT5

Posted: Sun Jul 26, 2026 3:30 pm
by PTScalper
Are you tracking your live equity drawdown, or only looking at closed account balance? Many traders get blind-sided by floating losses because standard MetaTrader platform features only report drawdown after positions are closed. To solve this, I prepared a lightweight, real-time Equity Drawdown Calculator snippet for both MT4 and MT5.

Why is monitoring real-time equity drawdown critical? When managing prop firm accounts or personal capital, your maximum trailing drawdown is often calculated against your highest peak equity—not your starting balance. If your equity reaches $10,000 and drops to $9,000 before recovering, you experienced a 10% drawdown regardless of whether you closed the trade at a loss or a profit.

How this calculator works:
The code continuously tracks your highest recorded equity peak during the session. On every tick, it compares your live floating equity against that historical high to compute both exact monetary drawdown and percentage drawdown.

Key benefits include:
• Universal Compatibility: Includes ready-to-use functions natively formatted for both MQL4 and MQL5 environments.
• Zero Lag: Evaluates floating profit and loss on every tick event to capture true intrabar equity troughs.
• Automated Risk Management: Can be embedded into existing Expert Advisors to trigger automated position closure, push notifications, or trading lockouts when your maximum threshold is breached.

Check the implementation code above, drop it into your EA or indicator, and take control of your downside risk. Let me know if you need custom modifications!
//--- Global variables to store peak values
double g_peakEquity = 0.0;

//+------------------------------------------------------------------+
//| Function: CalculateEquityDrawdown |
//| Outputs: current monetary drawdown and percentage drawdown |
//+------------------------------------------------------------------+
void CalculateEquityDrawdown(double &drawdownCash, double &drawdownPercent)
{
double currentEquity = AccountEquity();

// Initialize or update peak equity
if(g_peakEquity == 0.0 || currentEquity > g_peakEquity)
{
g_peakEquity = currentEquity;
}

// Calculate cash and percentage drawdown
drawdownCash = g_peakEquity - currentEquity;

if(g_peakEquity > 0.0)
{
drawdownPercent = (drawdownCash / g_peakEquity) * 100.0;
}
else
{
drawdownPercent = 0.0;
}
}

//+------------------------------------------------------------------+
//| Example usage inside OnTick() |
//+------------------------------------------------------------------+
void OnTick()
{
double ddCash = 0.0;
double ddPercent = 0.0;

CalculateEquityDrawdown(ddCash, ddPercent);

// Print to Journal or display on chart comment
Comment(StringFormat("Peak Equity: %.2f | DD ($): %.2f | DD (%%): %.2f%%",
g_peakEquity, ddCash, ddPercent));

// Example risk management trigger (e.g., 10% max drawdown limit)
if(ddPercent >= 10.0)
{
Print("CRITICAL: Maximum drawdown threshold reached!");
// Add position closing or lockout logic here
}
}
//--- Global variables to store peak values
double g_peakEquity = 0.0;

//+------------------------------------------------------------------+
//| Function: CalculateEquityDrawdown |
//| Outputs: current monetary drawdown and percentage drawdown |
//+------------------------------------------------------------------+
void CalculateEquityDrawdown(double &drawdownCash, double &drawdownPercent)
{
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);

// Initialize or update peak equity
if(g_peakEquity == 0.0 || currentEquity > g_peakEquity)
{
g_peakEquity = currentEquity;
}

// Calculate cash and percentage drawdown
drawdownCash = g_peakEquity - currentEquity;

if(g_peakEquity > 0.0)
{
drawdownPercent = (drawdownCash / g_peakEquity) * 100.0;
}
else
{
drawdownPercent = 0.0;
}
}

//+------------------------------------------------------------------+
//| Example usage inside OnTick() |
//+------------------------------------------------------------------+
void OnTick()
{
double ddCash = 0.0;
double ddPercent = 0.0;

CalculateEquityDrawdown(ddCash, ddPercent);

// Display on chart comment
Comment(StringFormat("Peak Equity: %.2f | DD ($): %.2f | DD (%%): %.2f%%",
g_peakEquity, ddCash, ddPercent));

// Example risk management trigger (e.g., 15% max drawdown limit)
if(ddPercent >= 15.0)
{
Print("CRITICAL: Maximum drawdown threshold breached!");
// Insert custom order execution / closing logic here
}
}