Bullion Vault EA: a FundedNext gold robot that enforces the rulebook
A funded challenge is not won by a big number; it is lost by breaking one hard rule. So this robot enforces the firm's rules in real time, with its own safety margin inside every limit.
XAUUSD · H1 · $6,000 start · 40-point pinned spread · MetaTrader 4 Strategy Tester · 2,684 lines of MQL4, 78 inputs
MT4 Strategy Tester, 12 months, guard active




The brief
A trader needed an Expert Advisor to run a FundedNext Stellar 2-Step challenge on a $6,000 account, trading gold (XAUUSD) on the H1 timeframe. The requirement was not "make as much as possible". It was "never breach a rule, and reach the target without doing anything the firm forbids".
That inverts normal EA design. Profit becomes the constraint-satisfaction result, not the objective, so the build started from the rulebook and worked backwards.
How each firm rule maps to code
| FundedNext rule | What the EA does about it |
|---|---|
| Max daily loss, 5% of initial | Daily-loss guard at 5% with a 1% safety buffer, re-anchored on the server-day roll. Halts and flattens before the line, resumes the next day. |
| Max total loss, 10% static | Static floor at 10% with a 2% buffer. On the $6,000 account this halts at $5,520 equity, $120 above the firm's real $5,400 floor. Permanent latch. |
| Profit target, 8% then 5% | Closes all at target, then verifies on realised balance before latching a pass. If the close-out slipped below target it resumes trading rather than declaring success. |
| Position risk | Total open stop-loss risk capped at 3% of initial ($180) across all orders. |
| Minimum trading days | Tracked and displayed (five-day requirement) so the pass is not latched prematurely. |
| Weekend and news exposure | Session windows per weekday, optional news filter with configurable pre and post windows. |
The honest part: no developer can guarantee a challenge pass, and I do not claim to. What this EA does is make sure the robot does not break the rules that fail most accounts.
How the strategy works
XAUUSD, H1, one trade at a time, hard stop-loss and take-profit on every order. No grid and no martingale in the shipped configuration. Both scale losses in exactly the way a drawdown-limited account cannot afford.
Four-factor confluence scoring
Each factor votes -1, 0 or +1 on the last closed bar, and a trade needs the absolute score to reach the minimum (3 of 4 in the shipped preset):
- Trend stack: H1 SMA20 and SMA50 alignment against price.
- Momentum extreme: H1 RSI(14) against configurable thresholds.
- Dual-horizon momentum: a 20-bar and a 5-bar percentage change that must agree, so a fresh impulse cannot be faked by a stale trend.
- Price action: engulfing candles with body-size comparison, pin bars (wick over twice the body, body under 30% of range), plus 20-bar support and resistance proximity confirmed by candle direction.
After scoring, a direction filter and a FIFO anti-hedge check run, blocking a buy while any sell is open, as US brokers and most prop firms require. Signals are evaluated once per H1 bar close, never intrabar, and every decision is logged so the client can read exactly why a bar did or did not trade.
Risk engineering
The guard runs first on every tick, before any trade management or entry logic, as an ordered chain: server-day roll, latched permanent halts, static floor, daily floor, then the profit target with realised-balance verification.
Position sizing computes the real per-lot dollar risk from tick size, tick value and the actual stop distance, subtracts the risk already committed by open orders, then either clamps the requested size or refuses the trade if even the broker minimum would breach the budget. Halt latches, the day-start anchor and the trading-day count persist across terminal restarts through namespaced global variables, and are deliberately disabled inside the Strategy Tester.
A wrong initial-balance setting used to silently mis-scale every limit. Now it raises a loud configuration error, blocks new entries and keeps the loss floors armed.
Verified results
All figures are MetaTrader 4 Strategy Tester runs on a $6,000 initial balance with a deliberately pinned 40-point spread, above typical live gold spreads, so every result already pays worst-case transaction costs. Pinning matters: with "current" spread the tester bakes whatever the market shows at that instant into the data, making runs irreproducible.
| Run | Net profit | Profit factor | Trades | Max DD |
|---|---|---|---|---|
| Phase 1 challenge (H2 2025), target reached in 78 days | +$482.74 | 1.78 | 33 | 6.41% |
| Phase 2 (H2 2025), target reached in about 70 days | +$305.84 | 1.50 | 31 | 6.41% |
| Full year, target stop off, guard on | +$1,027.43 (+17.1%) | 1.27 | 180 | 6.81% |
| 2026 hostile-regime stress (January to July) | +$179.98 | 1.08 | 102 | 7.21% |
The share of winning trades is intentionally low (21% to 33%). The system runs a 1:4 reward-to-risk ratio, so most trades are small losses and the winners carry the result. The 2026 stress window is the weak row, and it stays in the table: a profit factor of 1.08 is close to flat, and it recorded zero guard halts.
A real production incident, found and fixed
After delivery the client reported that on a fresh account the EA had taken zero trades for a week. No errors, no alerts. Reproduced in the tester: the packaged binary had been compiled one build before the change that made guard persistence live-account-only, so a Strategy Tester run had written halt latches that the live chart then read on attach. An instant, permanent, silent halt.
The fix rebuilt the binary with a build assertion that the shipped executable matches source, added a one-click latch reset, and added an observability layer: a support snapshot at attach, an hourly heartbeat, per-bar signal maths and explicit guard lines. The handoff note now tells the client which three log lines to send for a complete remote diagnosis.
Method notes
- Reproducible builds: a generator derives the production and an instrumented build from one source, with every anchored replacement asserting its expected occurrence count.
- A headless tester runner with model, date range, preset, report name and pinned spread as parameters.
- Custom optimisation metrics that rank candidates by challenge safety (worst daily loss, static drawdown, guard halts, days to target) rather than raw profit. A faster 2.5%-risk variant was rejected because one window dipped to $5,420, twenty dollars from a breach.
Historical backtest. Not a prediction of future results. Figures are transcribed from the Strategy Tester reports named in the text; nothing is estimated.
Need a rule guard on your own EA?
Prop-firm risk engines start at $175 on Upwork. Tell me the firm and the account size, and I write the spec back first.