Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

XANDER Grid XAUUSD - expert for MetaTrader 5

Views:
14785
Rating:
(21)
Published:
Updated:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

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.2 (November 2026): new entry guard. The EA now opens at most one new grid level per candle and side, and waits a few seconds between trade actions, so fast ticks can no longer open and close positions in a loop. A free margin check runs before every order. Grid logic and the rest of the settings are unchanged.

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.
  • One new level per candle (true by default) and Cooldown in seconds between trade actions (5 by default, 0 turns it off).
  • 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.2 (2026-11-20): entry guard, one new level per candle and side, cooldown between trade actions, free margin check before every order.
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.

BEC Lockin Dashboard Manager BEC Lockin Dashboard Manager

BEC Trade Manager helps you manage active positions on the current symbol using one-click controls for breakeven, trailing logic, partial close, stop-loss removal, profit-side closing, loss-side closing, and fast scalp entries. It also displays key account and symbol information on the chart, including equity, floating profit, daily profit, stop-loss labels, and basket breakeven preview.

XPro Trade Panel — Full Trade Management Panel for MT5/MT4 XPro Trade Panel — Full Trade Management Panel for MT5/MT4

One click trade panel for MT5 and MT4. Buy and sell with lot by fixed size or balance percent, SL and TP by price or distance, breakeven, close all, partial close, pending orders set on the chart. Updated October 2026 (v1.1). Open source code.

ASQ Session Manager ASQ Session Manager

Institutional-grade forex session detection and analysis library for MetaTrader 5.

QuantumAlgo Trade Panel QuantumAlgo Trade Panel

QuantumAlgo Trade Panel is a professional-grade trading utility for MetaTrader 5, designed to bridge the gap between complex institutional strategies and seamless execution. Whether you are a Scalper, Swing Trader, or follow Smart Money Concepts, this panel automates your risk management and technical analysis, allowing you to focus purely on the setup.