Skip to main content

Cross-Market & Arbitrage Tools

Building crypto arbitrage indicators, market regime filters, multi-timeframe regime filters, and getting the spread between instruments.

From Thrive on YouTube

Watch the matching Thrive video

Watch the series
Isolated vs Cross Margin: Which Should You Use and When

Isolated vs Cross Margin: Which Should You Use and When

Part of Start Here: Crypto Futures Basics. Education only. Not financial advice.

Building a Crypto Arbitrage Indicator

Price discrepancies between exchanges exist constantly in crypto. Binance BTCUSDT might trade at $65,210 while Coinbase BTC-USD shows $65,245. These spreads widen during high-volatility events and can signal which exchange is leading price discovery. Using request.security() with explicit exchange tickers, you can monitor these spreads directly on your chart.

The syminfo namespace provides metadata about the current symbol: exchange name, ticker, base currency, quote currency, and more. Use these to build indicators that dynamically adapt to whatever pair you are viewing.

pine-Cross-exchange spread monitor
1//@version=5
2indicator("Exchange Spread Monitor", overlay=false)
3
4// Compare BTC prices across three exchanges
5binancePrice = request.security("BINANCE:BTCUSDT", "", close)
6coinbasePrice = request.security("COINBASE:BTCUSD", "", close)
7bybitPrice = request.security("BYBIT:BTCUSDT", "", close)
8
9// Calculate spreads as percentage
10avgPrice = (binancePrice + coinbasePrice + bybitPrice) / 3
11spreadBnCb = (binancePrice - coinbasePrice) / avgPrice * 100
12spreadBnBy = (binancePrice - bybitPrice) / avgPrice * 100
13spreadCbBy = (coinbasePrice - bybitPrice) / avgPrice * 100
14
15// Plot spreads
16plot(spreadBnCb, "BN-CB Spread %", color.blue, 2)
17plot(spreadBnBy, "BN-BY Spread %", color.orange, 2)
18plot(spreadCbBy, "CB-BY Spread %", color.purple, 1)
19hline(0, "Zero", color.new(color.gray, 70))
20
21// Alert on extreme divergence (arb opportunity)
22maxSpread = math.max(math.abs(spreadBnCb),
23 math.abs(spreadBnBy), math.abs(spreadCbBy))
24bgcolor(maxSpread > 0.15 ? color.new(color.yellow, 85) : na)
25
26alertcondition(maxSpread > 0.15, "Wide Spread Alert",
27 "Exchange spread exceeds 0.15%: potential arb")
syminfo.tickerid

Full ticker including exchange prefix (e.g., "BINANCE:BTCUSDT")

syminfo.ticker

Just the symbol name without exchange (e.g., "BTCUSDT")

syminfo.basecurrency

The base asset (e.g., "BTC" from BTCUSDT)

syminfo.currency

The quote currency (e.g., "USDT" from BTCUSDT)

syminfo.type

Instrument type: "crypto", "stock", "futures", "forex"

syminfo.timezone

Exchange timezone string for session calculations

Market Regime Filter: Trending vs Ranging

The number one reason indicators fail in practice is that they are designed for one market condition but used in another. A moving average crossover prints perfect signals in a trending market but gets destroyed by whipsaws in a range. A market regime filter uses ADX (Average Directional Index) combined with a volatility measure to classify the current environment. Your other indicators should only generate signals when the regime supports their logic.

pine-ADX + volatility regime filter
1//@version=5
2indicator("Market Regime Filter", overlay=false)
3
4adxLen = input.int(14, "ADX Length")
5adxThresh = input.float(25.0, "ADX Trending Threshold")
6atrLen = input.int(14, "ATR Length")
7atrMaLen = input.int(50, "ATR MA Length (volatility baseline)")
8
9// ADX calculation
10[diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)
11
12// Volatility: current ATR vs its own moving average
13atr = ta.atr(atrLen)
14atrMA = ta.sma(atr, atrMaLen)
15volRatio = atr / atrMA
16
17// Regime classification
18isTrending = adx > adxThresh
19isHighVol = volRatio > 1.2
20isLowVol = volRatio < 0.8
21
22regime = isTrending and isHighVol ? 3 : // Strong trend
23 isTrending and not isHighVol ? 2 : // Moderate trend
24 not isTrending and isHighVol ? 1 : // Volatile range
25 0 // Quiet range
26
27// Visual output
28plot(adx, "ADX", color.white, 2)
29hline(adxThresh, "Trend Threshold", color.new(color.yellow, 50))
30plot(volRatio * 20, "Vol Ratio (scaled)", color.new(color.orange, 30), 1)
31
32regimeColor = switch regime
33 3 => color.new(color.green, 80)
34 2 => color.new(color.green, 90)
35 1 => color.new(color.red, 85)
36 => color.new(color.gray, 90)
37bgcolor(regimeColor, title="Regime Background")

Using the regime filter

Use regime = 2 or 3 (trending) to enable trend-following strategies (MA crossovers, breakouts). Use regime = 0 (quiet range) for mean-reversion strategies (RSI bounces off extremes, Bollinger Band plays). Avoid trading regime = 1 (volatile range). This is the chop zone where both approaches lose money.

Multi-Timeframe Regime Filter

A regime filter on a single timeframe can flip-flop. Combining regime detection across multiple timeframes gives a more stable read. If the daily, 4H, and 1H all agree the market is trending, you have strong confirmation. If the daily says trending but the 1H says ranging, you may be in a pullback within a larger trend: a very different context.

pine-Multi-timeframe regime composite
1//@version=5
2indicator("MTF Regime Composite", overlay=false)
3
4adxLen = input.int(14, "ADX Length")
5threshold = input.float(25.0, "ADX Threshold")
6
7// Get ADX from three timeframes
8getAdx(tf) =>
9 request.security(syminfo.tickerid, tf,
10 ta.dmi(adxLen, adxLen)[2], // [2] returns the ADX component
11 lookahead=barmerge.lookahead_off)
12
13adx1h = getAdx("60")
14adx4h = getAdx("240")
15adxD = getAdx("D")
16
17// Composite: count how many timeframes are trending
18trendCount = (nz(adx1h) > threshold ? 1 : 0) +
19 (nz(adx4h) > threshold ? 1 : 0) +
20 (nz(adxD) > threshold ? 1 : 0)
21
22// Plot each ADX
23plot(nz(adx1h), "ADX 1H", color.blue, 1)
24plot(nz(adx4h), "ADX 4H", color.orange, 1)
25plot(nz(adxD), "ADX 1D", color.purple, 2)
26hline(threshold, "Threshold", color.new(color.yellow, 60))
27
28// Background: green when 2+ TFs trending
29bgCol = trendCount >= 3 ? color.new(color.green, 85) :
30 trendCount == 2 ? color.new(color.green, 92) :
31 trendCount == 1 ? color.new(color.red, 92) :
32 color.new(color.red, 85)
33bgcolor(bgCol, title="Regime BG")

Spread Between Two Instruments

Tracking the spread between two crypto assets reveals relative strength, pairs trading opportunities, and macro rotations. The ETH/BTC ratio tells you whether capital is flowing toward altcoins or back to Bitcoin. A rising SOL/ETH ratio signals Solana outperformance. Building a spread indicator in PineScript requires fetching both prices and computing the ratio or difference.

pine-ETH/BTC ratio with trend analysis
1//@version=5
2indicator("ETH/BTC Ratio Analysis", overlay=false)
3
4ethPrice = request.security("BINANCE:ETHUSDT", "", close)
5btcPrice = request.security("BINANCE:BTCUSDT", "", close)
6
7// Ratio: how many BTC per 1 ETH
8ratio = ethPrice / btcPrice
9
10// Trend analysis on the ratio itself
11ratioEma = ta.ema(ratio, 21)
12ratioBull = ratio > ratioEma
13
14plot(ratio, "ETH/BTC", ratioBull ? color.green : color.red, 2)
15plot(ratioEma, "Ratio EMA 21", color.gray, 1)
16
17// Z-score: how far from mean (identifies extremes)
18ratioMean = ta.sma(ratio, 100)
19ratioStd = ta.stdev(ratio, 100)
20zScore = (ratio - ratioMean) / ratioStd
21
22plot(zScore, "Z-Score", color.orange, 1, display=display.pane)
23
24alertcondition(zScore > 2, "ETH Overvalued vs BTC",
25 "ETH/BTC ratio z-score above 2: ETH relatively expensive")
26alertcondition(zScore < -2, "ETH Undervalued vs BTC",
27 "ETH/BTC ratio z-score below -2: ETH relatively cheap")

Correlation Indicators

PineScript's built-in ta.correlation() computes the Pearson correlation coefficient between two series over a rolling window. A value of +1 means perfect positive correlation (assets move together), -1 means perfect inverse correlation, and 0 means no relationship. In crypto, BTC and ETH typically correlate above 0.8, but when this drops, it signals a regime change or sector rotation.

pine-Rolling correlation between BTC and altcoins
1//@version=5
2indicator("Crypto Correlations", overlay=false)
3
4corrLen = input.int(30, "Correlation Window", minval=10)
5
6btcClose = request.security("BINANCE:BTCUSDT", "", close)
7ethClose = request.security("BINANCE:ETHUSDT", "", close)
8solClose = request.security("BINANCE:SOLUSDT", "", close)
9
10// Compute rolling correlations vs BTC
11corrEth = ta.correlation(btcClose, ethClose, corrLen)
12corrSol = ta.correlation(btcClose, solClose, corrLen)
13corrEthSol = ta.correlation(ethClose, solClose, corrLen)
14
15plot(corrEth, "BTC-ETH Corr", color.blue, 2)
16plot(corrSol, "BTC-SOL Corr", color.purple, 2)
17plot(corrEthSol, "ETH-SOL Corr", color.orange, 1)
18hline(0.8, "High Corr", color.new(color.green, 70))
19hline(0, "Zero", color.new(color.gray, 70))
20hline(-0.5, "Inverse", color.new(color.red, 70))
21
22// Alert: correlation breakdown (decorrelation = rotation underway)
23alertcondition(corrEth < 0.5, "BTC-ETH Decorrelation",
24 "BTC and ETH correlation dropped below 0.5")

BTC Dominance Overlay

BTC dominance measures Bitcoin's market cap as a percentage of total crypto market cap. Rising dominance means money is flowing from altcoins back to BTC (risk-off). Falling dominance means capital is rotating into altcoins (risk-on, alt season). TradingView provides BTC.D as a tradeable symbol, which you can overlay on any chart.

pine-BTC dominance overlay with regime detection
1//@version=5
2indicator("BTC Dominance Overlay", overlay=false)
3
4btcDom = request.security("BTC.D", "D",
5 close[1], lookahead=barmerge.lookahead_on)
6btcDomEma = request.security("BTC.D", "D",
7 ta.ema(close, 21)[1], lookahead=barmerge.lookahead_on)
8
9domRising = btcDom > btcDomEma
10
11plot(btcDom, "BTC.D", domRising ? color.orange : color.blue, 2)
12plot(btcDomEma, "BTC.D EMA21", color.gray, 1)
13
14// Regime label
15bgcolor(domRising ? color.new(color.orange, 90) : color.new(color.blue, 90))
16
17if barstate.islast
18 label.new(bar_index, btcDom,
19 domRising ? "BTC Dom Rising\nRisk-Off" : "BTC Dom Falling\nAlt Season",
20 color=domRising ? color.new(color.orange, 20) : color.new(color.blue, 20),
21 textcolor=color.white, style=label.style_label_left,
22 size=size.normal)

Complete Build: Cross-Market Dashboard

This dashboard consolidates cross-market data into a single table: BTC dominance direction, ETH/BTC ratio trend, market-wide volatility state, and correlation readings. It gives you the macro context you need before deciding whether to go long altcoins, stick with BTC, or reduce exposure entirely.

pine-Cross-market dashboard (complete)
1//@version=5
2indicator("Cross-Market Dashboard", overlay=true)
3
4// Data collection (8 security calls total)
5btcClose = request.security("BINANCE:BTCUSDT", "D",
6 close[1], lookahead=barmerge.lookahead_on)
7ethClose = request.security("BINANCE:ETHUSDT", "D",
8 close[1], lookahead=barmerge.lookahead_on)
9solClose = request.security("BINANCE:SOLUSDT", "D",
10 close[1], lookahead=barmerge.lookahead_on)
11btcDom = request.security("BTC.D", "D",
12 close[1], lookahead=barmerge.lookahead_on)
13
14[btcEma, btcAtr] = request.security("BINANCE:BTCUSDT", "D",
15 [ta.ema(close, 21)[1], ta.atr(14)[1]],
16 lookahead=barmerge.lookahead_on)
17btcDomEma = request.security("BTC.D", "D",
18 ta.ema(close, 21)[1], lookahead=barmerge.lookahead_on)
19
20// Derived metrics
21ethBtcRatio = ethClose / btcClose
22corrEthBtc = ta.correlation(ethClose, btcClose, 30)
23btcTrend = btcClose > btcEma
24domRising = btcDom > btcDomEma
25volState = btcAtr / btcClose * 100
26
27if barstate.islast
28 t = table.new(position.top_right, 2, 6,
29 bgcolor=color.new(#0d0b14, 10),
30 border_width=1, border_color=color.new(color.gray, 70))
31
32 table.cell(t, 0, 0, "Metric", text_color=color.gray, text_size=size.small)
33 table.cell(t, 1, 0, "Status", text_color=color.gray, text_size=size.small)
34
35 table.cell(t, 0, 1, "BTC Trend", text_color=color.white, text_size=size.small)
36 table.cell(t, 1, 1, btcTrend ? "▲ Bullish" : "▼ Bearish",
37 text_color=btcTrend ? color.green : color.red, text_size=size.small)
38
39 table.cell(t, 0, 2, "BTC.D", text_color=color.white, text_size=size.small)
40 table.cell(t, 1, 2, domRising ? "Rising" : "Falling",
41 text_color=domRising ? color.orange : color.blue, text_size=size.small)
42
43 table.cell(t, 0, 3, "ETH/BTC", text_color=color.white, text_size=size.small)
44 table.cell(t, 1, 3, str.tostring(ethBtcRatio, "#.#####"),
45 text_color=color.white, text_size=size.small)
46
47 table.cell(t, 0, 4, "BTC-ETH Corr", text_color=color.white, text_size=size.small)
48 corrCol = corrEthBtc > 0.8 ? color.green :
49 corrEthBtc > 0.5 ? color.yellow : color.red
50 table.cell(t, 1, 4, str.tostring(corrEthBtc, "#.##"),
51 text_color=corrCol, text_size=size.small)
52
53 table.cell(t, 0, 5, "BTC Volatility", text_color=color.white, text_size=size.small)
54 volCol = volState > 3 ? color.red : volState > 1.5 ? color.yellow : color.green
55 table.cell(t, 1, 5, str.tostring(volState, "#.##") + "%",
56 text_color=volCol, text_size=size.small)

Actionable reading

When BTC is trending bullish, BTC.D is falling, and BTC-ETH correlation is high. This is prime alt season. Go heavy on ETH and SOL. When BTC is bearish and BTC.D is rising, rotate to stablecoins or BTC-only. When correlation breaks down, sector rotation is underway: analyze individual altcoin strength rather than trading the basket.

Put this lesson to work

Free on Thrive, no account needed.