Skip to main content
ATK Pine Script®

ta.* Namespace

Technical analysis helpers — moving averages, oscillators, multi-output indicators, signal helpers, and the TA-Lib passthrough.

ta.* Namespace#

Keep it in builders — All ta.* work belongs in build_indicator_frame or build_signal_frame, never in build_visuals or trade mapping.

Core helpers#

FunctionPurpose
ta.sma(series, length)Simple moving average.
ta.ema(series, length)Exponential moving average.
ta.rsi(series, length=14)Relative strength index.
ta.atr(frame, length=14)Average true range.
ta.williams(frame, length=14)Williams %R.
ta.true_range(frame)True range series.
ta.psar(frame, acceleration=0.02, maximum=0.2)Parabolic SAR.

Multi-output helpers#

FunctionReturns
ta.bbands(series, length=5, std=2.0, mamode="sma")upper, basis, lower
ta.macd(...)macd, signal, histogram
ta.stoch(...)k, d
ta.kdj(...)k, d, j

Signal helpers#

ta.crossover(a, b) and ta.crossunder(a, b) return boolean series and already handle shifted-bar comparisons.

TA-Lib passthrough#

ta is also a dynamic TA-Lib wrapper. If the runtime can resolve a TA-Lib function name or alias, ta.some_function(...) can dispatch into TA-Lib automatically.

Bollinger Bands example#

import pandas as pd

from source import indicator, input, linefill, plot, ta

indicator("Pyne BBands Fill", overlay=True, max_bars_back=240)
length = input.int(20, title="Length", key="length")
multiplier = input.float(2.0, title="StdDev Mult", key="multiplier")
mamode = input.string("sma", title="MA Mode", key="mamode")
source_type = input.string("close", title="Source", key="source_type")

plot("lb", key="bb_lower", title="Lower", color="#ff0000", width=1)
plot("cb", key="bb_basis", title="Basis", color="#ffa500", width=1)
plot("ub", key="bb_upper", title="Upper", color="#00aa00", width=1)
linefill.new("bb_lower", "bb_upper", key="bb_band_fill", color="rgba(63,57,100,0.44)")


def build_indicator_frame(df: pd.DataFrame, params: dict | None = None) -> pd.DataFrame:
    frame = df.copy().reset_index(drop=True)
    merged = {
        "length": int(length),
        "multiplier": float(multiplier),
        "mamode": str(mamode),
        "source_type": str(source_type),
    } | dict(params or {})
    source_series = (
        pd.to_numeric(frame[str(merged.get("source_type", "close"))], errors="coerce")
        if str(merged.get("source_type", "close")) in frame.columns
        else pd.to_numeric(frame["close"], errors="coerce")
    )
    upper, basis, lower = ta.bbands(
        source_series,
        length=max(int(merged.get("length", 20) or 20), 2),
        std=float(merged.get("multiplier", 2.0) or 2.0),
        mamode=str(merged.get("mamode", "sma") or "sma").lower(),
    )
    frame["lb"] = lower.reset_index(drop=True)
    frame["cb"] = basis.reset_index(drop=True)
    frame["ub"] = upper.reset_index(drop=True)
    return frame