openpinescript 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +332 -2
- package/dist/cli.mjs +108691 -0
- package/dist/index.cjs +108670 -0
- package/dist/index.mjs +108624 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/parser/v1/generated/PineV1Lexer.d.ts +66 -0
- package/dist/types/parser/v1/generated/PineV1Parser.d.ts +555 -0
- package/dist/types/parser/v1/generated/PineV1ParserVisitor.d.ts +318 -0
- package/dist/types/parser/v1/index.d.ts +39 -0
- package/dist/types/parser/v2/generated/PineV2Lexer.d.ts +67 -0
- package/dist/types/parser/v2/generated/PineV2Parser.d.ts +568 -0
- package/dist/types/parser/v2/generated/PineV2ParserVisitor.d.ts +325 -0
- package/dist/types/parser/v2/index.d.ts +2 -0
- package/dist/types/parser/v3/generated/PineV3Lexer.d.ts +67 -0
- package/dist/types/parser/v3/generated/PineV3Parser.d.ts +568 -0
- package/dist/types/parser/v3/generated/PineV3ParserVisitor.d.ts +325 -0
- package/dist/types/parser/v3/index.d.ts +2 -0
- package/dist/types/parser/v4/generated/PineV4Lexer.d.ts +86 -0
- package/dist/types/parser/v4/generated/PineV4Parser.d.ts +673 -0
- package/dist/types/parser/v4/generated/PineV4ParserVisitor.d.ts +367 -0
- package/dist/types/parser/v4/index.d.ts +2 -0
- package/dist/types/parser/v5/generated/PineV5Lexer.d.ts +95 -0
- package/dist/types/parser/v5/generated/PineV5Parser.d.ts +964 -0
- package/dist/types/parser/v5/generated/PineV5ParserVisitor.d.ts +521 -0
- package/dist/types/parser/v5/index.d.ts +2 -0
- package/dist/types/parser/v6/generated/PineV6Lexer.d.ts +98 -0
- package/dist/types/parser/v6/generated/PineV6Parser.d.ts +984 -0
- package/dist/types/parser/v6/generated/PineV6ParserVisitor.d.ts +528 -0
- package/dist/types/parser/v6/index.d.ts +2 -0
- package/dist/types/runtime/v1/Series.d.ts +61 -0
- package/dist/types/runtime/v1/broker/Broker.d.ts +325 -0
- package/dist/types/runtime/v1/broker/index.d.ts +158 -0
- package/dist/types/runtime/v1/broker/val.d.ts +28 -0
- package/dist/types/runtime/v1/constDefault.d.ts +11 -0
- package/dist/types/runtime/v1/context.d.ts +1705 -0
- package/dist/types/runtime/v1/footprint.d.ts +32 -0
- package/dist/types/runtime/v1/index.d.ts +7 -0
- package/dist/types/runtime/v1/language-spec.d.ts +12 -0
- package/dist/types/runtime/v1/openTrades.d.ts +12 -0
- package/dist/types/runtime/v1/palette.d.ts +18 -0
- package/dist/types/runtime/v1/session.d.ts +482 -0
- package/dist/types/runtime/v1/sessions.d.ts +31 -0
- package/dist/types/runtime/v1/stateClone.d.ts +19 -0
- package/dist/types/runtime/v1/stdlib/alerts.d.ts +31 -0
- package/dist/types/runtime/v1/stdlib/arrays.d.ts +133 -0
- package/dist/types/runtime/v1/stdlib/barmerge.d.ts +27 -0
- package/dist/types/runtime/v1/stdlib/barstate.d.ts +79 -0
- package/dist/types/runtime/v1/stdlib/cast.d.ts +81 -0
- package/dist/types/runtime/v1/stdlib/chart.d.ts +283 -0
- package/dist/types/runtime/v1/stdlib/color.d.ts +51 -0
- package/dist/types/runtime/v1/stdlib/core.d.ts +162 -0
- package/dist/types/runtime/v1/stdlib/dataset.d.ts +36 -0
- package/dist/types/runtime/v1/stdlib/display.d.ts +50 -0
- package/dist/types/runtime/v1/stdlib/drawings.d.ts +407 -0
- package/dist/types/runtime/v1/stdlib/errors.d.ts +21 -0
- package/dist/types/runtime/v1/stdlib/font.d.ts +20 -0
- package/dist/types/runtime/v1/stdlib/footprint.d.ts +76 -0
- package/dist/types/runtime/v1/stdlib/format.d.ts +57 -0
- package/dist/types/runtime/v1/stdlib/index.d.ts +71 -0
- package/dist/types/runtime/v1/stdlib/input.d.ts +14 -0
- package/dist/types/runtime/v1/stdlib/inputs.d.ts +60 -0
- package/dist/types/runtime/v1/stdlib/late_members.d.ts +97 -0
- package/dist/types/runtime/v1/stdlib/logging.d.ts +31 -0
- package/dist/types/runtime/v1/stdlib/maps.d.ts +55 -0
- package/dist/types/runtime/v1/stdlib/math.d.ts +71 -0
- package/dist/types/runtime/v1/stdlib/matrix.d.ts +201 -0
- package/dist/types/runtime/v1/stdlib/metadata.d.ts +14 -0
- package/dist/types/runtime/v1/stdlib/mtf.d.ts +15 -0
- package/dist/types/runtime/v1/stdlib/renames.d.ts +117 -0
- package/dist/types/runtime/v1/stdlib/renames5.d.ts +113 -0
- package/dist/types/runtime/v1/stdlib/renames6.d.ts +81 -0
- package/dist/types/runtime/v1/stdlib/request.d.ts +207 -0
- package/dist/types/runtime/v1/stdlib/scale.d.ts +19 -0
- package/dist/types/runtime/v1/stdlib/session.d.ts +113 -0
- package/dist/types/runtime/v1/stdlib/sort_field.d.ts +12 -0
- package/dist/types/runtime/v1/stdlib/sources.d.ts +24 -0
- package/dist/types/runtime/v1/stdlib/str.d.ts +117 -0
- package/dist/types/runtime/v1/stdlib/strategy.d.ts +314 -0
- package/dist/types/runtime/v1/stdlib/syminfo.d.ts +209 -0
- package/dist/types/runtime/v1/stdlib/ta.d.ts +409 -0
- package/dist/types/runtime/v1/stdlib/time.d.ts +158 -0
- package/dist/types/runtime/v1/stdlib/trades.d.ts +108 -0
- package/dist/types/runtime/v1/stdlib/ui.d.ts +196 -0
- package/dist/types/runtime/v1/stdlib/v6_members.d.ts +68 -0
- package/dist/types/runtime/v1/timeframes.d.ts +139 -0
- package/dist/types/runtime/v1/zones.d.ts +30 -0
- package/dist/types/transpiler/common/index.d.ts +51 -0
- package/dist/types/transpiler/common/libraries.d.ts +29 -0
- package/dist/types/transpiler/common/parseErrors.d.ts +38 -0
- package/dist/types/transpiler/common/passes/ScopeAnalysis.d.ts +158 -0
- package/dist/types/transpiler/common/passes/TypeRules.d.ts +26 -0
- package/dist/types/transpiler/common/profiles/index.d.ts +96 -0
- package/dist/types/transpiler/common/version.d.ts +40 -0
- package/dist/types/transpiler/v1/ToJsVisitor.d.ts +720 -0
- package/dist/types/transpiler/v2/ToJsVisitor.d.ts +72 -0
- package/dist/types/transpiler/v3/ToJsVisitor.d.ts +87 -0
- package/dist/types/transpiler/v4/ToJsVisitor.d.ts +263 -0
- package/dist/types/transpiler/v5/ToJsVisitor.d.ts +1101 -0
- package/dist/types/transpiler/v6/ToJsVisitor.d.ts +237 -0
- package/dist/types/transpiler/v6/rules.d.ts +94 -0
- package/dist/types/utils/v2/common.d.ts +4 -0
- package/package.json +92 -4
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pine Script matrices — the `matrix.*` namespace. v5, May 2022.
|
|
3
|
+
*
|
|
4
|
+
* ── Representation ──────────────────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* An array of row arrays, unwrapped, exactly as arrays and maps are (see
|
|
7
|
+
* ./arrays.ts for why there is no wrapper class). A matrix is therefore also a
|
|
8
|
+
* valid Pine ARRAY as far as `array.size` is concerned, which is a genuine
|
|
9
|
+
* looseness: Pine's type checker keeps them apart at compile time and this
|
|
10
|
+
* engine does not model element types at all. The alternative — a tagged
|
|
11
|
+
* wrapper — would have to be unwrapped at every boundary in the runtime for a
|
|
12
|
+
* check no script can trigger without already being rejected by TradingView.
|
|
13
|
+
*
|
|
14
|
+
* Rectangularity is an INVARIANT, not an assumption: every mutator that could
|
|
15
|
+
* break it (add_row, add_col, set) validates first, because a ragged matrix
|
|
16
|
+
* produces plausible numbers from `mult` and `det` rather than an error.
|
|
17
|
+
*
|
|
18
|
+
* ── What is deliberately absent ─────────────────────────────────────────────
|
|
19
|
+
*
|
|
20
|
+
* `matrix.eigenvalues` and `matrix.eigenvectors`. Both need an iterative
|
|
21
|
+
* eigendecomposition, and for a general (non-symmetric) matrix the eigenvalues
|
|
22
|
+
* can be complex — which Pine's `array<float>` return type cannot represent, so
|
|
23
|
+
* TradingView must be doing something the docs do not state. Guessing at it
|
|
24
|
+
* would produce numbers that look right and are not.
|
|
25
|
+
*
|
|
26
|
+
* An absent name is refused by the transpiler with "not available"; a present
|
|
27
|
+
* one that is subtly wrong is not refused at all. `pinv` IS here, because its
|
|
28
|
+
* restriction is statable — see the note on it.
|
|
29
|
+
*
|
|
30
|
+
* v5-only, which this file does not enforce: the registry split in ./index.ts
|
|
31
|
+
* keeps the namespace out of the v1–v4 views.
|
|
32
|
+
*/
|
|
33
|
+
import type { Context } from "../context.js";
|
|
34
|
+
type Matrix = any[][];
|
|
35
|
+
/**
|
|
36
|
+
* The property that marks an array as a MATRIX.
|
|
37
|
+
*
|
|
38
|
+
* A matrix is an array of arrays, which is also a perfectly good Pine array, so
|
|
39
|
+
* a value cannot answer "am I a matrix?" from its shape alone. v5's method-call
|
|
40
|
+
* syntax makes that answerable-or-not the difference between `m.get(r, c)`
|
|
41
|
+
* reaching `matrix.get` and reaching `array.get` — see `Context.builtinMethod`.
|
|
42
|
+
*
|
|
43
|
+
* NON-ENUMERABLE, and a Symbol rather than a string key, so a tagged matrix is
|
|
44
|
+
* indistinguishable from a plain array to everything else: `JSON.stringify`,
|
|
45
|
+
* spread, `Object.keys`, and the array functions in ./arrays.ts all behave
|
|
46
|
+
* exactly as they did before.
|
|
47
|
+
*/
|
|
48
|
+
export declare const MATRIX_TAG: unique symbol;
|
|
49
|
+
export declare const matrix: {
|
|
50
|
+
/**
|
|
51
|
+
* `matrix.new<type>(rows, columns, initial_value)`.
|
|
52
|
+
*
|
|
53
|
+
* The type argument is parsed by the grammar and discarded by the emitter;
|
|
54
|
+
* only the fill value distinguishes one element type from another here.
|
|
55
|
+
*/
|
|
56
|
+
new: (rows?: any, columns?: any, initial_value?: any) => Matrix;
|
|
57
|
+
rows: (id: any) => number;
|
|
58
|
+
columns: (id: any) => number;
|
|
59
|
+
elements_count: (id: any) => number;
|
|
60
|
+
is_square: (id: any) => boolean;
|
|
61
|
+
is_zero: (id: any) => boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The rest of the `matrix.is_*()` family.
|
|
64
|
+
*
|
|
65
|
+
* SOURCING. Each description below is the line TradingView's own
|
|
66
|
+
* `inspect()` example on the Matrices page prints when the predicate is
|
|
67
|
+
* true, which is as close to a definition as the manual gives:
|
|
68
|
+
*
|
|
69
|
+
* is_binary "Contains only 1s and 0s."
|
|
70
|
+
* is_triangular "Contains only 0s above and/or below its main diagonal."
|
|
71
|
+
* is_diagonal "Only has nonzero values in its main diagonal."
|
|
72
|
+
* is_antidiagonal "Only has nonzero values in its main antidiagonal."
|
|
73
|
+
* is_symmetric "Equals its transpose."
|
|
74
|
+
* is_antisymmetric "Equals the negative of its transpose."
|
|
75
|
+
* is_identity "Is the identity matrix."
|
|
76
|
+
*
|
|
77
|
+
* Squareness is required wherever the property is only defined for a square
|
|
78
|
+
* matrix — a transpose of a 2x3 has a different shape and cannot equal it,
|
|
79
|
+
* and "its main diagonal" names nothing otherwise.
|
|
80
|
+
*
|
|
81
|
+
* `matrix.is_stochastic()` is deliberately NOT here. It is a real Pine
|
|
82
|
+
* built-in and appears in the same list on that page, but the manual never
|
|
83
|
+
* says which convention it means — row-stochastic, column-stochastic or
|
|
84
|
+
* doubly stochastic are three different answers for the same matrix — and a
|
|
85
|
+
* predicate that is confidently wrong is worse than one that is missing.
|
|
86
|
+
*/
|
|
87
|
+
is_binary: (id: any) => boolean;
|
|
88
|
+
is_identity: (id: any) => boolean;
|
|
89
|
+
is_diagonal: (id: any) => boolean;
|
|
90
|
+
is_antidiagonal: (id: any) => boolean;
|
|
91
|
+
is_triangular: (id: any) => boolean;
|
|
92
|
+
is_symmetric: (id: any) => boolean;
|
|
93
|
+
is_antisymmetric: (id: any) => boolean;
|
|
94
|
+
get: (id: any, row: any, column: any) => any;
|
|
95
|
+
set: (id: any, row: any, column: any, value: any) => void;
|
|
96
|
+
/** A COPY of the row, as a Pine array. Mutating it must not reach back. */
|
|
97
|
+
row: (id: any, row: any) => any[];
|
|
98
|
+
col: (id: any, column: any) => any[];
|
|
99
|
+
add_row: (id: any, row?: any, array_id?: any) => void;
|
|
100
|
+
add_col: (id: any, column?: any, array_id?: any) => void;
|
|
101
|
+
remove_row: (id: any, row?: any) => any[];
|
|
102
|
+
remove_col: (id: any, column?: any) => any[];
|
|
103
|
+
swap_rows: (id: any, row1: any, row2: any) => void;
|
|
104
|
+
swap_columns: (id: any, column1: any, column2: any) => void;
|
|
105
|
+
fill: (id: any, value: any, from_row?: any, to_row?: any, from_column?: any, to_column?: any) => void;
|
|
106
|
+
/**
|
|
107
|
+
* `matrix.reverse(id)` — reverse the order of every element, in place.
|
|
108
|
+
*
|
|
109
|
+
* "This function moves the references of an m-by-n matrix id at the i-th row
|
|
110
|
+
* and j-th column to the m - 1 - i row and n - 1 - j column."
|
|
111
|
+
*
|
|
112
|
+
* Which is the rows reversed and each row reversed. In place, like the other
|
|
113
|
+
* structural mutators, and returning nothing.
|
|
114
|
+
*/
|
|
115
|
+
reverse: (id: any) => void;
|
|
116
|
+
copy: (id: any) => Matrix;
|
|
117
|
+
transpose: (id: any) => Matrix;
|
|
118
|
+
submatrix: (id: any, from_row?: any, to_row?: any, from_column?: any, to_column?: any) => Matrix;
|
|
119
|
+
/** Row-major reshape. The element count must be preserved exactly. */
|
|
120
|
+
reshape: (id: any, rows: any, columns: any) => Matrix;
|
|
121
|
+
concat: (id1: any, id2: any) => Matrix;
|
|
122
|
+
sum: (id1: any, id2: any) => Matrix;
|
|
123
|
+
diff: (id1: any, id2: any) => Matrix;
|
|
124
|
+
/**
|
|
125
|
+
* Matrix product, or a scalar/vector multiply.
|
|
126
|
+
*
|
|
127
|
+
* Pine overloads this three ways: matrix×matrix, matrix×array (treated as a
|
|
128
|
+
* column vector) and matrix×scalar. The overloads are distinguished by what
|
|
129
|
+
* the second argument IS, which is the only information available at run
|
|
130
|
+
* time here — the emitter does not track types.
|
|
131
|
+
*/
|
|
132
|
+
mult: (id1: any, id2: any) => any;
|
|
133
|
+
/**
|
|
134
|
+
* `matrix.pow(id, power)` — a square matrix multiplied by itself `power`
|
|
135
|
+
* times; the identity at 0. By repeated squaring.
|
|
136
|
+
*/
|
|
137
|
+
pow: (id: any, power: any) => Matrix;
|
|
138
|
+
/**
|
|
139
|
+
* `matrix.eigenvectors(id)` — a matrix whose COLUMNS are the eigenvectors,
|
|
140
|
+
* in the order `eigenvalues` returns their values. The accumulated QR
|
|
141
|
+
* rotations, which are the eigenvectors of a symmetric matrix exactly and
|
|
142
|
+
* the Schur vectors of any other.
|
|
143
|
+
*/
|
|
144
|
+
eigenvectors: (id: any) => Matrix;
|
|
145
|
+
/**
|
|
146
|
+
* `matrix.eigenvalues(id)` — a square matrix's eigenvalues, largest first.
|
|
147
|
+
* By the unshifted QR algorithm, which converges to the real eigenvalues;
|
|
148
|
+
* a pair of complex ones has no real answer and stays as the 2x2 block's
|
|
149
|
+
* diagonal.
|
|
150
|
+
*/
|
|
151
|
+
eigenvalues: (id: any) => number[];
|
|
152
|
+
/**
|
|
153
|
+
* Determinant by Gaussian elimination with partial pivoting.
|
|
154
|
+
*
|
|
155
|
+
* Not cofactor expansion: that is O(n!) and loses to rounding well before
|
|
156
|
+
* it loses to time. Partial pivoting is what keeps the result usable when a
|
|
157
|
+
* leading element is near zero, which is the common case for a matrix built
|
|
158
|
+
* from price data.
|
|
159
|
+
*/
|
|
160
|
+
det: (id: any) => number;
|
|
161
|
+
/** Inverse by Gauss-Jordan. `na`-filled when the matrix is singular. */
|
|
162
|
+
inv: (id: any) => Matrix;
|
|
163
|
+
/**
|
|
164
|
+
* Kronecker product. Exact — no tolerance, no iteration.
|
|
165
|
+
*
|
|
166
|
+
* `a` is `m×n` and `b` is `p×q`, so the result is `mp×nq`: every element of
|
|
167
|
+
* `a` is replaced by that element times the whole of `b`.
|
|
168
|
+
*/
|
|
169
|
+
kron: (id1: any, id2: any) => Matrix;
|
|
170
|
+
/**
|
|
171
|
+
* Rank — the number of linearly independent rows.
|
|
172
|
+
*
|
|
173
|
+
* Row echelon form with partial pivoting. A pivot counts as zero below a
|
|
174
|
+
* tolerance scaled to the matrix's largest element, because a rank computed
|
|
175
|
+
* against an absolute epsilon is a rank that depends on the units the
|
|
176
|
+
* prices are quoted in.
|
|
177
|
+
*/
|
|
178
|
+
rank: (id: any) => number;
|
|
179
|
+
/**
|
|
180
|
+
* Moore-Penrose pseudo-inverse, for a FULL-RANK matrix.
|
|
181
|
+
*
|
|
182
|
+
* Computed from the normal equations — `(AᵀA)⁻¹Aᵀ` when the columns are
|
|
183
|
+
* independent, `Aᵀ(AAᵀ)⁻¹` when the rows are — which is exact for a
|
|
184
|
+
* full-rank matrix and is the standard construction.
|
|
185
|
+
*
|
|
186
|
+
* A RANK-DEFICIENT matrix has a pseudo-inverse too, but computing it needs
|
|
187
|
+
* a singular value decomposition, and the cutoff that decides which
|
|
188
|
+
* singular values count as zero is a tolerance TradingView does not
|
|
189
|
+
* publish. Rather than pick one, this returns an `na`-filled matrix of the
|
|
190
|
+
* right shape — the same answer `inv` gives a singular matrix, so a script
|
|
191
|
+
* that checks for `na` catches both.
|
|
192
|
+
*/
|
|
193
|
+
pinv: (id: any) => Matrix;
|
|
194
|
+
trace: (id: any) => number;
|
|
195
|
+
avg: (id: any) => number;
|
|
196
|
+
max: (id: any) => number;
|
|
197
|
+
min: (id: any) => number;
|
|
198
|
+
/** Sorts ROWS by the value in `column`, ascending unless told otherwise. */
|
|
199
|
+
sort: (ctx: Context, id: any, column?: any, order?: any, sort_field?: any) => void;
|
|
200
|
+
};
|
|
201
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PineType {
|
|
2
|
+
kind: "scalar" | "series" | "tuple";
|
|
3
|
+
type?: string;
|
|
4
|
+
itemTypes?: PineType[];
|
|
5
|
+
}
|
|
6
|
+
export interface StdlibEntry {
|
|
7
|
+
uses_context: boolean;
|
|
8
|
+
args: string[];
|
|
9
|
+
is_getter: boolean;
|
|
10
|
+
returns: PineType;
|
|
11
|
+
is_value: boolean;
|
|
12
|
+
ref: any;
|
|
13
|
+
}
|
|
14
|
+
export declare function getGeneratedRegistry(): Record<string, StdlibEntry>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime/v1/stdlib/mtf.ts
|
|
3
|
+
* Multi-timeframe access — security() (P1).
|
|
4
|
+
*
|
|
5
|
+
* Pine: `security(symbol, resolution, expression)` evaluates `expression` on the
|
|
6
|
+
* (symbol, resolution) series and aligns the result onto the chart's bars.
|
|
7
|
+
*
|
|
8
|
+
* The transpiler passes `expression` as a deferred thunk (see emitSecurity in the
|
|
9
|
+
* visitor). We evaluate it over the supplied HTF candles inside a sub-context
|
|
10
|
+
* (ctx.evalSecurityBar rebinds the global series), advancing only through HTF bars
|
|
11
|
+
* that have already CLOSED at the current chart-bar time — never the forming HTF
|
|
12
|
+
* bar — so there is no lookahead / repaint.
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from "../context.js";
|
|
15
|
+
export declare function security(ctx: Context, symbol: any, resolution: any, expression: () => any, gaps?: any, lookahead?: any, ignore_invalid_symbol?: any, currency?: any, calc_bars_count?: any): any;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v3 → v4 rename table.
|
|
3
|
+
*
|
|
4
|
+
* ── What this is ────────────────────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* §3a of the v3→v4 migration guide is a pure alias list: v4 moved a pile of
|
|
7
|
+
* loose globals into namespaces and changed nothing about what they mean.
|
|
8
|
+
* `red` became `color.red`, `period` became `timeframe.period`, `ticker` became
|
|
9
|
+
* `syminfo.ticker`. Same value, same implementation, new spelling.
|
|
10
|
+
*
|
|
11
|
+
* So this is DATA, not code. Each entry names the v4 spelling and the v1–v3
|
|
12
|
+
* registry key it renames, and the alias inherits that key's entry wholesale —
|
|
13
|
+
* `uses_context`, `is_getter`, `args`, `returns`, `ref`. Re-implementing
|
|
14
|
+
* `timeframe.period` as a second function beside `period` would be two things
|
|
15
|
+
* to keep in step with no test that could catch them drifting.
|
|
16
|
+
*
|
|
17
|
+
* ── The bar counter is NOT here ─────────────────────────────────────────────
|
|
18
|
+
*
|
|
19
|
+
* `n` → `bar_index` is the one rename that is not an alias: v4 REMOVES `n`.
|
|
20
|
+
* Every other old spelling below is also removed at v4, but they are removed by
|
|
21
|
+
* absence from v4's registry view, which costs nothing. The bar counter needs a
|
|
22
|
+
* real poison pill because the runtime binds it directly as a series rather
|
|
23
|
+
* than through the registry — so it lives in LANGUAGE_PROFILES[4].banned.
|
|
24
|
+
*
|
|
25
|
+
* ── Source ──────────────────────────────────────────────────────────────────
|
|
26
|
+
*
|
|
27
|
+
* https://www.tradingview.com/pine-script-docs/migration-guides/to-pine-version-4/
|
|
28
|
+
* transcribed into docs/common/VERSIONS.md §3a.
|
|
29
|
+
*/
|
|
30
|
+
/** One rename: the v4 spelling, and where its value comes from. */
|
|
31
|
+
export interface RenameSpec {
|
|
32
|
+
/** The v4 spelling, e.g. "color.red". */
|
|
33
|
+
readonly to: string;
|
|
34
|
+
/** The v1–v3 registry key it renames, e.g. "red". */
|
|
35
|
+
readonly from?: string;
|
|
36
|
+
/**
|
|
37
|
+
* A literal, for the handful of v4 constants with no reachable v1–v3
|
|
38
|
+
* spelling in this engine. Used only where `from` genuinely cannot be given.
|
|
39
|
+
*/
|
|
40
|
+
readonly value?: unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Namespaces that exist ONLY from v4, and are therefore removed from the v1–v3
|
|
44
|
+
* registry view.
|
|
45
|
+
*
|
|
46
|
+
* They live in the ordinary stdlib source files — the runtime is one
|
|
47
|
+
* implementation across versions by design — so without this list the
|
|
48
|
+
* generator would make `array.new_float` and `label.new` resolvable at v1,
|
|
49
|
+
* where TradingView reports `Undeclared identifier`.
|
|
50
|
+
*
|
|
51
|
+
* Dates, from the v4 release notes:
|
|
52
|
+
* line, label June 2019
|
|
53
|
+
* array September 2020
|
|
54
|
+
* box, table May 2021
|
|
55
|
+
*
|
|
56
|
+
* `xloc`, `yloc`, `extend`, `position` and `text` are the constant namespaces
|
|
57
|
+
* that only exist to parameterise the above, so they are v4-only for the same
|
|
58
|
+
* reason.
|
|
59
|
+
*/
|
|
60
|
+
export declare const V4_ONLY_NAMESPACES: readonly string[];
|
|
61
|
+
/**
|
|
62
|
+
* FLAT names that exist only from v4 — the indicator functions TradingView
|
|
63
|
+
* added in March 2020.
|
|
64
|
+
*
|
|
65
|
+
* Separate from V4_ONLY_NAMESPACES because these are not namespaces: they are
|
|
66
|
+
* bare function names sitting in the same flat space as `sma` and `rsi`, so
|
|
67
|
+
* gating them needs an exact-name list rather than a root-prefix one.
|
|
68
|
+
*
|
|
69
|
+
* Until this existed, a //@version=3 script calling `bb()` compiled and ran
|
|
70
|
+
* here while TradingView answered
|
|
71
|
+
*
|
|
72
|
+
* Could not find function or function reference 'bb'
|
|
73
|
+
*
|
|
74
|
+
* — a parity gap in the opposite direction from most: the engine was too
|
|
75
|
+
* permissive, not too strict. It was recorded in conformance/golden/README.md
|
|
76
|
+
* as unfixable-for-now, because gating it would have made
|
|
77
|
+
* golden/v4/harness_builtins.pine unrunnable while v4 had no pipeline. It has
|
|
78
|
+
* one now, so the gate costs nothing.
|
|
79
|
+
*
|
|
80
|
+
* The volume family — obv, pvt, nvi, pvi, accdist, iii, wad, wvad — is still
|
|
81
|
+
* absent from the registry, so there is nothing to gate for those. Each has
|
|
82
|
+
* published variants that disagree on the SEED value, and a seed guessed wrong
|
|
83
|
+
* produces a series that is the right shape and the wrong number forever;
|
|
84
|
+
* an absent name is refused instead.
|
|
85
|
+
*/
|
|
86
|
+
export declare const V4_ONLY_NAMES: readonly string[];
|
|
87
|
+
export declare const V4_RENAMES: readonly RenameSpec[];
|
|
88
|
+
/**
|
|
89
|
+
* The v1–v3 spellings v4 removes.
|
|
90
|
+
*
|
|
91
|
+
* Every `from` above, minus the names that survive v4 under their old spelling
|
|
92
|
+
* because something ELSE of that name is what moved. `line` is the clearest
|
|
93
|
+
* case: `plot.style_line` is the renamed constant, but v4 also has a `line`
|
|
94
|
+
* DRAWING type, so the word itself is very much still in the language.
|
|
95
|
+
*
|
|
96
|
+
* Removal is what makes a v4 script fail on a v3 spelling the way TradingView
|
|
97
|
+
* does, instead of silently accepting both dialects.
|
|
98
|
+
*/
|
|
99
|
+
export declare const V4_REMOVED: readonly string[];
|
|
100
|
+
/**
|
|
101
|
+
* Pine names this engine knows about and deliberately does NOT implement.
|
|
102
|
+
*
|
|
103
|
+
* The volume family has published variants that disagree on the SEED value,
|
|
104
|
+
* and a seed guessed wrong produces a series that is the right shape and the
|
|
105
|
+
* wrong number forever — so no implementation is offered. See the note in
|
|
106
|
+
* runtime/v1/stdlib/renames.ts.
|
|
107
|
+
*
|
|
108
|
+
* They are listed here because "absent from the registry" and "not a Pine name
|
|
109
|
+
* at all" must not produce the same diagnostic. `accdist` is real Pine, so
|
|
110
|
+
* `Undeclared identifier` would be a lie; it also cannot be allowed to compile
|
|
111
|
+
* into a silent `undefined`. runtime/v1/index.ts binds each one as a poison pill that
|
|
112
|
+
* throws only when READ, which is what lets
|
|
113
|
+
* conformance/v3/corpus/cci_commodity_channel_index.pine keep running: it
|
|
114
|
+
* mentions `accdist` in a branch selected by an input, and every other branch
|
|
115
|
+
* still works.
|
|
116
|
+
*/
|
|
117
|
+
export declare const UNIMPLEMENTED_BUILTINS: ReadonlySet<string>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v4 → v5 rename table.
|
|
3
|
+
*
|
|
4
|
+
* ── What this is ────────────────────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* v5 is, in bulk, one enormous renaming. §4a of the migration guide moves the
|
|
7
|
+
* entire technical-analysis library under `ta.`, the maths under `math.`, the
|
|
8
|
+
* data requests under `request.`, the ticker constructors under `ticker.` and
|
|
9
|
+
* string handling under `str.`. Nothing about what any of them MEAN changed:
|
|
10
|
+
* `sma(close, 20)` and `ta.sma(close, 20)` are the same function.
|
|
11
|
+
*
|
|
12
|
+
* So this is DATA, exactly as ./renames.ts is for v3 → v4, and it shares that
|
|
13
|
+
* file's `RenameSpec` shape. Each entry names the v5 spelling and the v4
|
|
14
|
+
* registry key it renames, and the alias inherits that key's entry wholesale —
|
|
15
|
+
* `uses_context`, `is_getter`, `args`, `returns`, `ref`. Re-implementing
|
|
16
|
+
* `ta.sma` beside `sma` would be two things to keep in step with no test that
|
|
17
|
+
* could catch them drifting.
|
|
18
|
+
*
|
|
19
|
+
* ── The source list, and the two names that are not on it ───────────────────
|
|
20
|
+
*
|
|
21
|
+
* The lists below are transcribed from docs/common/VERSIONS.md §4a,
|
|
22
|
+
* which in turn is transcribed from TradingView's v4 → v5 migration guide.
|
|
23
|
+
*
|
|
24
|
+
* `trix` is the exception: it does not appear in the guide's enumeration and is
|
|
25
|
+
* moved here anyway, because the rule the guide states is that the
|
|
26
|
+
* technical-analysis library moved to `ta.` — the enumeration is the list of
|
|
27
|
+
* members, not a set of exceptions to it.
|
|
28
|
+
*
|
|
29
|
+
* `fixnan` was treated the same way and that was WRONG. It is na HANDLING, like
|
|
30
|
+
* `na` and `nz`, and none of that family moved. The argument for moving it
|
|
31
|
+
* cited conformance/v5/golden/harness_state.pine calling `ta.fixnan` — which
|
|
32
|
+
* was circular: the generator produced that spelling from this very list.
|
|
33
|
+
* TradingView's own compiler settled it, rejecting the generated harness with
|
|
34
|
+
*
|
|
35
|
+
* Could not find function or function reference 'ta.fixnan'
|
|
36
|
+
*
|
|
37
|
+
* so `ta.fixnan` does not resolve here either. The FLAT name is the v5
|
|
38
|
+
* spelling, and the next block keeps it.
|
|
39
|
+
*
|
|
40
|
+
* ── The bar counter is NOT here ─────────────────────────────────────────────
|
|
41
|
+
*
|
|
42
|
+
* `n` → `bar_index` happened at v4 and v5 inherits it. It is a poison pill on
|
|
43
|
+
* the language profile rather than an alias, for the reasons in ./renames.ts.
|
|
44
|
+
*
|
|
45
|
+
* ── Source ──────────────────────────────────────────────────────────────────
|
|
46
|
+
*
|
|
47
|
+
* https://www.tradingview.com/pine-script-docs/migration-guides/to-pine-version-5/
|
|
48
|
+
* transcribed into docs/common/VERSIONS.md §4.
|
|
49
|
+
*/
|
|
50
|
+
import type { RenameSpec } from "./renames.js";
|
|
51
|
+
/**
|
|
52
|
+
* Namespaces that exist ONLY from v5, and are therefore removed from the v1–v4
|
|
53
|
+
* registry views.
|
|
54
|
+
*
|
|
55
|
+
* They live in the ordinary stdlib source files — the runtime is one
|
|
56
|
+
* implementation across versions by design — so without this list the generator
|
|
57
|
+
* would make `str.length` and `matrix.new` resolvable at v1, where TradingView
|
|
58
|
+
* reports `Undeclared identifier`.
|
|
59
|
+
*
|
|
60
|
+
* Dates, from the v5 release notes:
|
|
61
|
+
* str, math, ta, request, ticker, log, runtime v5 launch
|
|
62
|
+
* matrix May 2022
|
|
63
|
+
* map August 2023
|
|
64
|
+
*
|
|
65
|
+
* `ta`, `math` and `ticker` carry no generated keys of their own — every member
|
|
66
|
+
* arrives as an ALIAS — so listing them removes nothing today. They are here so
|
|
67
|
+
* that a future `ta.*` implemented directly rather than aliased is gated by
|
|
68
|
+
* default rather than by remembering to.
|
|
69
|
+
*/
|
|
70
|
+
export declare const V5_ONLY_NAMESPACES: readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* EXACT keys that exist only from v5 — the typed input functions, and the
|
|
73
|
+
* dataset-extent variables.
|
|
74
|
+
*
|
|
75
|
+
* Separate from V5_ONLY_NAMESPACES because `input.*` is not a v5-only
|
|
76
|
+
* namespace: v4 has `input.float` as a CONSTANT and v5 has it as a FUNCTION, so
|
|
77
|
+
* gating the whole root would take v4's constants away with it. See the header
|
|
78
|
+
* of ./inputs.ts for how one runtime object serves both readings.
|
|
79
|
+
*/
|
|
80
|
+
export declare const V5_ONLY_NAMES: readonly string[];
|
|
81
|
+
export declare const V5_RENAMES: readonly RenameSpec[];
|
|
82
|
+
/**
|
|
83
|
+
* Every v4 spelling that is not writable at v5.
|
|
84
|
+
*
|
|
85
|
+
* The `from` side of every rename above, plus the outright removals. Removal is
|
|
86
|
+
* what makes a v5 script fail on `sma(close, 20)` the way TradingView does,
|
|
87
|
+
* instead of silently accepting both dialects — which is the failure mode this
|
|
88
|
+
* whole table exists to prevent.
|
|
89
|
+
*/
|
|
90
|
+
export declare const V5_REMOVED: readonly string[];
|
|
91
|
+
/**
|
|
92
|
+
* v5 positional orders that differ from the order of this engine's
|
|
93
|
+
* parameters, mapped by NAME the way V6_POSITIONAL is for v6.
|
|
94
|
+
*
|
|
95
|
+
* `strategy.exit`: v5's reference puts `comment_profit`, `comment_loss` and
|
|
96
|
+
* `comment_trailing` between `comment` and `when`. The engine's signature keeps
|
|
97
|
+
* v4's order, where `when` follows `comment`, and appends the three — so
|
|
98
|
+
* without this a v5 call passing them by position bound the first to `when`
|
|
99
|
+
* and the second to `alert_message`.
|
|
100
|
+
*/
|
|
101
|
+
export declare const V5_POSITIONAL: Readonly<Record<string, readonly string[]>>;
|
|
102
|
+
/**
|
|
103
|
+
* Keyword names that v5 renamed, by the name a v1-v4 script wrote, mapped to
|
|
104
|
+
* the engine's parameter. Read by Context.call when binding keywords below v5.
|
|
105
|
+
*
|
|
106
|
+
* docs/common/VERSIONS.md §4b, from the migration guide:
|
|
107
|
+
* `strategy.entry(long=)` -> `strategy.entry(direction=)`, and the same for
|
|
108
|
+
* `strategy.order`. The engine's `strategy.order` calls the parameter `dir`.
|
|
109
|
+
* Positionally nothing moved, so only keyword use needs this; before it
|
|
110
|
+
* `strategy.entry(id = "L", long = false)` dropped the direction and opened a
|
|
111
|
+
* long, or, with the argument recorded and ignored, nothing at all.
|
|
112
|
+
*/
|
|
113
|
+
export declare const V4_RENAMED_PARAMS: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v5 → v6 registry delta.
|
|
3
|
+
*
|
|
4
|
+
* ── Why there is no rename table ───────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* v4 and v5 were each, in bulk, a renaming: `sma` → `ta.sma`, `red` →
|
|
7
|
+
* `color.red`. v6 renames NOTHING. Every v5 spelling is still a v6 spelling,
|
|
8
|
+
* which is why this file has no `RenameSpec[]` and why `V6_VIEW` is built with
|
|
9
|
+
* an empty rename step.
|
|
10
|
+
*
|
|
11
|
+
* What v6 does to the registry instead is:
|
|
12
|
+
*
|
|
13
|
+
* ADD new built-ins, from the launch notes and the two years of monthly
|
|
14
|
+
* releases after it — V6_ONLY_NAMES / V6_ONLY_NAMESPACES below
|
|
15
|
+
* CHANGE the VALUE of three colour constants and one default — handled at
|
|
16
|
+
* the point of use, not here, because the key is unchanged
|
|
17
|
+
* REMOVE nothing that is a NAME
|
|
18
|
+
*
|
|
19
|
+
* ── Why V6_REMOVED is empty rather than absent ─────────────────────────────
|
|
20
|
+
*
|
|
21
|
+
* The migration guide does remove things: `transp` from six plotting
|
|
22
|
+
* functions, `when` from seven strategy functions. Neither is a registry key.
|
|
23
|
+
* They are PARAMETERS, and a parameter is removed by refusing it at the call
|
|
24
|
+
* site, where the error can name the argument and the line — which is
|
|
25
|
+
* transpiler/v6/ToJsVisitor.ts.
|
|
26
|
+
*
|
|
27
|
+
* The empty array is kept, and spread, so that `V6_VIEW` reads the same as
|
|
28
|
+
* `V4_VIEW` and `V5_VIEW` and so that the question "did v6 take a name away?"
|
|
29
|
+
* has an answer in the code rather than in a reader's memory.
|
|
30
|
+
*
|
|
31
|
+
* ── Source ─────────────────────────────────────────────────────────────────
|
|
32
|
+
*
|
|
33
|
+
* https://www.tradingview.com/pine-script-docs/migration-guides/to-pine-version-6/
|
|
34
|
+
* https://www.tradingview.com/pine-script-docs/release-notes/
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Namespaces that exist only from v6. A member of one of these must not
|
|
38
|
+
* resolve at v1–v5, however completely it is implemented in the shared
|
|
39
|
+
* stdlib — the same gate `V5_ONLY_NAMESPACES` applies to `str.*` and
|
|
40
|
+
* `matrix.*`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const V6_ONLY_NAMESPACES: readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* Individual names that arrive at v6, for namespaces that already existed.
|
|
45
|
+
*
|
|
46
|
+
* Listed by name rather than by namespace because every one of these joins a
|
|
47
|
+
* namespace v5 already has — `request.footprint()` is new, `request.*` is not
|
|
48
|
+
* — so gating the root would take the whole namespace out of v5 with it.
|
|
49
|
+
*/
|
|
50
|
+
export declare const V6_ONLY_NAMES: readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* The v6 POSITIONAL order of functions whose shared signature differs from it,
|
|
53
|
+
* by parameter name. Read by Context.positionalForVersion.
|
|
54
|
+
*
|
|
55
|
+
* The shared stdlib keeps one signature per function, the union of every
|
|
56
|
+
* version's, and v6 removed parameters from the middle of several — `transp`
|
|
57
|
+
* (MG §"The transp parameter is removed") and `when` (§"Removal of when
|
|
58
|
+
* parameter"). Opening a one-slot gap where each was assumed the rest already
|
|
59
|
+
* matched v6, and it did not: `fill()` has no `show_last`, and
|
|
60
|
+
* `strategy.entry`'s tenth v6 argument, `disable_alert`, landed in a broker
|
|
61
|
+
* internal. Mapping BY NAME has no such assumption: the n-th positional
|
|
62
|
+
* argument is the n-th name here, wherever the shared function keeps it, and a
|
|
63
|
+
* name the shared function lacks is dropped and recorded like any unknown
|
|
64
|
+
* argument.
|
|
65
|
+
*
|
|
66
|
+
* Names are the shared function's where they differ only in spelling — the
|
|
67
|
+
* engine's `strategy.order` calls its direction `dir`.
|
|
68
|
+
*/
|
|
69
|
+
export declare const V6_POSITIONAL: Readonly<Record<string, readonly string[]>>;
|
|
70
|
+
/** Spellings v6 takes away. See the header: there are none. */
|
|
71
|
+
export declare const V6_REMOVED: readonly string[];
|
|
72
|
+
/**
|
|
73
|
+
* Parameters v6 added to functions that earlier versions already have,
|
|
74
|
+
* keyed by registry name.
|
|
75
|
+
*
|
|
76
|
+
* Not a registry key, so not a view: the FUNCTION exists at every version and
|
|
77
|
+
* only its signature grew. Context.call reads this when binding keyword
|
|
78
|
+
* arguments, and below v6 a listed name is dropped and recorded as unknown —
|
|
79
|
+
* exactly the treatment it got before it was added.
|
|
80
|
+
*/
|
|
81
|
+
export declare const V6_ONLY_PARAMS: Readonly<Record<string, readonly string[]>>;
|