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
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.
1//@version=52indicator("Exchange Spread Monitor", overlay=false)34// Compare BTC prices across three exchanges5binancePrice = request.security("BINANCE:BTCUSDT", "", close)6coinbasePrice = request.security("COINBASE:BTCUSD", "", close)7bybitPrice = request.security("BYBIT:BTCUSDT", "", close)89// Calculate spreads as percentage10avgPrice = (binancePrice + coinbasePrice + bybitPrice) / 311spreadBnCb = (binancePrice - coinbasePrice) / avgPrice * 10012spreadBnBy = (binancePrice - bybitPrice) / avgPrice * 10013spreadCbBy = (coinbasePrice - bybitPrice) / avgPrice * 1001415// Plot spreads16plot(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))2021// 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)2526alertcondition(maxSpread > 0.15, "Wide Spread Alert",27 "Exchange spread exceeds 0.15%: potential arb")Full ticker including exchange prefix (e.g., "BINANCE:BTCUSDT")
Just the symbol name without exchange (e.g., "BTCUSDT")
The base asset (e.g., "BTC" from BTCUSDT)
The quote currency (e.g., "USDT" from BTCUSDT)
Instrument type: "crypto", "stock", "futures", "forex"
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.
1//@version=52indicator("Market Regime Filter", overlay=false)34adxLen = 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)")89// ADX calculation10[diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)1112// Volatility: current ATR vs its own moving average13atr = ta.atr(atrLen)14atrMA = ta.sma(atr, atrMaLen)15volRatio = atr / atrMA1617// Regime classification18isTrending = adx > adxThresh19isHighVol = volRatio > 1.220isLowVol = volRatio < 0.82122regime = isTrending and isHighVol ? 3 : // Strong trend23 isTrending and not isHighVol ? 2 : // Moderate trend24 not isTrending and isHighVol ? 1 : // Volatile range25 0 // Quiet range2627// Visual output28plot(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)3132regimeColor = switch regime33 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
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.
1//@version=52indicator("MTF Regime Composite", overlay=false)34adxLen = input.int(14, "ADX Length")5threshold = input.float(25.0, "ADX Threshold")67// Get ADX from three timeframes8getAdx(tf) =>9 request.security(syminfo.tickerid, tf,10 ta.dmi(adxLen, adxLen)[2], // [2] returns the ADX component11 lookahead=barmerge.lookahead_off)1213adx1h = getAdx("60")14adx4h = getAdx("240")15adxD = getAdx("D")1617// Composite: count how many timeframes are trending18trendCount = (nz(adx1h) > threshold ? 1 : 0) +19 (nz(adx4h) > threshold ? 1 : 0) +20 (nz(adxD) > threshold ? 1 : 0)2122// Plot each ADX23plot(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))2728// Background: green when 2+ TFs trending29bgCol = 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.
1//@version=52indicator("ETH/BTC Ratio Analysis", overlay=false)34ethPrice = request.security("BINANCE:ETHUSDT", "", close)5btcPrice = request.security("BINANCE:BTCUSDT", "", close)67// Ratio: how many BTC per 1 ETH8ratio = ethPrice / btcPrice910// Trend analysis on the ratio itself11ratioEma = ta.ema(ratio, 21)12ratioBull = ratio > ratioEma1314plot(ratio, "ETH/BTC", ratioBull ? color.green : color.red, 2)15plot(ratioEma, "Ratio EMA 21", color.gray, 1)1617// Z-score: how far from mean (identifies extremes)18ratioMean = ta.sma(ratio, 100)19ratioStd = ta.stdev(ratio, 100)20zScore = (ratio - ratioMean) / ratioStd2122plot(zScore, "Z-Score", color.orange, 1, display=display.pane)2324alertcondition(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.
1//@version=52indicator("Crypto Correlations", overlay=false)34corrLen = input.int(30, "Correlation Window", minval=10)56btcClose = request.security("BINANCE:BTCUSDT", "", close)7ethClose = request.security("BINANCE:ETHUSDT", "", close)8solClose = request.security("BINANCE:SOLUSDT", "", close)910// Compute rolling correlations vs BTC11corrEth = ta.correlation(btcClose, ethClose, corrLen)12corrSol = ta.correlation(btcClose, solClose, corrLen)13corrEthSol = ta.correlation(ethClose, solClose, corrLen)1415plot(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))2122// 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.
1//@version=52indicator("BTC Dominance Overlay", overlay=false)34btcDom = 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)89domRising = btcDom > btcDomEma1011plot(btcDom, "BTC.D", domRising ? color.orange : color.blue, 2)12plot(btcDomEma, "BTC.D EMA21", color.gray, 1)1314// Regime label15bgcolor(domRising ? color.new(color.orange, 90) : color.new(color.blue, 90))1617if barstate.islast18 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.
1//@version=52indicator("Cross-Market Dashboard", overlay=true)34// 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)1314[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)1920// Derived metrics21ethBtcRatio = ethClose / btcClose22corrEthBtc = ta.correlation(ethClose, btcClose, 30)23btcTrend = btcClose > btcEma24domRising = btcDom > btcDomEma25volState = btcAtr / btcClose * 1002627if barstate.islast28 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))3132 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)3435 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)3839 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)4243 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)4647 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.red50 table.cell(t, 1, 4, str.tostring(corrEthBtc, "#.##"),51 text_color=corrCol, text_size=size.small)5253 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.green55 table.cell(t, 1, 5, str.tostring(volState, "#.##") + "%",56 text_color=volCol, text_size=size.small)Actionable reading
Put this lesson to work
Free on Thrive, no account needed.