TradingView indicator calculations

Traders Dynamic Index: reconstruct the lines before trusting a cross

Traders Dynamic Index (TDI) combines RSI with a fast smoothing line, a slower signal line, and volatility bands calculated on RSI. These components share the same price input; their agreement is not independent confirmation. TradingView versions can use different averages, lengths, and extra filters. This guide defines one public construction and recalculates every line from the same hypothetical closes.

See the decision guide

What each TDI line measures

EarnForex publishes a TDI implementation with a 13-period RSI, 2-period fast SMA, 7-period slow SMA, and 34-period band window with multiplier 1.6185. Those are the chart-mode defaults below. They describe a particular public variant, not universal or optimal settings. The small worked example uses shorter windows so every intermediate value can be checked.

  • For change = current close minus previous close, use gain = max(change, 0) and loss = max(-change, 0). Seed U and D with the means of the first N valid changes. Thereafter each average is ((N - 1) × previous average + current gain or loss) / N.
  • For the last B valid consecutive RSI values, SD = sqrt(sum((R - M)²) / B). Dividing by B - 1 instead gives sample standard deviation and wider bands. This page uses B explicitly.
  • Before the RSI seed exists, output is missing. When U + D = 0 after initialization, this example returns 50 as an explicit neutral convention. If only D is zero, RSI is 100; if only U is zero, it is 0. Match another script's flat-data policy before comparing values.
ComponentDefinition hereInterpretation boundary
Raw RSI R100 × U / (U + D)U and D are Wilder-smoothed price changes.
Fast line F, usually greenSMA(R, fast length)Smoothing delays changes in raw RSI.
Signal line S, usually redSMA(R, slow length)This averages raw RSI, not the fast line.
Market base line M, usually yellowSMA(R, band length B)A slower momentum reference, not a price moving average.
Volatility bandsM ± k × population SD(R, B)Width measures dispersion of RSI, not price volatility in currency units.

Reconstruct TDI from twelve closes

Use closes 100, 102, 101, 104, 103, 102, 101, 103, 100, 99, 101, 98, with no earlier history. Set RSI N = 3, fast = 2, slow = 3, band B = 4, and k = 1.6185. Prices are hypothetical units. All plotted lines and bands below are in RSI points. Keep full precision during calculation and round only the displayed result.

  • At bar 4, changes are +2, -1, +3. U = 5/3 and D = 1/3, so R = 100 × (5/3) / 2 = 83.3333. At bar 5, U = 10/9 and D = 5/9, giving R = 66.6667 and F = (83.3333 + 66.6667) / 2 = 75.
  • At bar 7, the four RSI values are 83.3333, 66.6667, 51.2821, and 38.0952 before rounding. Their mean is 59.8443 and population SD is 16.9161. The band half-width is 1.6185 × 16.9161 = 27.3786; lower = 32.4657 and upper = 87.2230.
  • With valid consecutive closes, the first RSI occurs at bar N + 1 and the first band at bar N + B. For chart defaults, that is bars 14 and 47. A fast/slow cross can become available before the band. The example alerts require the band to be ready too.
Bar / closeRSI RFast FSignal SBase MLower / upper
1 / 100MissingMissingMissingMissingMissing
2 / 102MissingMissingMissingMissingMissing
3 / 101MissingMissingMissingMissingMissing
4 / 10483.33MissingMissingMissingMissing
5 / 10366.6775.00MissingMissingMissing
6 / 10251.2858.9767.09MissingMissing
7 / 10138.1044.6952.0159.8432.47 / 87.22
8 / 10365.0551.5751.4855.2736.53 / 74.02
9 / 10032.8648.9645.3446.8226.62 / 67.03
10 / 9926.3429.6041.4240.5916.75 / 64.42
11 / 10153.8240.0837.6744.5219.25 / 69.78
12 / 9829.2641.5436.4735.5718.11 / 53.03

A false cross has two different meanings

A bullish fast/slow crossing means F is now greater than S and was at or below S on the previous bar. Equality now is not a crossing. The first valid line pair has no valid predecessor, so it is not a signal. A cross that disappears during an open candle and a completed cross followed by adverse prices are different failures.

  • The alternative bar-8 case starts from the completed bar-7 averages each time. Do not feed every tick into the Wilder recurrence as if each tick were another closed candle.
  • In the main sequence, bar 8 fast and signal lines are both below the base line at 55.27. Requiring F > M would reject that event. This is a different rule; one rejected failure does not establish that the filter improves a strategy.
  • A band breakout means an RSI-derived value exceeded a chosen RSI band. It does not set a price target or a statistical confidence interval for the next close. Bands can also extend outside 0 to 100 even though RSI itself is bounded.
CaseCalculationWhat it shows
Confirmed bar 8 closes at 103F = 51.5745; S = 51.4770; prior F < SA bullish cross with only a 0.0975-point margin.
Next close is 100 at bar 9F = 48.9559 > S = 45.3357Price falls three units while the smoothed bullish state persists.
Bar 10 closes at 99F = 29.5991 < S = 41.4173The bearish cross arrives after another lower close.
Alternative bar 8: trades at 103, closes at 102Final R = 55.3265; F = 46.7108 < S = 48.2346The temporary bullish cross never becomes a confirmed signal.

Why two TradingView TDI versions disagree

A shared indicator name does not specify identical calculations. The public SystemAlpha description adds a Price Action Channel and signal-strength rules; ZyadaCharts describes added divergences, labels, and background conditions. These additions require their own definitions. This example reproduces neither those full scripts nor a protected commercial edition.

  • For the bar-7 window, changing only to sample SD multiplies width by sqrt(4/3), about 1.1547. Matching the base line while seeing wider bands can therefore be a denominator difference.
  • A smooth-looking line still changes during the live candle. The code below confirms chart-timeframe alerts at the close; it makes no claim about higher-timeframe requests, pivot backdating, or another script's behavior.
  • Levels such as 32, 50, and 68 are reference choices. Crossing a reference, crossing another line, and returning inside a band are separate events. Specify one before testing.
CheckPossible differenceHow to isolate it
Line sourceSlow average of RSI versus slow average of the fast lineCompare raw RSI first, then each average separately.
AveragingSMA versus EMA; different lengths or Wilder seedsRecord method, length, loaded history, and first valid bar.
BandsPopulation versus sample SD; raw versus smoothed RSI; multiplierCompare base, SD, and multiplier separately.
DataDifferent price source, session, timeframe, or candle typeMatch the exact symbol feed and chart settings.
SignalsCurrent candle, confirmed candle, divergence, or channel filterSeparate the plotted values from the event condition.

Pine Script v6 with a reproducible fixture mode

Paste this indicator into TradingView. Chart mode uses the public default lengths. Turn on the twelve-close fixture to reproduce the table above: it substitutes the twelve prices into the first twelve loaded bars and retains their results in an on-chart table. Load at least twelve bars. Fixture mode disables alerts and is independent of the market prices; it is a calculation check, not a backtest.

  • The fixture table should show bar 8 fast = 51.57 and signal = 51.48, then bar 10 fast = 29.60 and signal = 41.42. If it differs, compare the unrounded values and initialization before changing a trading rule.
  • Turn fixture mode off before using market data or creating alerts. Choose Once Per Bar Close and recreate the alert after changing the script or inputs. The code declares conditions; it places no orders.
  • Syntax checking establishes source acceptance. It does not prove chart execution, correct broker fills, or a profitable trading system. A strategy also needs exits, position sizing, costs, and a separate evaluation sample.
Original implementation of the stated public formula. Fixture mode fixes its own lengths and multiplier. Chart plots remain live; only alert conditions require a confirmed close.pine
//@version=6
indicator("TDI: explicit formula and fixture", overlay = false, precision = 2)
fixture = input.bool(false, "Use twelve-close fixture")
nInput = input.int(13, "RSI length", minval = 1)
fInput = input.int(2, "Fast SMA length", minval = 1)
sInput = input.int(7, "Signal SMA length", minval = 1)
bInput = input.int(34, "Band window", minval = 2)
k = input.float(1.6185, "Band multiplier", minval = 0.0)
n = fixture ? 3 : nInput
fLength = fixture ? 2 : fInput
sLength = fixture ? 3 : sInput
bLength = fixture ? 4 : bInput
multiplier = fixture ? 1.6185 : k
var prices = array.from(100.0, 102.0, 101.0, 104.0, 103.0, 102.0, 101.0, 103.0, 100.0, 99.0, 101.0, 98.0)
active = not fixture or bar_index < array.size(prices)
source = fixture ? (active ? array.get(prices, bar_index) : na) : close
change = ta.change(source)
u = ta.rma(math.max(change, 0.0), n)
d = ta.rma(math.max(-change, 0.0), n)
total = u + d
r = active and not na(total) ? (total == 0 ? 50.0 : 100.0 * u / total) : na
fast = ta.sma(r, fLength)
signal = ta.sma(r, sLength)
base = ta.sma(r, bLength)
sd = ta.stdev(r, bLength, true)
upper = base + multiplier * sd
lower = base - multiplier * sd
upCross = ta.crossover(fast, signal)
downCross = ta.crossunder(fast, signal)
ready = active and not na(base) and not na(fast[1]) and not na(signal[1])
confirmedUp = not fixture and ready and barstate.isconfirmed and upCross
confirmedDown = not fixture and ready and barstate.isconfirmed and downCross
plot(active ? fast : na, "Fast RSI SMA", color.green, 2)
plot(active ? signal : na, "Signal RSI SMA", color.red, 2)
plot(active ? base : na, "Market base line", color.orange)
plot(active ? upper : na, "Upper RSI band", color.blue)
plot(active ? lower : na, "Lower RSI band", color.blue)
plot(r, "Raw RSI", display = display.data_window)
plot(active ? sd : na, "Population RSI SD", display = display.data_window)
hline(50, "RSI midpoint", color.gray)
alertcondition(confirmedUp, "Confirmed bullish TDI cross", "Fast TDI SMA crossed above signal SMA at bar close.")
alertcondition(confirmedDown, "Confirmed bearish TDI cross", "Fast TDI SMA crossed below signal SMA at bar close.")
formatValue(float value) => na(value) ? "na" : str.tostring(value, "#.00")
var audit = table.new(position.top_right, 7, 13, bgcolor = color.white, border_width = 1)
if fixture and barstate.isfirst
    labels = array.from("Bar / close", "RSI", "Fast", "Signal", "Base", "Lower", "Upper")
    for col = 0 to 6
        table.cell(audit, col, 0, array.get(labels, col), text_color = color.black)
if fixture and active
    row = bar_index + 1
    table.cell(audit, 0, row, str.tostring(row) + " / " + str.tostring(source), text_color = color.black)
    values = array.from(r, fast, signal, base, lower, upper)
    for col = 0 to 5
        table.cell(audit, col + 1, row, formatValue(array.get(values, col)), text_color = color.black)

Give the coding agent a definition it can be checked against

The Pine Script AI Coding Agent can draft or revise a TDI indicator from this explicit formula. Provide the close sequence, Wilder initialization, separate fast and slow SMA inputs, population SD, flat-data convention, and confirmation rule. Ask it to preserve diagnostic outputs and then explicitly request a syntax check.

  • Use the twelve-close fixture as an acceptance case before adding a channel, divergence detector, or higher timeframe. Compare each added component against its own expected output.
  • Request a deliberate version change, such as EMA smoothing, as a separate experiment. Do not call the result equivalent merely because its colors and labels match.
  • Public formulas do not reveal proprietary filters. This workflow does not recreate protected source or establish trading performance.
Where Pineify fits

Pine Script AI Coding Agent

Draft a TDI variant with explicit formulas and a fixed calculation fixture, then request syntax checking and inspect the generated source.

Build an explicit TDI variant

Frequently asked questions

Educational information, not investment advice. All sample prices are hypothetical calculation inputs, not market observations or trading results. A valid TDI calculation or confirmed cross does not establish profitability.

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.