Skip to main content

ta.rsi(source, length) - Relative Strength Index

Returns a value between 0-100. Overbought > 70, oversold < 30 by convention.

ta.macd(source, fast?, slow?, signal?) - MACD

Returns an object { macd, signal, hist }. Defaults: fast=12, slow=26, signal=9.

ta.stoch(source, high, low, length) - Stochastic %K

Returns 0-100. Pass close, high, low as the first three sources.

ta.cci(source, length) - Commodity Channel Index

Typical input is ctx.hlc3 (typical price). Returns an unbounded oscillator around 0.

ta.mom(source, length) - Momentum

Current value minus the value length bars ago. Unbounded.

ta.roc(source, length) - Rate of Change

Percentage change from length bars ago: (close - close[length]) / close[length] * 100.

ta.dmi(high, low, close, length) - Directional Movement Index

Returns { plus, minus, adx }. plus = +DI, minus = -DI, adx = ADX.

Moving averages

Trend smoothing functions.

Volatility

ATR, Bollinger Bands, standard deviation.

RSI divergence example

Full working RSI indicator with divergence detection.

MACD histogram example

Full working MACD implementation.