The **Pairs Trading Cointegration Pro Suite** is an institutional-grade, high-performance statistical arbitrage trading suite comprising four advanced indicators:
Based on Modern Portfolio Theory and econometric cointegration, the suite decomposes the pricing relationship of two correlated assets into a stationary, volatility-normalized spread.
While traditional retail pairs trading methods rely on simple price correlation (which is highly unstable and prone to structural drift), this suite utilizes a dynamic rolling **Ordinary Least Squares (OLS) mathematical engine**. It dynamically calculates the rolling Hedge Ratio ($\beta$) and Intercept ($\alpha$) between any two assets to extract the true stationary spread.
### The Single-Symbol Paradigm & O(1) Memory Access
To maximize trading speed and simplify execution panels, the suite automatically determines **Symbol A** from the chart's native symbol (`_Symbol`). The trader only needs to input **Symbol B** (`InpSecondSymbol`) on the parameters window.
By binding Symbol A strictly to the current chart, the calculation engine accesses prices directly via the native `close[]` array inside the `OnCalculate()` function. This completely eliminates $O(N)$ lookup overheads (like `iBarShift` and `iClose`) for Symbol A, reducing tick processing time to a true $O(1)$ constant time complexity.
The statistical calculations operate on synchronized close prices for Asset $A$ ($P_{A,t}$, representing the native `_Symbol`) and Asset $B$ ($P_{B,t}$, representing `InpSecondSymbol`) over an active rolling or anchored window of size $N$ (`window_size`):
The calculator computes the rolling mean of Asset $A$ ($\bar{A}$) and Benchmark $B$ ($\bar{B}$). It solves the OLS regression of $A$ on $B$ to find the dynamic Hedge Ratio ($\beta$) and Intercept ($\alpha$):
The spread at each bar $t$ within the window is calculated. Because we subtract the OLS intercept ($\alpha_i$), the rolling mean of this spread over the window is **algebraically guaranteed to be exactly 0.0**:
The final Z-Score is calculated, representing how many standard deviations the current spread has drifted away from its statistical equilibrium of $0.0$:
By rearranging the spread equation back to the price space of Asset $A$ (the chart's active symbol), the suite projects the dynamic statistical boundaries as a 7-channel corridor directly onto the main price chart:
### C. Core Entry Bands (Z = +-2.0 / Outer Channel)
Statistically represents a 95.4% probability of price containment under a normal distribution. This is the optimal entry boundary for statistical arbitrage:
### D. Extreme Stop-Out Bands (Z = +-2.5 / Capitulation Channel)
A high-volatility cushion representing a 98.8% probability limit. Reaching this zone suggests a severe cointegration breakdown or macro capitulation. Useful for absolute stop-losses or hyper-aggressive reversal entries:
## 4. The Statistically Pure Cutoff (Session-Start Noise Filtering)
When employing session anchors (`ANCHOR_SESSION` or `ANCHOR_CUSTOM_SESSION`), the active window size resets to 1 at the beginning of each active period and increments bar-by-bar.
During the first 14 bars of a session, running OLS is statistically invalid due to severe degrees-of-freedom limitations. Calculating standard deviations on 3, 5, or 8 samples yields highly erratic, spiked, and squeezed channels that create false signals and compress the chart's vertical scale.
### A. The EMPTY_VALUE Cutoff Solution
To maintain institutional quantitative standards, the bands **strictly enforce a 15-bar minimum cutoff**.
* **The Rule:** If $N_{\text{active}} < 15$ or standard deviation is $\le 0$, all 7 band buffers are populated with `EMPTY_VALUE`.
* **The Visual Benefit:** Instead of collapsing the channels onto the raw price line (which creates a messy, overlapping web of lines at the start of every session), the channels simply remain invisible during the initialization phase, rendering only when the mathematical model has stabilized.
### B. Standard vs. MTF Cutoff Widths
You will observe that Multi-Timeframe (MTF) charts display a wider blank zone at the beginning of each session compared to standard single-timeframe charts. This is a mathematically correct scaling consequence:
* On a local **M15** chart, 15 bars require exactly **3.75 hours** of market activity to stabilize.
* On an **H1 (MTF)** chart, 15 bars require exactly **15 hours** of market activity to stabilize.
* Because the higher timeframe requires longer historical duration to construct its OLS sample pool, the MTF version correctly maintains a wider blank zone, shielding the trader from pre-stabilization noise on the macro level.
When trading in a Multi-Timeframe (MTF) environment (e.g. tracking $M5$ cointegration on an $M1$ chart), a distinct structural divergence occurs between the main-chart bands and the separate-window oscillator:
You may observe the lower timeframe price (M1) pierce the M5 outer band on the main chart, while the separate-window MTF Z-Score remains neutral (Gray).
* **The Reason:** The main chart compares the **live, real-time lower-timeframe price ($P_{A, \text{ltf}}$)** against the static higher-timeframe band. If the price spikes violently during the 5-minute interval, it will visually pierce the band. However, the **Pure MTF Oscillator** computes the Z-Score using the **closed higher-timeframe price ($P_{A, \text{htf}}$)**. Since the 5-minute candle hasn't closed yet or its average close is lower, the pure HTF Z-Score remains neutral.
* **Pure MTF (Default):** Calculates everything strictly on the higher timeframe. It provides the highest statistical stability and filters out intraday/micro-timeframe false breakouts.
* **Hybrid MTF (Optional Custom Setup):** Uses the higher timeframe's stable structural parameters ($\beta_{\text{htf}}$, $\alpha_{\text{htf}}$, and $\sigma_{\text{spread, htf}}$), but computes the Z-Score numerator using the live lower-timeframe price ($P_{A, \text{ltf}}$).
*Under this hybrid model, the separate window Z-Score is mathematically guaranteed to cross the $\pm 2.0$ boundaries at the exact second the price pierces the bands on the main chart.*
* **Comparison Symbol (`InpSecondSymbol`):** The benchmark asset to correlate with (Symbol B). Symbol A is automatically set to the chart's native `_Symbol`.
To ensure statistical validity, only trade assets that share a **fundamental, structural, or macroeconomic link**. Below are the most robust, cointegrated global pairs optimized for live execution, mapped in `PairsTrading_Preset_Manager.mqh` (Symbol A is set as the chart's main active asset):