pinets 0.9.16 → 0.9.18

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 (69) hide show
  1. package/README.md +14 -11
  2. package/dist/pinets.min.browser.es.js +29 -29
  3. package/dist/pinets.min.browser.es.js.map +1 -1
  4. package/dist/pinets.min.browser.js +29 -29
  5. package/dist/pinets.min.browser.js.map +1 -1
  6. package/dist/pinets.min.cjs +29 -29
  7. package/dist/pinets.min.cjs.map +1 -1
  8. package/dist/pinets.min.es.js +29 -29
  9. package/dist/pinets.min.es.js.map +1 -1
  10. package/dist/types/Context.class.d.ts +2 -0
  11. package/dist/types/PineTS.class.d.ts +20 -7
  12. package/dist/types/namespaces/line/LineHelper.d.ts +9 -0
  13. package/dist/types/namespaces/linefill/LinefillHelper.d.ts +11 -0
  14. package/dist/types/namespaces/polyline/PolylineObject.d.ts +3 -3
  15. package/dist/types/namespaces/strategy/methods/account_currency.d.ts +5 -0
  16. package/dist/types/namespaces/strategy/methods/any.d.ts +5 -0
  17. package/dist/types/namespaces/strategy/methods/avg_losing_trade.d.ts +6 -0
  18. package/dist/types/namespaces/strategy/methods/avg_losing_trade_percent.d.ts +5 -0
  19. package/dist/types/namespaces/strategy/methods/avg_trade.d.ts +5 -0
  20. package/dist/types/namespaces/strategy/methods/avg_trade_percent.d.ts +6 -0
  21. package/dist/types/namespaces/strategy/methods/avg_winning_trade.d.ts +5 -0
  22. package/dist/types/namespaces/strategy/methods/avg_winning_trade_percent.d.ts +5 -0
  23. package/dist/types/namespaces/strategy/methods/cancel.d.ts +1 -0
  24. package/dist/types/namespaces/strategy/methods/cancel_all.d.ts +6 -0
  25. package/dist/types/namespaces/strategy/methods/cash.d.ts +5 -0
  26. package/dist/types/namespaces/strategy/methods/close.d.ts +1 -0
  27. package/dist/types/namespaces/strategy/methods/close_all.d.ts +1 -0
  28. package/dist/types/namespaces/strategy/methods/closedtrades.d.ts +15 -0
  29. package/dist/types/namespaces/strategy/methods/convert_to_account.d.ts +9 -0
  30. package/dist/types/namespaces/strategy/methods/convert_to_symbol.d.ts +5 -0
  31. package/dist/types/namespaces/strategy/methods/default_entry_qty.d.ts +8 -0
  32. package/dist/types/namespaces/strategy/methods/entry.d.ts +1 -0
  33. package/dist/types/namespaces/strategy/methods/equity.d.ts +5 -0
  34. package/dist/types/namespaces/strategy/methods/eventrades.d.ts +2 -0
  35. package/dist/types/namespaces/strategy/methods/exit.d.ts +1 -0
  36. package/dist/types/namespaces/strategy/methods/fixed.d.ts +5 -0
  37. package/dist/types/namespaces/strategy/methods/grossloss.d.ts +5 -0
  38. package/dist/types/namespaces/strategy/methods/grossloss_percent.d.ts +4 -0
  39. package/dist/types/namespaces/strategy/methods/grossprofit.d.ts +5 -0
  40. package/dist/types/namespaces/strategy/methods/grossprofit_percent.d.ts +4 -0
  41. package/dist/types/namespaces/strategy/methods/initial_capital.d.ts +2 -0
  42. package/dist/types/namespaces/strategy/methods/long.d.ts +4 -0
  43. package/dist/types/namespaces/strategy/methods/losstrades.d.ts +2 -0
  44. package/dist/types/namespaces/strategy/methods/margin_liquidation_price.d.ts +13 -0
  45. package/dist/types/namespaces/strategy/methods/max_contracts_held_all.d.ts +2 -0
  46. package/dist/types/namespaces/strategy/methods/max_contracts_held_long.d.ts +2 -0
  47. package/dist/types/namespaces/strategy/methods/max_contracts_held_short.d.ts +2 -0
  48. package/dist/types/namespaces/strategy/methods/max_drawdown.d.ts +5 -0
  49. package/dist/types/namespaces/strategy/methods/max_drawdown_percent.d.ts +5 -0
  50. package/dist/types/namespaces/strategy/methods/max_runup.d.ts +5 -0
  51. package/dist/types/namespaces/strategy/methods/max_runup_percent.d.ts +5 -0
  52. package/dist/types/namespaces/strategy/methods/netprofit.d.ts +5 -0
  53. package/dist/types/namespaces/strategy/methods/netprofit_percent.d.ts +5 -0
  54. package/dist/types/namespaces/strategy/methods/openprofit.d.ts +5 -0
  55. package/dist/types/namespaces/strategy/methods/openprofit_percent.d.ts +5 -0
  56. package/dist/types/namespaces/strategy/methods/opentrades.d.ts +9 -0
  57. package/dist/types/namespaces/strategy/methods/order.d.ts +6 -0
  58. package/dist/types/namespaces/strategy/methods/param.d.ts +5 -0
  59. package/dist/types/namespaces/strategy/methods/percent_of_equity.d.ts +5 -0
  60. package/dist/types/namespaces/strategy/methods/position_avg_price.d.ts +5 -0
  61. package/dist/types/namespaces/strategy/methods/position_entry_name.d.ts +5 -0
  62. package/dist/types/namespaces/strategy/methods/position_size.d.ts +5 -0
  63. package/dist/types/namespaces/strategy/methods/risk.d.ts +22 -0
  64. package/dist/types/namespaces/strategy/methods/short.d.ts +4 -0
  65. package/dist/types/namespaces/strategy/methods/wintrades.d.ts +2 -0
  66. package/dist/types/namespaces/strategy/strategy.index.d.ts +7 -0
  67. package/dist/types/namespaces/strategy/types.d.ts +176 -0
  68. package/dist/types/namespaces/strategy/utils.d.ts +84 -0
  69. package/package.json +3 -3
@@ -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;
@@ -144,10 +144,6 @@ export declare class PineTS {
144
144
  on: (event: 'data' | 'error' | 'warning' | 'alert', callback: Function) => void;
145
145
  stop: () => void;
146
146
  };
147
- /**
148
- * Run the script completely and return the final context (backward compatible behavior)
149
- * @private
150
- */
151
147
  /**
152
148
  * Run an already-transpiled PineTS function in this instance — no
153
149
  * additional transpile/parse pass. Used by `request.security_lower_tf`'s
@@ -158,6 +154,16 @@ export declare class PineTS {
158
154
  * arbitrary function is unsafe.
159
155
  */
160
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.
165
+ * @private
166
+ */
161
167
  private _runComplete;
162
168
  /**
163
169
  * Run the script with pagination, yielding results page by page
@@ -196,9 +202,16 @@ export declare class PineTS {
196
202
  private _appendCandle;
197
203
  /**
198
204
  * Update the secondary context's tail with fresh market data.
199
- * Mirrors the streaming update logic in _runPaginated:
200
- * fetches new/updated candles, rolls back the last result, and re-executes
201
- * 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
+ *
202
215
  * @param context - The cached secondary context to update
203
216
  * @returns true if data was updated, false if no changes
204
217
  */
@@ -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;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Weighted-average entry price of the current open position.
3
+ * Returns NaN when flat — matches Pine's strategy.position_avg_price semantics.
4
+ */
5
+ export declare function position_avg_price(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Id string of the entry that initially opened the current position.
3
+ * Empty string when flat. Matches Pine's strategy.position_entry_name.
4
+ */
5
+ export declare function position_entry_name(context: any): () => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Signed position size — positive for long, negative for short, 0 for flat.
3
+ * Matches Pine's strategy.position_size.
4
+ */
5
+ export declare function position_size(context: any): () => any;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `strategy.risk` is a nested namespace with 6 setter functions that
3
+ * configure pre-trade risk rules. Each call mutates `context.strategy.risk_rules`;
4
+ * the actual blocking is performed by `checkRiskRules()` in utils.ts,
5
+ * invoked before each entry fills.
6
+ *
7
+ * Pine signatures:
8
+ * strategy.risk.allow_entry_in(value) → void
9
+ * strategy.risk.max_cons_loss_days(count, alert_message) → void
10
+ * strategy.risk.max_drawdown(value, type, alert_message) → void
11
+ * strategy.risk.max_intraday_filled_orders(count, alert_message) → void
12
+ * strategy.risk.max_intraday_loss(value, type, alert_message) → void
13
+ * strategy.risk.max_position_size(contracts) → void
14
+ */
15
+ export declare function risk(context: any): {
16
+ allow_entry_in: (value: "long" | "short" | "all") => void;
17
+ max_cons_loss_days: (count: number, alert_message?: string) => void;
18
+ max_drawdown: (value: number, type: "cash" | "percent_of_equity", _alert_message?: string) => void;
19
+ max_intraday_filled_orders: (count: number, alert_message?: string) => void;
20
+ max_intraday_loss: (value: number, type: "cash" | "percent_of_equity", _alert_message?: string) => void;
21
+ max_position_size: (contracts: number) => void;
22
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Constant representing short direction
3
+ */
4
+ export declare function short(context: any): () => string;
@@ -0,0 +1,2 @@
1
+ /** Count of closed trades with profit > 0. Matches Pine's strategy.wintrades. */
2
+ export declare function wintrades(context: any): () => any;
@@ -0,0 +1,7 @@
1
+ export type { StrategyConfig, StrategyState, Trade, Order } from './types';
2
+ export declare class Strategy {
3
+ private context;
4
+ [key: string]: any;
5
+ constructor(context: any);
6
+ }
7
+ export default Strategy;