pinets 0.9.15 → 0.9.17

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 (72) hide show
  1. package/README.md +14 -11
  2. package/dist/pinets.min.browser.es.js +24 -23
  3. package/dist/pinets.min.browser.es.js.map +1 -1
  4. package/dist/pinets.min.browser.js +23 -22
  5. package/dist/pinets.min.browser.js.map +1 -1
  6. package/dist/pinets.min.cjs +24 -23
  7. package/dist/pinets.min.cjs.map +1 -1
  8. package/dist/pinets.min.es.js +24 -23
  9. package/dist/pinets.min.es.js.map +1 -1
  10. package/dist/types/Context.class.d.ts +9 -3
  11. package/dist/types/PineTS.class.d.ts +92 -4
  12. package/dist/types/namespaces/Ticker.d.ts +104 -0
  13. package/dist/types/namespaces/line/LineHelper.d.ts +9 -0
  14. package/dist/types/namespaces/linefill/LinefillHelper.d.ts +11 -0
  15. package/dist/types/namespaces/polyline/PolylineObject.d.ts +3 -3
  16. package/dist/types/namespaces/strategy/methods/account_currency.d.ts +5 -0
  17. package/dist/types/namespaces/strategy/methods/any.d.ts +5 -0
  18. package/dist/types/namespaces/strategy/methods/avg_losing_trade.d.ts +6 -0
  19. package/dist/types/namespaces/strategy/methods/avg_losing_trade_percent.d.ts +5 -0
  20. package/dist/types/namespaces/strategy/methods/avg_trade.d.ts +5 -0
  21. package/dist/types/namespaces/strategy/methods/avg_trade_percent.d.ts +6 -0
  22. package/dist/types/namespaces/strategy/methods/avg_winning_trade.d.ts +5 -0
  23. package/dist/types/namespaces/strategy/methods/avg_winning_trade_percent.d.ts +5 -0
  24. package/dist/types/namespaces/strategy/methods/cancel.d.ts +1 -0
  25. package/dist/types/namespaces/strategy/methods/cancel_all.d.ts +6 -0
  26. package/dist/types/namespaces/strategy/methods/cash.d.ts +5 -0
  27. package/dist/types/namespaces/strategy/methods/close.d.ts +1 -0
  28. package/dist/types/namespaces/strategy/methods/close_all.d.ts +1 -0
  29. package/dist/types/namespaces/strategy/methods/closedtrades.d.ts +15 -0
  30. package/dist/types/namespaces/strategy/methods/convert_to_account.d.ts +9 -0
  31. package/dist/types/namespaces/strategy/methods/convert_to_symbol.d.ts +5 -0
  32. package/dist/types/namespaces/strategy/methods/default_entry_qty.d.ts +8 -0
  33. package/dist/types/namespaces/strategy/methods/entry.d.ts +1 -0
  34. package/dist/types/namespaces/strategy/methods/equity.d.ts +5 -0
  35. package/dist/types/namespaces/strategy/methods/eventrades.d.ts +2 -0
  36. package/dist/types/namespaces/strategy/methods/exit.d.ts +1 -0
  37. package/dist/types/namespaces/strategy/methods/fixed.d.ts +5 -0
  38. package/dist/types/namespaces/strategy/methods/grossloss.d.ts +5 -0
  39. package/dist/types/namespaces/strategy/methods/grossloss_percent.d.ts +4 -0
  40. package/dist/types/namespaces/strategy/methods/grossprofit.d.ts +5 -0
  41. package/dist/types/namespaces/strategy/methods/grossprofit_percent.d.ts +4 -0
  42. package/dist/types/namespaces/strategy/methods/initial_capital.d.ts +2 -0
  43. package/dist/types/namespaces/strategy/methods/long.d.ts +4 -0
  44. package/dist/types/namespaces/strategy/methods/losstrades.d.ts +2 -0
  45. package/dist/types/namespaces/strategy/methods/margin_liquidation_price.d.ts +13 -0
  46. package/dist/types/namespaces/strategy/methods/max_contracts_held_all.d.ts +2 -0
  47. package/dist/types/namespaces/strategy/methods/max_contracts_held_long.d.ts +2 -0
  48. package/dist/types/namespaces/strategy/methods/max_contracts_held_short.d.ts +2 -0
  49. package/dist/types/namespaces/strategy/methods/max_drawdown.d.ts +5 -0
  50. package/dist/types/namespaces/strategy/methods/max_drawdown_percent.d.ts +5 -0
  51. package/dist/types/namespaces/strategy/methods/max_runup.d.ts +5 -0
  52. package/dist/types/namespaces/strategy/methods/max_runup_percent.d.ts +5 -0
  53. package/dist/types/namespaces/strategy/methods/netprofit.d.ts +5 -0
  54. package/dist/types/namespaces/strategy/methods/netprofit_percent.d.ts +5 -0
  55. package/dist/types/namespaces/strategy/methods/openprofit.d.ts +5 -0
  56. package/dist/types/namespaces/strategy/methods/openprofit_percent.d.ts +5 -0
  57. package/dist/types/namespaces/strategy/methods/opentrades.d.ts +9 -0
  58. package/dist/types/namespaces/strategy/methods/order.d.ts +6 -0
  59. package/dist/types/namespaces/strategy/methods/param.d.ts +5 -0
  60. package/dist/types/namespaces/strategy/methods/percent_of_equity.d.ts +5 -0
  61. package/dist/types/namespaces/strategy/methods/position_avg_price.d.ts +5 -0
  62. package/dist/types/namespaces/strategy/methods/position_entry_name.d.ts +5 -0
  63. package/dist/types/namespaces/strategy/methods/position_size.d.ts +5 -0
  64. package/dist/types/namespaces/strategy/methods/risk.d.ts +22 -0
  65. package/dist/types/namespaces/strategy/methods/short.d.ts +4 -0
  66. package/dist/types/namespaces/strategy/methods/wintrades.d.ts +2 -0
  67. package/dist/types/namespaces/strategy/strategy.index.d.ts +7 -0
  68. package/dist/types/namespaces/strategy/types.d.ts +176 -0
  69. package/dist/types/namespaces/strategy/utils.d.ts +84 -0
  70. package/dist/types/transpiler/settings.d.ts +1 -0
  71. package/dist/types/transpiler/slicing/buildLtfSlices.d.ts +1 -0
  72. package/package.json +1 -1
@@ -4,6 +4,7 @@ import { Input } from './namespaces/input/input.index';
4
4
  import PineMath from './namespaces/math/math.index';
5
5
  import { PineRequest } from './namespaces/request/request.index';
6
6
  import TechnicalAnalysis from './namespaces/ta/ta.index';
7
+ import { StrategyState } from './namespaces/strategy/strategy.index';
7
8
  import { Series } from './Series';
8
9
  import type { IndicatorOptions } from './types/PineTypes';
9
10
  export declare class Context {
@@ -11,6 +12,7 @@ export declare class Context {
11
12
  indicator: IndicatorOptions;
12
13
  cache: any;
13
14
  taState: any;
15
+ strategy?: StrategyState;
14
16
  isSecondaryContext: boolean;
15
17
  chartTimezone: string | null;
16
18
  dataVersion: number;
@@ -66,6 +68,8 @@ export declare class Context {
66
68
  sDate: number;
67
69
  eDate: number;
68
70
  fullContext: Context;
71
+ viewportLeft: number | undefined;
72
+ viewportRight: number | undefined;
69
73
  pineTSCode: Function | String;
70
74
  inputs: Record<string, any>;
71
75
  constructor({ marketData, source, tickerId, timeframe, limit, sDate, eDate, fullContext, inputs, }: {
@@ -144,11 +148,13 @@ export declare class Context {
144
148
  */
145
149
  iter(source: any): any;
146
150
  /**
147
- * Resolve an iterable yielding [index, value] tuples for `for [i, x] in collection`
151
+ * Resolve an iterable yielding [key, value] tuples for `for [k, v] in collection`
148
152
  * destructuring codegen. PineArrayObject's [Symbol.iterator] yields scalar values, so
149
- * we must explicitly call `.entries()` on the underlying array.
153
+ * we must explicitly call `.entries()` on the underlying array. PineMapObject stores
154
+ * its data on `.map` (a JS Map) — without this branch the fallthrough returned an
155
+ * empty iterator and `for [k,v] in map` silently iterated 0 times.
150
156
  */
151
- entries(source: any): IterableIterator<[number, any]>;
157
+ entries(source: any): IterableIterator<[any, any]>;
152
158
  private _callStack;
153
159
  /**
154
160
  * Cumulative call-path stack. Each entry is the full path from the root to
@@ -57,6 +57,56 @@ export declare class PineTS {
57
57
  * @param mode Alert firing mode
58
58
  */
59
59
  setAlertMode(mode: 'realtime' | 'all'): void;
60
+ private _viewportLeft;
61
+ private _viewportRight;
62
+ private _usesVisibleRange;
63
+ private _lastRunViewport;
64
+ private _lastResult;
65
+ private _lastPineTSCode;
66
+ /**
67
+ * Set the visible range of bars from the host (e.g. chart UI viewport).
68
+ * Affects `chart.left_visible_bar_time` and `chart.right_visible_bar_time`.
69
+ * Defaults derive from `marketData[0]/[last].openTime` if never called.
70
+ *
71
+ * The setter only stores values; it does NOT trigger a re-run. Call
72
+ * `update()` afterwards to apply the change. For scripts that don't
73
+ * reference visible-range built-ins, `update()` is a no-op.
74
+ *
75
+ * @param left openTime of the leftmost visible bar
76
+ * @param right openTime of the rightmost visible bar
77
+ */
78
+ setVisibleRange(left: number, right: number): void;
79
+ /**
80
+ * Whether the loaded script references any visible-range built-in
81
+ * (e.g. `chart.left_visible_bar_time`). Detected statically during
82
+ * transpile. Consumers fanning viewport changes across many indicators
83
+ * should skip non-tagged instances to avoid unnecessary re-runs.
84
+ */
85
+ usesVisibleRange(): boolean;
86
+ /** Current viewport left (undefined if setter never called). */
87
+ get visibleRangeLeft(): number | undefined;
88
+ /** Current viewport right (undefined if setter never called). */
89
+ get visibleRangeRight(): number | undefined;
90
+ /**
91
+ * Smart re-run: executes `run()` only if a re-run is actually needed.
92
+ *
93
+ * - First call: behaves like `run()` (always executes).
94
+ * - Subsequent calls: returns the cached previous result UNLESS the script
95
+ * is viewport-dependent (`usesVisibleRange()`) AND the viewport has
96
+ * changed since the last cached run.
97
+ *
98
+ * The typical pattern for a chart consumer with multiple indicators:
99
+ *
100
+ * // user pans the chart
101
+ * for (const p of indicators) {
102
+ * p.setVisibleRange(left, right);
103
+ * await p.update(code); // no-op for non-viewport indicators
104
+ * }
105
+ *
106
+ * The pineTSCode argument is optional after the first call — the same code
107
+ * is reused. Pass it again only when the script source itself has changed.
108
+ */
109
+ update(pineTSCode?: Indicator | Function | String): Promise<Context>;
60
110
  constructor(source: IProvider | any[], tickerId?: string, timeframe?: string, limit?: number, sDate?: number, eDate?: number);
61
111
  setDebugSettings({ ln, debug }: {
62
112
  ln: boolean;
@@ -95,7 +145,23 @@ export declare class PineTS {
95
145
  stop: () => void;
96
146
  };
97
147
  /**
98
- * Run the script completely and return the final context (backward compatible behavior)
148
+ * Run an already-transpiled PineTS function in this instance no
149
+ * additional transpile/parse pass. Used by `request.security_lower_tf`'s
150
+ * slow path to execute the slice produced at primary-transpile time
151
+ * (a truncated body containing only the prefix up to the call). The
152
+ * caller is responsible for ensuring `transpiledFn` was produced by
153
+ * this transpiler against the same source — calling this with an
154
+ * arbitrary function is unsafe.
155
+ */
156
+ runPretranspiled(transpiledFn: Function, inputs?: Record<string, any>, periods?: number): Promise<Context>;
157
+ /**
158
+ * Run the script completely and return the final context.
159
+ *
160
+ * Execution is split: all bars except the last are processed first, then a
161
+ * var-state snapshot is taken, then the last bar is processed. This gives
162
+ * updateTail() a reliable snapshot-based restore point, matching the
163
+ * pattern used by _runPaginated and eliminates the pop-based drift that
164
+ * occurred when var variables were modified in-place during re-execution.
99
165
  * @private
100
166
  */
101
167
  private _runComplete;
@@ -136,9 +202,16 @@ export declare class PineTS {
136
202
  private _appendCandle;
137
203
  /**
138
204
  * Update the secondary context's tail with fresh market data.
139
- * Mirrors the streaming update logic in _runPaginated:
140
- * fetches new/updated candles, rolls back the last result, and re-executes
141
- * only the affected bars.
205
+ *
206
+ * Uses snapshot-restore for reliable var state rollback, matching the
207
+ * approach used by _runPaginated. The pop-based _removeLastResult is
208
+ * only used as a fallback for contexts that have no snapshot (e.g. those
209
+ * produced by runPretranspiled, which skips the split-execute pattern).
210
+ *
211
+ * After restoring state and re-executing, a fresh snapshot is taken before
212
+ * the last bar so that subsequent updateTail() calls also have a valid
213
+ * restore point.
214
+ *
142
215
  * @param context - The cached secondary context to update
143
216
  * @returns true if data was updated, false if no changes
144
217
  */
@@ -186,6 +259,21 @@ export declare class PineTS {
186
259
  * @private
187
260
  */
188
261
  private _transpileCode;
262
+ /**
263
+ * Static analysis on the transpiled function body to detect references to
264
+ * host-bound built-ins (currently visible-range; extensible via
265
+ * VIEWPORT_DEPENDENT_BUILTINS). Comments are stripped during pine2js, so
266
+ * scanning the post-transpile output is comment-safe.
267
+ *
268
+ * Why post-transpile (not regex on Pine source): a `chart.left_visible_bar_time`
269
+ * literal inside a // comment would be a false positive at the source level.
270
+ * After pine2js, only live code remains.
271
+ *
272
+ * Why regex (not AST visitor): `chart` is a reserved namespace in
273
+ * KNOWN_NAMESPACES — Pine scripts cannot shadow it with a local identifier,
274
+ * so a whole-word match on `chart.<prop>` is unambiguous.
275
+ */
276
+ private _detectViewportUsage;
189
277
  /**
190
278
  * Execute iterations from startIdx to endIdx, updating the context
191
279
  * @private
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Pine Script `ticker.*` namespace.
3
+ *
4
+ * The methods here construct "ticker ID" strings that are passed to
5
+ * `request.security` / `request.security_lower_tf` to fetch data for a
6
+ * specific symbol — potentially with extra modifiers (session,
7
+ * adjustment, non-standard chart type). PineTS' data providers serve
8
+ * standard candles only; chart-type modifiers (Heikin-Ashi, Renko,
9
+ * Kagi, Line Break, Point & Figure) are silently dropped at the
10
+ * `request.security` boundary, since we can't render alternative
11
+ * bar-construction algorithms from the raw OHLCV feed.
12
+ *
13
+ * For the plain "no-modifier" cases — which cover virtually every
14
+ * real-world Pine script — the returned tickerid strings match
15
+ * TradingView's exact log output, so automation tests pass strictly.
16
+ * Non-default `adjustment` values trigger TV's encoded
17
+ * `={"adjustment":"…","symbol":"…"}` form; PineTS only emits the
18
+ * plain symbol there (since `request.security` doesn't honor
19
+ * adjustment either). Document as a known divergence.
20
+ */
21
+ export declare class Ticker {
22
+ private context;
23
+ constructor(context: any);
24
+ /**
25
+ * Type B param wrapper — extract scalar from series/primitive.
26
+ * Used by the transpiler to wrap ticker.* arguments.
27
+ */
28
+ param(source: any, index?: number, _name?: string): any;
29
+ /**
30
+ * ticker.inherit(from_tickerid, symbol) → simple string
31
+ *
32
+ * Returns a ticker ID that uses `symbol` and inherits modifier
33
+ * settings (session, currency, adjustment, chart type) from
34
+ * `from_tickerid`. For data-fetching purposes the result is
35
+ * effectively `symbol` — modifiers can't be honored without a TV
36
+ * datafeed, and `symbol` is what `request.security` needs.
37
+ */
38
+ inherit(_from_tickerid: any, symbol: any): string;
39
+ /**
40
+ * ticker.new(prefix, ticker, session?, adjustment?, ...) → simple string
41
+ *
42
+ * Returns "prefix:ticker". Modifier arguments are accepted but
43
+ * ignored — see class-level note. Returns an empty string if
44
+ * either prefix or ticker is empty (matches TV).
45
+ */
46
+ new(prefix: any, ticker: any, _session?: any, _adjustment?: any, _backadjustment?: any, _settlement_as_close?: any): string;
47
+ /**
48
+ * ticker.modify(tickerid, session?, adjustment?, ...) → simple string
49
+ *
50
+ * Returns the tickerid unchanged — modifier args are accepted but
51
+ * ignored.
52
+ */
53
+ modify(tickerid: any, _session?: any, _adjustment?: any, _backadjustment?: any, _settlement_as_close?: any): string;
54
+ /**
55
+ * ticker.standard(symbol?) → simple string
56
+ *
57
+ * Returns the symbol stripped of any non-standard chart-type
58
+ * modifiers. Since PineTS doesn't synthesise non-standard chart
59
+ * types in the first place, this is effectively a pass-through
60
+ * (the standard form IS what our providers serve). If `symbol` is
61
+ * undefined, falls back to `syminfo.tickerid`.
62
+ */
63
+ standard(symbol?: any): string;
64
+ /**
65
+ * ticker.heikinashi(symbol) → simple string
66
+ *
67
+ * In TV this returns an encoded tickerid that instructs the
68
+ * datafeed to deliver Heikin-Ashi bars. PineTS' providers don't
69
+ * synthesise HA candles, so we return the plain symbol — downstream
70
+ * `request.security` fetches standard candles, NOT HA-transformed
71
+ * ones. Behavior diverges from TV when the script depends on the
72
+ * HA values matching TV's HA computation. Documented limitation.
73
+ */
74
+ heikinashi(symbol: any): string;
75
+ /**
76
+ * ticker.renko(symbol, style?, param?, request_wicks?, source?) → simple string
77
+ *
78
+ * Stub: returns the plain symbol. See heikinashi() note.
79
+ */
80
+ renko(symbol: any, _style?: any, _param?: any, _request_wicks?: any, _source?: any): string;
81
+ /**
82
+ * ticker.kagi(symbol, reversal) → simple string
83
+ *
84
+ * Stub: returns the plain symbol. See heikinashi() note.
85
+ */
86
+ kagi(symbol: any, _reversal?: any): string;
87
+ /**
88
+ * ticker.linebreak(symbol, number_of_lines) → simple string
89
+ *
90
+ * Stub: returns the plain symbol. See heikinashi() note.
91
+ */
92
+ linebreak(symbol: any, _number_of_lines?: any): string;
93
+ /**
94
+ * ticker.pointfigure(symbol, source, style, param, reversal) → simple string
95
+ *
96
+ * Stub: returns the plain symbol. See heikinashi() note.
97
+ */
98
+ pointfigure(symbol: any, _source?: any, _style?: any, _param?: any, _reversal?: any): string;
99
+ /**
100
+ * Coerce a runtime value to a plain string. Handles Series wrappers
101
+ * (used by the transpiler), `na`/null/undefined, and primitives.
102
+ */
103
+ private _coerce;
104
+ }
@@ -15,6 +15,15 @@ export declare class LineHelper {
15
15
  * scalar value is used for line properties.
16
16
  */
17
17
  private _resolve;
18
+ /**
19
+ * Resolve a color value, PRESERVING na markers so renderers can
20
+ * detect "no color". Pine emits na as null (from `color(na)` —
21
+ * `color.any` returns null) or NaN (from raw `na` literal). Both
22
+ * must survive into the plot data — collapsing them to a default
23
+ * forces the renderer to paint a visible line where the script
24
+ * asked for none. Mirrors Box/Polyline `_resolveColor`.
25
+ */
26
+ private _resolveColor;
18
27
  private _createLine;
19
28
  private _enforceMaxCount;
20
29
  new(...args: any[]): LineObject;
@@ -11,6 +11,17 @@ export declare class LinefillHelper {
11
11
  * Resolve a value that may be a Series, a bound function, or a plain scalar.
12
12
  */
13
13
  private _resolve;
14
+ /**
15
+ * Resolve a color value, PRESERVING na markers so renderers can
16
+ * detect "no color" instead of being forced to paint a default.
17
+ * Pine emits na either as null (from `color(na)` — `color.any`
18
+ * returns null) or as NaN (from raw `na` literals). The previous
19
+ * implementation collapsed both to '' via `_resolve(color) || ''`,
20
+ * which destroyed the signal and made `linefill.new(line1, line2,
21
+ * color(na))` render as a default-coloured fill instead of being
22
+ * invisible. Mirror Box/Polyline `_resolveColor`.
23
+ */
24
+ private _resolveColor;
14
25
  new(line1: LineObject, line2: LineObject, color: any): LinefillObject;
15
26
  any(...args: any[]): LinefillObject | null;
16
27
  set_color(id: LinefillObject, color: any): void;
@@ -6,15 +6,15 @@ export declare class PolylineObject {
6
6
  curved: boolean;
7
7
  closed: boolean;
8
8
  xloc: string;
9
- line_color: string;
10
- fill_color: string;
9
+ line_color: any;
10
+ fill_color: any;
11
11
  line_style: string;
12
12
  line_width: number;
13
13
  force_overlay: boolean;
14
14
  _deleted: boolean;
15
15
  /** Bar index at which this object was created (for streaming rollback) */
16
16
  _createdAtBar: number;
17
- constructor(points: ChartPointObject[], curved?: boolean, closed?: boolean, xloc?: string, line_color?: string, fill_color?: string, line_style?: string, line_width?: number, force_overlay?: boolean);
17
+ constructor(points: ChartPointObject[], curved?: boolean, closed?: boolean, xloc?: string, line_color?: any, fill_color?: any, line_style?: string, line_width?: number, force_overlay?: boolean);
18
18
  delete(): void;
19
19
  toPlotData(): any;
20
20
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Account currency configured in the strategy() declaration's `currency=`.
3
+ * Defaults to 'USD'. Matches Pine's strategy.account_currency.
4
+ */
5
+ export declare function account_currency(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Declares a strategy and initializes strategy state
3
+ * Usage: strategy(title, overlay=false, ...)
4
+ */
5
+ export declare function any(context: any): (...args: any[]) => any;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Average loss across losing closed trades, returned as a POSITIVE number
3
+ * (Pine convention: average loss is unsigned). NaN when no losers yet.
4
+ * Matches Pine's strategy.avg_losing_trade.
5
+ */
6
+ export declare function avg_losing_trade(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Average per-trade loss (as a positive percent) across losing closed trades.
3
+ * NaN when no losers yet. Matches Pine's strategy.avg_losing_trade_percent.
4
+ */
5
+ export declare function avg_losing_trade_percent(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Average profit/loss across all closed trades (post-commission).
3
+ * NaN when no trades have closed. Matches Pine's strategy.avg_trade.
4
+ */
5
+ export declare function avg_trade(context: any): () => number;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Average per-trade return as a percent. Computed as the mean of each
3
+ * closed trade's individual profit_percent = profit / (entry_price * |size|) * 100.
4
+ * NaN when no trades have closed. Matches Pine's strategy.avg_trade_percent.
5
+ */
6
+ export declare function avg_trade_percent(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Average profit across winning closed trades. NaN when no winners yet.
3
+ * Matches Pine's strategy.avg_winning_trade.
4
+ */
5
+ export declare function avg_winning_trade(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Average per-trade return (as a percent) across winning closed trades.
3
+ * NaN when no winners yet. Matches Pine's strategy.avg_winning_trade_percent.
4
+ */
5
+ export declare function avg_winning_trade_percent(context: any): () => number;
@@ -0,0 +1 @@
1
+ export declare function cancel(context: any): (...args: any[]) => void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Cancel all pending orders (entries only — exits attached to open trades
3
+ * are not affected since they ride on positions, not orders).
4
+ * Pine signature: strategy.cancel_all() → void
5
+ */
6
+ export declare function cancel_all(context: any): () => void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Constant for order sizing type: cash
3
+ * Used in default_qty_type parameter
4
+ */
5
+ export declare function cash(context: any): () => string;
@@ -0,0 +1 @@
1
+ export declare function close(context: any): (...args: any[]) => void;
@@ -0,0 +1 @@
1
+ export declare function close_all(context: any): (...args: any[]) => void;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Pine's `strategy.closedtrades` serves a dual role:
3
+ * - As a scalar: a series int count of closed trades.
4
+ * - As a namespace: `strategy.closedtrades.profit(idx)` etc.
5
+ *
6
+ * Our transpiler renders the bare access as a CALL (`strategy.closedtrades()`),
7
+ * and the chained access as a CHAINED CALL (`strategy.closedtrades().profit(0)`).
8
+ * Both must work. The trick: the call returns a hybrid object that:
9
+ * - has `valueOf()` returning the count (so it behaves like an int in
10
+ * arithmetic/comparison contexts, e.g. `_ct > 0`),
11
+ * - has the per-trade methods (`profit`, `size`, ...) attached.
12
+ *
13
+ * This pattern keeps the transpiler unchanged while supporting both shapes.
14
+ */
15
+ export declare function closedtrades(context: any): () => any;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Convert a value from the symbol's currency to the account currency.
3
+ *
4
+ * For the common same-currency case (e.g. BTCUSDC's quote currency USDC ≈ USD),
5
+ * this is an identity. Genuine cross-currency conversion would require an FX
6
+ * rate source which we don't model; returns the input unchanged in that case
7
+ * with a console warning on first call.
8
+ */
9
+ export declare function convert_to_account(context: any): (value: number) => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Inverse of convert_to_account: from account currency → symbol currency.
3
+ * Same identity passthrough for matching-currency case.
4
+ */
5
+ export declare function convert_to_symbol(context: any): (value: number) => number;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the qty that would be used for an entry at the given fill price,
3
+ * given the strategy's `default_qty_type` and `default_qty_value`. Mirrors
4
+ * `calculateOrderQty()` without a specified qty (always uses the default).
5
+ *
6
+ * Pine signature: strategy.default_entry_qty(fill_price) → series float
7
+ */
8
+ export declare function default_entry_qty(context: any): (fillPrice: number) => number;
@@ -0,0 +1 @@
1
+ export declare function entry(context: any): (...args: any[]) => void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns the current equity (initial_capital + netprofit + openprofit).
3
+ * Matches Pine's strategy.equity.
4
+ */
5
+ export declare function equity(context: any): () => any;
@@ -0,0 +1,2 @@
1
+ /** Count of breakeven (profit === 0) closed trades. Matches Pine's strategy.eventrades. */
2
+ export declare function eventrades(context: any): () => any;
@@ -0,0 +1 @@
1
+ export declare function exit(context: any): (...args: any[]) => void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Constant for order sizing type: fixed
3
+ * Used in default_qty_type parameter
4
+ */
5
+ export declare function fixed(context: any): () => string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Total currency value of all completed losing trades, as a POSITIVE number
3
+ * (the absolute sum of losses). Matches Pine's strategy.grossloss semantics.
4
+ */
5
+ export declare function grossloss(context: any): () => any;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * strategy.grossloss as a percent of initial capital.
3
+ */
4
+ export declare function grossloss_percent(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Total currency value of all completed winning trades (post-commission).
3
+ * Matches Pine's strategy.grossprofit.
4
+ */
5
+ export declare function grossprofit(context: any): () => any;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * strategy.grossprofit as a percent of initial capital.
3
+ */
4
+ export declare function grossprofit_percent(context: any): () => number;
@@ -0,0 +1,2 @@
1
+ /** The initial capital configured on the strategy() declaration. Matches Pine's strategy.initial_capital. */
2
+ export declare function initial_capital(context: any): () => any;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Constant representing long direction
3
+ */
4
+ export declare function long(context: any): () => string;
@@ -0,0 +1,2 @@
1
+ /** Count of closed trades with profit < 0. Matches Pine's strategy.losstrades. */
2
+ export declare function losstrades(context: any): () => any;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Price at which the current leveraged position would be force-liquidated.
3
+ * Returns NaN when flat or when the relevant margin% is 100 (no leverage).
4
+ *
5
+ * Formula (simplified):
6
+ * long → entry_avg_price * (1 - margin_long / 100)
7
+ * short → entry_avg_price * (1 + margin_short / 100)
8
+ *
9
+ * This is the simple peak-loss-tolerable price; real broker liquidation
10
+ * depends on maintenance margin schedules which we don't model.
11
+ * Matches Pine's strategy.margin_liquidation_price in the common case.
12
+ */
13
+ export declare function margin_liquidation_price(context: any): () => number;
@@ -0,0 +1,2 @@
1
+ /** Peak |position_size| seen across the run. Matches Pine's strategy.max_contracts_held_all. */
2
+ export declare function max_contracts_held_all(context: any): () => any;
@@ -0,0 +1,2 @@
1
+ /** Peak long-side position_size seen. Matches Pine's strategy.max_contracts_held_long. */
2
+ export declare function max_contracts_held_long(context: any): () => any;
@@ -0,0 +1,2 @@
1
+ /** Peak |short-side position_size| seen. Matches Pine's strategy.max_contracts_held_short. */
2
+ export declare function max_contracts_held_short(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Maximum peak-to-trough equity drawdown over the whole run (currency).
3
+ * Matches Pine's strategy.max_drawdown.
4
+ */
5
+ export declare function max_drawdown(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Maximum drawdown as a percent of the equity high-water mark.
3
+ * Matches Pine's strategy.max_drawdown_percent.
4
+ */
5
+ export declare function max_drawdown_percent(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Maximum equity run-up over the whole run (currency).
3
+ * Matches Pine's strategy.max_runup.
4
+ */
5
+ export declare function max_runup(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Maximum equity run-up as a percent of initial capital.
3
+ * Matches Pine's strategy.max_runup_percent.
4
+ */
5
+ export declare function max_runup_percent(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Realized P&L summed across all closed trades.
3
+ * Matches Pine's strategy.netprofit.
4
+ */
5
+ export declare function netprofit(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Realized net profit expressed as a percent of initial capital.
3
+ * Matches Pine's strategy.netprofit_percent.
4
+ */
5
+ export declare function netprofit_percent(context: any): () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Unrealized P&L across all currently-open trades.
3
+ * Matches Pine's strategy.openprofit. Updated each bar by updateUnrealizedPnL().
4
+ */
5
+ export declare function openprofit(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Unrealized P&L expressed as a percent of initial capital.
3
+ * Matches Pine's strategy.openprofit_percent.
4
+ */
5
+ export declare function openprofit_percent(context: any): () => number;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Pine's `strategy.opentrades` mirrors strategy.closedtrades' dual-role
3
+ * pattern — see that file's header for the rationale.
4
+ *
5
+ * strategy.opentrades → scalar count via valueOf
6
+ * strategy.opentrades.profit(0) → per-trade unrealized P&L
7
+ * strategy.opentrades.capital_held → property (sum of held capital)
8
+ */
9
+ export declare function opentrades(context: any): () => any;
@@ -0,0 +1,6 @@
1
+ import { Order } from '../types';
2
+ /**
3
+ * Place a basic order.
4
+ * Pine reference: https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}order
5
+ */
6
+ export declare function order(context: any): (...args: any[]) => Order;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Parameter wrapper for strategy namespace
3
+ * Type B - Simple Unwrapping (like input, array, map, matrix)
4
+ */
5
+ export declare function param(context: any): (source: any, index?: number) => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Constant for order sizing type: percent_of_equity
3
+ * Used in default_qty_type parameter
4
+ */
5
+ export declare function percent_of_equity(context: any): () => string;