Pairs Spread ZScore
- Indicatori
-
Alexey Nazarov
MQL4/MQL5 developer with 10+ years of hands-on trading experience. I build Expert Advisors, indicators and scripts for your strategy: trend, grid, martingale, breakout, multi-currency. I implement logic based on ICT/SMC, Elliott Wave, divergences and liquidity levels. Track record: 3 products on - Versione: 1.0
- Attivazioni: 5
How it works The indicator builds a normalized spread between the base symbol and a second symbol (Symbol2) using a rolling lookback window (Period). Both price series are standardized before the spread is calculated, so the result is a dimensionless Z-Score that is comparable across different instruments regardless of their absolute volatility or price scale.
When the Z-Score moves beyond the entry threshold, the spread is considered statistically stretched. A long spread setup (long the base symbol, short the second symbol) forms when the Z-Score drops below the negative entry level; a short spread setup (short the base symbol, long the second symbol) forms when it rises above the positive entry level. The setup is considered closed when the Z-Score reverts toward zero (exit threshold). A stop threshold defines how far the spread can stretch before the statistical assumption behind the setup is treated as broken.
Hedge ratio panel A second part of the indicator is a lot-sizing panel. It calculates the dollar volatility of each leg (price standard deviation multiplied by contract size) and derives the lot ratio needed to balance the dollar risk between the two legs — this matters when the contract sizes of the two instruments differ. The panel displays the suggested lot for the second instrument based on the base lot you enter.
How to execute a signal This is an indicator, not an Expert Advisor — it does not place any trades by itself. To act on a signal, two opposite positions need to be opened together. On a buy spread signal: buy the base symbol using your base lot, and sell the second symbol using the lot size shown on the panel. On a sell spread signal: sell the base symbol using your base lot, and buy the second symbol using the panel lot. Both positions are managed as one position pair and closed together — either on an exit signal or when the stop threshold is reached.
Inputs
- Symbol2 — second instrument used to build the spread (default: ETHUSD)
- Period — rolling window length for the Z-Score calculation
- EntryZ / ExitZ / StopZ — entry, exit and stop thresholds in Z-Score units
- ChartArrows, BuyColor, SellColor, ExitColor, ArrowSize — visual signal settings
- ShowPanel, BaseLot, LotStep2, PanelFS — hedge ratio panel settings
Recommendations The indicator is built for symbols that historically move together (correlated or cointegrated pairs). It does not predict direction on its own — it measures how far the relationship between two instruments has deviated from its recent average, which is one input among several a trader should weigh before opening a position. Test it in the Strategy Tester's visual mode on your own symbols and timeframe before using it on a live chart; results on historical data do not guarantee future results.

