pinets 0.9.6 → 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 (62) hide show
  1. package/dist/pinets.min.browser.es.js +19 -36
  2. package/dist/pinets.min.browser.es.js.map +1 -1
  3. package/dist/pinets.min.browser.js +46 -63
  4. package/dist/pinets.min.browser.js.map +1 -1
  5. package/dist/pinets.min.cjs +19 -36
  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 +23 -0
  10. package/dist/types/PineTS.class.d.ts +10 -1
  11. package/dist/types/namespaces/Core.d.ts +40 -2
  12. package/dist/types/transpiler/analysis/ScopeManager.d.ts +2 -0
  13. package/dist/types/transpiler/pineToJS/codegen.d.ts +33 -0
  14. package/dist/types/transpiler/pineToJS/parser.d.ts +1 -0
  15. package/dist/types/transpiler/settings.d.ts +1 -0
  16. package/package.json +1 -1
  17. package/dist/types/NaProxy.d.ts +0 -19
  18. package/dist/types/TimeSeries.class.d.ts +0 -49
  19. package/dist/types/TimeSeries.d.ts +0 -15
  20. package/dist/types/namespaces/Input.d.ts +0 -24
  21. package/dist/types/namespaces/PineArray.d.ts +0 -62
  22. package/dist/types/namespaces/PineColor.d.ts +0 -0
  23. package/dist/types/namespaces/PineMath.d.ts +0 -28
  24. package/dist/types/namespaces/PineRequest.d.ts +0 -8
  25. package/dist/types/namespaces/Plot.helper.d.ts +0 -16
  26. package/dist/types/namespaces/TechnicalAnalysis.d.ts +0 -30
  27. package/dist/types/namespaces/request/types/barmerge.type.d.ts +0 -7
  28. package/dist/types/namespaces/strategy/StrategySimulator.d.ts +0 -84
  29. package/dist/types/namespaces/strategy/closedtrades/index.d.ts +0 -18
  30. package/dist/types/namespaces/strategy/methods/any.d.ts +0 -5
  31. package/dist/types/namespaces/strategy/methods/cancel.d.ts +0 -1
  32. package/dist/types/namespaces/strategy/methods/cancel_all.d.ts +0 -1
  33. package/dist/types/namespaces/strategy/methods/cash.d.ts +0 -5
  34. package/dist/types/namespaces/strategy/methods/close.d.ts +0 -1
  35. package/dist/types/namespaces/strategy/methods/close_all.d.ts +0 -1
  36. package/dist/types/namespaces/strategy/methods/closedtrades.d.ts +0 -4
  37. package/dist/types/namespaces/strategy/methods/entry.d.ts +0 -3
  38. package/dist/types/namespaces/strategy/methods/equity.d.ts +0 -4
  39. package/dist/types/namespaces/strategy/methods/exit.d.ts +0 -3
  40. package/dist/types/namespaces/strategy/methods/fixed.d.ts +0 -5
  41. package/dist/types/namespaces/strategy/methods/long.d.ts +0 -4
  42. package/dist/types/namespaces/strategy/methods/netprofit.d.ts +0 -4
  43. package/dist/types/namespaces/strategy/methods/opentrades.d.ts +0 -4
  44. package/dist/types/namespaces/strategy/methods/order.d.ts +0 -6
  45. package/dist/types/namespaces/strategy/methods/param.d.ts +0 -5
  46. package/dist/types/namespaces/strategy/methods/percent_of_equity.d.ts +0 -5
  47. package/dist/types/namespaces/strategy/methods/position_avg_price.d.ts +0 -5
  48. package/dist/types/namespaces/strategy/methods/position_entry.d.ts +0 -5
  49. package/dist/types/namespaces/strategy/methods/position_entry_name.d.ts +0 -5
  50. package/dist/types/namespaces/strategy/methods/position_size.d.ts +0 -5
  51. package/dist/types/namespaces/strategy/methods/short.d.ts +0 -4
  52. package/dist/types/namespaces/strategy/models/Order.d.ts +0 -31
  53. package/dist/types/namespaces/strategy/models/Position.d.ts +0 -16
  54. package/dist/types/namespaces/strategy/models/Trade.d.ts +0 -45
  55. package/dist/types/namespaces/strategy/opentrades/index.d.ts +0 -10
  56. package/dist/types/namespaces/strategy/risk/index.d.ts +0 -11
  57. package/dist/types/namespaces/strategy/strategy.index.d.ts +0 -53
  58. package/dist/types/namespaces/strategy/types.d.ts +0 -92
  59. package/dist/types/namespaces/strategy/utils.d.ts +0 -28
  60. package/dist/types/namespaces/ta/getters/obv.d.ts +0 -12
  61. package/dist/types/namespaces/ta/getters/tr.d.ts +0 -1
  62. package/dist/types/transpiler/ScopeManager.class.d.ts +0 -36
@@ -16,6 +16,29 @@ export declare class Context {
16
16
  dataVersion: number;
17
17
  __maxLoops: number;
18
18
  NA: any;
19
+ /** Runtime warnings (OOB access, etc.) — non-blocking, script continues. */
20
+ warnings: {
21
+ message: string;
22
+ method?: string;
23
+ bar: number;
24
+ }[];
25
+ /** Alert events emitted by alert() and alertcondition() calls. */
26
+ alerts: {
27
+ type: string;
28
+ id: string;
29
+ message: string;
30
+ title?: string;
31
+ freq?: string;
32
+ bar_index: number;
33
+ time: number;
34
+ }[];
35
+ /** Alert mode: 'realtime' = only fire on live bars (TV behavior), 'all' = fire on every bar (backtest). */
36
+ _alertMode: 'realtime' | 'all';
37
+ /** Monotonically increasing counter, incremented each time a bar starts executing.
38
+ * Used by alertcondition/AlertHelper to detect re-execution of the same bar. */
39
+ _execTick: number;
40
+ /** Emit a runtime warning. The script continues execution (returns na/no-op). */
41
+ warn(message: string, method?: string): void;
19
42
  lang: any;
20
43
  length: number;
21
44
  /** References to drawing helpers for streaming rollback */
@@ -48,6 +48,15 @@ export declare class PineTS {
48
48
  * @param maxLoops Maximum iterations per loop (default: 500000)
49
49
  */
50
50
  setMaxLoops(maxLoops: number): void;
51
+ private _alertMode;
52
+ /**
53
+ * Set alert mode.
54
+ * - 'realtime' (default): alerts only fire on the last (realtime) bar,
55
+ * matching TradingView behavior.
56
+ * - 'all': alerts fire on every bar, useful for backtesting alert strategies.
57
+ * @param mode Alert firing mode
58
+ */
59
+ setAlertMode(mode: 'realtime' | 'all'): void;
51
60
  constructor(source: IProvider | any[], tickerId?: string, timeframe?: string, limit?: number, sDate?: number, eDate?: number);
52
61
  setDebugSettings({ ln, debug }: {
53
62
  ln: boolean;
@@ -82,7 +91,7 @@ export declare class PineTS {
82
91
  live?: boolean;
83
92
  interval?: number;
84
93
  }): {
85
- on: (event: 'data' | 'error', callback: Function) => void;
94
+ on: (event: 'data' | 'error' | 'warning' | 'alert', callback: Function) => void;
86
95
  stop: () => void;
87
96
  };
88
97
  /**
@@ -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,7 @@ export declare class ScopeManager {
15
15
  private taCallIdCounter;
16
16
  private userCallIdCounter;
17
17
  private plotCallIdCounter;
18
+ private alertCallIdCounter;
18
19
  private loopGuardCounter;
19
20
  private hoistingStack;
20
21
  private suppressHoisting;
@@ -26,6 +27,7 @@ export declare class ScopeManager {
26
27
  getNextTACallId(): any;
27
28
  getNextUserCallId(): any;
28
29
  getNextPlotCallId(): any;
30
+ getNextAlertCallId(): any;
29
31
  getNextLoopGuardName(): string;
30
32
  constructor();
31
33
  pushScope(type: string): 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;
@@ -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[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinets",
3
- "version": "0.9.6",
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",
@@ -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
- }
@@ -1,18 +0,0 @@
1
- import { Series } from '../../../Series';
2
- export declare class ClosedTradesAccessor {
3
- private context;
4
- constructor(context: any);
5
- private getSimulator;
6
- get first_index(): number;
7
- size(tradeNum: number | Series): number;
8
- profit(tradeNum: number | Series): number;
9
- profit_percent(tradeNum: number | Series): number;
10
- entry_price(tradeNum: number | Series): number;
11
- exit_price(tradeNum: number | Series): number;
12
- entry_bar_index(tradeNum: number | Series): number;
13
- exit_bar_index(tradeNum: number | Series): number;
14
- commission(tradeNum: number | Series): number;
15
- [Symbol.toPrimitive](hint: string): number | string;
16
- valueOf(): number;
17
- toString(): string;
18
- }
@@ -1,5 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export declare function cancel(context: any): (id: string) => void;
@@ -1 +0,0 @@
1
- export declare function cancel_all(context: any): () => void;
@@ -1,5 +0,0 @@
1
- /**
2
- * Constant for order sizing type: cash
3
- * Used in default_qty_type parameter
4
- */
5
- export declare function cash(context: any): () => string;
@@ -1 +0,0 @@
1
- export declare function close(context: any): (id?: string, comment?: string) => void;
@@ -1 +0,0 @@
1
- export declare function close_all(context: any): (comment?: string) => void;
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns the number of closed trades
3
- */
4
- export declare function closedtrades(context: any): () => any;
@@ -1,3 +0,0 @@
1
- import { Series } from '../../../Series';
2
- import { EntryOptions } from '../types';
3
- export declare function entry(context: any): (id: string, direction: "long" | "short", qty?: number | Series, options?: EntryOptions) => void;
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns the current equity (initial capital + net profit + unrealized P&L)
3
- */
4
- export declare function equity(context: any): () => any;
@@ -1,3 +0,0 @@
1
- import { Series } from '../../../Series';
2
- import { ExitOptions } from '../types';
3
- export declare function exit(context: any): (id: string, from_entry?: string, qty?: number | Series, qty_percent?: number | Series, options?: ExitOptions) => void;
@@ -1,5 +0,0 @@
1
- /**
2
- * Constant for order sizing type: fixed
3
- * Used in default_qty_type parameter
4
- */
5
- export declare function fixed(context: any): () => string;
@@ -1,4 +0,0 @@
1
- /**
2
- * Constant representing long direction
3
- */
4
- export declare function long(context: any): () => string;
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns the total net profit (realized P&L)
3
- */
4
- export declare function netprofit(context: any): () => any;
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns the number of currently open trades
3
- */
4
- export declare function opentrades(context: any): () => any;
@@ -1,6 +0,0 @@
1
- import { Order } from '../types';
2
- /**
3
- * Places a basic order
4
- * Usage: strategy.order(id, direction, qty=na, limit=na, stop=na, ...)
5
- */
6
- export declare function order(context: any): (id: any, direction: any, qty?: any, limit?: any, stop?: any, ...rest: any[]) => Order;