This strategy identifies divergence opportunities between two correlated assets using a combination of Z-Score spread analysis, trend confirmation, RSI & MACD momentum checks, correlation filters, and ATR-based stop-loss/take-profit management. It’s optimized for positive P&L and realistic trade execution.
Key Features:
Pair Divergence Detection: Measures deviation between returns of two assets and identifies overbought/oversold spread conditions using Z-Score.
Trend Alignment: Trades only in the direction of the primary asset’s trend using a fast EMA vs slow EMA filter.
Momentum Confirmation: Confirms trades with RSI and MACD to reduce false signals.
Correlation Filter: Ensures the pair is strongly correlated before taking trades, avoiding noisy si…
This strategy identifies divergence opportunities between two correlated assets using a combination of Z-Score spread analysis, trend confirmation, RSI & MACD momentum checks, correlation filters, and ATR-based stop-loss/take-profit management. It’s optimized for positive P&L and realistic trade execution.
Key Features:
Pair Divergence Detection: Measures deviation between returns of two assets and identifies overbought/oversold spread conditions using Z-Score.
Trend Alignment: Trades only in the direction of the primary asset’s trend using a fast EMA vs slow EMA filter.
Momentum Confirmation: Confirms trades with RSI and MACD to reduce false signals.
Correlation Filter: Ensures the pair is strongly correlated before taking trades, avoiding noisy signals.
Risk Management: Dynamic ATR-based stop-loss and take-profit ensures proper reward-to-risk ratio.
Exit Conditions: Automatically closes positions when Z-Score normalizes, or ATR-based exits are hit.
How It Works:
Calculate Returns: Computes returns for both assets over the selected timeframe.
Z-Score Spread: Calculates the spread between returns and normalizes it using moving average and standard deviation.
Trend Filter: Only takes long trades if the fast EMA is above the slow EMA, and short trades if the fast EMA is below the slow EMA.
Momentum Confirmation: Confirms trade direction with RSI (>50 for longs, <50 for shorts) and MACD alignment.
Correlation Check: Ensures the pair’s recent correlation is strong enough to validate divergence signals.
Trade Execution: Opens positions when Z-Score crosses thresholds and all conditions align. Positions close when Z-Score normalizes or ATR-based SL/TP is hit.
Plot Explanation:
- Z-Score: Blue line shows divergence magnitude.
- Entry Levels: Red/Green lines mark long/short thresholds.
- Exit Zone: Gray lines show normalization zone.
- EMA Trend Lines: Purple (fast), Orange (slow) for trend alignment.
- Correlation: Teal overlay shows current correlation strength. Usage Tips: Use highly correlated pairs for best results (e.g., EURUSD/GBPUSD). Run on higher timeframe charts (1h or 4h) to reduce noise. Adjust ATR multiplier based on volatility to avoid premature stops. Combine with alerts for automated notifications or webhook execution.
Conclusion:
The Profitable Pair Correlation Divergence Scanner v6 is designed for traders who want systematic, low-risk, positive P&L trading opportunities with minimal manual monitoring. By combining trend alignment, momentum confirmation, correlation filters, and dynamic exits, it reduces false signals and improves execution reliability.
Run it on TradingView and watch how it captures divergence opportunities while maintaining positive P&L across trades.
//@version=6
strategy("Profitable Pair Correlation Divergence Scanner v6",
overlay=false,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=10,
commission_type=strategy.commission.percent,
commission_value=0.02)
// INPUTS
sym1 = input.symbol("OANDA:EURUSD", "Primary Asset")
sym2 = input.symbol("OANDA:GBPUSD", "Secondary Asset")
corrLen = input.int(50, "Correlation Length")
zLen = input.int(30, "Z-Score Length")
entryZ = input.float(1.0, "Z Entry Threshold")
exitZ = input.float(0.1, "Z Exit Threshold")
atrLen = input.int(14, "ATR Length")
atrMult = input.float(1.5, "ATR Multiplier for SL/TP")
fastEMA = input.int(20, "Fast EMA")
slowEMA = input.int(50, "Slow EMA")
rsiLen = input.int(14, "RSI Length")
macdFast = input.int(12, "MACD Fast Length")
macdSlow = input.int(26, "MACD Slow Length")
macdSig = input.int(9, "MACD Signal Length")
// DATA
s1 = request.security(sym1, timeframe.period, close)
s2 = request.security(sym2, timeframe.period, close)
// RETURNS
ret1 = ta.roc(s1, 1)
ret2 = ta.roc(s2, 1)
// NORMALIZED SPREAD
spread = ret1 - ret2
spreadMA = ta.sma(spread, zLen)
spreadSD = ta.stdev(spread, zLen)
zScore = (spread - spreadMA) / spreadSD
// TREND FILTER
emaFast = ta.ema(s1, fastEMA)
emaSlow = ta.ema(s1, slowEMA)
trendLong = emaFast > emaSlow
trendShort = emaFast < emaSlow
// RSI CONFIRMATION
rsiVal = ta.rsi(s1, rsiLen)
rsiLong = rsiVal > 50
rsiShort = rsiVal < 50
// MACD CONFIRMATION
[macdLine, signalLine, _] = ta.macd(s1, macdFast, macdSlow, macdSig)
macdLong = macdLine > signalLine
macdShort = macdLine < signalLine
// CORRELATION FILTER
corrVal = ta.correlation(ret1, ret2, corrLen)
corrFilter = corrVal > 0.5
// ATR FOR SL/TP
atrVal = ta.atr(atrLen)
sl = atrVal * atrMult
tp = atrVal * atrMult * 2 // reward > risk
// ENTRY CONDITIONS
longCond = zScore < -entryZ and trendLong and rsiLong and macdLong and corrFilter
shortCond = zScore > entryZ and trendShort and rsiShort and macdShort and corrFilter
exitLong = math.abs(zScore) < exitZ
exitShort = math.abs(zScore) < exitZ
// EXECUTION
if (longCond)
strategy.entry("LongSpread", strategy.long)
if (shortCond)
strategy.entry("ShortSpread", strategy.short)
if (exitLong)
strategy.close("LongSpread")
if (exitShort)
strategy.close("ShortSpread")
// ATR-BASED EXIT
strategy.exit("Exit Long", "LongSpread", stop=close - sl, limit=close + tp)
strategy.exit("Exit Short", "ShortSpread", stop=close + sl, limit=close - tp)
// PLOTTING
plot(zScore, "Z-Score", color=color.new(color.blue, 0))
hline( entryZ, "Upper Entry", color=color.red)
hline(-entryZ, "Lower Entry", color=color.green)
hline( exitZ, "Exit Zone", color=color.gray)
hline(-exitZ, "Exit Zone", color=color.gray)
plot(emaFast, "Fast EMA", color=color.new(color.purple, 0))
plot(emaSlow, "Slow EMA", color=color.new(color.orange, 0))
plot(corrVal, "Correlation", color=color.new(color.teal, 40))