당사 팬 페이지에 가입하십시오
- 조회수:
- 109
- 게시됨:
- 업데이트됨:
-
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

A grid or martingale basket on Gold (XAUUSD), forex or indices usually carries one position deep in profit and one deep in loss at the same time. This EA pairs them: it finds the best winner and the worst loser, adds profit, swap and commission, and when the combined result reaches your minimum it closes both, winner first to lock the gain. It never opens a trade.
The filter decides what it manages: the chart symbol or all symbols, one magic number or every position, manual trades included, so it runs next to any grid EA or cleans a basket you built by hand. Two optional basket rules close everything at once: a take profit and a stop loss in account currency. Every close is checked by return code and retried after a pause.
The panel is plain on purpose: positions, floating result, best and worst tickets, the pair sum against your minimum and a strip that turns green when a pair is ready, with buttons to close the pair, close all or pause. It trims exposure trade by trade. It does not turn a losing basket into a winning one by itself.
Settings
- Enable pair close: turns the pair logic on or off.
- Minimum combined profit of the pair (money): the pair closes when winner plus loser, swap and commission included, is at least this value. 0 closes at break even. Default 0.50.
- Minimum open positions before acting: the pair logic waits until this many managed positions are open. Default 2.
- Enable basket take profit and Basket take profit (money): close every managed position when the total floating result reaches this value. Off by default.
- Enable basket stop loss and Basket stop loss (money, positive number): close everything when the total floating result falls to minus this value. 50 means close at -50. Off by default.
- Magic number to manage: 0 manages every position, manual trades included. Set the magic of your grid EA to manage only its basket.
- Manage the chart symbol only: true limits the EA to the chart symbol. Set it to false to manage positions on all symbols from one chart, which is also what a netting account needs, since one symbol holds a single position there.
- Pause between close actions (seconds): wait after a close before the next action so the terminal and the broker settle. Default 3.
- Max deviation (points): slippage allowed on market close orders.
- Show panel, Panel X offset, Panel Y offset, Panel font size: panel on or off and its position and size.
How to use it
Attach it to one chart of the symbol whose basket you want to manage. Any timeframe works, the EA runs on every tick and on a one second timer, so the chart period does not matter. Use one instance per symbol, or one instance with the chart symbol filter off to cover the whole account. The single symbol pair logic needs a hedging account, because it closes a buy and a sell, or two trades of the same side, that live together on one symbol. On a netting account use the all symbols mode.
Before running it on a live account test it in the strategy tester in visual mode: open three or four positions by hand, watch the strip turn green when the pair sum passes your minimum and check the log, every close is printed with the ticket numbers and the combined result.
Make it yours
The pair logic is isolated in two functions, XP_FindPair and XP_ClosePair, so you can lift it straight into your own grid or martingale EA. Natural extensions are one winner against two losers, pairing by lot size instead of money, a trailing basket take profit, a session filter or an equity based pause. It works next to XANDER Grid XAUUSD (magic 2001), XANDER Gold Recovery, any martingale EA or your manual scalping on gold, EURUSD, GBPUSD, US30 or NAS100. Keep your own entries, Smart Money Concepts, support and resistance or whatever you trade, and let this one handle the exits of the basket.
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: XANDER Grid XAUUSD, XANDER Gold Recovery, XPro Trade Panel.
The overlap idea comes from Grid EA Pro by Nguyen Nghiem Duy (MQL5 Code Base, 2020). This code is rewritten from scratch for MT5 as a standalone position manager.
Changelog
v1.0 (2026-10-25): initial release.
Cointegration: ADF, Engle-Granger and Johansen tests with a pair scanner
Unit root and cointegration tests (ADF, Engle-Granger, Johansen) with MacKinnon p-values, hedge ratio, half-life and z-score of the spread, and a pair scanner.
Kalman: exact diffuse Kalman filter, local level and time-varying hedge ratio
Kalman filter and smoother with an exact diffuse start, missing values and maximum likelihood: local level, local linear trend and a regression whose hedge ratio drifts.
DataSnooping: SPA test, Reality Check, StepM and model confidence set
Is the best of many strategies really better than the benchmark? Hansen's SPA test, White's Reality Check, Romano-Wolf StepM and the model confidence set.
MACD Signals
Indicator edition for new platform.