Trading robot · MT5

Advanced Grid Trading

by jepli-1225

Advanced Grid Trading is a MetaTrader 5 expert advisor that manages a complex grid strategy across four configurable layers.

High risk

GitHub stars2
Forks1
Last update6 months ago12 Mar 2026
LicenceNone stated

Overview

Advanced Grid Trading places stop and limit orders at fixed intervals, employing either fixed or geometric lot scaling for increased grid depth. Trade management includes a shared profit pool used to close losing positions once specific thresholds are met. The EA features a USD-based trailing profit system, optional profit locking, and lot size scaling tied to account growth. Risk controls involve session-based resets and breakeven exit logic.

Details

Author

jepli-1225 on GitHub

Type

Trading robot

Platform

MetaTrader 5 (MQL5)

Strategy

Grid, Martingale, Mean reversion, Hedging

Markets

Any symbol

Timeframes

Any timeframe

Risk profile

  • Uses martingale lot scaling: losses can grow fast
  • Opens a grid of orders: exposure builds up in a trend
  • Holds opposite positions at once
  • Trades without a fixed stop loss

Input parameters

Read from AdvancedGridTrading.mq5. Defaults are the author's; change them in the EA's Inputs tab.

NameTypeDefaultDescription
GridDistancePipsdouble2000.0Grid distance (pips)
MaxGridLevelsint40Max grid levels per side (above/below base line)
MagicNumberint123456Magic Number (AA=this, BB=this+1, CC=this+2, DD=this+3)
CommentOrderstringEA GridOrder comment (same for all)
EnableAAbooltrueEnable AA (Buy Stop + Sell Stop)
LotSizeAAdouble0.05AA: Lot size level 1
AALotScaleENUM_LOT_SCALELOT_GEOMETRICAA: Fixed / Geometric
LotMultAAdouble1.3AA: Lot multiplier for level 2+ (Geometric)
MaxLotAAdouble1.5AA: Max lot per order (0=no limit)
TakeProfitPipsAAdouble0.0AA: Take profit (pips; 0=off)
EnableBalanceAAByBBbooltrueAA: Balance when (pool + loss) >= 20 USD; cooldown 300s. Prepare at 3 levels, execute at 5
EnableBBbooltrueEnable BB (Buy Stop + Sell Stop)
Show all 40 inputs
NameTypeDefaultDescription
LotSizeBBdouble0.05BB: Lot size level 1
BBLotScaleENUM_LOT_SCALELOT_GEOMETRICBB: Fixed / Geometric
LotMultBBdouble1.3BB: Lot multiplier for level 2+ (Geometric)
MaxLotBBdouble1.5BB: Max lot per order (0=no limit)
TakeProfitPipsBBdouble2000.0BB: Take profit (pips; 0=off)
EnableBalanceBBbooltrueBB: Balance when (pool + loss) >= 20 USD; cooldown 300s. Prepare at 3 levels, execute at 5
EnableCCbooltrueEnable CC (Buy Stop + Sell Stop)
LotSizeCCdouble0.05CC: Lot size level 1
CCLotScaleENUM_LOT_SCALELOT_FIXEDCC: Fixed / Geometric
LotMultCCdouble1.3CC: Lot multiplier for level 2+ (Geometric)
MaxLotCCdouble2.0CC: Max lot per order (0=no limit)
TakeProfitPipsCCdouble2000.0CC: Take profit (pips; 0=off)
EnableBalanceCCbooltrueCC: Balance when (pool + loss) >= 20 USD; cooldown 300s. Prepare at 3 levels, execute at 5
EnableDDbooltrueEnable DD (Sell Limit above base + Buy Limit below base; no balance)
LotSizeDDdouble0.01DD: Lot size level 1
DDLotScaleENUM_LOT_SCALELOT_FIXEDDD: Fixed / Geometric
LotMultDDdouble1.3DD: Lot multiplier for level 2+ (Geometric)
MaxLotDDdouble1.5DD: Max lot per order (0=no limit)
TakeProfitPipsDDdouble2000.0DD: Take profit (pips; 0=off)
EnableTrailingTotalProfitbooltrueEnable trailing: cancel pending, move SL when open profit >= threshold
TrailingThresholdUSDdouble200.0Start trailing when open profit >= (USD)
TrailingDropModeENUM_TRAILING_DROP_MODETRAILING_MODE_RETURNWhen profit drops: Lock profit | Return to initial
TrailingDropPctdouble20.0% (both modes): trigger when profit drops X%. E.g. threshold 100 USD, 20% = trigger when drops to 80 USD
TrailingPointAPipsdouble1500.0Point A (pips): base = grid level closest to price at threshold. Buy: A = base + X pip; Sell: A = base - X pip. SL at A
GongLaiStepPipsdouble1000.0Pips: trailing step (price moves 1 step -> SL trails 1 step)
EnableResetAtBreakevenWhenNearBaseboolfalseBreakeven cut: max open level >= X levels and (open USD + closed TP minus lock) >= 0 -> Reset. Current session only
ResetBreakevenMaxLevelsFromBaseint10Min grid levels from base for open positions to apply breakeven reset (>= X levels)
EnableScaleByAccountGrowthbooltrueScale lot, TP, SL, trailing by % capital growth

How to install it

  1. 1Download the sourceUse "Download source (.zip)" above, or clone jepli-1225/AdvancedGridTrading from GitHub, and unzip it.
  2. 2Open the data folderIn MetaTrader choose File, then Open Data Folder, and go to MQL5/Experts.
  3. 3Copy the filesCopy the .mq5 file into Experts.
  4. 4Compile in MetaEditorOpen the file in MetaEditor and press Compile. Fix any missing includes the compiler reports.
  5. 5Test before you tradeRun it in the Strategy Tester, then attach it to a demo chart and allow algorithmic trading.
Third-party code. ForexR did not write, test or endorse this EA, and the summary above was generated automatically from its README and code. ForexR lists only repositories with readable source code and never hosts files. Read the code, backtest it and use a demo account first; automated trading can lose money quickly.

Similar expert advisors

AW Full Recovery EA

by wongthep
2 stars

This MetaTrader 5 expert advisor functions as a grid-based recovery system that can operate independently or manage trades from external EAs via magic number filtering. It initiates entries using Bollinger Bands and RSI indicators, then manages drawdown through a recovery grid matrix. The system employs dynamic ATR-bas

MT5 Trading robot GridMartingaleHedging High risk
Updated 3 months ago None stated GitHub repository of AW Full Recovery EA
2 stars

This MetaTrader 5 expert advisor implements a multi-layered grid strategy that manages up to three independent grids simultaneously on a single instrument. It uses the Relative Strength Index (RSI) across different timeframes to determine the initial trade direction for each grid. The EA employs martingale lot scaling,

MT5 Trading robot GridMartingaleMean reversion High risk
Updated 2 years ago None stated GitHub repository of Springfield 3 Grids
1 stars

This Expert Advisor for MetaTrader 5 focuses on gold trading through a combination of mean-reversion signals and a grid management system. It uses multi-timeframe filters, including exponential moving averages and ADX on the H1 timeframe, to identify trend direction while executing entries on M15 based on RSI and Bolli

MT5 Trading robot Mean reversionGridMartingale High risk

Icarus

by fraggli
7 stars

Icarus is an automated trading system for MetaTrader 4 that employs a grid strategy with Martingale lot scaling. It utilizes Bollinger Bands and the Stochastic Oscillator to identify entry points, offering a conjunctive mode for filtered execution. The EA manages risk through maximum position limits, equity warning thr

MT4 Trading robot GridMartingaleMean reversion High risk
Updated 4 years ago GPL-3.0 GitHub repository of Icarus

North East Way

by Yogurt-Peng
3 stars

This MetaTrader 4 robot implements a multi-currency mean-reversion strategy, targeting price returns to the average on correlated forex pairs. It manages trades using a grid system with a significant martingale multiplier to scale lot sizes. The expert advisor allows for simultaneous trading on multiple symbols to dive

MT4 Trading robot Mean reversionGridMartingale High risk
Updated 1 year ago None stated GitHub repository of North East Way

Blessing Three

by duanwujie
1 stars

This MetaTrader 4 expert advisor is an automated grid trading system that utilizes a variety of indicators including Moving Averages, CCI, Bollinger Bands, and MACD for trade entries. It employs a martingale-style lot multiplier to manage position sizing across sequential grid levels. The software includes risk control

MT4 Trading robot GridMartingaleIndicator crossover High risk
Updated 9 years ago None stated GitHub repository of Blessing Three

More trading robots

Need a broker for MT5?

Compare regulated brokers that support MetaTrader, with spreads, minimum deposits and leverage side by side.

Compare brokers