The Context Class (Context.class.ts)
The Context is the central object (usually named $) passed to the transpiled function. It acts as the container for:
- Market Data:
$.data.open,$.data.close, etc. - User Variables:
$.let,$.const,$.var. - Function State:
$.taState,$.params. - Namespaces:
$.ta,$.math,$.request,$.pine.
Initialization (init)
The init method is used for every variable assignment.
init(target, source, index = 0)
- If
targetexists, it updates the current value. - If
targetis null, it creates a newSeries. - It handles converting raw values or arrays into
Series.
Accessors (get / set)
PineTS uses specific accessors to handle Pine Script indexing semantics.
get(series, index): Returnsseries[length - 1 - index]. Index 0 is the most recent item.set(series, value): Updatesseries[length - 1].
Precision
All numeric outputs are routed through context.precision() to enforce consistent decimal rounding (default 10 places), matching Pine Script behavior.