openpinescript 0.0.0-stage → 0.1.0

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.
Files changed (103) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +346 -2
  3. package/dist/cli.mjs +108686 -0
  4. package/dist/index.cjs +108670 -0
  5. package/dist/index.mjs +108624 -0
  6. package/dist/types/index.d.ts +31 -0
  7. package/dist/types/parser/v1/generated/PineV1Lexer.d.ts +66 -0
  8. package/dist/types/parser/v1/generated/PineV1Parser.d.ts +555 -0
  9. package/dist/types/parser/v1/generated/PineV1ParserVisitor.d.ts +318 -0
  10. package/dist/types/parser/v1/index.d.ts +39 -0
  11. package/dist/types/parser/v2/generated/PineV2Lexer.d.ts +67 -0
  12. package/dist/types/parser/v2/generated/PineV2Parser.d.ts +568 -0
  13. package/dist/types/parser/v2/generated/PineV2ParserVisitor.d.ts +325 -0
  14. package/dist/types/parser/v2/index.d.ts +2 -0
  15. package/dist/types/parser/v3/generated/PineV3Lexer.d.ts +67 -0
  16. package/dist/types/parser/v3/generated/PineV3Parser.d.ts +568 -0
  17. package/dist/types/parser/v3/generated/PineV3ParserVisitor.d.ts +325 -0
  18. package/dist/types/parser/v3/index.d.ts +2 -0
  19. package/dist/types/parser/v4/generated/PineV4Lexer.d.ts +86 -0
  20. package/dist/types/parser/v4/generated/PineV4Parser.d.ts +673 -0
  21. package/dist/types/parser/v4/generated/PineV4ParserVisitor.d.ts +367 -0
  22. package/dist/types/parser/v4/index.d.ts +2 -0
  23. package/dist/types/parser/v5/generated/PineV5Lexer.d.ts +95 -0
  24. package/dist/types/parser/v5/generated/PineV5Parser.d.ts +964 -0
  25. package/dist/types/parser/v5/generated/PineV5ParserVisitor.d.ts +521 -0
  26. package/dist/types/parser/v5/index.d.ts +2 -0
  27. package/dist/types/parser/v6/generated/PineV6Lexer.d.ts +98 -0
  28. package/dist/types/parser/v6/generated/PineV6Parser.d.ts +984 -0
  29. package/dist/types/parser/v6/generated/PineV6ParserVisitor.d.ts +528 -0
  30. package/dist/types/parser/v6/index.d.ts +2 -0
  31. package/dist/types/runtime/v1/Series.d.ts +61 -0
  32. package/dist/types/runtime/v1/broker/Broker.d.ts +325 -0
  33. package/dist/types/runtime/v1/broker/index.d.ts +158 -0
  34. package/dist/types/runtime/v1/broker/val.d.ts +28 -0
  35. package/dist/types/runtime/v1/constDefault.d.ts +11 -0
  36. package/dist/types/runtime/v1/context.d.ts +1705 -0
  37. package/dist/types/runtime/v1/footprint.d.ts +32 -0
  38. package/dist/types/runtime/v1/index.d.ts +7 -0
  39. package/dist/types/runtime/v1/language-spec.d.ts +12 -0
  40. package/dist/types/runtime/v1/openTrades.d.ts +12 -0
  41. package/dist/types/runtime/v1/palette.d.ts +18 -0
  42. package/dist/types/runtime/v1/session.d.ts +482 -0
  43. package/dist/types/runtime/v1/sessions.d.ts +31 -0
  44. package/dist/types/runtime/v1/stateClone.d.ts +19 -0
  45. package/dist/types/runtime/v1/stdlib/alerts.d.ts +31 -0
  46. package/dist/types/runtime/v1/stdlib/arrays.d.ts +133 -0
  47. package/dist/types/runtime/v1/stdlib/barmerge.d.ts +27 -0
  48. package/dist/types/runtime/v1/stdlib/barstate.d.ts +79 -0
  49. package/dist/types/runtime/v1/stdlib/cast.d.ts +81 -0
  50. package/dist/types/runtime/v1/stdlib/chart.d.ts +283 -0
  51. package/dist/types/runtime/v1/stdlib/color.d.ts +51 -0
  52. package/dist/types/runtime/v1/stdlib/core.d.ts +162 -0
  53. package/dist/types/runtime/v1/stdlib/dataset.d.ts +36 -0
  54. package/dist/types/runtime/v1/stdlib/display.d.ts +50 -0
  55. package/dist/types/runtime/v1/stdlib/drawings.d.ts +407 -0
  56. package/dist/types/runtime/v1/stdlib/errors.d.ts +21 -0
  57. package/dist/types/runtime/v1/stdlib/font.d.ts +20 -0
  58. package/dist/types/runtime/v1/stdlib/footprint.d.ts +76 -0
  59. package/dist/types/runtime/v1/stdlib/format.d.ts +57 -0
  60. package/dist/types/runtime/v1/stdlib/index.d.ts +71 -0
  61. package/dist/types/runtime/v1/stdlib/input.d.ts +14 -0
  62. package/dist/types/runtime/v1/stdlib/inputs.d.ts +60 -0
  63. package/dist/types/runtime/v1/stdlib/late_members.d.ts +97 -0
  64. package/dist/types/runtime/v1/stdlib/logging.d.ts +31 -0
  65. package/dist/types/runtime/v1/stdlib/maps.d.ts +55 -0
  66. package/dist/types/runtime/v1/stdlib/math.d.ts +71 -0
  67. package/dist/types/runtime/v1/stdlib/matrix.d.ts +201 -0
  68. package/dist/types/runtime/v1/stdlib/metadata.d.ts +14 -0
  69. package/dist/types/runtime/v1/stdlib/mtf.d.ts +15 -0
  70. package/dist/types/runtime/v1/stdlib/renames.d.ts +117 -0
  71. package/dist/types/runtime/v1/stdlib/renames5.d.ts +113 -0
  72. package/dist/types/runtime/v1/stdlib/renames6.d.ts +81 -0
  73. package/dist/types/runtime/v1/stdlib/request.d.ts +207 -0
  74. package/dist/types/runtime/v1/stdlib/scale.d.ts +19 -0
  75. package/dist/types/runtime/v1/stdlib/session.d.ts +113 -0
  76. package/dist/types/runtime/v1/stdlib/sort_field.d.ts +12 -0
  77. package/dist/types/runtime/v1/stdlib/sources.d.ts +24 -0
  78. package/dist/types/runtime/v1/stdlib/str.d.ts +117 -0
  79. package/dist/types/runtime/v1/stdlib/strategy.d.ts +314 -0
  80. package/dist/types/runtime/v1/stdlib/syminfo.d.ts +209 -0
  81. package/dist/types/runtime/v1/stdlib/ta.d.ts +409 -0
  82. package/dist/types/runtime/v1/stdlib/time.d.ts +158 -0
  83. package/dist/types/runtime/v1/stdlib/trades.d.ts +108 -0
  84. package/dist/types/runtime/v1/stdlib/ui.d.ts +196 -0
  85. package/dist/types/runtime/v1/stdlib/v6_members.d.ts +68 -0
  86. package/dist/types/runtime/v1/timeframes.d.ts +139 -0
  87. package/dist/types/runtime/v1/zones.d.ts +30 -0
  88. package/dist/types/transpiler/common/index.d.ts +51 -0
  89. package/dist/types/transpiler/common/libraries.d.ts +29 -0
  90. package/dist/types/transpiler/common/parseErrors.d.ts +38 -0
  91. package/dist/types/transpiler/common/passes/ScopeAnalysis.d.ts +158 -0
  92. package/dist/types/transpiler/common/passes/TypeRules.d.ts +26 -0
  93. package/dist/types/transpiler/common/profiles/index.d.ts +96 -0
  94. package/dist/types/transpiler/common/version.d.ts +40 -0
  95. package/dist/types/transpiler/v1/ToJsVisitor.d.ts +720 -0
  96. package/dist/types/transpiler/v2/ToJsVisitor.d.ts +72 -0
  97. package/dist/types/transpiler/v3/ToJsVisitor.d.ts +87 -0
  98. package/dist/types/transpiler/v4/ToJsVisitor.d.ts +263 -0
  99. package/dist/types/transpiler/v5/ToJsVisitor.d.ts +1101 -0
  100. package/dist/types/transpiler/v6/ToJsVisitor.d.ts +237 -0
  101. package/dist/types/transpiler/v6/rules.d.ts +94 -0
  102. package/dist/types/utils/v2/common.d.ts +4 -0
  103. package/package.json +92 -4
@@ -0,0 +1,409 @@
1
+ import { Context } from "../context.js";
2
+ /**
3
+ * Simple Moving Average
4
+ * @returns series float
5
+ */
6
+ export declare function sma(ctx: Context, sourceInput: any, lengthInput: any): number;
7
+ /**
8
+ * Exponential Moving Average
9
+ * @returns series float
10
+ */
11
+ export declare function ema(ctx: Context, sourceInput: any, lengthInput: any): number;
12
+ /**
13
+ * Rolling Moving Average (Used in RSI)
14
+ * @returns series float
15
+ */
16
+ export declare function rma(ctx: Context, sourceInput: any, lengthInput: any): number;
17
+ /**
18
+ * Weighted Moving Average
19
+ * @returns series float
20
+ */
21
+ export declare function wma(ctx: Context, sourceInput: any, lengthInput: any): number;
22
+ /**
23
+ * Volume Weighted Moving Average
24
+ * @returns series float
25
+ */
26
+ export declare function vwma(ctx: Context, sourceInput: any, lengthInput: any): number;
27
+ /**
28
+ * Symmetrically Weighted Moving Average
29
+ * @returns series float
30
+ */
31
+ export declare function swma(ctx: Context, sourceInput: any): number;
32
+ /**
33
+ * TRIX Oscillator
34
+ * @returns series float
35
+ */
36
+ export declare function trix(ctx: Context, sourceInput: any, lengthInput: any): number;
37
+ /**
38
+ * Relative Strength Index
39
+ * @returns series float
40
+ */
41
+ export declare function rsi(ctx: Context, sourceInput: any, lengthInput: any): number;
42
+ /**
43
+ * Calculates MACD
44
+ * @returns [series float, series float, series float]
45
+ */
46
+ export declare function macd(ctx: Context, sourceInput: any, fastLenInput: any, slowLenInput: any, sigLenInput: any): [number, number, number];
47
+ /**
48
+ * Momentum
49
+ * @returns series float
50
+ */
51
+ export declare function mom(ctx: Context, sourceInput: any, lengthInput: any): number;
52
+ /**
53
+ * Bollinger Bands
54
+ * @returns [series float, series float, series float]
55
+ */
56
+ export declare function bb(ctx: Context, sourceInput: any, lengthInput: any, multInput: any): [number, number, number];
57
+ /**
58
+ * Commodity Channel Index
59
+ * @returns series float
60
+ */
61
+ export declare function cci(ctx: Context, sourceInput: any, lengthInput: any): number;
62
+ /**
63
+ * Cross
64
+ * @returns bool
65
+ */
66
+ export declare function cross(ctx: Context, xInput: any, yInput: any): boolean;
67
+ /**
68
+ * Crossover
69
+ * @returns bool
70
+ */
71
+ export declare function crossover(ctx: Context, xInput: any, yInput: any): boolean;
72
+ /**
73
+ * Crossunder
74
+ * @returns bool
75
+ */
76
+ export declare function crossunder(ctx: Context, xInput: any, yInput: any): boolean;
77
+ /**
78
+ * Highest value in window.
79
+ *
80
+ * Pine has TWO forms: `highest(source, length)` and `highest(length)`, where the
81
+ * one-argument form defaults its source to `high`. The short form is the one
82
+ * published breakout strategies actually use (`highest(enter_fast)`), and
83
+ * without it `length` arrived undefined and every bar was NaN.
84
+ *
85
+ * @returns series float
86
+ */
87
+ export declare function highest(ctx: Context, source: any, length?: any): number;
88
+ /**
89
+ * Lowest value in window.
90
+ *
91
+ * As with highest(), the one-argument form `lowest(length)` defaults its source
92
+ * to `low`.
93
+ *
94
+ * @returns series float
95
+ */
96
+ export declare function lowest(ctx: Context, source: any, length?: any): number;
97
+ /**
98
+ * Offset to highest value
99
+ * @returns series int
100
+ */
101
+ export declare function highestbars(ctx: Context, source: any, length?: any): number;
102
+ /**
103
+ * Offset to lowest value
104
+ * @returns series int
105
+ */
106
+ export declare function lowestbars(ctx: Context, source: any, length?: any): number;
107
+ /**
108
+ * Stochastic
109
+ * @returns series float
110
+ */
111
+ export declare function stoch(ctx: Context, sourceInput: any, highInput: any, lowInput: any, lengthInput: any): number;
112
+ /**
113
+ * valuewhen: Returns the value of 'source' when 'condition' was true on the nth occurrence.
114
+ * @returns series float
115
+ */
116
+ export declare function valuewhen(ctx: Context, conditionInput: any, sourceInput: any, occurrenceInput: any): number;
117
+ /**
118
+ * barssince: Returns the number of bars since the condition last evaluated to true.
119
+ * @returns series int
120
+ */
121
+ export declare function barssince(ctx: Context, conditionInput: any): number;
122
+ /**
123
+ * atr: Average True Range (requires contextual high/low/close data)
124
+ * @returns series float
125
+ */
126
+ export declare function atr(ctx: Context, lengthInput: any): number;
127
+ /**
128
+ * `ta.vwap(source)` — Volume Weighted Average Price.
129
+ *
130
+ * The accumulation restarts at the beginning of every SESSION; it is not
131
+ * cumulative over the chart. That is the whole character of the indicator, and
132
+ * getting it wrong is invisible on a short export and badly wrong on a long
133
+ * one — the old sessionless version drifted further from TradingView the more
134
+ * history it was given.
135
+ *
136
+ * On a daily or higher timeframe every bar is its own session, so this returns
137
+ * `source` unchanged. That is not a degenerate case to work around: TradingView
138
+ * does the same, exactly, on all 2,475 daily bars of
139
+ * conformance/v5/golden/harness_state.BTCUSDT.1D.log. VWAP is an intraday
140
+ * indicator, and on a daily chart there is nothing for it to average.
141
+ *
142
+ * ../sessions.ts owns the boundary, shared with `session.isfirstbar`.
143
+ *
144
+ * @returns series float
145
+ */
146
+ export declare function vwap(ctx: Context, sourceInput: any, anchor?: any, stdev_mult?: any): number | number[];
147
+ /**
148
+ * linreg: Linear Regression Curve
149
+ * @returns series float
150
+ */
151
+ export declare function linreg(ctx: Context, sourceInput: any, lengthInput: any, offsetInput?: any): number;
152
+ /**
153
+ * `ta.sar(start, inc, max)` — Parabolic SAR.
154
+ *
155
+ * This follows the `pine_sar` reference implementation published alongside
156
+ * `ta.sar` in TradingView's Pine Script reference manual, step for step. It is
157
+ * not the textbook Wilder algorithm, and the differences are not cosmetic —
158
+ * each of the four below moved the output on real data, and all four together
159
+ * reproduce TradingView's own values on 2,475 BTCUSDT daily bars to 1e-6 with
160
+ * no exceptions (conformance/v5/golden/harness_state.BTCUSDT.1D.log):
161
+ *
162
+ * - It returns `na` on bar 0 and SEEDS on bar 1, using `close > close[1]` to
163
+ * pick the initial direction. A bar-0 seed puts every later value one bar
164
+ * early for the whole chart.
165
+ * - The parabola advances BEFORE the stop is tested, so the reversal test
166
+ * sees this bar's advanced stop rather than the previous bar's.
167
+ * - On reversal the new stop is `max(high, maxMin)` (or `min(low, maxMin)`),
168
+ * which can pick the CURRENT bar's extreme rather than the trend's.
169
+ * - The acceleration factor and extreme point are frozen on the bar a trend
170
+ * begins — `isFirstTrendBar` — so a reversal bar never also bumps `af`.
171
+ *
172
+ * The closing clamp keeps the stop out of the previous two bars' range. Note
173
+ * it is `low[1]`/`low[2]`, NOT Wilder's `low`/`low[1]`: clamping against the
174
+ * current bar suppresses reversals TradingView takes (it first diverged at bar
175
+ * 263 of that export).
176
+ *
177
+ * @returns series float
178
+ */
179
+ export declare function sar(ctx: Context, startInput: any, incInput: any, maxInput: any): number;
180
+ /**
181
+ * cum: Cumulative sum of source over all bars.
182
+ * @returns series float
183
+ */
184
+ export declare function cum(ctx: Context, sourceInput: any): number;
185
+ /**
186
+ * roc: Rate of Change. 100 * (source - source[length]) / source[length]
187
+ * @returns series float
188
+ */
189
+ export declare function roc(ctx: Context, sourceInput: any, lengthInput: any): number;
190
+ /**
191
+ * change: Difference between current value and value N bars ago.
192
+ * @returns series float
193
+ */
194
+ export declare function change(ctx: Context, sourceInput: any, lengthInput?: any): number;
195
+ /**
196
+ * falling: True if source has been falling (decreasing) for `length` consecutive bars.
197
+ * @returns series bool
198
+ */
199
+ export declare function falling(ctx: Context, sourceInput: any, lengthInput: any): boolean;
200
+ /**
201
+ * rising: True if source has been rising (increasing) for `length` consecutive bars.
202
+ * @returns series bool
203
+ */
204
+ export declare function rising(ctx: Context, sourceInput: any, lengthInput: any): boolean;
205
+ /**
206
+ * dev: Deviation. Mean absolute deviation of source over length bars.
207
+ * @returns series float
208
+ */
209
+ export declare function dev(ctx: Context, sourceInput: any, lengthInput: any): number;
210
+ /**
211
+ * variance: Variance of source over length bars.
212
+ * @returns series float
213
+ */
214
+ export declare function variance(ctx: Context, sourceInput: any, lengthInput: any): number;
215
+ /**
216
+ * stdev: Standard Deviation of source over length bars.
217
+ * @returns series float
218
+ */
219
+ export declare function stdev(ctx: Context, sourceInput: any, lengthInput: any): number;
220
+ /**
221
+ * correlation: Pearson correlation coefficient between two series over length bars.
222
+ * @returns series float
223
+ */
224
+ export declare function correlation(ctx: Context, source1Input: any, source2Input: any, lengthInput: any): number;
225
+ /**
226
+ * percentrank: Percent rank. Percentage of past `length` values that are <= current value.
227
+ * @returns series float
228
+ */
229
+ export declare function percentrank(ctx: Context, sourceInput: any, lengthInput: any): number;
230
+ /**
231
+ * wpr: Williams %R
232
+ * @returns series float
233
+ */
234
+ export declare function wpr(ctx: Context, lengthInput: any): number;
235
+ /**
236
+ * mfi: Money Flow Index
237
+ * @returns series float
238
+ */
239
+ export declare function mfi(ctx: Context, sourceInput: any, lengthInput: any): number;
240
+ /**
241
+ * alma: Arnaud Legoux Moving Average
242
+ * @returns series float
243
+ */
244
+ export declare function alma(ctx: Context, sourceInput: any, lengthInput: any, offsetInput?: any, sigmaInput?: any): number;
245
+ /**
246
+ * cog: Center of Gravity oscillator
247
+ * @returns series float
248
+ */
249
+ export declare function cog(ctx: Context, sourceInput: any, lengthInput: any): number;
250
+ /**
251
+ * tsi: True Strength Index
252
+ * @returns series float
253
+ */
254
+ export declare function tsi(ctx: Context, sourceInput: any, longLenInput: any, shortLenInput: any): number;
255
+ /**
256
+ * pivothigh: Pivot High. Returns the value of the pivot high point, NaN otherwise.
257
+ * Looks for a high that is higher than `leftbars` bars to the left and `rightbars` bars to the right.
258
+ * @returns series float
259
+ */
260
+ export declare function pivothigh(ctx: Context, sourceInput: any, leftbarsInput: any, rightbarsInput: any): number;
261
+ /**
262
+ * pivotlow: Pivot Low. Returns the value of the pivot low point, NaN otherwise.
263
+ * @returns series float
264
+ */
265
+ export declare function pivotlow(ctx: Context, sourceInput: any, leftbarsInput: any, rightbarsInput: any): number;
266
+ /**
267
+ * `tr` / `ta.tr` — True Range, as a VARIABLE.
268
+ *
269
+ * A getter, because a script reads it by name:
270
+ *
271
+ * trBalance := trBalance + sign(tr - tr[_i])
272
+ *
273
+ * is TradingView's own `v4-debugging-11`, and `tr` there is a series, not a
274
+ * function. Registered without `@getter` it emitted the FUNCTION OBJECT, so
275
+ * `tr - tr[5]` was arithmetic on a function and every bar of the plot was na —
276
+ * with no diagnostic, because a built-in that exists is not an undeclared read.
277
+ *
278
+ * The one-argument call form `ta.tr(handle_na)` is a separate question. Nothing
279
+ * in the manual or the release notes states what `handle_na` does, and no
280
+ * script in the corpus passes it, so no parameter is offered rather than one
281
+ * that guesses.
282
+ *
283
+ * @getter
284
+ * @returns {series float} The bar's true range.
285
+ */
286
+ export declare function tr(ctx: Context): number;
287
+ /**
288
+ * sum: Rolling sum of source over length bars. (Equivalent to sma * length.)
289
+ * @returns series float
290
+ */
291
+ export declare function sum(ctx: Context, sourceInput: any, lengthInput: any): number;
292
+ /**
293
+ * fixnan: Replaces NaN with the last non-NaN value (per call site).
294
+ * @returns series float
295
+ */
296
+ export declare function fixnan(ctx: Context, xInput: any): number;
297
+ /**
298
+ * percentile_nearest_rank: the value at `percentage` percentile of the last
299
+ * `length` values, using the nearest-rank method (no interpolation).
300
+ *
301
+ * Nearest rank is `ceil(P/100 * N)` over the ASCENDING sample, so the result is
302
+ * always one of the observed values — which is what distinguishes it from
303
+ * percentile_linear_interpolation.
304
+ *
305
+ * @returns series float
306
+ */
307
+ export declare function percentile_nearest_rank(ctx: Context, sourceInput: any, lengthInput: any, percentageInput: any): number;
308
+ /**
309
+ * percentile_linear_interpolation: the value at `percentage` percentile of the
310
+ * last `length` values, interpolating between the two straddling samples.
311
+ *
312
+ * @returns series float
313
+ */
314
+ export declare function percentile_linear_interpolation(ctx: Context, sourceInput: any, lengthInput: any, percentageInput: any): number;
315
+ /**
316
+ * bbw: Bollinger Bands Width — the bands' span as a fraction of the basis.
317
+ *
318
+ * (basis + mult*stdev - (basis - mult*stdev)) / basis = 2*mult*stdev / sma
319
+ *
320
+ * @returns series float
321
+ */
322
+ export declare function bbw(ctx: Context, sourceInput: any, lengthInput: any, multInput: any): number;
323
+ /**
324
+ * kc: Keltner Channels — [basis, upper, lower].
325
+ *
326
+ * The basis is an EMA of the source; the band width is an EMA of the bar's
327
+ * range. `useTrueRange` chooses which range: the true range (the default, and
328
+ * what makes the channel gap-aware) or the plain high-low span.
329
+ *
330
+ * @returns [float, float, float]
331
+ */
332
+ export declare function kc(ctx: Context, sourceInput: any, lengthInput: any, multInput: any, useTrueRangeInput?: any): [number, number, number];
333
+ /**
334
+ * kcw: Keltner Channels Width — the channel span over its basis.
335
+ * @returns series float
336
+ */
337
+ export declare function kcw(ctx: Context, sourceInput: any, lengthInput: any, multInput: any, useTrueRangeInput?: any): number;
338
+ /**
339
+ * hma: Hull Moving Average.
340
+ *
341
+ * wma(2 * wma(src, len/2) - wma(src, len), round(sqrt(len)))
342
+ *
343
+ * The doubled short WMA minus the long one is what removes the lag; the final
344
+ * smoothing over sqrt(len) is what removes the noise that leaves behind.
345
+ *
346
+ * @returns series float
347
+ */
348
+ export declare function hma(ctx: Context, sourceInput: any, lengthInput: any): number;
349
+ /**
350
+ * cmo: Chande Momentum Oscillator.
351
+ *
352
+ * 100 * (sum(gains) - sum(losses)) / (sum(gains) + sum(losses))
353
+ *
354
+ * Unlike RSI, the sums are plain rolling sums rather than Wilder-smoothed, so
355
+ * the result reacts faster and swings the full -100..100.
356
+ *
357
+ * @returns series float
358
+ */
359
+ export declare function cmo(ctx: Context, sourceInput: any, lengthInput: any): number;
360
+ /**
361
+ * dmi: Directional Movement Index — [+DI, -DI, ADX].
362
+ *
363
+ * Transcribed from the reference implementation in TradingView's v5 manual
364
+ * rather than from a textbook: the +DM/-DM tie-breaks ("strictly greater than
365
+ * the other AND positive") and the zero-sum guard in ADX are exactly where
366
+ * published variants disagree with each other.
367
+ *
368
+ * @returns [float, float, float]
369
+ */
370
+ export declare function dmi(ctx: Context, diLengthInput: any, adxSmoothingInput: any): [number, number, number];
371
+ /**
372
+ * supertrend: [supertrend, direction].
373
+ *
374
+ * `direction` is -1 while the trend is up (the line sits below price) and 1
375
+ * while it is down. That sign convention is TradingView's and reads backwards
376
+ * to most people, so it is worth stating: a script testing `direction < 0` is
377
+ * testing for an UPTREND.
378
+ *
379
+ * The bands RATCHET — each one may only tighten toward price until price
380
+ * crosses it — which is the whole behaviour of the indicator and the reason it
381
+ * cannot be composed from the smoothers alone.
382
+ *
383
+ * @returns [float, float]
384
+ */
385
+ export declare function supertrend(ctx: Context, factorInput: any, atrPeriodInput: any): [number, number];
386
+ /**
387
+ * range: the span of `source` over `length` bars — highest minus lowest.
388
+ * @returns series float
389
+ */
390
+ export declare function range(ctx: Context, sourceInput: any, lengthInput: any): number;
391
+ /**
392
+ * median: the middle value of the last `length` samples.
393
+ *
394
+ * `na` until the window is full, matching every other windowed function here —
395
+ * a median over three of the twenty bars requested is not a median over twenty.
396
+ *
397
+ * @returns series float
398
+ */
399
+ export declare function median(ctx: Context, sourceInput: any, lengthInput: any): number;
400
+ /**
401
+ * mode: the most frequent value of the last `length` samples.
402
+ *
403
+ * Ties go to the SMALLEST value, which is what TradingView documents. Without
404
+ * that rule the answer would depend on iteration order, and two runs of the
405
+ * same script could differ.
406
+ *
407
+ * @returns series float
408
+ */
409
+ export declare function mode(ctx: Context, sourceInput: any, lengthInput: any): number;
@@ -0,0 +1,158 @@
1
+ import { Context } from "../context.js";
2
+ /**
3
+ * `timestamp(...)` — a UNIX timestamp in milliseconds, in all three spellings.
4
+ *
5
+ * SOURCING. TradingView's `v5-concepts-time-20` demonstrates every one, and
6
+ * annotates each with the zone it is read in:
7
+ *
8
+ * timestamp("2021-01-01") // "in the UTC+0 time zone"
9
+ * timestamp(2021, 1, 1, 0, 0) // "in the exchange time zone"
10
+ * timestamp("America/New_York", 2021, 1, 1, 0, 0) // in the named zone
11
+ * timestamp("UTC0", 2021, 1, 1, 0, 0) // in "UTC0" (UTC+0)
12
+ *
13
+ * ── What this used to be ────────────────────────────────────────────────────
14
+ *
15
+ * Only the middle one, and always in UTC. The date-STRING form returned
16
+ * `Date.UTC(Number("2021-01-01"), …)` — NaN — so `input.time(timestamp(
17
+ * "2021-01-01"))` was `na` and every plot gated on it drew nothing. The
18
+ * timezone form had no parameter to bind to, so the zone was dropped and the
19
+ * answer came back in UTC, silently off by up to half a day.
20
+ *
21
+ * Declared at top level, not as a member of the `time` object: Pine spells this
22
+ * as a global `timestamp(...)`, and the registry generator only hoists top-level
23
+ * exports to unprefixed keys. As an object member it generated
24
+ * "time.timestamp", which no Pine source can reach.
25
+ *
26
+ * The parameters are named for BOTH shapes, because the keyword form has to
27
+ * bind: `timestamp(timezone = "UTC+4", year = 2021, …)` and
28
+ * `timestamp(year = 2021, …)` are the same function. Which shape a positional
29
+ * call is in is decided by whether the first argument is a string.
30
+ *
31
+ * @returns {number} UNIX timestamp in milliseconds, or na.
32
+ */
33
+ export declare function timestamp(ctx: Context, timezone?: any, year?: any, month?: any, day?: any, hour?: any, minute?: any, second?: any, dateString?: any): number;
34
+ /**
35
+ * `year` / `year(time, timezone)` — the four-digit year.
36
+ * @getter
37
+ * @returns {series int} The year of `time` in `timezone`.
38
+ */
39
+ export declare function year(ctx: Context, time?: any, timezone?: any): number;
40
+ /**
41
+ * `month` / `month(time, timezone)` — 1 for January, 12 for December.
42
+ * @getter
43
+ * @returns {series int} The month of `time` in `timezone`.
44
+ */
45
+ export declare function month(ctx: Context, time?: any, timezone?: any): number;
46
+ /**
47
+ * `dayofmonth` / `dayofmonth(time, timezone)` — 1 to 31.
48
+ * @getter
49
+ * @returns {series int} The day of the month of `time` in `timezone`.
50
+ */
51
+ export declare function dayofmonth(ctx: Context, time?: any, timezone?: any): number;
52
+ /**
53
+ * `dayofweek` / `dayofweek(time, timezone)` — Sunday is 1, Saturday is 7.
54
+ * @getter
55
+ * @returns {series int} The day of the week of `time` in `timezone`.
56
+ */
57
+ export declare function dayofweek(ctx: Context, time?: any, timezone?: any): number;
58
+ /**
59
+ * `hour` / `hour(time, timezone)` — 0 to 23.
60
+ * @getter
61
+ * @returns {series int} The hour of `time` in `timezone`.
62
+ */
63
+ export declare function hour(ctx: Context, time?: any, timezone?: any): number;
64
+ /**
65
+ * `minute` / `minute(time, timezone)` — 0 to 59.
66
+ * @getter
67
+ * @returns {series int} The minute of `time` in `timezone`.
68
+ */
69
+ export declare function minute(ctx: Context, time?: any, timezone?: any): number;
70
+ /**
71
+ * `second` / `second(time, timezone)` — 0 to 59.
72
+ * @getter
73
+ * @returns {series int} The second of `time` in `timezone`.
74
+ */
75
+ export declare function second(ctx: Context, time?: any, timezone?: any): number;
76
+ /**
77
+ * `weekofyear` / `weekofyear(time, timezone)` — the ISO week, 1 to 53.
78
+ * @getter
79
+ * @returns {series int} The week of the year of `time` in `timezone`.
80
+ */
81
+ export declare function weekofyear(ctx: Context, time?: any, timezone?: any): number;
82
+ /**
83
+ * `time(resolution)` / `time(resolution, session)`.
84
+ *
85
+ * With one argument, the current bar's UNIX time. With a session, the bar's
86
+ * time when it falls INSIDE that session and `na` otherwise — which is how
87
+ * pre-v4 scripts express "only trade the cash session".
88
+ *
89
+ * TIMEZONE. The session window, and its day mask, are evaluated in the
90
+ * `timezone` argument when one is given, otherwise in the symbol's exchange
91
+ * timezone (`ctx.timezone`, which a host sets with `Session.setChart`; "UTC"
92
+ * until it does). Evidence: TradingView's Pine Logs for the ICT Silver Bullet
93
+ * script (conformance/v5/parity/harness_ict_silver_bullet.BTCUSDT.5.csv) show
94
+ * "0300-0400" in "America/New_York" opening at 07:00 UTC on 2026-10-05 (EDT,
95
+ * UTC-4); evaluated in UTC it opened at 03:00. Daylight saving follows the
96
+ * zone, so the same window opens at 08:00 UTC in winter. An unknown zone name
97
+ * reads as UTC, as for `hour()` and the other calendar accessors.
98
+ *
99
+ * The `resolution` argument is accepted and ignored: honouring it means
100
+ * re-aggregating the chart into that timeframe, which is the same missing
101
+ * engine that blocks `heikinashi()`.
102
+ *
103
+ * ⚠ THE DEFAULT SESSION IS NOT APPLIED. Omitting `session` returns the bar
104
+ * time unfiltered. TradingView instead applies the SYMBOL's session, and the
105
+ * v4 → v5 guide records its literal fallback widening from `"23456"` (Mon-Fri)
106
+ * to `"1234567"` (Sun-Sat) — a difference this engine therefore does not model.
107
+ *
108
+ * Applying either literal was tried and reverted. It needs the same exchange
109
+ * calendar the timezone note above is missing, and Mon-Fri broke a published
110
+ * script in the corpus outright: sunday.pine marks Sunday opens by testing
111
+ * `dayofweek(time('D'))`, and a weekday mask makes that `na` on every bar it
112
+ * exists to find. See the note in transpiler/common/profiles/index.ts.
113
+ *
114
+ * @returns {series float} The bar's UNIX time in ms, or na.
115
+ */
116
+ export declare function time(ctx: any, _resolution?: any, session?: any, timezone?: any, bars_back?: any, timeframe_bars_back?: any): number;
117
+ /**
118
+ * `time_close(resolution, session, timezone)` — the bar's CLOSING time.
119
+ *
120
+ * Added in Pine v4. Where `time` is the instant a bar opened, this is the
121
+ * instant it closes, which is what a script needs to place a drawing at the
122
+ * right-hand edge of the current bar rather than its left.
123
+ *
124
+ * It is derived from the chart's resolution rather than read from the data,
125
+ * because the closing time of the bar being evaluated is the OPENING time of a
126
+ * bar that has not arrived yet — on the last bar there is no next bar to read.
127
+ *
128
+ * `session` filters exactly as it does for `time()`, in the same timezone
129
+ * (the `timezone` argument, else the exchange's).
130
+ *
131
+ * Marked `@getter` because Pine documents it as "both a variable and a
132
+ * function": bare `time_close` must read as the current bar's closing time,
133
+ * while `time_close("D")` still resolves through the ordinary call path. `time`
134
+ * itself does not need the tag only because the runtime binds an `opsv2_time`
135
+ * SERIES into the sandbox for the bare form to find; there is no such series
136
+ * here, and without the tag `plot(time_close)` plotted the function object,
137
+ * which reads as `na`.
138
+ *
139
+ * @getter
140
+ * @returns {series float} The bar's closing UNIX time in ms, or na.
141
+ */
142
+ export declare function time_close(ctx: any, resolution?: any, session?: any, timezone?: any, bars_back?: any, timeframe_bars_back?: any): number;
143
+ /**
144
+ * `time_tradingday` — the start of the trading day the bar belongs to.
145
+ *
146
+ * Added in Pine v4 (February 2021): "the beginning time of the trading day the
147
+ * current bar belongs to". The v5 manual states it as the 00:00 UTC start of
148
+ * the last trading day in the bar's final session.
149
+ *
150
+ * With no exchange calendar this is UTC midnight of the bar's own day — exact
151
+ * for a symbol whose session does not straddle midnight, and shifted for one
152
+ * that does. Same limitation, and same remedy, as the rest of this file:
153
+ * supply bar timestamps already shifted to the exchange timezone.
154
+ *
155
+ * @getter
156
+ * @returns {series float} UNIX time of the trading day's start, in ms.
157
+ */
158
+ export declare function time_tradingday(ctx: any): number;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * `strategy.opentrades.*` and `strategy.closedtrades.*` — the trade inspectors.
3
+ *
4
+ * SOURCING. From the manual's strategies page, these are indexed accessors:
5
+ * `strategy.opentrades.entry_price(trade_num)` "returns the entry price of the
6
+ * open trade at `trade_num`", and the `closedtrades` family answers the same
7
+ * questions about trades that have already been closed. Trade numbers are
8
+ * ZERO-BASED and count from the oldest.
9
+ *
10
+ * ── Why this is a file of its own ───────────────────────────────────────────
11
+ *
12
+ * `strategy.opentrades` is BOTH a number — how many trades are open — and the
13
+ * root of these functions. `runtime/v1/stdlib/strategy.ts` is a namespace
14
+ * module, so its exported `function opentrades(ctx)` already claims that key,
15
+ * and TypeScript will not let one name be a function and an object literal in
16
+ * one file.
17
+ *
18
+ * So the sub-members are declared here, in a non-namespace file whose exported
19
+ * object is called `strategy`. The generator reads the object literal and emits
20
+ * `strategy.opentrades.entry_price`; `createStdlib` then attaches those members
21
+ * onto the getter function, which is the merge it already does for `log.info`
22
+ * beside a flat `log`.
23
+ *
24
+ * ── What is a trade ─────────────────────────────────────────────────────────
25
+ *
26
+ * An open trade is one filled entry not yet fully closed (see ../openTrades),
27
+ * so `strategy.opentrades` is the length of the list these functions index. A
28
+ * partial close shrinks the oldest entry's size; it does not add a trade.
29
+ * The excursions (`max_drawdown`, `max_runup`) are tracked for the position as
30
+ * a whole, and every open trade reports that figure.
31
+ */
32
+ import { Context } from "../context.js";
33
+ export declare const strategy: {
34
+ opentrades: {
35
+ /** The entry price of the open trade at `trade_num`. */
36
+ entry_price: (ctx: Context, trade_num?: any) => number;
37
+ /** The bar index on which the open trade at `trade_num` was entered. */
38
+ entry_bar_index: (ctx: Context, trade_num?: any) => number;
39
+ /** The order id that opened the trade at `trade_num`. */
40
+ entry_id: (ctx: Context, trade_num?: any) => any;
41
+ /** The trade's UNREALISED profit, in the strategy's currency. */
42
+ profit: (ctx: Context, trade_num?: any) => number;
43
+ /** The trade's direction as a signed size: positive long, negative short. */
44
+ size: (ctx: Context, trade_num?: any) => number;
45
+ /** The open position's largest adverse and favourable excursions so far. */
46
+ max_drawdown: (ctx: Context, trade_num?: any) => number;
47
+ max_runup: (ctx: Context, trade_num?: any) => number;
48
+ /** Unrealised result as a percentage of the entry value. */
49
+ profit_percent: (ctx: Context, trade_num?: any) => number;
50
+ /** When the open trade began, UNIX ms. */
51
+ entry_time: (ctx: Context, trade_num?: any) => number;
52
+ /** Entry commission paid on the open trade. */
53
+ commission: (ctx: Context, trade_num?: any) => number;
54
+ /** The entry order's comment, which this engine does not record: na. */
55
+ entry_comment: (_ctx: Context, _trade_num?: any) => any;
56
+ };
57
+ closedtrades: {
58
+ /**
59
+ * v6: the index of the oldest closed trade that has not been trimmed —
60
+ * "0, representing the actual first trade in the simulation" until the
61
+ * strategy has more than 9000. A v6-only name; see renames6.ts.
62
+ * @getter
63
+ */
64
+ first_index: (ctx: Context) => number;
65
+ /** The entry price of the closed trade at `trade_num`. */
66
+ entry_price: (ctx: Context, trade_num?: any) => number;
67
+ /** The exit price of the closed trade at `trade_num`. */
68
+ exit_price: (ctx: Context, trade_num?: any) => number;
69
+ /**
70
+ * The order id that opened the closed trade at `trade_num`. `id` is the
71
+ * CLOSING order's name, which is what this returned until TradingView's
72
+ * log showed "L" where it read "Exit XL1".
73
+ */
74
+ entry_id: (ctx: Context, trade_num?: any) => any;
75
+ /**
76
+ * The id of the order that closed the trade at `trade_num`, or na when
77
+ * there is no such trade — the string "NaN" passed `na()` as a value.
78
+ */
79
+ exit_id: (ctx: Context, trade_num?: any) => any;
80
+ /** The comment of the order that closed the trade, or na when it had none. */
81
+ exit_comment: (ctx: Context, trade_num?: any) => any;
82
+ /** Commission paid on the trade's entry and exit, in the account currency. */
83
+ commission: (ctx: Context, trade_num?: any) => number;
84
+ /** The bar index the closed trade was entered on. */
85
+ entry_bar_index: (ctx: Context, trade_num?: any) => number;
86
+ /** The bar index the closed trade was exited on. */
87
+ exit_bar_index: (ctx: Context, trade_num?: any) => number;
88
+ /** The trade's REALISED profit, in the strategy's currency. */
89
+ profit: (ctx: Context, trade_num?: any) => number;
90
+ /** The trade's size as a signed number: positive long, negative short. */
91
+ size: (ctx: Context, trade_num?: any) => number;
92
+ /** The largest adverse excursion while the trade was open, in money. */
93
+ max_drawdown: (ctx: Context, trade_num?: any) => number;
94
+ /** The largest favourable excursion, in money. */
95
+ max_runup: (ctx: Context, trade_num?: any) => number;
96
+ /** The drawdown as a percentage of the trade's entry value. */
97
+ max_drawdown_percent: (ctx: Context, trade_num?: any) => number;
98
+ /** The run-up as a percentage of the trade's entry value. */
99
+ max_runup_percent: (ctx: Context, trade_num?: any) => number;
100
+ /** The trade's result as a percentage of its entry value. */
101
+ profit_percent: (ctx: Context, trade_num?: any) => number;
102
+ /** When the trade opened and closed, UNIX ms. */
103
+ entry_time: (ctx: Context, trade_num?: any) => number;
104
+ exit_time: (ctx: Context, trade_num?: any) => number;
105
+ /** The entry order's comment, which this engine does not record: na. */
106
+ entry_comment: (_ctx: Context, _trade_num?: any) => any;
107
+ };
108
+ };