거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
Experts

Basket Pair Closer - MetaTrader 5용 expert

Cristhian Alexander Gaibor Cuasquer
Cristhian Alexander Gaibor Cuasquer
4.9 (30)
2017년부터 트레이더이자 MQL5 회원입니다.
9년 동안, 대부분 XAUUSD 차트 앞에서 보낸 뒤, 제가 실제 매매에서 쓰는 도구들을 공개하기로 했습니다. 팔기 위해 만든 것은 하나도 없습니다. 모두 제게 필요해서 만들었습니다. 더 명확한 차트 해석, 모든 거래를 위한 계획, 정직한 통계, 통제된 리스크, 그리고 휴대폰으로 오는 알림입니다.
조회수:
109
게시됨:
업데이트됨:
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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 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: 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 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 MACD Signals

Indicator edition for new platform.