pinets 0.9.27 → 0.9.29

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.
@@ -15,6 +15,7 @@ export declare class Context {
15
15
  strategy?: StrategyState;
16
16
  isSecondaryContext: boolean;
17
17
  chartTimezone: string | null;
18
+ chartStyle: string;
18
19
  dataVersion: number;
19
20
  __maxLoops: number;
20
21
  NA: any;
@@ -11,6 +11,7 @@ export type { IProvider, ISymbolInfo, BaseProviderConfig, ApiKeyProviderConfig }
11
11
  export type { Kline, PeriodType } from './marketData/types';
12
12
  export { computeNextPeriodStart, localTimeToUTC, computeSessionClose, TIMEFRAME_SECONDS, TIMEFRAME_PERIOD_INFO } from './marketData/types';
13
13
  export { aggregateCandles, selectSubTimeframe, getAggregationRatio } from './marketData/aggregation';
14
+ export { splitTickerModifier, stripTickerModifier, withTickerModifier } from './tickerModifier';
14
15
  export { PineTS, Context, Provider, Indicator, PineRuntimeError };
15
16
  export type { IPineInput, IPineProp, PineInputType, PineInputDisplay, PinePropType, PreparedScript } from './Indicator';
16
17
  export { INDICATOR_PROPS, STRATEGY_PROPS, propsForDeclaration } from './Indicator';
@@ -4,11 +4,17 @@
4
4
  * The methods here construct "ticker ID" strings that are passed to
5
5
  * `request.security` / `request.security_lower_tf` to fetch data for a
6
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.
7
+ * adjustment, non-standard chart type).
8
+ *
9
+ * CHART-TYPE modifiers travel as an EXTENDED-TICKER suffix
10
+ * (`"BINANCE:BTCUSDT;heikinashi"` see `tickerModifier.ts`):
11
+ * `ticker.heikinashi()` appends it, `ticker.standard()` strips it, and
12
+ * `request.security` passes it through to the data source untouched. An
13
+ * embedding host that owns the transform honors it; PineTS' own bundled
14
+ * providers serve standard candles only and strip it at their boundary
15
+ * (documented no-op for standalone use). The other non-standard types
16
+ * (Renko, Kagi, Line Break, Point & Figure) remain plain-symbol stubs —
17
+ * no data source we route to can construct those bars.
12
18
  *
13
19
  * For the plain "no-modifier" cases — which cover virtually every
14
20
  * real-world Pine script — the returned tickerid strings match
@@ -27,13 +33,14 @@ export declare class Ticker {
27
33
  */
28
34
  param(source: any, index?: number, _name?: string): any;
29
35
  /**
30
- * ticker.inherit(from_tickerid, symbol) → simple string
36
+ * ticker.inherit(from_tickerid, symbol) → string
31
37
  *
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.
38
+ * Returns a ticker ID that uses `symbol` and inherits modifier settings from
39
+ * `from_tickerid`. The CHART-TYPE modifier is honored: inheriting from a
40
+ * `";heikinashi"` ticker (e.g. `syminfo.tickerid` on a Heikin-Ashi chart)
41
+ * yields `"symbol;heikinashi"`, so the derived request keeps the chart type.
42
+ * The other modifier kinds (session, currency, adjustment) can't be honored
43
+ * without a TV datafeed and are dropped, as before.
37
44
  */
38
45
  inherit(_from_tickerid: any, symbol: any): string;
39
46
  /**
@@ -54,22 +61,22 @@ export declare class Ticker {
54
61
  /**
55
62
  * ticker.standard(symbol?) → simple string
56
63
  *
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`.
64
+ * Returns the symbol stripped of any chart-type modifier suffix —
65
+ * on a Heikin-Ashi chart, `ticker.standard(syminfo.tickerid)` turns
66
+ * `"BINANCE:BTCUSDT;heikinashi"` back into `"BINANCE:BTCUSDT"`, so a
67
+ * `request.security` call on the result fetches STANDARD candles.
68
+ * If `symbol` is undefined, falls back to `syminfo.tickerid`.
62
69
  */
63
70
  standard(symbol?: any): string;
64
71
  /**
65
- * ticker.heikinashi(symbol) → simple string
72
+ * ticker.heikinashi(symbol) → extended-ticker string
66
73
  *
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.
74
+ * Returns the symbol with the Heikin-Ashi chart-type modifier
75
+ * appended (`"BINANCE:BTCUSDT;heikinashi"`). `request.security`
76
+ * passes it through to the data source: an embedding host that owns
77
+ * the Heikin-Ashi transform serves derived bars; PineTS' own bundled
78
+ * providers strip the modifier and serve standard candles (documented
79
+ * standalone limitation). Idempotent on already-modified tickers.
73
80
  */
74
81
  heikinashi(symbol: any): string;
75
82
  /**
@@ -31,6 +31,7 @@ import { toradians } from './methods/toradians';
31
31
  import { __eq } from './methods/__eq';
32
32
  import { __ge } from './methods/__ge';
33
33
  import { __gt } from './methods/__gt';
34
+ import { __idiv } from './methods/__idiv';
34
35
  import { __le } from './methods/__le';
35
36
  import { __lt } from './methods/__lt';
36
37
  import { __neq } from './methods/__neq';
@@ -68,6 +69,7 @@ declare const methods: {
68
69
  __eq: typeof __eq;
69
70
  __ge: typeof __ge;
70
71
  __gt: typeof __gt;
72
+ __idiv: typeof __idiv;
71
73
  __le: typeof __le;
72
74
  __lt: typeof __lt;
73
75
  __neq: typeof __neq;
@@ -108,6 +110,7 @@ export declare class PineMath {
108
110
  __eq: ReturnType<typeof methods.__eq>;
109
111
  __ge: ReturnType<typeof methods.__ge>;
110
112
  __gt: ReturnType<typeof methods.__gt>;
113
+ __idiv: ReturnType<typeof methods.__idiv>;
111
114
  __le: ReturnType<typeof methods.__le>;
112
115
  __lt: ReturnType<typeof methods.__lt>;
113
116
  __neq: ReturnType<typeof methods.__neq>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pine integer division — the `/` (and `%`, via the transpiler) operator applied
3
+ * to two **integer** operands. In Pine, `int / int` yields an `int`: the result
4
+ * is truncated toward zero (`11 / 2 === 5`, `-11 / 2 === -5`), whereas JavaScript
5
+ * `/` is always float division (`5.5`).
6
+ *
7
+ * The transpiler rewrites a `/` BinaryExpression to this helper ONLY when BOTH
8
+ * operands are provably `int` at compile time (see TypeInferencePass). Any float
9
+ * operand keeps native `/`, so genuine float division (`4.0 / 2.0`, `close / 2`)
10
+ * is untouched.
11
+ *
12
+ * Semantics:
13
+ * - `na` (NaN) in either operand propagates → NaN.
14
+ * - Division by zero follows the same rule as native `/`: `Math.trunc` preserves
15
+ * `1 / 0 → Infinity` and `0 / 0 → NaN`, matching PineTS's existing div-by-zero
16
+ * behavior (truncation only changes finite results).
17
+ * - Non-numeric operands fall back to native `/` (defensive; should not occur
18
+ * given the compile-time int guard).
19
+ */
20
+ export declare function __idiv(context: any): (a: any, b: any) => number;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Pine Script integer division (`int / int → int`).
3
+ *
4
+ * TradingView truncates the quotient toward zero when BOTH operands are of
5
+ * type `int` (Java semantics: `11 / 2 == 5`, `-7 / 2 == -3`). Plain JS `/`
6
+ * always yields a float, which breaks idioms like `pivots(high, depth / 2)`
7
+ * where the result feeds a series history offset.
8
+ *
9
+ * The pine2js codegen emits this helper only when both operands are
10
+ * statically provable ints (declared `int` vars/params, int literals,
11
+ * `input.int`, int-result expressions). Anything unprovable keeps plain `/`.
12
+ *
13
+ * - `na` in either operand propagates (`NaN`).
14
+ * - Division by zero returns `na` (`NaN`) instead of JS `Infinity`.
15
+ */
16
+ export declare function __intDiv(context: any): (a: any, b: any) => number;
@@ -0,0 +1,9 @@
1
+ /** Split `"SYM;modifier"` into its parts. Plain symbols yield `modifier: null`. */
2
+ export declare function splitTickerModifier(tickerId: string): {
3
+ symbol: string;
4
+ modifier: string | null;
5
+ };
6
+ /** The plain symbol with any chart-type modifier removed. */
7
+ export declare function stripTickerModifier(tickerId: string): string;
8
+ /** Append a chart-type modifier (replacing any existing one; idempotent). */
9
+ export declare function withTickerModifier(tickerId: string, modifier: string): string;
@@ -0,0 +1,2 @@
1
+ import ScopeManager from './ScopeManager';
2
+ export declare function runTypeInferencePass(ast: any, _scopeManager: ScopeManager): void;
@@ -35,5 +35,5 @@ export declare class Lexer {
35
35
  isIdentifierStart(ch: any): boolean;
36
36
  isIdentifierChar(ch: any): boolean;
37
37
  getCurrentIndent(): number;
38
- addToken(type: any, value: any, indent?: any): void;
38
+ addToken(type: any, value: any, indent?: any, raw?: any): void;
39
39
  }
@@ -29,5 +29,6 @@ export declare class Token {
29
29
  line: number;
30
30
  column: number;
31
31
  indent: number;
32
- constructor(type: string, value: any, line: number, column: number, indent?: number);
32
+ raw: string;
33
+ constructor(type: string, value: any, line: number, column: number, indent?: number, raw?: string);
33
34
  }
@@ -21,6 +21,7 @@ export declare const ASTFactory: {
21
21
  createMathEqCall(left: any, right: any): any;
22
22
  createMathNeqCall(left: any, right: any): any;
23
23
  createMathCompareCall(method: string, left: any, right: any): any;
24
+ createMathIntDivCall(left: any, right: any): any;
24
25
  createWrapperFunction(body: any): any;
25
26
  createVariableDeclaration(name: string, init: any): any;
26
27
  createAwaitExpression(argument: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinets",
3
- "version": "0.9.27",
3
+ "version": "0.9.29",
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",