DEV Community

xuks124
xuks124

Posted on

Prop firm 5% daily drawdown: why most EAs fail it on the first restart

Prop firms hand out a simple rule set: 5% daily drawdown, 10% overall, touch it and you are out. Plenty of people try to pass the challenge with an EA. Here is the uncomfortable part: most EAs with a "daily loss cap" lose that cap the moment MetaTrader restarts.

VigilDesk risk-control dashboard

The usual implementation

double today_pnl = 0.0;      // module-level variable
bool   daily_blocked = false;
Enter fullscreen mode Exit fullscreen mode

Terminal restart, EA recompile, chart switch, reinstall — every one of them re-runs OnInit() and zeroes the variable. Your 5% budget comes back untouched.

The cruel part: crashes and restarts cluster on bad days, exactly when that guard is the only thing standing between you and a blown challenge.

The three fields you must persist

struct GuardState
{
   long   day_stamp;          // which trading day this belongs to
   double day_start_balance;  // drawdown anchor
   bool   blocked;            // has today already tripped
};
Enter fullscreen mode Exit fullscreen mode

Write it into the terminal common folder, keyed by account, so reinstalls, extra terminals and machine changes all keep the state.

Two pitfalls that will bite you

Pitfall 1 — the trading day. Compute the date with TimeLocal() and your cap resets in the middle of the broker session (DST changes and weekends make it worse). Use TimeTradeServer().

Pitfall 2 — write before you send. Get the order wrong and one crash between two lines is enough to let an order through that should never exist:

if(blocked) return;
if(!risk_ok) { blocked = true; SaveState(); return; }
SendOrder();
Enter fullscreen mode Exit fullscreen mode

The guard EA attached to an XAUUSD chart

The only acceptance test worth running

  1. Set a cap that trips within minutes.
  2. Let it trip.
  3. Kill the terminal process (not the EA) with positions still open.
  4. Reopen and try to send another order.

If the fresh process sends the order, your state lived in memory and the guard was decoration. I have run this test against paid EAs. Many fail.

Takeaway

A prop-firm challenge is a risk-control challenge. Before strategy, make sure those three defences still exist after a restart.

I packaged the implementation as a free MT5 tool — pure MQL5, no DLL, no network calls, percentages only:
https://xuks124.github.io/vigildesk/free.html

Risk control only. No profit promises.

Top comments (0)