Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Institutional StatArb and Cointegration Spread Z-Score - indicator for MetaTrader 5

Amanda V | KayruYuta
Published by:
Amanda Vitoria De Paula Pereira
Views:
334
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The Flaw in Directional Trading & Simple Correlation

Most retail algorithms attempt to predict directional market moves, exposing capital to unpredictable macroeconomic shocks. To mitigate this, some traders use simple "Correlation" across pairs (e.g., EURUSD vs GBPUSD). However, correlation is a flawed metric for trading because two assets can be highly correlated while their spread diverges indefinitely.

Print


The Institutional Edge: Cointegration & StatArb

Top-tier quantitative hedge funds operate Market Neutral portfolios through Statistical Arbitrage (StatArb). Instead of predicting direction, they rely on Cointegration—a mathematical property ensuring that the spread between two historically linked assets will eventually revert to its mean.

The Institutional StatArb Spread Z-Score brings this advanced portfolio mathematics directly to your MQL5 terminal.


Core Quantitative Architecture

  • Logarithmic Spread Calculation: The engine does not simply subtract prices. It calculates the natural logarithm differential ( Log(Asset A) - Log(Asset B) ) to normalize volatility across instruments with different pricing scales (e.g., Gold vs. Silver).

  • Dynamic Spread Z-Score: It applies a rolling standard deviation (Z-Score) to the spread. This unbound metric reveals exactly how many standard deviations the current spread has strayed from its historical baseline.

  • Multi-Asset Time Synchronization: Native MQL5 handling perfectly synchronizes the time-series data between the chart symbol and the secondary injected symbol, ensuring accurate tick-by-tick spread calculation even if one asset has missing broker data.


How to Execute a Pairs Trade (Market Neutral)

  1. Attach the Indicator: Place it on an asset (e.g., AUDUSD ) and input the naturally cointegrated pair in the settings (e.g., NZDUSD ).

  2. Identify Divergence: Wait for the Spread Z-Score to breach the critical extremes (e.g., +2.5 or -2.5 ).

  3. Execute the Arbitrage:

    • If Z-Score hits +2.5 (Spread is too wide): Sell Asset A and Buy Asset B.

    • If Z-Score hits -2.5 (Spread is too narrow): Buy Asset A and Sell Asset B.

    • Close both legs simultaneously when the Z-Score returns to 0.0 (The Mean).

XANDER Pulse Candles XANDER Pulse Candles

Color your candles by momentum state. Four bias levels + neutral — built for dark charts.

Half Line For Exit 123 Half Line For Exit 123

Using arrow to open a position and the middle line to exit from the position that is currently open.

Precision Sniper Precision Sniper

Precision Sniper is a multi-confluence MT5 indicator inspired by TradingView's top signal tools, grading every buy/sell signal (A+, A, B, C) based on EMA structure, RSI, MACD, ADX, VWAP, and volume alignment, with 8 presets, HTF bias confirmation, auto TP/SL levels, trailing stop, and a built-in backtest dashboard.

MACD Signals MACD Signals

Indicator edition for new platform.