Files
Miha Kralj 35a6702b06 fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
Deep review of all indicator categories verified .md headers against .cs WarmupPeriod, parameters, inputs, and outputs. Fixes include warmup corrections, parameter documentation, output type accuracy, and Pine Script alignment.
2026-03-10 18:38:23 -07:00

63 lines
2.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("MCNMA - McNicholl EMA", "MCNMA", overlay=true)
//@function Calculates the McNicholl EMA (Zero-Lag TEMA).
// Dennis McNicholl, "Better Bollinger Bands," Futures Magazine, October 1998.
// MCNMA = 2·TEMA(src,N) TEMA(TEMA(src,N),N)
// TEMA(x,N) = 3·EMA1 3·EMA2 + EMA3
// Six cascaded EMA stages; na-guard init to source eliminates warmup bias.
//@param source Series to smooth
//@param period Lookback period (must be > 0)
//@returns McNicholl EMA value from bar 1
mcnma(series float source, simple int period) =>
float src = nz(source)
float alpha = 2.0 / (period + 1)
float beta = 1.0 - alpha
var float e1 = na
var float e2 = na
var float e3 = na
var float e4 = na
var float e5 = na
var float e6 = na
if na(e1)
e1 := src
e2 := src
e3 := src
e4 := src
e5 := src
e6 := src
else
e1 := alpha * src + beta * e1
e2 := alpha * e1 + beta * e2
e3 := alpha * e2 + beta * e3
float tema1 = 3.0 * e1 - 3.0 * e2 + e3
e4 := alpha * tema1 + beta * e4
e5 := alpha * e4 + beta * e5
e6 := alpha * e5 + beta * e6
float tema2 = 3.0 * e4 - 3.0 * e5 + e6
// result is assigned below — but we need it outside the else
// Pine requires expression, so use a different structure:
// recompute after update (valid on all bars after init)
float tema1 = 3.0 * e1 - 3.0 * e2 + e3
float tema2 = 3.0 * e4 - 3.0 * e5 + e6
2.0 * tema1 - tema2
// ── Inputs ─────────────────────────────────────────────────────────────
int i_period = input.int(14, "Period", minval=1)
float i_source = input.source(close, "Source")
// ── Calculation ────────────────────────────────────────────────────────
float value = mcnma(i_source, i_period)
// ── Plot ───────────────────────────────────────────────────────────────
plot(value, "MCNMA", color.yellow, 2)