Code Library / Risk Management
MQL5 Drawdown Monitor
Pause trading when drawdown exceeds threshold.
Language: MQL5 · Category: Risk Management · Tags: drawdown, monitoring, MQL5, risk control, account protection
Source code
input double MaxDD=15; input double DailyLimit=3;
double peakEq, dayBal;
bool DDExceeded() {
double eq=AccountInfoDouble(ACCOUNT_EQUITY);
peakEq=MathMax(peakEq,eq);
return (peakEq-eq)/peakEq*100>=MaxDD;
}
bool DailyExceeded() {
return (dayBal-AccountInfoDouble(ACCOUNT_EQUITY))/dayBal*100>=DailyLimit;
}
bool SafeToTrade() { return !DDExceeded()&&!DailyExceeded(); }How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL5 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.