pinets 0.9.5 → 0.9.7

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 (74) hide show
  1. package/dist/pinets.min.browser.es.js +23 -40
  2. package/dist/pinets.min.browser.es.js.map +1 -1
  3. package/dist/pinets.min.browser.js +48 -65
  4. package/dist/pinets.min.browser.js.map +1 -1
  5. package/dist/pinets.min.cjs +23 -40
  6. package/dist/pinets.min.cjs.map +1 -1
  7. package/dist/pinets.min.es.js +45 -62
  8. package/dist/pinets.min.es.js.map +1 -1
  9. package/dist/types/Context.class.d.ts +24 -0
  10. package/dist/types/PineTS.class.d.ts +18 -1
  11. package/dist/types/errors/PineRuntimeError.d.ts +27 -0
  12. package/dist/types/index.d.ts +10 -1
  13. package/dist/types/marketData/Alpaca/AlpacaProvider.class.d.ts +115 -0
  14. package/dist/types/marketData/BaseProvider.d.ts +92 -0
  15. package/dist/types/marketData/Binance/BinanceProvider.class.d.ts +10 -12
  16. package/dist/types/marketData/FMP/FMPProvider.class.d.ts +69 -0
  17. package/dist/types/marketData/IProvider.d.ts +20 -7
  18. package/dist/types/marketData/Mock/MockProvider.class.d.ts +12 -29
  19. package/dist/types/marketData/Provider.class.d.ts +4 -1
  20. package/dist/types/marketData/aggregation.d.ts +38 -0
  21. package/dist/types/marketData/types.d.ts +106 -0
  22. package/dist/types/namespaces/Core.d.ts +40 -2
  23. package/dist/types/transpiler/analysis/ScopeManager.d.ts +4 -0
  24. package/dist/types/transpiler/pineToJS/codegen.d.ts +34 -1
  25. package/dist/types/transpiler/pineToJS/parser.d.ts +1 -0
  26. package/dist/types/transpiler/settings.d.ts +1 -0
  27. package/dist/types/transpiler/transformers/StatementTransformer.d.ts +10 -0
  28. package/package.json +4 -4
  29. package/dist/types/NaProxy.d.ts +0 -19
  30. package/dist/types/TimeSeries.class.d.ts +0 -49
  31. package/dist/types/TimeSeries.d.ts +0 -15
  32. package/dist/types/namespaces/Input.d.ts +0 -24
  33. package/dist/types/namespaces/PineArray.d.ts +0 -62
  34. package/dist/types/namespaces/PineColor.d.ts +0 -0
  35. package/dist/types/namespaces/PineMath.d.ts +0 -28
  36. package/dist/types/namespaces/PineRequest.d.ts +0 -8
  37. package/dist/types/namespaces/Plot.helper.d.ts +0 -16
  38. package/dist/types/namespaces/TechnicalAnalysis.d.ts +0 -30
  39. package/dist/types/namespaces/request/types/barmerge.type.d.ts +0 -7
  40. package/dist/types/namespaces/strategy/StrategySimulator.d.ts +0 -84
  41. package/dist/types/namespaces/strategy/closedtrades/index.d.ts +0 -18
  42. package/dist/types/namespaces/strategy/methods/any.d.ts +0 -5
  43. package/dist/types/namespaces/strategy/methods/cancel.d.ts +0 -1
  44. package/dist/types/namespaces/strategy/methods/cancel_all.d.ts +0 -1
  45. package/dist/types/namespaces/strategy/methods/cash.d.ts +0 -5
  46. package/dist/types/namespaces/strategy/methods/close.d.ts +0 -1
  47. package/dist/types/namespaces/strategy/methods/close_all.d.ts +0 -1
  48. package/dist/types/namespaces/strategy/methods/closedtrades.d.ts +0 -4
  49. package/dist/types/namespaces/strategy/methods/entry.d.ts +0 -3
  50. package/dist/types/namespaces/strategy/methods/equity.d.ts +0 -4
  51. package/dist/types/namespaces/strategy/methods/exit.d.ts +0 -3
  52. package/dist/types/namespaces/strategy/methods/fixed.d.ts +0 -5
  53. package/dist/types/namespaces/strategy/methods/long.d.ts +0 -4
  54. package/dist/types/namespaces/strategy/methods/netprofit.d.ts +0 -4
  55. package/dist/types/namespaces/strategy/methods/opentrades.d.ts +0 -4
  56. package/dist/types/namespaces/strategy/methods/order.d.ts +0 -6
  57. package/dist/types/namespaces/strategy/methods/param.d.ts +0 -5
  58. package/dist/types/namespaces/strategy/methods/percent_of_equity.d.ts +0 -5
  59. package/dist/types/namespaces/strategy/methods/position_avg_price.d.ts +0 -5
  60. package/dist/types/namespaces/strategy/methods/position_entry.d.ts +0 -5
  61. package/dist/types/namespaces/strategy/methods/position_entry_name.d.ts +0 -5
  62. package/dist/types/namespaces/strategy/methods/position_size.d.ts +0 -5
  63. package/dist/types/namespaces/strategy/methods/short.d.ts +0 -4
  64. package/dist/types/namespaces/strategy/models/Order.d.ts +0 -31
  65. package/dist/types/namespaces/strategy/models/Position.d.ts +0 -16
  66. package/dist/types/namespaces/strategy/models/Trade.d.ts +0 -45
  67. package/dist/types/namespaces/strategy/opentrades/index.d.ts +0 -10
  68. package/dist/types/namespaces/strategy/risk/index.d.ts +0 -11
  69. package/dist/types/namespaces/strategy/strategy.index.d.ts +0 -53
  70. package/dist/types/namespaces/strategy/types.d.ts +0 -92
  71. package/dist/types/namespaces/strategy/utils.d.ts +0 -28
  72. package/dist/types/namespaces/ta/getters/obv.d.ts +0 -12
  73. package/dist/types/namespaces/ta/getters/tr.d.ts +0 -1
  74. package/dist/types/transpiler/ScopeManager.class.d.ts +0 -36
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Standardized candlestick / kline data shape used by all providers.
3
+ */
4
+ export interface Kline {
5
+ openTime: number;
6
+ open: number;
7
+ high: number;
8
+ low: number;
9
+ close: number;
10
+ volume: number;
11
+ closeTime: number;
12
+ quoteAssetVolume: number;
13
+ numberOfTrades: number;
14
+ takerBuyBaseAssetVolume: number;
15
+ takerBuyQuoteAssetVolume: number;
16
+ ignore: number | string;
17
+ }
18
+ /**
19
+ * Interval duration in milliseconds, keyed by normalized interval strings.
20
+ * Used by providers for pagination and date-range estimation.
21
+ *
22
+ * These use Binance-style interval keys ('1m', '1h', '1d', etc.)
23
+ * which are also the de-facto standard across most market data APIs.
24
+ */
25
+ export declare const INTERVAL_DURATION_MS: Record<string, number>;
26
+ /**
27
+ * Period types for timeframe-aware date arithmetic.
28
+ */
29
+ export type PeriodType = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month';
30
+ /**
31
+ * Duration in seconds for each canonical timeframe.
32
+ *
33
+ * Uses seconds (not minutes) to naturally accommodate TradingView's
34
+ * sub-minute timeframes ('1S', '5S', etc.) without fractional values.
35
+ * D/W/M values are approximate — used for ratio math, not calendar grouping.
36
+ */
37
+ export declare const TIMEFRAME_SECONDS: Record<string, number>;
38
+ /**
39
+ * Map from canonical timeframe to { periodType, multiplier }.
40
+ * Used by aggregation to determine grouping strategy.
41
+ */
42
+ export declare const TIMEFRAME_PERIOD_INFO: Record<string, {
43
+ periodType: PeriodType;
44
+ multiplier: number;
45
+ }>;
46
+ /**
47
+ * Compute the start of the next period given an openTime (fixed duration math).
48
+ *
49
+ * For intraday / daily / weekly: adds fixed duration.
50
+ * For monthly: uses calendar math to land on the 1st of the next month.
51
+ *
52
+ * **Suitable for 24/7 crypto markets** where there are no session gaps.
53
+ * For stock/regulated markets, prefer `computeSessionClose()` or
54
+ * the Alpaca Calendar API which account for session boundaries,
55
+ * early closes, and holidays.
56
+ *
57
+ * @param openTimeMs - The bar's open time in epoch milliseconds
58
+ * @param periodType - The period unit ('minute', 'hour', 'day', 'week', 'month')
59
+ * @param multiplier - How many units per bar (e.g., 3 for 3Min, 4 for 4Hour). Default: 1
60
+ */
61
+ export declare function computeNextPeriodStart(openTimeMs: number, periodType: PeriodType, multiplier?: number): number;
62
+ /**
63
+ * Convert a local date + time string in a given IANA timezone to UTC milliseconds.
64
+ *
65
+ * Uses `Intl.DateTimeFormat` for DST-correct conversion — no external dependencies.
66
+ *
67
+ * @param dateStr - Date in "YYYY-MM-DD" format
68
+ * @param timeStr - Time in "HH:MM" format (24h)
69
+ * @param timezone - IANA timezone name (e.g. "America/New_York", "Etc/UTC")
70
+ * @returns UTC epoch milliseconds
71
+ */
72
+ export declare function localTimeToUTC(dateStr: string, timeStr: string, timezone: string): number;
73
+ /**
74
+ * Compute the session close time for a bar.
75
+ *
76
+ * For providers without a per-day calendar API (like FMP), this computes
77
+ * closeTime from the session string and exchange timezone.
78
+ *
79
+ * Logic by period type:
80
+ * - **24x7 session**: closeTime = openTime + barDuration (no gaps)
81
+ * - **Intraday** (minute, hour): min(openTime + barDuration, sessionEndOnThatDay)
82
+ * - **Daily** (day): same date at session end time in timezone
83
+ * - **Weekly** (week): Friday of that week at session end (approximation: no holiday calendar)
84
+ * - **Monthly** (month): last weekday of month at session end (approximation: no holiday calendar)
85
+ *
86
+ * @param openTimeMs - Bar open time in UTC epoch milliseconds
87
+ * @param session - Session string, e.g. "0930-1600" or "24x7"
88
+ * @param timezone - IANA timezone name, e.g. "America/New_York"
89
+ * @param periodType - The period unit
90
+ * @param multiplier - How many units per bar (default: 1)
91
+ */
92
+ export declare function computeSessionClose(openTimeMs: number, session: string, timezone: string, periodType: PeriodType, multiplier?: number): number;
93
+ /**
94
+ * Normalize closeTime for 24/7 crypto providers (Binance, Mock).
95
+ *
96
+ * Many crypto APIs (e.g. Binance) return closeTime as `nextBarOpen - 1ms`.
97
+ * For 24/7 markets, `nextBar.openTime == sessionClose`, so this is correct:
98
+ * - For bars 0..N-2: closeTime = next bar's openTime (exact for 24/7)
99
+ * - For the last bar: closeTime = raw closeTime + 1ms (best estimate)
100
+ *
101
+ * **Not suitable for stock/regulated market providers** — those must use
102
+ * `computeSessionClose()` or the Alpaca Calendar API for session-aware close times.
103
+ *
104
+ * Mutates the array in place.
105
+ */
106
+ export declare function normalizeCloseTime(data: Kline[]): void;
@@ -11,6 +11,41 @@ export declare class NAHelper {
11
11
  param(source: any, index?: number): any;
12
12
  any(series: any): boolean;
13
13
  }
14
+ /**
15
+ * Alert frequency constants (Pine Script alert.freq_* enum values).
16
+ */
17
+ export declare const ALERT_FREQ: {
18
+ freq_all: string;
19
+ freq_once_per_bar: string;
20
+ freq_once_per_bar_close: string;
21
+ };
22
+ /**
23
+ * AlertHelper implements the dual-use `alert` identifier.
24
+ * - `alert(msg, freq)` → `alert.any(msg, freq, {__callsiteId})` — fires an alert event
25
+ * - `alert.freq_once_per_bar` → frequency constant
26
+ *
27
+ * Each `alert()` call site gets a stable ID (`alert_0`, `alert_1`, ...)
28
+ * injected by the transpiler at compile time via `__callsiteId`. This ensures
29
+ * per-callsite frequency gating works correctly even when live bars are
30
+ * re-executed or when alert() calls are inside conditional branches.
31
+ */
32
+ export declare class AlertHelper {
33
+ private context;
34
+ /**
35
+ * Per-callsite, per-bar frequency gating.
36
+ * Key: `${callsiteId}:${barIdx}`, tracks which (callsite, bar) pairs have fired.
37
+ */
38
+ private _firedKeys;
39
+ /** Fallback counter for PineTS-syntax (non-transpiled) calls without __callsiteId. */
40
+ private _fallbackCounter;
41
+ private _fallbackLastExecTick;
42
+ constructor(context: any);
43
+ get freq_all(): string;
44
+ get freq_once_per_bar(): string;
45
+ get freq_once_per_bar_close(): string;
46
+ param(source: any, _index?: number, _id?: string): any;
47
+ any(message: any, freq?: any, opts?: any): void;
48
+ }
14
49
  export declare class Core {
15
50
  private context;
16
51
  constructor(context: any);
@@ -20,8 +55,11 @@ export declare class Core {
20
55
  na(series: any): boolean;
21
56
  nz(series: any, replacement?: number): any;
22
57
  fixnan(series: any): any;
23
- alertcondition(condition: any, title: any, message: any): void;
24
- alert(...args: any[]): void;
58
+ private _acCounter;
59
+ private _acLastExecTick;
60
+ /** Per-callsite, per-bar dedup for alertcondition (prevents duplicate fires on live re-execution). */
61
+ private _acFiredKeys;
62
+ alertcondition(condition: any, title?: any, message?: any): void;
25
63
  error(...args: any[]): void;
26
64
  max_bars_back(series?: any, length?: any): void;
27
65
  /**
@@ -15,6 +15,8 @@ export declare class ScopeManager {
15
15
  private taCallIdCounter;
16
16
  private userCallIdCounter;
17
17
  private plotCallIdCounter;
18
+ private alertCallIdCounter;
19
+ private loopGuardCounter;
18
20
  private hoistingStack;
19
21
  private suppressHoisting;
20
22
  private reservedNames;
@@ -25,6 +27,8 @@ export declare class ScopeManager {
25
27
  getNextTACallId(): any;
26
28
  getNextUserCallId(): any;
27
29
  getNextPlotCallId(): any;
30
+ getNextAlertCallId(): any;
31
+ getNextLoopGuardName(): string;
28
32
  constructor();
29
33
  pushScope(type: string): void;
30
34
  popScope(): void;
@@ -15,6 +15,39 @@ export declare class CodeGenerator {
15
15
  });
16
16
  generate(ast: any): string;
17
17
  private preProcessAST;
18
+ /**
19
+ * Scan the program body for variable declarations and assignments whose
20
+ * names collide with Pine namespace/built-in names (e.g., `fill`, `size`,
21
+ * `color`, `line`). Rename them with a `_$N` suffix so they don't shadow
22
+ * the namespace destructured from `$.pine`.
23
+ *
24
+ * Only renames **user variables** — function parameters are handled
25
+ * separately in generateFunctionDeclaration().
26
+ *
27
+ * Renaming rules:
28
+ * - Variable declaration target (let fill = ...) → renamed
29
+ * - Assignment target (fill := ...) → renamed
30
+ * - Bare identifier read (return fill) → renamed
31
+ * - Call callee (fill(...)) → NOT renamed (namespace call)
32
+ * - MemberExpression object (size.tiny) → NOT renamed (namespace access)
33
+ * - MemberExpression property (array.size) → NOT renamed (method name)
34
+ * - Object property key ({size: ...}) → NOT renamed (named arg key)
35
+ */
36
+ private renameConflictingVariables;
37
+ /**
38
+ * Walk the AST and collect variable declarations / assignment targets
39
+ * whose names conflict with CONFLICTING_NAMES.
40
+ */
41
+ private collectConflictingVarNames;
42
+ /**
43
+ * Context-aware variable reference renaming.
44
+ * Renames Identifiers that are user-variable references, but skips:
45
+ * - CallExpression callees (namespace function calls)
46
+ * - MemberExpression objects with non-computed property (namespace.member)
47
+ * - MemberExpression non-computed properties (obj.namespace)
48
+ * - Object property keys ({namespace: value})
49
+ */
50
+ private renameVariableRefsInAST;
18
51
  private collectFunctionParams;
19
52
  writeSourceComment(startLine: any, endLine?: any): void;
20
53
  write(str: any): void;
@@ -57,5 +90,5 @@ export declare class CodeGenerator {
57
90
  generateSwitchAsIfElse(node: any): void;
58
91
  generateLoopAsExpression(node: any, loopType: any): void;
59
92
  generateSequenceExpression(node: any): void;
60
- getPrecedence(node: any): 0 | 10 | 1 | 2 | 3 | 4 | 5 | 9 | 12 | 13 | 15 | 20 | 19;
93
+ getPrecedence(node: any): 3 | 5 | 15 | 2 | 4 | 1 | 10 | 0 | 9 | 12 | 13 | 20 | 19;
61
94
  }
@@ -4,6 +4,7 @@ export declare class Parser {
4
4
  private tokens;
5
5
  private pos;
6
6
  private functionNames;
7
+ private noLineContinuation;
7
8
  constructor(tokens: Token[]);
8
9
  peek(offset?: number): Token;
9
10
  advance(): Token;
@@ -2,6 +2,7 @@ export declare const KNOWN_NAMESPACES: string[];
2
2
  export declare const NAMESPACES_LIKE: string[];
3
3
  export declare const ASYNC_METHODS: string[];
4
4
  export declare const FACTORY_METHODS: string[];
5
+ export declare const NAMESPACE_COLLISION_NAMES: Set<string>;
5
6
  export declare const CONTEXT_DATA_VARS: string[];
6
7
  export declare const CONTEXT_PINE_VARS: string[];
7
8
  export declare const CONTEXT_CORE_VARS: string[];
@@ -1,4 +1,14 @@
1
1
  import ScopeManager from '../analysis/ScopeManager';
2
+ /**
3
+ * Creates the AST nodes for a loop guard:
4
+ * 1. A counter declaration: `let __lgN = 0;` (to be hoisted before the loop)
5
+ * 2. A guard check: `if (++__lgN > __maxLoops) throw new Error("Loop exceeded maximum iterations (__lgN)");`
6
+ * (to be prepended to the loop body)
7
+ */
8
+ export declare function createLoopGuardNodes(guardName: string): {
9
+ counterDecl: any;
10
+ guardCheck: any;
11
+ };
2
12
  export declare function transformAssignmentExpression(node: any, scopeManager: ScopeManager): void;
3
13
  export declare function transformVariableDeclaration(varNode: any, scopeManager: ScopeManager): void;
4
14
  export declare function transformForStatement(node: any, scopeManager: ScopeManager, c: any): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinets",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "Run Pine Script anywhere. PineTS is an open-source transpiler and runtime that brings Pine Script logic to Node.js and the browser with 1:1 syntax compatibility. Reliably write, port, and run indicators or strategies on your own infrastructure.",
5
5
  "keywords": [
6
6
  "Pine Script",
@@ -81,14 +81,13 @@
81
81
  "astring": "^1.9.0"
82
82
  },
83
83
  "devDependencies": {
84
- "typescript": "~5.9.3",
85
84
  "@rollup/plugin-commonjs": "^29.0.0",
86
85
  "@rollup/plugin-json": "^6.1.0",
87
86
  "@rollup/plugin-node-resolve": "^16.0.3",
88
87
  "@types/react": "^19.2.10",
89
88
  "@types/react-dom": "^19.2.3",
90
89
  "@vitejs/plugin-react": "^5.1.2",
91
- "@vitest/coverage-v8": "^2.0.0",
90
+ "@vitest/coverage-v8": "^4.1.0",
92
91
  "autoprefixer": "^10.4.23",
93
92
  "badgen": "^3.2.3",
94
93
  "cross-env": "^7.0.3",
@@ -99,9 +98,10 @@
99
98
  "rollup-plugin-typescript-paths": "^1.5.0",
100
99
  "tailwindcss": "^4.1.18",
101
100
  "tsx": "^4.21.0",
101
+ "typescript": "~5.9.3",
102
102
  "vite": "^7.3.1",
103
103
  "vite-tsconfig-paths": "^4.3.2",
104
- "vitest": "^2.0.0"
104
+ "vitest": "^4.1.0"
105
105
  },
106
106
  "repository": {
107
107
  "type": "git",
@@ -1,19 +0,0 @@
1
- /**
2
- * NaProxy: A proxy object that represents `na` for UDT (User-Defined Type) values.
3
- *
4
- * In Pine Script, accessing a property on `na` returns `na`, and calling a method on
5
- * `na` returns `na`. In JavaScript, NaN doesn't support property access, so we use
6
- * this proxy as a stand-in.
7
- *
8
- * Behavior:
9
- * - Any property access returns the proxy itself (chaining: proxy.bx.get_top → proxy)
10
- * - Called as a function, returns proxy (proxy() → proxy, for chaining: proxy.method().field)
11
- * - valueOf() returns NaN (arithmetic: proxy + 5 → NaN)
12
- * - na.any(proxy) → true
13
- */
14
- /** Symbol used to identify NaProxy objects */
15
- export declare const NA_MARKER: unique symbol;
16
- /** Singleton NaProxy instance */
17
- export declare const NA_PROXY: any;
18
- /** Check if a value is a NaProxy */
19
- export declare function isNaProxy(val: any): boolean;
@@ -1,49 +0,0 @@
1
- import Context from '../Context.class';
2
- /**
3
- * A lightweight wrapper around arrays to provide Pine Script-like "series" access behavior.
4
- * Pine Script series are indexed relative to the current bar:
5
- * - series[0] is the current value
6
- * - series[1] is the previous value
7
- *
8
- * This class maps this reversed, relative indexing to the underlying chronological array
9
- * using the Context's current index.
10
- */
11
- export declare class TimeSeries<T = any> {
12
- private readonly _data;
13
- private readonly _ctx;
14
- constructor(_data: T[], _ctx: Context);
15
- /**
16
- * Get the value at the specified offset from the current bar.
17
- * @param offset The lookback offset (0 = current, 1 = previous, etc.)
18
- */
19
- get(offset: number): T;
20
- /**
21
- * Set the value at the specified offset from the current bar.
22
- * Usually used for setting current value (offset 0).
23
- */
24
- set(offset: number, value: T): T;
25
- /**
26
- * Get the length of the series *so far* (up to current index)
27
- * Note: This mimics the behavior where future data isn't "visible" yet
28
- */
29
- get length(): number;
30
- /**
31
- * Returns the underlying raw data array.
32
- * Useful for performance-critical bulk operations that understand the indexing.
33
- */
34
- get data(): T[];
35
- /**
36
- * Creates a copy of the visible series as a reversed array (Pine Script standard format for bulk ops).
37
- * Warning: This is O(N) and should be used sparingly.
38
- */
39
- toArray(): T[];
40
- /**
41
- * Push a value to the underlying array.
42
- * Used when constructing user-defined series dynamically.
43
- */
44
- push(value: T): number;
45
- /**
46
- * Update the underlying array reference (e.g. for re-assignment)
47
- */
48
- replaceData(newData: T[]): void;
49
- }
@@ -1,15 +0,0 @@
1
- export interface IContext {
2
- idx: number;
3
- NA: any;
4
- }
5
- export declare class TimeSeries<T = any> {
6
- private _data;
7
- private context;
8
- constructor(context: IContext, data?: T[]);
9
- get(offset: number): T;
10
- set(value: T, offset?: number): void;
11
- push(value: T): void;
12
- pop(): T | undefined;
13
- get data(): T[];
14
- get length(): number;
15
- }
@@ -1,24 +0,0 @@
1
- type InputOptions = {
2
- title?: string;
3
- group?: string;
4
- } | any;
5
- export declare class Input {
6
- private context;
7
- constructor(context: any);
8
- param(source: any, index?: number): any[];
9
- any(value: any, { title, group }?: InputOptions): any;
10
- int(value: number, { title, group }?: InputOptions): any;
11
- float(value: number, { title, group }?: InputOptions): any;
12
- bool(value: boolean, { title, group }?: InputOptions): any;
13
- string(value: string, { title, group }?: InputOptions): any;
14
- timeframe(value: string, { title, group }?: InputOptions): any;
15
- time(value: number, { title, group }?: InputOptions): any;
16
- price(value: number, { title, group }?: InputOptions): any;
17
- session(value: string, { title, group }?: InputOptions): any;
18
- source(value: any, { title, group }?: InputOptions): any;
19
- symbol(value: string, { title, group }?: InputOptions): any;
20
- text_area(value: string, { title, group }?: InputOptions): any;
21
- enum(value: string, { title, group }?: InputOptions): any;
22
- color(value: string, { title, group }?: InputOptions): any;
23
- }
24
- export default Input;
@@ -1,62 +0,0 @@
1
- declare class PineArrayObject {
2
- array: any;
3
- constructor(array: any);
4
- }
5
- /**
6
- * This class implements an array port of PineScript's array functions.
7
- */
8
- export declare class PineArray {
9
- private context;
10
- private _cache;
11
- constructor(context: any);
12
- param(source: any, index?: number): any;
13
- /**
14
- * This function simulates PineScript's array.get() function
15
- * @param id - the array object to get the value from
16
- * @param index - the index of the value to get
17
- * @returns the value at the given index
18
- */
19
- get(id: PineArrayObject, index: number): any;
20
- set(id: PineArrayObject, index: number, value: any): void;
21
- push(id: PineArrayObject, value: any): void;
22
- sum(id: PineArrayObject): number;
23
- avg(id: PineArrayObject): number;
24
- min(id: PineArrayObject, nth?: number): number;
25
- max(id: PineArrayObject, nth?: number): number;
26
- size(id: PineArrayObject): number;
27
- new_bool(size: number, initial_value?: boolean): PineArrayObject;
28
- new_float(size: number, initial_value?: number): PineArrayObject;
29
- new_int(size: number, initial_value?: number): PineArrayObject;
30
- new_string(size: number, initial_value?: string): PineArrayObject;
31
- new<T>(size: number, initial_value: T): PineArrayObject;
32
- slice(id: PineArrayObject, start: number, end?: number): PineArrayObject;
33
- reverse(id: PineArrayObject): void;
34
- includes(id: PineArrayObject, value: any): boolean;
35
- indexof(id: PineArrayObject, value: any): number;
36
- lastindexof(id: PineArrayObject, value: any): number;
37
- stdev(id: PineArrayObject, biased?: boolean): number;
38
- variance(id: PineArrayObject, biased?: boolean): number;
39
- covariance(arr1: PineArrayObject, arr2: PineArrayObject, biased?: boolean): number;
40
- first(id: PineArrayObject): any;
41
- last(id: PineArrayObject): any;
42
- clear(id: PineArrayObject): void;
43
- join(id: PineArrayObject, separator?: string): string;
44
- /** Array Manipulation Functions */
45
- abs(id: PineArrayObject): PineArrayObject;
46
- concat(id: PineArrayObject, other: PineArrayObject): PineArrayObject;
47
- copy(id: PineArrayObject): PineArrayObject;
48
- every(id: PineArrayObject, callback: (val: any) => boolean): boolean;
49
- fill(id: PineArrayObject, value: any, start?: number, end?: number): void;
50
- from(source: any[]): PineArrayObject;
51
- insert(id: PineArrayObject, index: number, value: any): void;
52
- pop(id: PineArrayObject): any;
53
- range(id: PineArrayObject): number;
54
- remove(id: PineArrayObject, index: number): any;
55
- shift(id: PineArrayObject): any;
56
- sort(id: PineArrayObject, order?: 'asc' | 'desc'): void;
57
- sort_indices(id: PineArrayObject, comparator?: (a: any, b: any) => number): PineArrayObject;
58
- standardize(id: PineArrayObject): PineArrayObject;
59
- unshift(id: PineArrayObject, value: any): void;
60
- some(id: PineArrayObject, callback: (val: any) => boolean): boolean;
61
- }
62
- export {};
File without changes
@@ -1,28 +0,0 @@
1
- export declare class PineMath {
2
- private context;
3
- private _cache;
4
- constructor(context: any);
5
- param(source: any, index: any, name?: string): any;
6
- __eq(a: number, b: number): boolean;
7
- abs(source: number[]): number;
8
- pow(source: number[], power: number[]): number;
9
- sqrt(source: number[]): number;
10
- log(source: number[]): number;
11
- ln(source: number[]): number;
12
- exp(source: number[]): number;
13
- floor(source: number[]): number;
14
- ceil(source: number[]): number;
15
- round(source: number[]): number;
16
- random(): number;
17
- max(...source: number[]): number;
18
- min(...source: number[]): number;
19
- sum(source: number[], length: number): number;
20
- sin(source: number[]): number;
21
- cos(source: number[]): number;
22
- tan(source: number[]): number;
23
- acos(source: number[]): number;
24
- asin(source: number[]): number;
25
- atan(source: number[]): number;
26
- avg(...sources: number[][]): number;
27
- }
28
- export default PineMath;
@@ -1,8 +0,0 @@
1
- export declare class PineRequest {
2
- private context;
3
- private _cache;
4
- constructor(context: any);
5
- param(source: any, index: any, name?: string): any[];
6
- security(symbol: any, timeframe: any, expression: any, gaps?: boolean, lookahead?: boolean, ignore_invalid_symbol?: boolean, currency?: any, calc_bars_count?: any): Promise<any>;
7
- private _findSecContextIdx;
8
- }
@@ -1,16 +0,0 @@
1
- export declare class PlotHelper {
2
- private context;
3
- constructor(context: any);
4
- private extractPlotOptions;
5
- plotchar(series: number[], title: string, options: PlotCharOptions): void;
6
- plot(...args: any[]): void;
7
- }
8
- export declare class HlineHelper {
9
- private context;
10
- constructor(context: any);
11
- get style_dashed(): string;
12
- get style_solid(): string;
13
- get style_dotted(): string;
14
- param(source: any, index?: number, name?: string): any;
15
- any(price: any, title: any, color: any, linestyle: any, linewidth: any, editable: any, display: any): any;
16
- }
@@ -1,30 +0,0 @@
1
- export declare class TechnicalAnalysis {
2
- private context;
3
- constructor(context: any);
4
- get tr(): any;
5
- param(source: any, index: any, name?: string): any;
6
- ema(source: any, _period: any, _callId?: any): any;
7
- sma(source: any, _period: any, _callId?: any): any;
8
- vwma(source: any, _period: any, _callId?: any): any;
9
- wma(source: any, _period: any, _callId?: any): any;
10
- hma(source: any, _period: any, _callId?: any): any;
11
- rma(source: any, _period: any, _callId?: any): any;
12
- change(source: any, _length?: number, _callId?: any): any;
13
- rsi(source: any, _period: any, _callId?: any): any;
14
- atr(_period: any, _callId?: any): any;
15
- mom(source: any, _length: any, _callId?: any): any;
16
- roc(source: any, _length: any, _callId?: any): any;
17
- dev(source: any, _length: any, _callId?: any): any;
18
- variance(source: any, _length: any, _callId?: any): any;
19
- highest(source: any, _length: any, _callId?: any): any;
20
- lowest(source: any, _length: any, _callId?: any): any;
21
- median(source: any, _length: any, _callId?: any): any;
22
- stdev(source: any, _length: any, _bias?: boolean, _callId?: any): any;
23
- linreg(source: any, _length: any, _offset: any, _callId?: any): any;
24
- supertrend(_factor: any, _atrPeriod: any, _callId?: any): any[][];
25
- crossover(source1: any, source2: any): boolean;
26
- crossunder(source1: any, source2: any): boolean;
27
- pivothigh(source: any, _leftbars: any, _rightbars: any): any;
28
- pivotlow(source: any, _leftbars: any, _rightbars: any): any;
29
- }
30
- export default TechnicalAnalysis;
@@ -1,7 +0,0 @@
1
- declare const barmerge: {
2
- gaps_on: string;
3
- gaps_off: string;
4
- lookahead_on: string;
5
- lookahead_off: string;
6
- };
7
- export default barmerge;
@@ -1,84 +0,0 @@
1
- import { Trade } from './models/Trade';
2
- import { StrategyConfig, EntryOptions, ExitOptions, OrderOptions, OHLCV } from './types';
3
- export declare class StrategySimulator {
4
- private context;
5
- private config;
6
- private equity;
7
- private peakEquity;
8
- private maxDrawdown;
9
- private maxRunup;
10
- private intradayLoss;
11
- private filledOrdersToday;
12
- private lastTradingDay;
13
- private consecutiveLossDays;
14
- private lastLossDay;
15
- private position;
16
- private maxContractsHeld;
17
- private trades;
18
- private closedTrades;
19
- private pendingOrders;
20
- private maxDrawdownLimit?;
21
- private maxPositionSize?;
22
- private maxIntradayLoss?;
23
- private allowedEntryDirection;
24
- private stats;
25
- constructor(config: StrategyConfig, context: any);
26
- entry(id: string, direction: 'long' | 'short', qty?: number, options?: EntryOptions): void;
27
- exit(id: string, fromEntry?: string, qty?: number, qtyPercent?: number, options?: ExitOptions): void;
28
- close(id?: string, comment?: string): void;
29
- closeAll(comment?: string): void;
30
- order(id: string, direction: 'long' | 'short', qty: number, options?: OrderOptions): void;
31
- cancel(id: string): void;
32
- cancelAll(): void;
33
- processBar(barIndex: number, ohlcv: OHLCV): void;
34
- getEquity(): number;
35
- getNetProfit(): number;
36
- getOpenProfit(): number;
37
- getOpenProfitPercent(): number;
38
- getPositionSize(): number;
39
- getPositionAvgPrice(): number;
40
- getPositionEntryName(): string;
41
- getClosedTradesCount(): number;
42
- getOpenTradesCount(): number;
43
- getWinningTradesCount(): number;
44
- getLosingTradesCount(): number;
45
- getEvenTradesCount(): number;
46
- getAvgTrade(): number;
47
- getAvgTradePercent(): number;
48
- getAvgWinningTrade(): number;
49
- getAvgWinningTradePercent(): number;
50
- getAvgLosingTrade(): number;
51
- getAvgLosingTradePercent(): number;
52
- getMaxDrawdown(): number;
53
- getMaxDrawdownPercent(): number;
54
- getMaxRunup(): number;
55
- getMaxRunupPercent(): number;
56
- getMaxContractsHeldAll(): number;
57
- getMaxContractsHeldLong(): number;
58
- getMaxContractsHeldShort(): number;
59
- getGrossProfit(): number;
60
- getGrossLoss(): number;
61
- getMarginLiquidationPrice(): number;
62
- getClosedTrade(index: number): Trade | null;
63
- getOpenTrade(index: number): Trade | null;
64
- setMaxDrawdown(maxDD: number, percent?: boolean): void;
65
- setMaxPositionSize(maxSize: number): void;
66
- setMaxIntradayLoss(maxLoss: number): void;
67
- setAllowedEntryDirection(direction: 'all' | 'long' | 'short'): void;
68
- setMaxConsecutiveLossDays(maxDays: number): void;
69
- setMaxIntradayFilledOrders(maxOrders: number): void;
70
- private canEnter;
71
- private isRiskLimitExceeded;
72
- private calculateQuantity;
73
- private calculateExitQuantity;
74
- private checkPyramiding;
75
- private getEntryPrice;
76
- private getCurrentPrice;
77
- private calculateCommission;
78
- private closePosition;
79
- private executeExit;
80
- private processPendingOrders;
81
- private updateEquity;
82
- private updateMaxContractsHeld;
83
- private checkRiskLimits;
84
- }