Join our fan page
- Views:
- 166
- Rating:
- Published:
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
A grid expert advisor for Gold (XAUUSD) that starts each basket on an RSI signal: when RSI comes back above the oversold level it opens a buy, when it comes back below the overbought level it opens a sell, always on a closed candle. A Reverse switch flips both signals if you trade the other way.
While a basket is open and price moves against it, the EA adds a new level every set distance in points, with a lot multiplier and a maximum number of levels. The first lot can be fixed or sized from a percent of balance or equity. The whole basket closes together at a target in money or in points from the average price, with an optional basket stop loss and an optional trading hours filter.
Be clear about what this is: a grid with a lot multiplier and no stop loss on each position. Margin use grows with every level, and a long move against the basket can take a large part of the account when the basket stop is off. Run it in the Strategy Tester first and size the lot, the step and the number of levels to your own account. No result is promised.
Settings
Strategy
- RSI period (14) and RSI applied price (Close).
- Oversold level (30): a buy basket starts when RSI comes back above it.
- Overbought level (70): a sell basket starts when RSI comes back below it.
- Reverse signals (false): buy at overbought and sell at oversold instead.
- Only one direction open at a time (true): no sell basket while a buy basket is running, and the other way around.
Lot settings
- Lot mode (Fixed lot): or Percent of balance, or Percent of equity.
- Fixed lot (0.01) and Percent used to size the first lot (0.5): in percent mode the first lot uses that share of balance or equity as margin.
- Lot multiplier per grid level (1.5): 1.0 keeps the same lot on every level.
- Maximum grid levels per direction (8).
- Distance between levels (400 points).
Close / Exit
- Basket take profit mode (Money): or Points from the average price.
- Basket take profit (5.0): money in the account currency, or points.
- Close the basket on the opposite signal (false).
Risk protection
- Use a basket stop loss (false) and Basket stop loss (50, money): closes the whole basket when its loss reaches that amount.
- Maximum positions of this EA at the same time (16).
Filters
- Use the time filter (false), Start hour (8) and End hour (20), server time. The window can cross midnight. Outside it no basket starts and no level is added, while open baskets keep being managed.
Expert settings
- Magic number (2610251), Order comment (XanderGridRSI), Max slippage (30 points), Show status on chart (true).
What it needs
- MetaTrader 5 with Algo Trading enabled and a hedging account. On a netting account the levels merge into one position and the grid does not work as designed.
- Distances are in points, so check the digits of your symbol. On a gold quote with 2 decimals 400 points are 4.00 in price, with 3 decimals they are 0.40.
- It only manages positions with its own magic number on the chart symbol, so it can run next to other EAs and manual trades.
Make it yours
The whole entry lives in one function, XP_Signal(), which returns 1 for buy, -1 for sell and 0 for nothing. Replace it with any other indicator and you keep the same grid, lot sizing and basket exits with MACD, Bollinger Bands or Stochastic. Run your own backtest on XAUUSD, EURUSD, GBPUSD and BTCUSD, compare the steps and multipliers, and keep the basket stop on until you know how deep your settings can go. For partial exits on single trades, pair it with my Partial Close Multi TP Manager.
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
Provided as is, use at your own risk.
Related
Changelog
- v1.0 - 2026-10-25 - Initial release
Trade Manager Utility
Manages positions that are already open: it adds a missing SL/TP, moves the stop to break even, trails it, caps the position count and applies daily equity limits. It never opens trades.
Session Range Breakout
Draws the high and low of a chosen time window and alerts on the first break on each side. The levels are also available through iCustom.
Trade Journal Exporter - closed trades to CSV, one row per position, with MFE/MAE, R multiple and session
Exports your closed trade history to a CSV file with one row per position (not per deal), ready for Excel, Python or any journal. Each row has ticket, symbol, magic number, comment, side, volume, entry and exit time and price, duration, initial SL and TP when known, gross profit, commission, swap, net result and R multiple. It also calculates MFE and MAE (best and worst price reached while the trade was open, in points and in money) from the M1 bars between entry and exit, plus the entry session (Asia, London, New York) and weekday. Filter by magic number (lists and ranges) and symbol (wildcards), pick the period, the column separator (; or ,) and the decimal mark, and save to MQL5\Files or the common folder. Tested on hedging accounts and in the Strategy Tester (netting logic included; feedback welcome), where the file is written when the test ends. Read-only: it never opens, modifies or closes a trade. No DLLs, no web requests.
Daily Loss Guard - daily loss and total drawdown limits for funded / prop-firm accounts
Utility Expert Advisor that watches the account equity against two limits: a maximum daily loss and a maximum total drawdown. Each limit can be set as a percentage or as a money amount, and the daily loss can be measured from the balance or from the equity at the start of the day, as many prop firms do. When a limit is touched the EA closes all positions, deletes all pending orders and keeps the account locked until the next trading day: anything opened in the meantime, by another EA or by hand, is closed again. Optional early warning at a percentage of the limit (Alert and push), a small on-chart panel, a magic number / symbol filter, a configurable day-reset time and retries when a close fails. The state is stored in terminal global variables, so a restart does not unlock the account. Works on hedging and netting accounts. No DLLs, no web requests. It never opens trades (only the optional Strategy Tester demo mode does).