How to make an EA prop-firm compliant
Many funded accounts are lost to a rule, not to the strategy. Here is how to enforce each rule inside the EA itself, with code, so one bad day cannot end the account.
An Expert Advisor can follow a strategy perfectly and still fail a prop-firm evaluation. The usual causes are small: the daily loss limit crossed by a few dollars on a spread spike, a position held through restricted news, a lot size over the cap, or a restart that made the EA forget how much it had already lost. None of these is about the strategy’s edge. All of them can be prevented in code.
This guide goes through the rules that end the most accounts and how to enforce each one inside an MT4 or MT5 EA. Firms word their rules differently and change them, so treat the specifics as examples and check your own firm’s current rulebook.
1. Find out exactly how your firm measures the daily loss
“5% daily loss” sounds simple, but three details change the number your EA has to defend:
- The base. Some firms take a percentage of the starting account size; others take a percentage of the balance at the start of each day.
- The starting point. The day’s loss is usually measured from the balance at the daily reset, and some firms use the higher of balance and equity at that moment.
- The reset time. Often midnight in the firm’s own timezone, which is rarely your broker’s server time or your local time.
Floating losses almost always count. That means your EA must watch equity, not balance, and must know the firm’s reset time to know when “today” starts.
2. Enforce the limits on equity, every tick, with a buffer
Checking the daily loss once per bar is not enough: a fast move can take equity through the limit between two bars. The guard has to run on every tick, before any new entry, and it has to stop early. If the firm’s limit is 5%, stop at around 4%. By the time the EA reacts, spread widening and slippage on the closing orders can easily cost the rest.
A guard has three jobs: block new entries, close open positions, and stay halted until the next reset. The limits should be inputs, so the same EA can match any firm.
Use the prop-firm drawdown calculator to see what these floors look like for your account.
3. Make the EA remember after a restart
Terminals restart. VPS providers reboot servers. If your EA keeps its start-of-day equity or its trailing high-water mark only in memory, a restart quietly resets them, and the EA may trade into a loss it believed it still had room for.
Persist anything the rules depend on. In MetaTrader, terminal global variables are the simplest place:
1// Keep the trailing high-water mark across terminal and VPS restarts2string PeakKey() { return "VX_PEAK_" + IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN)); }3 4double LoadPeak(double fallback)5{6 if(GlobalVariableCheck(PeakKey())) return GlobalVariableGet(PeakKey());7 GlobalVariableSet(PeakKey(), fallback);8 return fallback;9}10 11void UpdatePeak(double &peak)12{13 double equity = AccountInfoDouble(ACCOUNT_EQUITY);14 if(equity <= peak) return;15 peak = equity;16 GlobalVariableSet(PeakKey(), peak);17 GlobalVariablesFlush(); // write to disk now, not at shutdown18}The same applies to the day’s starting equity and to a “halted until reset” flag. On start-up the EA should also rebuild its view of open positions from the terminal, rather than assuming it has none.
4. Size every trade from the stop, and cap the lots
Fixed lot sizes are the quiet killer of funded accounts. A 2-lot trade with a 10-pip stop and a 2-lot trade with a 60-pip stop risk very different amounts. Size each trade so the money at risk is a fixed percentage of equity, then apply the firm’s lot cap:
1// Lots from risk %: the same money at risk whatever the stop distance2double LotsForRisk(double riskPct, double stopPrice, double entryPrice)3{4 double riskMoney = AccountInfoDouble(ACCOUNT_EQUITY) * riskPct / 100.0;5 double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);6 double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);7 double lossPerLot = MathAbs(entryPrice - stopPrice) / tickSize * tickValue;8 if(lossPerLot <= 0) return 0.0;9 10 double step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);11 double lots = MathFloor(riskMoney / lossPerLot / step) * step; // round DOWN12 return MathMin(lots, InpMaxLots); // firm's lot cap13}Then check the arithmetic against the rules. At 0.5% risk per trade and a 4% daily stop, you can take eight full losses in a day before the guard trips. If your strategy’s tested losing streaks are longer than that, reduce the risk per trade, not the guard.
5. Handle news restrictions properly
Some firms restrict opening or closing trades in a window around high-impact news on certain account types. An EA that respects this needs three things: a reliable list of events, a configurable window before and after each one, and a decision about open positions (close before, or hold through if the firm allows it).
MT5 has a built-in economic calendar that EAs can read. It is not available in the Strategy Tester, so for backtests the EA needs a saved list of past events. Otherwise your test trades through news that your live EA would avoid, and the results do not match.
6. Weekends, overnight and time-based rules
Some programmes require you to be flat over the weekend. Give the EA a Friday cut-off in the firm’s timezone, after which it stops opening trades, and a close time a little before the market closes. Do not rely on the last tick of the week, because liquidity is thin and spreads are wide.
7. Avoid behaviour that firms restrict
Many firms restrict some or all of the following. If your logic does any of these, find out before you pay for an evaluation:
- Martingale sizing, where lots increase after losses
- Grid systems without a hard cap and a basket stop
- High-frequency or latency-based trading, and tick scalping
- Third-party EAs used by many traders at once
- Copying or hedging trades between different people’s accounts
An EA built from your own rules avoids the shared-EA problem. Tools designed to hide restricted behaviour from a firm are a different matter: they get accounts closed and payouts refused.
8. Consistency rules
Some firms limit how much of your total profit can come from a single day. A simple guard is a daily profit lock: once the day’s profit reaches a set share of the target, the EA stops opening trades until the next reset.
9. Test against the rules, not only for profit
A backtest that shows a good total return can still contain days that would have breached a daily limit. When you test, export the trade list and calculate for every day:
- the lowest equity reached relative to that day’s starting point
- the deepest drawdown from the highest point so far
- the profit made on the best day, as a share of the total
Then reshuffle the trade order a few thousand times (a Monte Carlo test) to see how often a bad sequence would have hit the limits. That probability, not the total return, tells you whether the strategy belongs on a funded account at your current risk.
Checklist
- Daily loss measured on equity, from the firm’s reset time, with a buffer
- Maximum drawdown in the firm’s mode (static or trailing), with a buffer
- State saved to disk and restored after restarts
- Position size from the stop distance, capped at the firm’s maximum
- News windows, weekend cut-off and time rules as inputs
- No restricted behaviour hidden in the logic
- Tested day by day against the rules, plus a Monte Carlo check