TradingView chart workflows

TradingView spread and ratio charts: expressions and alignment

Create a TradingView spread chart by entering a formula in Symbol Search, such as NASDAQ:AAPL - NASDAQ:MSFT. Use / for a ratio and * for a coefficient. The result is one synthetic price series. Before interpreting it, check the units, sessions and timestamps of both inputs. A chart expression does not establish a mean-reverting relationship or execute two underlying positions.

Build an expression monitor

Enter a formula in Symbol Search

Open Supercharts and select the symbol field. Enter the first exchange-qualified symbol, an operator followed by a space, and the second symbol or number. TradingView supports +, -, * and /, with up to 10 unique symbols in one expression. Select the expression to open its chart.

  • Start with NASDAQ:AAPL / NASDAQ:MSFT on a standard time-based chart. The symbols demonstrate syntax; they are not a recommended trading pair.
  • Record the exact formula, interval, sessions, price-adjustment settings and feed status. Keep each underlying chart available for a timestamp check.
  • Use Compare or Add Symbol when you want separate overlaid series. Enter an expression when you need one calculated series with its own values.

Choose the calculation and interpret its units

These hypothetical observations use A = 120 and B = 80, both quoted in USD per share. Exchange-qualified examples below show where the real symbols go; the numbers are invented. A coefficient of 1.5 is an arithmetic choice, not an estimated hedge ratio.

  • If both prices rise 10%, A becomes 132 and B becomes 88. A - B rises from 40 to 44, while A / B stays at 1.5 and A - 1.5 × B stays at zero. An expanding unweighted difference need not indicate relative underperformance.
  • For two positive prices, a rising A / B means A has the stronger percentage change over the comparison interval. Both assets can still be falling.
  • A zero denominator makes a ratio undefined; a near-zero denominator can dominate it. Mixed currencies, contract multipliers and unequal quote units need explicit conversion before subtraction.
ExpressionWorked valueWhat it measures
NASDAQ:AAPL - NASDAQ:MSFTA - B = 120 - 80 = 40A difference between the two quoted share prices. Its change corresponds to one share of A against one share of B, before costs.
NASDAQ:AAPL / NASDAQ:MSFTA / B = 120 / 80 = 1.5A relative price. With matching quote units the ratio is dimensionless; it is not a dollar profit.
NASDAQ:AAPL - 1.5 * NASDAQ:MSFTA - 1.5 × B = 120 - 120 = 0A weighted difference. For these cash equities, fixed holdings of one A and minus 1.5 B replicate changes in this value before costs.
NASDAQ:AAPL / FX_IDC:EURUSD120 USD / 1.20 USD per EUR = 100 EURA currency conversion when the FX quote direction is USD per EUR. Check the FX timestamp as well as the stock timestamp.

Check bar alignment before trusting a jump

Use this audit when the expression moves while one market is closed, a gap appears, or a script disagrees with the chart. This is a comparison policy: accept observations only when both required prices cover the intended interval. It is not a claim that every native spread chart applies this policy.

  • Missing-bar example: at 10:00, A = 120 and B = 80, so A / B = 1.5. At 10:05, A = 122 but B has no new observation. Reusing B = 80 gives 1.525; under a matched-observation policy, the ratio is unavailable instead.
  • Changing the displayed timezone only relabels instants. It cannot make two exchanges open together or create a missing observation.
CheckFailure exampleAction
Bar endpointsTwo hourly bars open at 09:00 and 09:30.Compare opening and closing timestamps, not just the interval label. Choose a common observation schedule.
Sessions and holidaysOne leg has extended-hours bars; the other has only regular-session observations.Inspect both individual charts. Mark unmatched observations as unavailable instead of assuming a simultaneous quote.
Feed freshnessA updates now while B is delayed or halted.Check each feed status. Matching displayed bar labels cannot prove equal quote freshness.
Adjustment and contract historyA split or futures roll changes one series definition.Record adjustment conventions and contract selection. Investigate mechanical jumps before interpreting a relationship change.

Synthetic OHLC cannot be read as synchronized fills

TradingView builds historical intraday spreads from one-minute OHLC data and then assembles the selected interval. Live spread bars use tick updates, so reloading can change bars and affect alerts. Daily spread OHLC uses a separate calculation; it need not equal an aggregation of the intraday spread.

  • Assume these are the only two simultaneous observations. The largest observed difference is 50. Combining A high = 110 with B low = 50 gives 60, a difference that never occurred together. Likewise, 110 / 50 = 2.2 exceeds both observed ratios.
  • This arithmetic demonstrates the information lost when separate extrema replace synchronized observations. It does not assert that TradingView uses high(A) - low(B) for every spread candle.
  • The official daily-versus-intraday example makes the aggregation issue explicit: multiplying intraday highs 2 × 5 and 3 × 4 yields a maximum of 12, while multiplying the separate daily highs gives 3 × 5 = 15.
  • Keep interval and reconstruction method fixed when comparing thresholds. Neither a synthetic wick nor its historical high proves that both legs were executable at those prices.
Hypothetical instantABA - BA / B
First observation10050502.000
Second observation11060501.833

Build a close-only monitor with explicit missing values

Apply this Pine Script v6 indicator to leg A on standard time-based candles. Select leg B and set both instruments to the intended regular-session context. The code requests B in its regular session and compares its bar endpoints with A. It plots a weighted difference or ratio only on confirmed chart bars with matching data; it does not recreate native spread OHLC.

  • gaps_on leaves unavailable requested observations as na; linebr preserves visible gaps. The alert requires two adjacent accepted chart bars, so the first value after a missing observation cannot trigger a crossing.
  • Set a threshold in the selected expression units. In TradingView, create an alert for Expression crossed above and choose Once Per Bar Close. Changing the mode or coefficient requires reviewing the threshold and recreating the alert with the new settings.
  • For a threshold of 1.5 in ratio mode, adjacent accepted values 1.49 and 1.51 trigger the condition. Values 1.49, missing and 1.51 do not. The condition monitors an upward crossing only.
  • The chart supplies the execution timeline: the script cannot observe periods with no A bars. Regular sessions are instrument-specific. This example performs no FX conversion, adjustment reconciliation or near-zero-denominator filter.
  • Confirmed chart bars and equal endpoints reduce ambiguity but cannot guarantee synchronized feeds. Provider revisions or temporary differences between requested data and chart data can still change results after reload.
Use A = 120, B = 80 and coefficient = 1.5 to check the arithmetic: weighted difference 0 or ratio 1.5. Defaults are demonstration inputs.pine
//@version=6
indicator("Aligned close expression monitor", overlay = false)
string symbolB = input.symbol("NASDAQ:MSFT", "Leg B (chart is leg A)")
string mode = input.string("Weighted difference", "Expression", options = ["Weighted difference", "Ratio"])
float coefficient = input.float(1.5, "B coefficient for difference")
float threshold = input.float(0.0, "Upper alert threshold")
string regularB = ticker.modify(symbolB, session = session.regular)
[closeB, openTimeB, closeTimeB] = request.security(regularB, timeframe.period, [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
bool aligned = not na(closeB) and not na(close) and openTimeB == time and closeTimeB == time_close
bool validRatio = mode != "Ratio" or closeB != 0
bool ready = aligned and validRatio and barstate.isconfirmed
float value = ready ? (mode == "Ratio" ? close / closeB : close - coefficient * closeB) : na
bool crossedUp = not na(value) and not na(value[1]) and value > threshold and value[1] <= threshold
plot(value, "Expression close", color = color.blue, linewidth = 2, style = plot.style_linebr)
plot(threshold, "Upper threshold", color = color.orange)
plot(ready ? 1 : 0, "Accepted observation", display = display.data_window)
alertcondition(crossedUp, "Expression crossed above", "Aligned expression crossed above its upper threshold.")

Keep observation, relationship research and execution separate

A usable chart answers what the expression did under recorded data settings. Deciding whether that expression should revert requires a separate model and test. Executing it requires separate quantities, orders and costs for both instruments. The pairs trading strategy guide covers relationship selection, hedge estimation and two-leg accounting.

  • Before enabling an alert, manually reconcile several accepted closes, one missing interval and one session boundary. Save the exact script inputs and alert creation time; check the alert log against the contemporaneous data.
  • An alert is a notification condition. This indicator contains no orders and does not validate simultaneous fills, short availability, borrowing costs, margin or portfolio profit.
  • Give Pineify the two symbols, expression, sessions, interval, missing-data policy and alert rule. Ask for an editable monitor, then inspect the generated source and compare the output with recorded observations.
Where Pineify fits

Pine Script AI Coding Agent

Use Pineify to generate or revise a Pine monitor from an explicit two-asset formula and alert rule. Review its data requests and validate its output in TradingView. This workflow does not provide automatic two-leg execution.

Build an expression monitor

Frequently asked questions

Educational chart and code examples, not investment advice. Prices and coefficients are hypothetical. Synthetic values, syntax validation and alerts do not establish a profitable relationship or executable two-leg prices.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.