TradingView indicator calculations

Derivative Oscillator indicator: formula and limits

The Derivative Oscillator indicator applies two exponential averages to RSI, then subtracts a simple average of that smoothed series. This page uses Constance Brown's 14/5/3/9 version: RSI(14) → EMA(5) → EMA(3), minus SMA(9) of the second EMA. Its zero line measures a gap between filtered RSI values. The name does not mean a mathematical derivative of price or an indicator of options and other derivative contracts.

Draft a Derivative Oscillator

Follow the Brown calculation in four stages

Brown's original MTA Journal article describes two exponential smoothing stages followed by a simple moving average, with the second EMA minus that average plotted as a histogram. TC2000's official implementation documents the same 14/5/3/9 defaults. Here, every period counts chart bars and the final nine-bar average includes the current observation.

  • For ordinary nonzero average gains and losses, RSI = 100 − 100 / (1 + average gain / average loss). Wilder smoothing uses alpha = 1/14; this is different from the EMA alpha of 2/(length + 1).
  • For an established EMA, new value = alpha × current input + (1 − alpha) × previous EMA. Replacing the final SMA with an EMA changes the indicator.
  • A separate arithmetic check: Wilder average gain 1.5 and average loss 1 produce RSI = 60. These are assumed averages, not the last single-bar gain and loss.
StageCalculationDefault
R: relative strengthWilder RSI of close14 bars
A: first smoothingEMA(R)5 bars; alpha = 1/3
B: second smoothingEMA(A)3 bars; alpha = 1/2
S: signal baselineSMA(B)9 bars; equal weights
D: histogramB − SRSI-point difference

Reproduce six hypothetical bars layer by layer

This fixture starts after initialization: assume both EMAs equal 50 and the preceding eight B values all equal 50. Feed the already-computed RSI values 62, 62, 38, 38, 50, 50 into the smoothing stages. It isolates those stages rather than reconstructing a price history. The table rounds to six decimals; calculations retain full precision.

  • Bar 1: A = 62/3 + 50 × 2/3 = 54; B = (54 + 50)/2 = 52; S = (8 × 50 + 52)/9 = 50.222222; D = 1.777778.
  • Bar 2: S = (7 × 50 + 52 + 54.333333…)/9 = 50.703704. Keeping eight old 50s would incorrectly use ten observations.
  • Bar 3 is the failure case for reading a positive histogram as rising RSI: RSI falls from 62 to 38, while D stays positive at 1.419753. The negative zero crossing arrives on bar 4.
  • Bar 5 is another timing mismatch: RSI recovers to 50, but D falls further below zero. On bar 6 D rises while remaining negative. Level and direction are different measurements.
BarRSI REMA(5) AEMA(3) BSMA(9) SD = B − S
16254.00000052.00000050.2222221.777778
26256.66666754.33333350.7037043.629630
33850.44444452.38888950.9691361.419753
43846.29629649.34259350.896091−1.553498
55047.53086448.43672850.722394−2.285665
65048.35390948.39531950.544096−2.148777

Use zero as a comparison, not a price forecast

A positive D means B is above its recent average. A negative D means it is below. A rising D only means the gap has increased since the preceding bar. None of these statements establishes where the next price closes. The six-bar fixture shows why a histogram color or a zero crossing needs its own precise definition.

  • If RSI remains at a constant level and the filters settle there, D approaches zero even when that RSI level is high. Zero does not prove a neutral price trend.
  • This version shares the series-minus-signal structure of a MACD histogram, but its input is double-smoothed RSI. It does not subtract the usual fast and slow price EMAs.
Proposed ruleWhat it testsFailure or boundary
D crosses zeroB crosses its nine-bar SMAMay occur after RSI has already turned; repeated crossings can occur near zero.
D rises from the previous barThe signed gap increasesD can rise below zero, as on bar 6.
D exceeds a chosen thresholdA minimum gap in RSI pointsA threshold is a separate rule to evaluate for the chosen inputs and chart interval.
Apply RSI 30/70 levels to DAn unrelated scale assumptionD is a difference, not the original 0-100 RSI reading.

Separate warm-up, smoothing delay and bar confirmation

Warm-up concerns whether enough inputs exist and how recursive averages were seeded. Smoothing delay concerns how the computed series responds to changes. Bar confirmation concerns whether the current input can still change. These are separate checks; adding 14 + 5 + 3 + 9 does not establish a universal delay or a universal first valid bar across implementations.

  • Keep unavailable history as unavailable. The signal requires nine valid B observations. Different RSI and EMA initialization policies can create early differences even when the displayed periods match.
  • Load additional earlier history and compare the same later completed timestamps. Recursive averages retain diminishing influence from their initial state, so a first numeric value is not proof that initialization differences have become negligible.
  • Two EMAs and a trailing SMA blend past observations. The fixture demonstrates a delayed zero crossing, but it does not establish a fixed number of bars of delay for every input sequence.
  • On a realtime bar, close changes can alter RSI and every downstream value. The example below calculates every update and hides the developing output by default; completed-bars mode does not remove smoothing delay.

Audit the intermediate values in Pine Script v6

Add this indicator to a standard candle chart and inspect the Data Window at a completed timestamp. Subtract Signal SMA from Second EMA to reproduce the histogram. The plot colors encode sign only: blue for zero or positive, orange for negative. They do not encode whether D is rising or falling. This is a calculation example with no orders or alerts.

  • First match symbol, feed, session, interval, candle type and source. Then compare RSI, first EMA, second EMA and signal in that order to find the earliest disagreement.
  • A signal length of 1 makes D equal zero wherever B is valid. This boundary check follows directly from B − SMA(B, 1).
  • The example uses built-in RSI and averaging functions without replacing missing values with zero. An altered source or RSI formula is a different implementation that needs its own numerical check.
Chart-timeframe calculation with explicit average types, lengths and completed-bar display policy. Syntax checking does not establish trading performance.pine
//@version=6
indicator("Derivative Oscillator calculation audit", overlay = false, precision = 6)
rsiLength = input.int(14, "RSI bars", minval = 2)
firstLength = input.int(5, "First EMA bars", minval = 1)
secondLength = input.int(3, "Second EMA bars", minval = 1)
signalLength = input.int(9, "Signal SMA bars", minval = 1)
confirmedOnly = input.bool(true, "Show completed bars only")
rsiValue = ta.rsi(close, rsiLength)
firstEma = ta.ema(rsiValue, firstLength)
secondEma = ta.ema(firstEma, secondLength)
signal = ta.sma(secondEma, signalLength)
oscillator = secondEma - signal
canShow = not confirmedOnly or barstate.isconfirmed
plot(canShow ? oscillator : na, "Derivative Oscillator", style = plot.style_histogram, color = oscillator >= 0 ? color.blue : color.orange, linewidth = 2)
hline(0, "Zero", color = color.gray)
plot(canShow ? rsiValue : na, "RSI", display = display.data_window)
plot(canShow ? firstEma : na, "First EMA", display = display.data_window)
plot(canShow ? secondEma : na, "Second EMA", display = display.data_window)
plot(canShow ? signal : na, "Signal SMA", display = display.data_window)

Give Pineify a specification that can be checked

Ask the Pine Script AI Coding Agent to draft or explain the Brown 14/5/3/9 calculation using close, Wilder RSI, two EMAs and a final SMA. Require the four intermediate Data Window outputs and specify completed-bar confirmation. Keep the six-bar fixture as a separate smoothing test with its stated initial values.

  • Require bar 3 to remain positive after RSI drops and bar 4 to cross below zero. A script that colors every rising RSI value as bullish has not reproduced this rule.
  • For alerts, state whether the event is a zero crossing, a change in D direction or a threshold crossing, and whether it is confirmed at the bar close.
  • Review source, validate syntax and compare bar values before adding strategy logic. Define entries, exits, position sizing, commissions and slippage separately; this indicator does not supply them.
Where Pineify fits

Pine Script AI Coding Agent

Draft and review a Derivative Oscillator with explicit calculation stages, confirmation timing and diagnostic outputs.

Draft a Derivative Oscillator

Frequently asked questions

Educational information, not investment advice. The numerical fixture is hypothetical and is not a backtest. Histogram readings, alerts and syntax validation do not guarantee trading returns.

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.