XANDER Grid XAUUSD

A bidirectional grid for Gold (XAUUSD) where the previous candle decides the side. A bullish close allows a new buy level, a bearish close a new sell level, and a level is only added once price has moved the full grid step against the last entry. Each level doubles the previous lot up to the cap you set, and every lot is validated against the broker’s minimum, maximum and step before it is sent.
Exits are handled at basket level. Average TP mode takes the volume weighted average of the best and worst position, adds a minimum profit distance and sets that price as a shared take profit on both. Partial Close mode waits for price to reach the average, then closes the starting lot of the best position and the whole worst position, trimming the basket from both ends. A single open position gets a plain fixed take profit.
Risk tools are simple on purpose: a daily profit target that closes everything and stops for the day, and a maximum floating drawdown that pauses new entries without closing anything. This is a grid with lot doubling and no stop loss per position, so margin use grows with every level. Run it in the strategy tester first and size it to your account.
Update v1.1 (October 2026): header and documentation rewritten, link to my MQL5 channel for updates, contact inputs removed, price data and tick checked before every trading pass, input labels now say points, which is the unit the code uses. Grid logic unchanged, your settings keep working.
Settings
- Take Profit, Grid Step, Min Profit (points): distances in points of the symbol. On a gold quote with 2 decimals 390 points is a 3.90 USD move, with 3 decimals it is 0.39 USD. Check your broker’s digits before testing.
- Starting lot / Maximum lot: the sequence is 0.01, 0.02, 0.04 and then stays at the maximum. 0 removes the cap, which I do not recommend.
- Close method: Average TP or Partial Close.
- Daily Profit Target and Max Floating Drawdown: in account currency, both off by default. The daily target uses the current floating result of the basket.
- Magic Number and Slippage (points).
What it needs
An MT5 hedging account, because it holds buys and sells at the same time. It only touches positions with its own magic number on the chart symbol, so it can run next to other EAs or manual trades. The chart is cleaned on load (grid, volumes, trade history, trade levels, bid and ask lines) and restored when you remove the EA. Built and tested on XAUUSD M5 and M15.
Make it yours
Nothing in the code is tied to gold. Run your own backtests on XAUUSD, XAGUSD, EURUSD, GBPUSD, US30 or NAS100 and compare M5, M15 and H1 to see how grid step and lot cap change the drawdown. The entry filter is a single candle check, the natural place to plug in a moving average or ADX trend filter, a session filter, a news pause, Smart Money Concepts zones or your own support and resistance levels. For an external exit, my Basket Pair Closer works next to this EA with magic 2001.
About this code
Open source. Use it as it is, adapt it, build your own version on top of it. New versions and new tools are announced first on my MQL5 channel: https://www.mql5.com/en/channels/xander. Questions, suggestions and your own backtests are welcome in the Xander Lab group: https://www.mql5.com/en/messages/02eec85e4364dd01. More tools on my profile: https://www.mql5.com/en/users/09151993a
Related: Basket Pair Closer, XANDER Gold Recovery, XPro Trade Panel.
Changelog
v1.1 (2026-10-25): documentation and header update, MQL5 channel link, contact inputs removed, data checks before trading, labels in points.
v1.0 (2026-04-09): initial release.