Paste this indicator into Pine Editor and add it to a chart. Synthetic mode fixes N at 3, uses the table inputs from the first loaded chart bar, and repeats 110 after observation 7. Locate those first seven observations with the Data Window. The green matched EMA markers should sit on the orange SMMA line; the blue equal-length EMA differs. The Data Window exposes their difference, a deliberately shifted seed, and the built-in EMA/RMA difference.
Controlled recurrences share an SMA seed. Built-in functions retain their own startup behavior. This indicator plots only completed chart bars and places no orders.pine
//@version=6
indicator("EMA vs SMMA: seed audit", overlay = false, precision = 6)
bool fixture = input.bool(true, "Use synthetic example (N = 3)")
int chartLength = input.int(14, "Chart source length", minval = 1, maxval = 500)
float chartSource = input.source(close, "Chart source")
bool insertGap = input.bool(false, "Synthetic example: omit observation 5")
int n = fixture ? 3 : chartLength
int emaLength = 2 * n - 1
float sample = switch bar_index
0 => 100.0
1 => 110.0
2 => 90.0
3 => 120.0
4 => 80.0
5 => 100.0
=> 110.0
float src = fixture ? (insertGap and bar_index == 4 ? na : sample) : chartSource
float aSame = 2.0 / (n + 1)
float aMatched = 2.0 / (emaLength + 1)
float aSmma = 1.0 / n
var int count = 0
var float seedSum = 0.0
var float sameEma = na
var float matchedEma = na
var float smma = na
var float shiftedSeed = na
// Skip missing inputs; count only valid observations for the shared seed.
if not na(src)
if count < n
seedSum += src
count += 1
if count == n
float seed = seedSum / n
sameEma := seed
matchedEma := seed
smma := seed
shiftedSeed := seed + 3.0
else
sameEma := aSame * src + (1.0 - aSame) * sameEma
matchedEma := aMatched * src + (1.0 - aMatched) * matchedEma
smma := aSmma * src + (1.0 - aSmma) * smma
shiftedSeed := aSmma * src + (1.0 - aSmma) * shiftedSeed
// Built-ins keep their own initialization. Always calculate on every bar.
float nativeEma = ta.ema(src, emaLength)
float nativeRma = ta.rma(src, n)
bool show = barstate.isconfirmed and not na(src)
plot(show ? src : na, "Source", color.gray, style = plot.style_circles)
plot(show ? sameEma : na, "EMA(N), shared seed", color.blue, style = plot.style_linebr)
plot(show ? smma : na, "SMMA(N), shared seed", color.orange, 2, plot.style_linebr)
plot(show ? matchedEma : na, "EMA(2N-1), shared seed", color.green, style = plot.style_circles)
plot(show ? matchedEma - smma : na, "Shared-seed difference", display = display.data_window)
plot(show ? shiftedSeed - smma : na, "Seed +3 difference", display = display.data_window)
plot(show ? nativeEma - nativeRma : na, "Built-in EMA minus RMA", display = display.data_window)
plot(bar_index + 1, "Observation number", display = display.data_window)