bg c grid ea

bg c grid ea
Download ALL MT5 experts (1593)
YouTube Video Thumbnail



Similar MetaTrader Tools

bg c grid ea

Info

The bg c grid ea is a Expert Advisor for MetaTrader 5 that overviewthis expert advisor implements a regime-aware, restartable grid-trading system based on the bi-directional grid constrained (bgc) stochastic process research. the research proves that naive grids lead to ruin, but finite cycles with regime-gating can transform grid trading into a viable strategy with positive expected value under specific conditions.

Usage

This tool is typically used for automated trading on major forex pairs and gold.

Platform

This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use bg c grid ea

1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.

2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.

3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.

4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.

Frequently Asked Questions

Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.

Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.

Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.

What this tool does

overviewthis expert advisor implements a regime-aware, restartable grid-trading system based on the bi-directional grid constrained (bgc) stochastic process research.

Typical Use Case

This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.

Description & Settings

Related: xander grid ea for xauusd (mt5) - another powerful expert for MetaTrader 5 traders.

overview

this expert advisor implements a regime-aware, restartable grid-trading system based on the bi-directional grid constrained (bgc) stochastic process research. the research proves that naive grids lead to ruin, but finite cycles with regime-gating can transform grid trading into a viable strategy with positive expected value under specific conditions.

Also recommended: rs i grid ea pro: advanced rsi-based grid trading system - similar expert with strong performance on MetaTrader 5.


the ea operates in short, restartable cycles, each with an anchor price, a grid, and active supervision. cycles close when profit targets, drawdown thresholds, age limits, or weekend rules trigger, then restart at current market conditions, resetting variance and exposure.

three grid algorithms are employed:

bgt (bi-directional grid trading)
- places buy and sell orders at each level, designed for ranging markets.

tgt (trending grid trading)
- places stop orders in the trend direction with no per-trade take profit, activating during detected trends.

mgt (mean-reversion grid trading)
- places counter-trend limit orders with take profit toward the anchor, capturing post-trend reversions.

mode selection is automatic, based on volatilitygate (atr/drift ratio) and cpdengine (cusum structural break detector).


recommended setup

setting
recommended value
notes
symbol
xauusd (gold)
primary development instrument. adaptable to any symbol.
chart timeframe
m1 (1-minute)
for tick-level execution. regime detection uses higher timeframes (default h4 and d1).
account type
hedged
required for simultaneous long/short positions and closeby shutdown.

important:
always test on a demo account. grid trading involves risk. the research demonstrates potential and limitations. past performance is not indicative of future results.

key features

regime detection and mode switching

volatilitygate calculates sigma_t / mu_t ratio (atr vs. drift) with cooldown-based state transitions.
cpdengine uses frozen-baseline cusum for structural break detection.
three start gates prevent cycle deployment in unfavorable conditions.

adaptive grid infrastructure

atr-dynamic spacing adjusts grid width based on daily atr at each cycle.
equity-based dynamic lot sizing compounds or scales down base lot.
mild multiplier or stress-responsive dynamic lot mode for per-level sizing.

cycle management

equity-based drawdown kill switch with optional tighter mgt threshold.
profit-target basket close with automatic restart.
unconditional age-based restart (default 72 hours).
weekend flat close on friday with delayed monday restart.

diagnostics pipeline

csv logging of per-bar snapshots, per-cycle summaries, and event records.
l_t formula computation and ruin probability diagnostics.
two python scripts for post-run analysis and cross-run parameter calibration.

file structure

the ea consists of one main file, nine header modules, and two python scripts:

mql5 source files
file
role
description
gridea.mq5
orchestrator
main ea file for inputs, oninit/ontick/ondeinit, cycle policy, weekend rules, and module glue code.
defines.mqh
shared types
enums, structs, and constants.
gridcore.mqh
execution engine
order placement, sync, re-arm, and closeallpositions with closeby hedging.
lotengine.mqh
lot sizing
per-level lot calculation with mild multiplier and dynamic stress modes.
ltmonitor.mqh
risk diagnostics
l_t, weighted dollar loss, snapshot rpr, path-aware l_t, and ruin probability.
profitmonitor.mqh
profit logic
cycle profit calculation and target checks.
volatilitygate.mqh
regime filter
atr and drift computation, sigma_t/mu_t ratio, and state transitions.
cpdengine.mqh
break detector
frozen-baseline cusum for structural break detection.
statemanager.mqh
persistence
saves and loads cycle state with atr-dynamic mode tolerance.
diagnosticlog.mqh
csv logging
buffers barsnapshot, diagcyclesummary, and diageventrecord rows for csv output.
analyze_backtest.py
post-run analysis
loads csvs, prints analysis, runs bug checks, and generates charts.
calibrate_parameters.py
cross-run calibration
loads csvs, runs calibration passes for variance, profitability, and regime detection.

input parameters

the ea has 12 input groups. key parameters with defaults:

group
key parameters
defaults
grid structure
inpgridspacing, inpgridlevels, inpbaselot
500 pts, 8 levels/side, 0.01 lot
dynamic spacing
inpuseatrspacing, inpatrspacingtf, inpatrspacingmultiplier
true, d1, 0.12
dynamic lot sizing
inpusedynamicbaselot, inplotfraction
true, 0.000003
exit conditions
inpruinthreshold, inpprofittargetpercent, inpmaxcyclehours
0.25 (25%), 3.0%, 72 hours
regime detection
inpregimetf, inpminsigmamuratio, inpatrperiod, inpmaperiod
h4, 5.0, 14, 20
mode switching
inpenabletgt, inpenablemgt, inptgtsigmamuthreshold
true, true, 5.0
cpd
inpusecpd, inpcpdwindow, inpcpddelta, inpcpdthreshold
true, 50, 2.0, 15.0
weekend
inpenableweekendclose, inpfridayclosehour, inpmondayresumehour
true, 22, 1

note: disable free-margin closures if not needed.

research basis

the ea is based on academic research:

gambler's ruin problem and bi-directional grid constrained trading and investment strategies — imfi, 2026

drawdown and drawup of bi-directional grid constrained stochastic processes — jms, 2026

application of bi-directional grid constrained stochastic processes to algorithmic trading — jms, 2026

iterated logarithm bounds of bi-directional grid constrained stochastic processes — gsa, 2026

bi-directional grid constrained stochastic processes and their applications in mathematical finance — phd thesis, 2026

a companion article series explains the mathematical foundations and implementation.

You may also like: reversing grid on limit orders - excellent alternative for expert users on MetaTrader 5.

Source Code

#property copyright "robotfx"
#property version   "3.00"
#property strict
#include "defines.mqh"
#include "statemanager.mqh"
#include "lotengine.mqh"
#include "gridcore.mqh"
#include "ltmonitor.mqh"
#include "profitmonitor.mqh"
#include "volatilitygate.mqh"

.......

Leave your opinion, ask a question, share some knowledge

Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.