Smart Pair Trading — Input Parameters Guide

25 June 2026, 11:20
Sugianto
0
166

A detailed reference for every input of the Smart Pair Trading EA. This build adds symbol substitution, single-leg mode, lot-sizing modes, per-magic daily drawdown protection, string-based trading-time windows, unit-aware close targets, broker-visible SL/TP for single-leg mode, duplicate-position protection, and OHLC-style tick sampling.

What's New in v1.22

— Duplicate-position protection. After an EA restart / recompile / chart reload, the EA now re-adopts any live position tagged with its MagicNumber (rebuilding its state from the account) instead of assuming it is flat — closing the gap that could otherwise open a second trade on top of the old one. A defensive entry guard also refuses to open while a position with this magic already exists.

— Broker-visible SL/TP (single-leg mode). In single-leg mode (one LotSize = 0), the CloseProfit / CloseLoss targets can be written to the server as real SL/TP price levels via UseBrokerSLTP, so the protection survives even if the EA or terminal goes offline. Works for every CloseUnit. In pair mode the targets stay virtual, since a combined-money target cannot map to a single price.

— OHLC-style tick sampling. New input UseSecondGate evaluates the signal, entries and exits only at the M1-OHLC checkpoints (:00 / :20 / :40 / :59) instead of on every intrabar tick — sampling like MT5's "1 minute OHLC" backtest model and cutting intrabar noise. Safety layers still run on every tick.


Inputs (General)

MainSymbol (default: EURUSD) — The primary symbol, analyzed as leg A, the first side of the spread. The signal (correlation, OLS, Z-score) is always computed from this symbol.

SecondSymbol (default: XAUUSD) — The second symbol, analyzed as leg B. The EA hedges A against B, so the two should be correlated (or inversely correlated).

TradeSymbolA (default: empty) — Execute leg A on a different instrument than the one analyzed. Leave blank to trade MainSymbol itself. The statistical signal still comes from MainSymbol; only order routing, lots, margin, digits/slippage and market-open checks use this execution symbol. Useful for trading a CFD / mini / proxy while keeping the signal on the real pair.

TradeSymbolB (default: empty) — Same as above, for leg B. Blank = trade SecondSymbol itself.

LotSizeA (default: 0.04) — Lot size for leg A. Set to 0 to analyze only and NOT trade leg A (single-leg mode). In the auto lot modes this value instead serves as the A:B ratio rather than a fixed size. Automatically normalized to your broker's volume rules (min / step / max).

LotSizeB (default: 0.02) — Lot size for leg B. Set to 0 to analyze only and NOT trade leg B. At least one of LotSizeA / LotSizeB must be greater than 0. Ideally set so both legs are balanced (beta-weighted), keeping the spread market-neutral.

ShowPanel (default: false) — Show or hide the on-chart dashboard. Visual only; it does not affect trading.

CalcTF (default: M1) — The timeframe used for all calculations (correlation, OLS regression, Z-score). This is the data timeframe, not the chart timeframe.

ZPeriod (default: 1000) — Number of bars used to compute the mean, standard deviation, beta/alpha, and Z-score. Larger values are smoother and more stable but slower to react. Minimum 10 (the EA fails to initialize below this).


Money Management (Lot Sizing)

LotMode (default: Fixed lots) — How lot sizes are resolved. Fixed lots uses LotSizeA / LotSizeB as-is. Auto by free-margin scales both legs so the pair's total margin ≈ RiskPercent% of free margin. Per-balance scales both fixed lots by a balance-step multiplier. All three modes preserve the LotSizeA:LotSizeB ratio.

RiskPercent (default: 5.0) — [Auto-margin mode only] Percentage of free margin used as the margin budget for one pair. The EA sizes both legs so the pair's total margin ≈ RiskPercent% of current free margin, keeping the A:B ratio intact. Range 0.1–100. Removes the need to re-tune lots when the account size changes.

BalanceStepForLot (default: 1000.0) — [Per-balance mode only] Each block of this much balance adds +1× of the fixed lots. Example: at 1000 per step, a 3000 balance trades 3× the fixed lots. Both legs grow together as the account grows.

LotPerBalanceUseEquity (default: false) — [Per-balance mode only] Size from current equity instead of balance.


Daily Drawdown Protection

UseDailyDD (default: false) — Enable the per-magic daily maximum-drawdown guard. When the day's loss reaches the limit, all floating positions are cut at market and trading is paused for the rest of the server day. It auto-resets and resumes the next day. The trigger state is persisted in terminal global variables, so an EA/terminal restart cannot lift an active pause.

MaxDailyDDPercent (default: 15.0) — Daily loss limit as a percentage of the day-start equity or balance (see DailyDDBasis). 0 = off. The loss itself is counted per-magic (this EA's realized + floating P/L only); other EAs / manual trades on the account are not counted.

MaxDailyDDMoney (default: 0.0) — Daily loss limit in account currency. 0 = off. If both the percent and money limits are set, the tighter one applies.

DailyDDBasis (default: Equity) — The day-start reference for the percent limit. Equity = balance + floating P/L at day start. Balance = realized only (floating ignored at day start).


Entries / Exits

EntryThreshold (default: 1.92) — The Z-score level required to open a position. When |Z| ≥ this value, the spread is considered stretched enough to enter. Recommended range 1.5–2.0. Higher = more selective.

ExitThreshold (default: 0.9) — The Z-score level for a normal exit (full mean-reversion). When |Z| falls to ≤ this value, the trade is closed. Must be smaller than EntryThreshold (otherwise the EA fails to initialize).

BetaSmoothing (default: 0.2) — EMA smoothing factor applied to the Z-score to reduce noise and false signals. 0 = off (raw Z), 0.1–0.5 = light-to-moderate smoothing. (Despite the name, this is a smoothing coefficient, not the regression beta.)

UseSecondGate (default: false) — [v1.22] OHLC-style tick sampling. When enabled, the EA evaluates the signal, entries and exits only at the M1-OHLC checkpoints — :00, :20, :40 and :59 seconds of each minute — instead of on every intrabar tick. This makes live / real-tick behavior sample like MT5's "1 minute OHLC" backtest model and cuts intrabar noise. The safety layers (daily drawdown, Friday close, daily close, orphan-leg sync, market gate) still run on every tick regardless of this setting.


Correlation Filter

MinCorrelation (default: 0.80) — Minimum correlation between the two symbols required to allow a trade. Below this, entries are blocked — preventing trades when the relationship weakens. Range 0.5–1.

UseReturnsForCorr (default: false) — Compute correlation from log-returns instead of price levels. A short, dedicated window then captures recent co-movement rather than long-run noise.

CorrPeriod (default: 100) — Number of bars used for returns-based correlation. Ignored while UseReturnsForCorr = false.

UseAbsoluteCorr (default: true) — Use the absolute value of correlation. When true, a strong negative correlation (e.g. −0.85) still counts as valid — useful for pairs that move in opposite directions (such as EURUSD vs XAUUSD).


Risk / Logistics

MagicNumber (default: 2026) — Unique ID tagging this EA's positions, so they are never confused with manual trades or other EAs. Also the key used by the daily-drawdown guard, restart reconciliation, and the duplicate-position guard.

SlippagePoints (default: 30) — Maximum allowed slippage on execution (in points). Automatically multiplied by 10 for 3/5-digit symbols (3-digit gold, 5-digit forex).

CloseTarget (default: 5) — The "Smart Exit" — closes early once the Z-score has converged part of the way from entryZ back toward zero. Range 1–9: 1 = exit very early (90% of |entryZ| remaining), 5 = mid-way (50%), 9 = very late (10% remaining).

CloseProfit (default: 0.0) — Take-profit for the pair's combined P/L, expressed in the CloseUnit unit. 0 = off.

CloseLoss (default: 0.0) — Stop-loss for the pair's combined P/L, expressed in the CloseUnit unit. 0 = off. Recommended to set a value for live trading.

CloseUnit (default: Account currency) — The unit for CloseProfit / CloseLoss. Account currency (money), Points (auto-adjusted for 3-digit gold / 5-digit FX), % of account balance, or % of instrument price (of the reference leg). Point/price-percent targets are converted to money using the reference leg.

CloseRefLeg (default: Leg A) — [Points / % price only] Which leg (A or B) is the price/value reference when converting a points or %-of-price close target into money. Falls back to the other traded leg in single-leg mode.

UseBrokerSLTP (default: true) — [v1.22] [single-leg mode only] Also place CloseProfit / CloseLoss on the broker as real SL/TP price levels on the single open position. A pair trade's combined-money target cannot map to one price, so this only applies when exactly one leg is traded (the other LotSize = 0). Works for every CloseUnit: the target is converted to money, then to a price distance on the traded leg. Distances are widened to the broker's minimum stop level when needed. The benefit: protection survives even if the EA or terminal goes offline. In pair mode the targets remain virtual (monitored by the EA).

SecondsWaitAfterClose (default: 600) — Mandatory pause (in seconds) after any close before a new trade may open. 600 = 10 minutes. Range 0–86400.

SecondsWaitAfterLoss (default: 60) — Extra rest (in seconds) applied specifically after a losing close. It runs in parallel with SecondsWaitAfterClose (not added on top), so after a loss the effective pause is the longer of the two. Range 0–3600.


Trading Time Settings

All four times are HH:MM strings in server time. Set any of them to "00:00" to disable that particular cutoff.

InpDailyStartTime (default: 01:15) — Server time to START allowing new entries each day.

InpDailyPauseTime (default: 20:00) — Server time to STOP new entries each day (existing positions are still managed).

InpPendingCloseTime (default: 20:45) — Server time to CLOSE any open positions and stop entries for the rest of the day. Trading resumes the next day.

InpFridayCloseTime (default: 18:00) — Friday server time to stop trading into the weekend. Once reached, the stop stays in force through Saturday and Sunday and lifts automatically on Monday. Being purely time-based, an EA/terminal restart over the weekend keeps the stop in force.

InpCloseFridayPositions (default: true) — Also close open positions at the Friday cutoff. When false, the EA only blocks new entries and lets existing positions keep running.


Dashboard

FontSize (default: 15) — Dashboard font size in points. Cosmetic only.


Built-in Safeguards (automatic, not inputs)

These behaviors are always active and shape how the inputs play out:

  • Dual-symbol market gate — the EA only trades when the required leg(s)' markets are open, avoiding the "Market closed" leg failure on Monday reopen. In single-leg mode only the traded instrument's market must be open.
  • Retry brake — a failed open/close locks the candle and starts the cooldown, so the EA can't spam rejected orders every tick.
  • Affordability (margin) guard — entries are skipped cleanly if free margin can't cover both legs, preventing "No money" rejects.
  • Verified close — the pair is marked flat only after both legs are confirmed closed; if a leg's market is shut, the close is deferred and retried, so positions are never orphaned.
  • Orphan-leg sync — every tick, if one leg of a pair was closed externally, the surviving leg is closed to stay flat.
  • Symbol substitution — analyze one pair but execute on proxy instruments via TradeSymbolA / TradeSymbolB; substitute trades take the same side as the leg they replace.
  • Restart reconciliation (v1.20) — after an EA restart / recompile / chart reload, any live position tagged with this MagicNumber is re-adopted (state rebuilt from the account) instead of being treated as flat.
  • Duplicate-position guard (v1.20) — the EA refuses to open a new trade while the account already holds a position with this magic; on any state desync it re-syncs rather than stacking a duplicate.

This guide reflects the Smart Pair Trading EA up to version 1.22. Core behavior (signal, correlation filter, lot modes, daily DD, time windows) is unchanged from prior versions; v1.22 only add extra protection and sampling controls.