update runs, so updating inside an if gives a different result (Pine’s call-site rule, made visible). Values match TradingView’s built-ins, including their seeds and how they treat na.
ta
Seeded with the simple average of the first
length values, as TradingView’s ta.ema.Linearly weighted moving average: the newest value weighs
length, the oldest 1.Hull moving average, a weighted average of weighted averages that lags less.
Volume-weighted moving average of the last
length values.Standard deviation of the last
length values, over length as TradingView divides (not length - 1).Bars since the highest or lowest value in the window, as a negative offset like TradingView’s.
Commodity channel index: the distance from the
length-bar average in units of mean deviation, over 0.015.The least-squares line through the last
length values, read offset bars back from its end (0, the default, is the current bar).The percent of the previous
length values that are at or below the current one.True when the value has risen on each of the last
length bars (a step within 1e-10 does not count).True when the value has fallen on each of the last
length bars.True on the bar where
a goes from at or below b to above it.True on the bar where
a goes from at or above b to below it.Bars since
condition was last true: 0 on a bar where it is, na until the first time.value on the bar where condition was true, the occurrence-th time back (0, the default, is the latest).A pivot high: a value higher than the
left before it and the right after it. It is known
only right bars later, so it is returned on that bar, na on every other.A pivot low, as
pivotHigh: returned right bars after the low, na on every other bar.MACD: the fast EMA less the slow EMA, its
signal-bar EMA, and the difference of the two as the histogram.Bollinger Bands: the
length-bar SMA, and bands mult standard deviations either side.Keltner Channels: the
length-bar EMA of the close, and bands mult times the length-bar EMA of the true range (or of the bar’s range) either side.Stochastic: where the close sits in the
length-bar range of highs and lows, 0 to 100. Smooth it with ta.sma for %K and %D.Money flow index, 0 to 100: an RSI of the typical price weighted by volume.
On-balance volume: the running sum of volume, added on up closes and taken away on down closes.
True range.
handleNa as TradingView: on the first bar, high − low.Average true range: Wilder’s average of the true range over
length bars.Directional movement: +DI, -DI and the ADX, which measures trend strength whatever its direction.
Supertrend: a trailing line
factor ATRs from the price that flips side when the close crosses it, with its direction.Volume-weighted average price from quote and base volume, reset at each anchor (UTC).