| layout | default |
|---|---|
| title | Context Class |
| parent | Runtime |
| nav_order | 1 |
| permalink | /architecture/runtime/context/ |
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.
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.
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].
All numeric outputs are routed through context.precision() to enforce consistent decimal rounding (default 10 places), matching Pine Script behavior.