Guardian Grid MT5
- 专家
- 版本: 1.1
- 激活: 10
Guardian Grid
Multi-module Expert Advisor with grid trade management for EURUSD H1. The MetaTrader 4 and MetaTrader 5 versions have the same logic; the MT5 version works only on a hedging account.
The first order is opened on a signal from one of 18 entry modules: nine Price Action candlestick patterns and nine indicator rules. If the price moves against the position, the EA adds grid orders with a growing lot to the basket and closes the whole basket at a common target.
The EA panel lets you set the lot, grid, exit targets, time (including the broker server time zone), trading direction, which entry modules are enabled, and controls (close all orders, chart button, breakeven lines).
The EA was tested on EURUSD H1 on 2010–2026 history with real-account costs: swap BUY −6.74, SELL +1.43 points per lot per night, commission of 5 USD per lot round turn. MT4 — Strategy Tester in "Every tick" mode (modelling quality 99.90%), variable spread, slippage of ±5 points. MT5 — Strategy Tester on real ticks (Dukascopy).
Features:
18 entry modules: Pin Bar, Engulfing, Full Engulfing, Marubozu, Doji, Morning / Evening Star, Gap, Rising Sun / Dark Cloud, Spinning Top, Trending, Keltner, DMI, CCI, RSI, Parabolic SAR, Stochastic, Bollinger Bands, Envelopes.
Entry selection by module priority: if there is a signal in both directions, the side of the higher-priority module is opened.
Grid with a growing lot: each next order is larger than the previous one by an increment — fixed or calculated from the balance (auto lot).
Wider grid step from a set basket order (default — 12 pips from the 9th order): a long move against the position is covered with fewer orders.
Grid order inside the bar (enabled by default): from the 9th basket order the next order is opened on any tick as soon as the price has moved 15 pips, without waiting for a new bar. The first basket orders are placed on the first tick of a bar.
Fixed lot (default: first order 0.01, increment 0.02) or auto lot — the UseAutoLot switch.
Auto lot: the lot is calculated from the balance, with limits on the first lot, the increment, the lot of one order and (optionally) the balance the lot is calculated from.
A grid order above the per-order lot limit (a large order) is opened in parts (enabled by default): a grid order larger than the maximum lot of one order (MaxOrderLot, or the broker's maximum if it is lower) is opened as several orders, so the lot proportions in the basket — and with them the basket target and closing moment — do not depend on the balance size.
Three exit conditions: single-order target (on every tick); common basket target — by price, excluding swap (on the first tick of a bar; from a set basket order on — a lower target, by default 1 pip instead of 5 from the 3rd order); basket profit as a percentage of the balance — 25% by default, this profit includes swap and commission (on every tick).
Basket loss stop (on by default): the basket is closed when its loss, including swap and commission, reaches a set share of the balance — 50% by default; checked on every tick, trading continues after the close.
Tick exit for a large grid (optional): a grid of a set number of orders or more is closed on any tick as soon as the price returns to the basket average price, excluding swap (or moves beyond it into profit by a set number of pips, excluding swap).
Entry filters: market direction, market regime by ADX, monthly hour window for the Trending module (configurable, can be disabled).
Broker time zone: all hours in the settings are set in base time — GMT+2 in winter and GMT+3 in summer on the US schedule (New York + 7 hours, 00:00 is the New York close). The EA converts the server time to base time itself from the server's winter GMT offset and the broker's summer-time schedule (default: GMT+2 with the European switch) and recalculates the shift when summer time starts or ends. The H4 direction for the Trending and Doji modules is calculated on 4-hour blocks of base time; while there is too little history for them (the first days of a test), the terminal's H4 chart is used.
Delayed trading start on Monday. On Friday at a set time (23:50 by default, before the market closes) the basket is checked: a basket in profit by price is closed, excluding swap; if the price has moved one step against it, a new grid order is opened; no new baskets until Monday.
Trading direction: both sides, BUY only or SELL only.
Account check at startup (the "account check" line in the journal): Expert Advisors allowed by the broker on the account — otherwise the EA does not start on a real account; AutoTrading enabled; symbol trade mode; margin of a 21-order basket at the current lot — a warning if at a floating loss of 45% of the balance the margin level is below 150%; leverage, Stop Out level and swaps are written to the journal. MT5 also checks: hedging account (the EA does not start on a netting account; in the tester it runs with single orders, without the grid), market orders allowed for the symbol, the symbol volume limit, the FIFO rule — with it the basket is closed from the oldest positions to the newest.
On the first tick of a real account the EA compares the server time with the time zone settings and warns about a mismatch; in MT4 the first tick also checks that trading in the symbol is open (no false alarm when the EA is started on a weekend, when the market is closed).
Free margin check before every order (for a grid order opened in parts — before each part) and a check of the broker's limit on the number of orders; the basket close is repeated until the basket is fully closed.
Broker trading session: while trading in the symbol is closed (daily break, Friday close, Sunday evening), the EA sends neither new orders nor closes — everything is checked on the first tick inside the session, and instead of server rejections the journal gets one line per bar.
Repeated refusals (no margin, order limit) and send errors are written to the journal.
Close all EA orders and stop trading — with a panel input or with a chart button (with confirmation).
Closing by the FIFO rule (UseFIFOClose): the basket and "close all" close from the oldest orders to the newest — for brokers with this rule; with false, MT5 follows the account property, and MT4 switches to this order itself after a broker refusal (error 150).
Basket lines on the chart: breakeven (including swap and commission), target and tick exit (by price).
Input check at startup; the module that opened the first order is written to the journal.
Recommendations:
Symbol and timeframe: EURUSD H1, both sides. On a chart above H1 — single orders without a grid.
Settings for EURUSD H1 — the defaults: step 5 pips, from the 9th order 12 pips and an in-bar grid order every 15 pips, target 5 pips, 1 pip from the 3rd order, trading window by the broker, Friday check at 23:50. Lot — fixed (first order 0.01 and increment 0.02 per every 10,000 of deposit) or auto lot: UseAutoLot = true, LotStartDivisor = 10000, LotIncDivisor = 5000.
Time zone: set your broker's server time (see the contract specification or Market Watch): BrokerGMTWinter — the GMT offset in winter, BrokerSummerTime — the summer-time schedule. Examples: GMT+2 / +3 with the European switch — 2 and Europe (default); London — 0 and Europe; GMT+2 / +3 with the US switch equals base time — UseTimeShift can be turned off. The time shift works on M1 … H1 charts; on higher charts the hours are server time.
Trading window — your broker's EURUSD trading session (00:15–23:55 broker time in the tests).
Brokers: ECN brokers, low spread and commission, leverage 1:500 on the whole basket volume. Many brokers lower the leverage for a large open volume (for example, 1:200 above 2 million USD, 1:100 above 7 million USD), and also before weekends and around news. At the worst point of history the basket held about 4.4 lots per every 10,000 of deposit, so for an account above 40,000 check the margin against your broker's table: cap the balance used for the lot (EnableLotBalanceCap, LotBalanceCap) or raise the divisors. The EA writes the margin of a 21-order basket to the journal at startup.
Hedging account only.
Trading conditions: ranging market. The main risk is a long one-way move without pullbacks: the basket keeps growing until the price returns. Protection — the basket loss stop (EnableLossStop, 50% of the balance by default).
There is no stop loss or take profit on the orders: the EA closes the basket — at the target, on profit relative to the balance or by the loss stop (a loss of 50% of the balance by default). To close everything manually, use the chart button or the CloseAllAndStop input.
The basket target is calculated by price, excluding swap. The EURUSD BUY swap is negative, so a BUY basket held for weeks may close at its target with a small loss. This is intended: waiting for the price to cover the swap as well keeps the basket open longer and raises the risk.
Minimum deposit:
Conservative risk (recommended): 10,000 per every 0.01 of the first lot and 5,000 per every 0.01 of the increment — fixed lot 0.01 / 0.02 per 10,000, or auto lot LotStartDivisor = 10000, LotIncDivisor = 5000.
High risk: 5,000 per every 0.01 of the first lot and 2,500 per every 0.01 of the increment (LotStartDivisor = 5000, LotIncDivisor = 2500). This is the same grid with twice the lot per dollar of deposit: the trades in money are the same, the profit and the drawdown in percent are twice as large. The loss stop (50% of the balance by default) triggers more often at high risk: on history the high-risk drawdown exceeded 50% in some years.
Parameters:
All switches are true / false; modes with several values are selected from a list: TradeDirection — both directions, BUY only, SELL only; BrokerSummerTime — no summer time, Europe, USA.
SetupName: set name, shown in the first line of the panel, in the journal and on the chart.
LOT
UseAutoLot: auto lot — lot from the balance; false (default) — fixed lot.
FixedFirstLot: fixed lot of the first order (default 0.01).
FixedLotIncrement: fixed increment — how much larger each next grid order is than the previous one (default 0.02).
LotStartDivisor: auto lot — balance amount per every 0.01 lot of the first order.
StartLotMaxLimit: auto lot — maximum lot of the first order.
LotIncDivisor: auto lot — balance amount per every 0.01 lot by which the next grid order is larger than the previous one.
IncLotMaxLimit: auto lot — maximum lot increment to the next grid order.
MaxOrderLot: maximum lot of one order.
SplitLotAboveMax: a grid order whose lot exceeds the maximum of one order (MaxOrderLot, or the broker's maximum if it is lower) is opened as several orders with one comment: full ones at the maximum, the last one with the remainder. For the basket this is one grid order: the order number, the step, the next order lot and the exit are counted for it as a whole. If disabled, the grid order lot is cut to the maximum, and as the balance grows the last orders of a large basket get a smaller share than the lot ladder intends: the basket average price is farther from the current price, the target is higher, and the basket closes later than it would on a smaller balance. The first order is not split.
EnableLotBalanceCap: auto lot — cap the balance the lot is calculated from.
LotBalanceCap: auto lot — the balance used for the lot is not above this amount if the cap is enabled; for example, when everything above this amount is withdrawn or the broker lowers the leverage for a large volume.
GRID
GridStepPips: grid step — how many pips the price must move against the last basket order for the next one to open.
WideStepFromOrder: basket order number from which the grid step is wider; 0 — off, GridStepPips everywhere.
WideStepPips: grid step from that order on, in pips; for example, with WideStepFromOrder = 9 orders 2–8 are placed at GridStepPips, the ninth and further ones at WideStepPips.
MaxTrades: maximum number of orders in a basket.
MaxSlippagePoints: maximum slippage, in points.
IntraBarKnee: open a grid order on any tick as soon as the price has moved one step; false — only on the first tick of a bar.
IntraBarStepPips: grid step inside a bar, in pips; 0 — the grid step (GridStepPips or WideStepPips).
IntraBarFromOrder: basket order number from which IntraBarKnee applies (2 — from the second).
TickExitOn: tick exit of a large grid inside a bar; false — the grid is closed only on the first tick of a bar.
TickExitFromOrder: basket order number from which the tick exit applies, not less than 2.
TickExitPips: how many pips the price must move beyond the basket average price into profit; 0 — breakeven by price.
EXIT
FirstOrderProfitPips: single-order target, in pips; checked on every tick.
GridBasketProfitPips: grid target — basket profit reduced to the first order lot, in pips; checked on the first tick of every bar.
UseLowerGridTarget: lower grid target from a set basket order; false — GridBasketProfitPips everywhere.
GridDeepFromOrder: basket order number from which the lower grid target applies — 2 or more; 0 — off.
GridDeepProfitPips: lower grid target from that order, pips per first order lot; for example, with GridDeepFromOrder = 3 a basket of two orders closes at GridBasketProfitPips, of three or more — at GridDeepProfitPips. A basket that falls short of its target on the first tick of a bar waits for the next bar; the lower target reduces the risk that during that hour the price starts a long move against the basket.
EnableProfitSpike: close the basket when its profit reaches a set share of the balance.
ProfitSpikePct: basket profit threshold, % of the balance.
EnableLossStop: close the basket when its loss (including swap and commission) reaches a set share of the balance; checked on every tick, trading continues after the close; on by default.
LossStopPct: basket loss threshold, % of the balance (default 50).
UseFIFOClose: close the basket orders and all orders by the button from the oldest to the newest (FIFO rule); false — MT5 follows the account property, MT4 closes as usual and after a broker refusal under the FIFO rule (error 150) — from the oldest to the newest.
TIME & DIRECTION
UseTimeShift: the hours in the settings below are in base time (GMT+2 in winter / GMT+3 in summer on the US schedule), and the EA converts the server time to it; false — the hours are taken as server time as is. Works on M1 … H1 charts).
BrokerGMTWinter: broker server time in winter — GMT plus this many hours (for example, 2 for GMT+2, 0 for London).
BrokerSummerTime: broker server summer time (+1 hour): no summer time — none; Europe — from the last Sunday of March to the last Sunday of October; USA — from the second Sunday of March to the first Sunday of November.
UseTradingWindow: daily trading window — outside it the EA neither opens nor closes orders (broker trading session); the exit and grid order of a bar that started outside the window are checked on the first tick inside it.
TradingStartTime / TradingEndTime: window start and end, HH:MM (end excluded), in base time (server time if UseTimeShift = false); default 00:15–23:55. If the start is later than the end, the window spans midnight.
UseMondayDelay: delayed trading start on Monday — before the start time there are no new entries or grid orders; closing works.
MondayStartTime: Monday start time, HH:MM.
UseFridayStop: basket check on Friday at a set time, as on the first tick of a new bar: a basket in profit by price (the sum of lot × points from the open price is above zero, excluding swap and commission) is closed; otherwise the normal grid exit is checked and, if the price has moved one grid step from the last order, a new grid order is opened; from this time no new baskets are opened until Monday.
FridayStopTime: Friday check time, HH:MM; default 23:50 — 10 minutes before the New York close (24:00 base time). Set it slightly before the symbol's market close at your broker.
TradeDirection: trading direction — both sides, BUY only or SELL only.
UseTrendingHours: monthly hour window for the Trending module; false — Trending at any hour.
TrendingHoursJan … TrendingHoursDec: Trending window for each month in the "from-to" format (base time; server time if UseTimeShift = false); the end hour is not included; "23-01" — across midnight, "00-24" — the whole day, "-" — no window.
ENTRY MODULES (by priority)
UseTrending, UsePinBar, UseEngulfing, UseFullEngulfing, UseMarubozu, UseDoji, UseStar, UseGap, UseRisingSun, UseSpinningTop, UseKeltner, UseDMI, UseCCI, UseRSI, UsePSAR, UseStochastic, UseBollinger, UseEnvelopes: enable the entry module.
CONTROL & CHART
CloseAllAndStop: close all EA orders (this symbol and Magic Number) and stop trading until the input is set back to false.
ShowCloseButton: "Close all EA orders" button on the chart: the first click arms it for 5 seconds, the second closes all orders and stops trading, the next one resumes trading; the stop is kept after a terminal restart; the button does not work in the tester.
ShowBasketLines: show the basket lines on the chart: breakeven (the price at which the result including swap and commission is zero), the exit target and the tick exit (by price, excluding swap).
OTHER
MagicNumber: magic number of the EA orders.
LogEntryModule: write to the journal which module opened the first order.
Order comments: GG_1 — the first basket order, GG_2, GG_3… — grid orders; a grid order opened in parts (SplitLotAboveMax) is several orders with one comment.
