Exciting Update: Version 1.0.6 is now available, introducing Direct Pine Script Mode, Pine Logs Runtime Bridge, Zero-Repaint Linting, Source Maps, Intrabar MFE/MAE Stats, and expanded Pine v5/v6 Transpiler Parity. Read more

Indicators Reference

Detailed schema configurations and built-in calculation subroutines for standard indicators.

Active Indicators Schema (ctx.indicators)

Execute standard technical indicator calculations on-demand. You can now use the global ta.* namespace (e.g., ta.sma, ta.crossover) for a simpler, Pine Script-like syntax, which aliases directly to these ctx.* methods.

BacktestX Script
const indicator = {
  type: "rsi",               // Indicator type key
  params: { period: 14 },     // Calculation parameters
  color: "#9c27b0",          // Default display color
  enabled: true,             // Active state toggle
  style: {                    // Thickness, opacity, and shape overrides
    plotColor: "#9c27b0",
    plotThickness: 2
  }
};

Standard Indicators Specifications

Type Key Indicator Name Parameters Schema Styling Override References
"sma" Simple Moving Avg { period } plotShow, plotColor, plotThickness, plotStyle
"ema" Exponential Moving Avg { period } plotShow, plotColor, plotThickness, plotStyle
"wma" Weighted Moving Avg { period } plotShow, plotColor, plotThickness, plotStyle
"dema" Double Exp Moving Avg { period } plotShow, plotColor, plotThickness, plotStyle
"tema" Triple Exp Moving Avg { period } plotShow, plotColor, plotThickness, plotStyle
"bb" Bollinger Bands { period, mult } midShow, midColor, upperShow, upperColor, fillShow, fillColor
"vwap" VWAP {} plotShow, plotColor, plotThickness, plotStyle
"ichimoku" Ichimoku Cloud {} tenkanShow, tenkanColor, kijunShow, kijunColor, cloudShow, cloudUpColor
"psar" Parabolic SAR { step, maxStep } dotsShow, dotsColor, dotsSize, dotsOpacity
"rsi" Relative Strength Index { period } plotShow, plotColor, upperLevel, lowerLevel
"macd" MACD { fast, slow, sig } macdShow, macdColor, signalShow, signalColor, histShow, histColor
"vol" Volume {} volShow, volUpColor, volDownColor, maShow, maColor
"stoch" Stochastic Oscillator { kPeriod, dPeriod } kShow, kColor, dShow, dColor, upperLevel, lowerLevel
"atr" Average True Range { period } plotShow, plotColor, plotThickness, plotStyle
"cci" Commodity Channel Index { period } plotShow, plotColor, upperLevel, lowerLevel
"roc" Rate of Change { period } plotShow, plotColor, plotThickness, plotStyle
"adx" Avg Directional Index { period } adxShow, adxColor, plusDiShow, plusDiColor, minusDiShow, minusDiColor
"obv" On Balance Volume {} plotShow, plotColor, plotThickness, plotStyle

Exposed Indicator Math APIs (ta.* / ctx.*)

Execute standard technical indicator calculations on-demand. These functions accept raw historical data arrays or bar arrays, and return calculated history arrays of matching lengths.

Method Signature Return Type & Value Shape
ta.sma(dataArray, period) Array<number|null> - Simple Moving Average
ta.ema(dataArray, period) Array<number|null> - Exponential Moving Average
ta.wma(dataArray, period) Array<number|null> - Weighted Moving Average
ta.dema(dataArray, period) Array<number|null> - Double Exponential Moving Average
ta.tema(dataArray, period) Array<number|null> - Triple Exponential Moving Average
ta.rsi(dataArray, period) Array<number|null> - Relative Strength Index
ta.macd(dataArray, fast, slow, signal) { line: Array, signal: Array, hist: Array } - MACD Components
ta.bollingerBands(dataArray, period, mult) { mid: Array, upper: Array, lower: Array } - Bollinger Bands Bands
ctx.vwap(barsArray) Array<number|null> - Volume Weighted Average Price
ctx.stochastic(barsArray, kPeriod, dPeriod) { kVals: Array, dVals: Array } - Stochastic Oscillator
ctx.atr(barsArray, period) Array<number|null> - Average True Range
ctx.cci(barsArray, period) Array<number|null> - Commodity Channel Index
ctx.roc(dataArray, period) Array<number|null> - Rate of Change (percent)
ctx.psar(barsArray, step, maxStep) Array<number|null> - Parabolic SAR points
ctx.hma(dataArray, period) Array<number|null> - Hull Moving Average
ctx.alma(dataArray, period, offset, sigma) Array<number|null> - Arnaud Legoux Moving Average
ctx.lsma(dataArray, period, offset) Array<number|null> - Least Squares Moving Average
ctx.rma(dataArray, period) Array<number|null> - Relative Moving Average
ctx.stdev(dataArray, period) Array<number|null> - Standard Deviation
ctx.variance(dataArray, period) Array<number|null> - Variance
ctx.covariance(dataArray1, dataArray2, period) Array<number|null> - Covariance
ctx.correlation(dataArray1, dataArray2, period) Array<number|null> - Correlation Coefficient
ctx.median(dataArray, period) Array<number|null> - Rolling Median
ctx.mode(dataArray, period) Array<number|null> - Rolling Mode
ctx.kc(dataArray, period, multiplier, useTrueRange) { mid: Array, upper: Array, lower: Array } - Keltner Channels
ctx.donchian(period) { basis: Array, upper: Array, lower: Array } - Donchian Channels
ctx.supertrend(factor, period) { supertrend: Array, direction: Array } - Supertrend Line & Direction
ctx.stoch(source, highs, lows, period) Array<number|null> - Stochastic Oscillator series
ctx.cmf(period) Array<number|null> - Chaikin Money Flow
ctx.wpr(period) Array<number|null> - Williams %R
ctx.tsi(dataArray, short_length, long_length) Array<number|null> - True Strength Index
ctx.ao(period1, period2) Array<number|null> - Awesome Oscillator
ctx.linreg(dataArray, period, offset) Array<number|null> - Linear Regression Curve
ctx.slope(dataArray, period) Array<number|null> - Linear Regression Slope
ctx.r2(dataArray, period) Array<number|null> - Coefficient of Determination (R2)
ctx.percentrank(dataArray, period) Array<number|null> - Percent Rank (0-100)
ctx.ichimoku(barsArray) { tenkan: Array, kijun: Array, senkouA: Array, senkouB: Array, chikou: Array } - Ichimoku Components
ctx.adx(barsArray, period) { adx: Array, plusDI: Array, minusDI: Array } - ADX Components
ctx.obv(barsArray) Array<number> - On Balance Volume series
ctx.ta.tr(barsArray, handle_na) / ta.tr Array<number|null> - True Range with previous bar close[1] gap checks (v1.0.6)
ta.pivothigh([src,] left, right) / ta.pivotlow Non-repainting pivot high/low confirmed at +right bars; defaults to high/low in 2-arg form (v1.0.6)
ta.dmi / ta.sar / ta.kama / ta.vwma Directional Movement, Parabolic SAR, Kaufman Adaptive MA, VWMA (v1.0.6)
ta.mcg / ta.cks / ta.ce / ta.fisher / ta.crsi / ta.cvd v1.0.6 adapters plus bop, cho, ci, bbtrend, bbpb, bbw, env, hv, bbp, cc, efi, eom, adr (see TA APIs)

Copy-Paste Indicator Boilerplate Templates

Complete production-ready indicator scripts featuring dynamic Inputs tab wiring, proper numeric array dereferencing, and customizable Style tab outputs.

1. Custom EMA Overlay (Length, Source, Offset & Style)

BacktestX Script
// 1. INPUTS TAB
const length = ctx.input('length', 20, { title: 'Length', type: 'int', min: 1, max: 500 });
const source = ctx.input('source', 'Close', {
  title: 'Source',
  type: 'string',
  options: ['Close', 'Open', 'High', 'Low', 'HL2', 'HLC3', 'OHLC4']
});
const offset = ctx.input('offset', 0, { title: 'Offset', type: 'int', min: -500, max: 500 });

// 2. DATA EXTRACTION
const getVal = (b) => {
  const s = String(source).toLowerCase();
  if (s === 'open') return b.open;
  if (s === 'high') return b.high;
  if (s === 'low') return b.low;
  if (s === 'hl2') return (b.high + b.low) / 2;
  if (s === 'hlc3') return (b.high + b.low + b.close) / 3;
  if (s === 'ohlc4') return (b.open + b.high + b.low + b.close) / 4;
  return b.close;
};
const src = (ctx.bars || []).map(getVal);

// 3. TA CALCULATION
const emaData = ctx.ta.ema(src, length);
const finalData = offset === 0 ? emaData : emaData.map((v, i, arr) => arr[i - offset] ?? null);

// 4. STYLE TAB & PLOT
ctx.plot(finalData, {
  title: `EMA (${length})`,
  color: '#2962ff',
  width: 2,
  style: 'solid'
});

2. Custom Supertrend Overlay (ctx.bars, Factor & Period)

BacktestX Script
// 1. INPUTS TAB
const factor = ctx.input('factor', 3, { title: 'Factor', type: 'float', min: 0.1, max: 20, step: 0.1 });
const period = ctx.input('period', 10, { title: 'ATR Period', type: 'int', min: 1, max: 100 });

// 2. TA CALCULATION (requires ctx.bars)
const { supertrend, direction } = ctx.ta.supertrend(ctx.bars, factor, period);

// 3. STYLE TAB & PLOTS
ctx.plot(supertrend, {
  title: `Supertrend (${period}, ${factor})`,
  color: '#089981',
  width: 2,
  style: 'solid'
});

3. Custom RSI Sub-Panel (HLines & Dedicated Pane)

BacktestX Script
// 1. DEDICATED SUB-PANEL
ctx.pane = 'new';

// 2. INPUTS TAB
const length = ctx.input('length', 14, { title: 'RSI Length', type: 'int', min: 1, max: 100 });
const obLevel = ctx.input('obLevel', 70, { title: 'Overbought Level', type: 'int', min: 50, max: 100 });
const osLevel = ctx.input('osLevel', 30, { title: 'Oversold Level', type: 'int', min: 0, max: 50 });

// 3. TA CALCULATION
const closes = (ctx.bars || []).map(b => b.close);
const rsiData = ctx.ta.rsi(closes, length);

// 4. STYLE TAB & REFERENCE LINES
ctx.hline(obLevel, { title: 'Overbought', color: '#f23645', width: 1, style: 'dashed' });
ctx.hline(50,      { title: 'Middle Line', color: '#787b86', width: 1, style: 'dotted' });
ctx.hline(osLevel, { title: 'Oversold',   color: '#089981', width: 1, style: 'dashed' });

ctx.plot(rsiData, {
  title: `RSI (${length})`,
  color: '#9c27b0',
  width: 2,
  style: 'solid'
});

4. Custom MACD Sub-Panel (Multi-line & Zero Line)

BacktestX Script
ctx.pane = 'new';

// 1. INPUTS TAB
const fast = ctx.input('fast', 12, { title: 'Fast Length', type: 'int', min: 1 });
const slow = ctx.input('slow', 26, { title: 'Slow Length', type: 'int', min: 1 });
const sig  = ctx.input('sig', 9,   { title: 'Signal Smoothing', type: 'int', min: 1 });

// 2. TA CALCULATION
const closes = (ctx.bars || []).map(b => b.close);
const { line, signal, hist } = ctx.ta.macd(closes, fast, slow, sig);

// 3. STYLE TAB & PLOTS
ctx.hline(0, { title: 'Zero Line', color: '#787b86', width: 1, style: 'dotted' });
ctx.plot(hist,   { title: 'Histogram', color: '#26a69a', width: 4 });
ctx.plot(line,   { title: 'MACD', color: '#2962ff', width: 2 });
ctx.plot(signal, { title: 'Signal', color: '#ff6d00', width: 2 });

5. Direct Pine Mode Sub-Pane Indicator (v1.0.6, overlay=false)

Pine Script (Auto-Sub-Pane)
//@version=5
indicator("Pine RSI Momentum", overlay=false)
len = input.int(14, "RSI Length")
r = ta.rsi(hlc3, len)
hTop = hline(70, "Overbought", color=color.red)
hBot = hline(30, "Oversold", color=color.green)
fill(hTop, hBot, color=color.new(color.purple, 90))
plot(r, title="RSI", color=color.purple, linewidth=2)