oakscriptjs 0.9.5 → 0.10.0
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.
- package/README.md +1 -1
- package/dist/cjs/array/index.d.ts +93 -50
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +239 -78
- package/dist/cjs/array/index.js.map +3 -3
- package/dist/cjs/callsite/index.d.ts +81 -2
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +62 -1
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts +7 -3
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +6 -1
- package/dist/cjs/color/index.js.map +2 -2
- package/dist/cjs/drawing/bar-time.d.ts +24 -0
- package/dist/cjs/drawing/bar-time.d.ts.map +1 -0
- package/dist/cjs/drawing/bar-time.js +47 -0
- package/dist/cjs/drawing/bar-time.js.map +7 -0
- package/dist/cjs/drawing/output.d.ts +32 -0
- package/dist/cjs/drawing/output.d.ts.map +1 -0
- package/dist/cjs/drawing/output.js +184 -0
- package/dist/cjs/drawing/output.js.map +7 -0
- package/dist/cjs/drawing/registry.d.ts +5 -4
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +11 -2
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +2 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +1 -0
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +76 -21
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js +155 -41
- package/dist/cjs/math/index.js.map +3 -3
- package/dist/cjs/matrix/index.d.ts.map +1 -1
- package/dist/cjs/matrix/index.js +42 -36
- package/dist/cjs/matrix/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +3 -5
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js +0 -5
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/series.d.ts +9 -0
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +16 -2
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +22 -0
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/index.d.ts +97 -36
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +173 -26
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +15 -2
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/str/index.d.ts +50 -38
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +43 -15
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/str/messageformat.d.ts +2 -1
- package/dist/cjs/str/messageformat.d.ts.map +1 -1
- package/dist/cjs/str/messageformat.js +4 -1
- package/dist/cjs/str/messageformat.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts +4 -0
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +26 -4
- package/dist/cjs/str/numberformat.js.map +3 -3
- package/dist/cjs/ta/index.d.ts +86 -43
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +173 -267
- package/dist/cjs/ta/index.js.map +3 -3
- package/dist/cjs/ta/running-sum.d.ts +54 -2
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +132 -52
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta-series.d.ts +4 -4
- package/dist/cjs/ta-series.d.ts.map +1 -1
- package/dist/cjs/ta-series.js +4 -3
- package/dist/cjs/ta-series.js.map +2 -2
- package/dist/cjs/table/index.d.ts +87 -0
- package/dist/cjs/table/index.d.ts.map +1 -0
- package/dist/cjs/table/index.js +150 -0
- package/dist/cjs/table/index.js.map +7 -0
- package/dist/cjs/text/index.d.ts +17 -2
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js +15 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/time/datestring.d.ts +1 -0
- package/dist/cjs/time/datestring.d.ts.map +1 -1
- package/dist/cjs/time/datestring.js +7 -0
- package/dist/cjs/time/datestring.js.map +2 -2
- package/dist/cjs/time/index.d.ts.map +1 -1
- package/dist/cjs/time/index.js +2 -1
- package/dist/cjs/time/index.js.map +2 -2
- package/dist/cjs/time/session.d.ts +28 -9
- package/dist/cjs/time/session.d.ts.map +1 -1
- package/dist/cjs/time/session.js +74 -28
- package/dist/cjs/time/session.js.map +2 -2
- package/dist/cjs/time/timezone.d.ts +5 -0
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +15 -1
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/cjs/types/index.d.ts +30 -1
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -0
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +258 -26
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/esm/array/index.d.ts +93 -50
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +383 -133
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts +81 -2
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +145 -3
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/color/index.d.ts +7 -3
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +15 -3
- package/dist/esm/color/index.js.map +1 -1
- package/dist/esm/drawing/bar-time.d.ts +24 -0
- package/dist/esm/drawing/bar-time.d.ts.map +1 -0
- package/dist/esm/drawing/bar-time.js +44 -0
- package/dist/esm/drawing/bar-time.js.map +1 -0
- package/dist/esm/drawing/output.d.ts +32 -0
- package/dist/esm/drawing/output.d.ts.map +1 -0
- package/dist/esm/drawing/output.js +190 -0
- package/dist/esm/drawing/output.js.map +1 -0
- package/dist/esm/drawing/registry.d.ts +5 -4
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +12 -2
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +7 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +2 -1
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +3 -0
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +76 -21
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +227 -61
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/matrix/index.d.ts.map +1 -1
- package/dist/esm/matrix/index.js +57 -43
- package/dist/esm/matrix/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +3 -5
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +3 -9
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/series.d.ts +9 -0
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +18 -1
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +22 -0
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +97 -36
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +211 -22
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +22 -2
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/str/index.d.ts +50 -38
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +103 -52
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/str/messageformat.d.ts +2 -1
- package/dist/esm/str/messageformat.d.ts.map +1 -1
- package/dist/esm/str/messageformat.js +7 -2
- package/dist/esm/str/messageformat.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts +4 -0
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +38 -4
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts +86 -43
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +296 -348
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/running-sum.d.ts +54 -2
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +166 -71
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta-series.d.ts +4 -4
- package/dist/esm/ta-series.d.ts.map +1 -1
- package/dist/esm/ta-series.js +5 -4
- package/dist/esm/ta-series.js.map +1 -1
- package/dist/esm/table/index.d.ts +87 -0
- package/dist/esm/table/index.d.ts.map +1 -0
- package/dist/esm/table/index.js +169 -0
- package/dist/esm/table/index.js.map +1 -0
- package/dist/esm/text/index.d.ts +17 -2
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +17 -2
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/time/datestring.d.ts +1 -0
- package/dist/esm/time/datestring.d.ts.map +1 -1
- package/dist/esm/time/datestring.js +12 -0
- package/dist/esm/time/datestring.js.map +1 -1
- package/dist/esm/time/index.d.ts.map +1 -1
- package/dist/esm/time/index.js +3 -1
- package/dist/esm/time/index.js.map +1 -1
- package/dist/esm/time/session.d.ts +28 -9
- package/dist/esm/time/session.d.ts.map +1 -1
- package/dist/esm/time/session.js +113 -42
- package/dist/esm/time/session.js.map +1 -1
- package/dist/esm/time/timezone.d.ts +5 -0
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +21 -1
- package/dist/esm/time/timezone.js.map +1 -1
- package/dist/esm/types/index.d.ts +30 -1
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +14 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +258 -26
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +364 -150
- package/src/callsite/index.ts +147 -3
- package/src/color/index.ts +15 -5
- package/src/drawing/bar-time.ts +42 -0
- package/src/drawing/output.ts +214 -0
- package/src/drawing/registry.ts +16 -6
- package/src/index.ts +9 -3
- package/src/label/index.ts +2 -1
- package/src/linefill/index.ts +2 -0
- package/src/math/index.ts +256 -74
- package/src/matrix/index.ts +52 -52
- package/src/polyline/index.ts +3 -12
- package/src/runtime/series.ts +22 -1
- package/src/runtime/types.ts +23 -0
- package/src/script/index.ts +307 -25
- package/src/session/calendar.ts +22 -2
- package/src/str/index.ts +95 -51
- package/src/str/messageformat.ts +7 -2
- package/src/str/numberformat.ts +39 -4
- package/src/ta/index.ts +306 -386
- package/src/ta/running-sum.ts +187 -74
- package/src/ta-series.ts +8 -7
- package/src/table/index.ts +221 -0
- package/src/text/index.ts +18 -2
- package/src/time/datestring.ts +10 -0
- package/src/time/index.ts +3 -1
- package/src/time/session.ts +97 -47
- package/src/time/timezone.ts +21 -1
- package/src/types/index.ts +32 -1
- package/src/types/metadata.ts +325 -26
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/polyline/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Polyline namespace\n * Functions for creating and manipulating polyline drawing objects.\n *\n * @remarks\n * Polylines allow connecting multiple points with line segments, enabling complex chart drawings\n * like trend channels, patterns, and custom shapes.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,sBAAqD;AAMrD,IAAI,oBAAoB;AAKxB,SAAS,aAAqB;AAC5B,SAAO,YAAY,EAAE,iBAAiB;AACxC;
|
|
4
|
+
"sourcesContent": ["/**\n * Polyline namespace\n * Functions for creating and manipulating polyline drawing objects.\n *\n * @remarks\n * Polylines allow connecting multiple points with line segments, enabling complex chart drawings\n * like trend channels, patterns, and custom shapes. The `curved` flag goes to the renderer\n * (`result.polylines` of the script API), which draws the curve.\n *\n * @version 6\n */\n\nimport type { ChartPoint, Polyline, color } from '../types/index.js';\nimport { all as allDrawings, register, remove } from '../drawing/registry.js';\n\n// Re-export the Polyline type for convenience\nexport type { Polyline };\n\n// Internal counter for generating unique IDs\nlet polylineIdCounter = 0;\n\n/**\n * Generates a unique ID for a polyline\n */\nfunction generateId(): string {\n return `polyline_${++polylineIdCounter}`;\n}\n\n/**\n * Creates a new polyline connecting all points.\n *\n * @param points - Array of chart.point objects to connect\n * @param curved - If true, use curved line segments (default: false)\n * @param closed - If true, connect first point to last point (default: false)\n * @param xloc - X-coordinate mode: 'bar_index' or 'bar_time' (default: 'bar_index')\n * @param line_color - Color of line segments (default: '#2196F3' - blue)\n * @param fill_color - Fill color for closed polylines (default: null)\n * @param line_style - Line style (default: 'solid')\n * @param line_width - Line width in pixels (default: 1)\n * @param force_overlay - Force display on main pane (default: false)\n * @returns New Polyline object\n *\n * @remarks\n * - For meaningful polylines, provide at least 2 points.\n * - Closed polylines can be filled with a color by setting fill_color.\n *\n * @example\n * ```typescript\n * import { chartPoint, polyline } from 'oakscriptjs';\n *\n * // Create points\n * const points = [\n * chartPoint.from_index(0, 100),\n * chartPoint.from_index(10, 120),\n * chartPoint.from_index(20, 110)\n * ];\n *\n * // Create a basic polyline\n * const myPolyline = polyline.new(points);\n *\n * // Create a closed polygon with fill\n * const polygon = polyline.new(\n * points,\n * false, // curved\n * true, // closed\n * 'bar_index', // xloc\n * '#FF5722', // line_color\n * 'rgba(255, 87, 34, 0.3)' // fill_color\n * );\n * ```\n */\nexport function new_polyline(\n points: ChartPoint[],\n curved: boolean = false,\n closed: boolean = false,\n xloc: 'bar_index' | 'bar_time' = 'bar_index',\n line_color: color = '#2196F3',\n fill_color: color | null = null,\n line_style: 'solid' | 'dotted' | 'dashed' = 'solid',\n line_width: number = 1,\n force_overlay: boolean = false\n): Polyline {\n // Validate line_width is positive\n if (line_width < 1) {\n console.warn('polyline.new(): line_width must be at least 1. Using 1.');\n line_width = 1;\n }\n\n const polyline: Polyline = {\n id: generateId(),\n points: [...points], // Create a copy of the points array\n curved,\n closed,\n xloc,\n line_color,\n fill_color,\n line_style,\n line_width,\n force_overlay,\n };\n\n return register('polyline', polyline);\n}\n\n/**\n * Deletes a polyline.\n *\n * @param id - Polyline object to delete\n *\n * @remarks\n * Removes the polyline from `polyline.all()` (the drawing registry, see drawing/registry).\n *\n * @example\n * ```typescript\n * const myPolyline = polyline.new(points);\n * polyline.delete(myPolyline);\n * ```\n */\nexport function delete_polyline(id: Polyline): void {\n remove('polyline', id);\n}\n\n/**\n * Gets all active polylines.\n *\n * @returns Array of all active polylines\n *\n * @remarks\n * Returns a copy of the internal polylines array to prevent external modification.\n *\n * @example\n * ```typescript\n * console.log('Total polylines:', polyline.all.length);\n *\n * for (const p of polyline.all) {\n * console.log('Polyline ID:', p.id, 'Points:', p.points.length);\n * }\n * ```\n */\nexport function get_all(): readonly Polyline[] {\n return allDrawings('polyline');\n}\n\n/**\n * All live polylines, in creation order (PineScript `polyline.all`). A new array.\n */\nexport function all(): Polyline[] {\n return allDrawings('polyline');\n}\n\n/**\n * Deletes all polylines.\n *\n * @remarks\n * This is useful for resetting state, especially in tests.\n * Not part of the PineScript API.\n */\nexport function clear_all(): void {\n for (const p of allDrawings('polyline')) remove('polyline', p);\n}\n\n/**\n * Resets the polyline ID counter.\n *\n * @remarks\n * This is useful for resetting state, especially in tests.\n * Not part of the PineScript API.\n */\nexport function reset_id_counter(): void {\n polylineIdCounter = 0;\n}\n\n// Aliases to match PineScript API\nexport { new_polyline as new };\nexport { delete_polyline as delete };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,sBAAqD;AAMrD,IAAI,oBAAoB;AAKxB,SAAS,aAAqB;AAC5B,SAAO,YAAY,EAAE,iBAAiB;AACxC;AA6CO,SAAS,aACd,QACA,SAAkB,OAClB,SAAkB,OAClB,OAAiC,aACjC,aAAoB,WACpB,aAA2B,MAC3B,aAA4C,SAC5C,aAAqB,GACrB,gBAAyB,OACf;AAEV,MAAI,aAAa,GAAG;AAClB,YAAQ,KAAK,yDAAyD;AACtE,iBAAa;AAAA,EACf;AAEA,QAAM,WAAqB;AAAA,IACzB,IAAI,WAAW;AAAA,IACf,QAAQ,CAAC,GAAG,MAAM;AAAA;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,aAAO,0BAAS,YAAY,QAAQ;AACtC;AAgBO,SAAS,gBAAgB,IAAoB;AAClD,8BAAO,YAAY,EAAE;AACvB;AAmBO,SAAS,UAA+B;AAC7C,aAAO,gBAAAA,KAAY,UAAU;AAC/B;AAKO,SAAS,MAAkB;AAChC,aAAO,gBAAAA,KAAY,UAAU;AAC/B;AASO,SAAS,YAAkB;AAChC,aAAW,SAAK,gBAAAA,KAAY,UAAU,EAAG,6BAAO,YAAY,CAAC;AAC/D;AASO,SAAS,mBAAyB;AACvC,sBAAoB;AACtB;",
|
|
6
6
|
"names": ["allDrawings"]
|
|
7
7
|
}
|
|
@@ -121,6 +121,10 @@ export declare class BarData {
|
|
|
121
121
|
* const materialized = complex.materialize(); // Breaks closure chain
|
|
122
122
|
* ```
|
|
123
123
|
*/
|
|
124
|
+
/** Largest history reference of a script series (PineScript max_bars_back limit). */
|
|
125
|
+
export declare const MAX_BARS_BACK = 5000;
|
|
126
|
+
/** PineScript's runtime error RE10008 text. */
|
|
127
|
+
export declare function historyError(bar: number, barsBack: number): string;
|
|
124
128
|
export declare class Series {
|
|
125
129
|
private extractor;
|
|
126
130
|
private dataSource;
|
|
@@ -132,6 +136,11 @@ export declare class Series {
|
|
|
132
136
|
* @param data - Bar data (Bar[] or BarData)
|
|
133
137
|
* @param extractor - Function to extract/compute value for each bar
|
|
134
138
|
*/
|
|
139
|
+
/**
|
|
140
|
+
* True for PineScript's built-in price variables (open, high, low, close, volume, hl2...): their history covers
|
|
141
|
+
* every bar, so references further than 5000 bars back are allowed (measured: close[bar_index] runs).
|
|
142
|
+
*/
|
|
143
|
+
fullHistory: boolean;
|
|
135
144
|
constructor(data: Bar[] | BarData, extractor: SeriesExtractor);
|
|
136
145
|
/**
|
|
137
146
|
* Get the underlying bar data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"series.d.ts","sourceRoot":"","sources":["../../../src/runtime/series.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO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__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var series_exports = {};
|
|
30
30
|
__export(series_exports, {
|
|
31
31
|
BarData: () => BarData,
|
|
32
|
-
|
|
32
|
+
MAX_BARS_BACK: () => MAX_BARS_BACK,
|
|
33
|
+
Series: () => Series,
|
|
34
|
+
historyError: () => historyError
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(series_exports);
|
|
35
37
|
var compare = __toESM(require("../compare/index.js"), 1);
|
|
@@ -136,6 +138,10 @@ class BarData {
|
|
|
136
138
|
return new BarData(bars);
|
|
137
139
|
}
|
|
138
140
|
}
|
|
141
|
+
const MAX_BARS_BACK = 5e3;
|
|
142
|
+
function historyError(bar, barsBack) {
|
|
143
|
+
return `Error on bar ${bar}: The script attempts to reference historical data that is too far from the current bar (${barsBack} bars back). The history-referencing length for the expression must be a value between 0 and ${MAX_BARS_BACK}.`;
|
|
144
|
+
}
|
|
139
145
|
class Series {
|
|
140
146
|
extractor;
|
|
141
147
|
dataSource;
|
|
@@ -147,6 +153,11 @@ class Series {
|
|
|
147
153
|
* @param data - Bar data (Bar[] or BarData)
|
|
148
154
|
* @param extractor - Function to extract/compute value for each bar
|
|
149
155
|
*/
|
|
156
|
+
/**
|
|
157
|
+
* True for PineScript's built-in price variables (open, high, low, close, volume, hl2...): their history covers
|
|
158
|
+
* every bar, so references further than 5000 bars back are allowed (measured: close[bar_index] runs).
|
|
159
|
+
*/
|
|
160
|
+
fullHistory = false;
|
|
150
161
|
constructor(data, extractor) {
|
|
151
162
|
this.dataSource = data instanceof BarData ? data : new BarData(data);
|
|
152
163
|
this.extractor = extractor;
|
|
@@ -175,7 +186,9 @@ class Series {
|
|
|
175
186
|
* @returns Series with extracted field values
|
|
176
187
|
*/
|
|
177
188
|
static fromBars(bars, field) {
|
|
178
|
-
|
|
189
|
+
const series = new Series(bars, (bar) => bar[field] ?? NaN);
|
|
190
|
+
series.fullHistory = true;
|
|
191
|
+
return series;
|
|
179
192
|
}
|
|
180
193
|
/**
|
|
181
194
|
* Create a constant series (same value for all bars)
|
|
@@ -444,6 +457,7 @@ class Series {
|
|
|
444
457
|
*/
|
|
445
458
|
offset(offset) {
|
|
446
459
|
if (offset < 0) throw new RangeError(`Series.offset(${offset}): the offset cannot be negative (it would read a future bar).`);
|
|
460
|
+
if (offset > MAX_BARS_BACK && !this.fullHistory) throw new Error(historyError(0, Math.floor(offset)));
|
|
447
461
|
return new Series(this.dataSource, (_bar, i, data) => {
|
|
448
462
|
const targetIndex = i - offset;
|
|
449
463
|
if (targetIndex < 0 || targetIndex >= data.length) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/series.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Simplified Series class for lazy time-series computation\n * Represents a time-series of values with lazy evaluation\n * @module runtime/series\n */\n\nimport * as compare from '../compare/index.js';\nimport type { Bar } from '../types/index.js';\n\n/**\n * Function that computes a value for each bar\n */\nexport type SeriesExtractor = (bar: Bar, index: number, data: Bar[]) => number;\n\n/**\n * BarData - Versioned wrapper around Bar[] array for cache invalidation\n * \n * This class wraps a Bar[] array and tracks a version number that increments\n * whenever the data is mutated. Series objects reference this to detect when\n * their cached values need to be recomputed.\n * \n * @example\n * ```typescript\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * \n * barData.push(newBar); // Increments version\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * ```\n */\nexport class BarData {\n private _bars: Bar[];\n private _version: number = 0;\n\n /**\n * Create a new BarData wrapper\n * @param bars - Initial bar data (defaults to empty array)\n */\n constructor(bars: Bar[] = []) {\n this._bars = bars;\n }\n\n /**\n * Get the current version number\n * Version increments whenever data is mutated\n */\n get version(): number {\n return this._version;\n }\n\n /**\n * Get the underlying bar array\n * Note: Direct mutations to this array will NOT increment version\n * Use the provided mutation methods instead\n */\n get bars(): Bar[] {\n return this._bars;\n }\n\n /**\n * Get the number of bars\n */\n get length(): number {\n return this._bars.length;\n }\n\n /**\n * Add a new bar to the end\n * @param bar - Bar to add\n */\n push(bar: Bar): void {\n this._bars.push(bar);\n this._version++;\n }\n\n /**\n * Remove and return the last bar\n * @returns The removed bar, or undefined if empty\n */\n pop(): Bar | undefined {\n const bar = this._bars.pop();\n if (bar !== undefined) {\n this._version++;\n }\n return bar;\n }\n\n /**\n * Replace a bar at a specific index\n * @param index - Index to update\n * @param bar - New bar data\n */\n set(index: number, bar: Bar): void {\n if (index >= 0 && index < this._bars.length) {\n this._bars[index] = bar;\n this._version++;\n }\n }\n\n /**\n * Update the last bar (useful for real-time/streaming updates)\n * @param bar - New bar data\n */\n updateLast(bar: Bar): void {\n if (this._bars.length > 0) {\n this._bars[this._bars.length - 1] = bar;\n this._version++;\n }\n }\n\n /**\n * Replace all bars with new data\n * @param bars - New bar array\n */\n setAll(bars: Bar[]): void {\n this._bars = bars;\n this._version++;\n }\n\n /**\n * Manually increment version (for advanced use cases)\n * Call this after direct mutations to the bars array\n */\n invalidate(): void {\n this._version++;\n }\n\n /**\n * Get a bar at a specific index\n * @param index - Bar index\n * @returns Bar at that index, or undefined\n */\n at(index: number): Bar | undefined {\n return this._bars[index];\n }\n\n /**\n * Create a BarData from an existing Bar array\n * @param bars - Bar array\n * @returns New BarData instance\n */\n static from(bars: Bar[]): BarData {\n return new BarData(bars);\n }\n}\n\n/**\n * Series - represents a time-series of values with lazy evaluation\n *\n * Series are lazy - they don't compute values until needed.\n * Operations on Series return new Series with composed extractors.\n *\n * Now supports automatic cache invalidation via BarData versioning\n * and memory-efficient closure chain breaking via materialize().\n *\n * @example\n * ```typescript\n * // Basic usage (backward compatible)\n * const close = Series.fromBars(bars, 'close');\n * const open = Series.fromBars(bars, 'open');\n * const range = close.sub(open); // Creates new Series, doesn't compute yet\n * const values = range.toArray(); // Now computes for all bars\n * \n * // With automatic cache invalidation\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * barData.push(newBar); // Version increments\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * \n * // Breaking closure chains for memory efficiency\n * const complex = a.add(b).mul(c).div(d).sub(e);\n * const materialized = complex.materialize(); // Breaks closure chain\n * ```\n */\nexport class Series {\n private extractor: SeriesExtractor;\n private dataSource: BarData;\n private cached: number[] | null = null;\n private cachedVersion: number = -1;\n\n /**\n * Create a new Series\n *\n * @param data - Bar data (Bar[] or BarData)\n * @param extractor - Function to extract/compute value for each bar\n */\n constructor(data: Bar[] | BarData, extractor: SeriesExtractor) {\n // Support both Bar[] and BarData for backward compatibility\n this.dataSource = data instanceof BarData ? data : new BarData(data);\n this.extractor = extractor;\n }\n\n /**\n * Get the underlying bar data\n * @returns Bar array\n */\n get bars(): Bar[] {\n return this.dataSource.bars;\n }\n\n /**\n * Get the underlying BarData source\n * @returns BarData instance\n */\n get barData(): BarData {\n return this.dataSource;\n }\n\n // ============================================\n // Static Factory Methods\n // ============================================\n\n /**\n * Create Series from bar data by extracting a specific field\n * @param bars - Bar data (Bar[] or BarData)\n * @param field - Field to extract ('open', 'high', 'low', 'close', 'volume')\n * @returns Series with extracted field values\n */\n static fromBars(bars: Bar[] | BarData, field: 'open' | 'high' | 'low' | 'close' | 'volume'): Series {\n return new Series(bars, (bar) => bar[field] ?? NaN);\n }\n\n /**\n * Create a constant series (same value for all bars)\n * @param bars - Bar data (Bar[] or BarData)\n * @param value - Constant value\n * @returns Series with constant value\n */\n static constant(bars: Bar[] | BarData, value: number): Series {\n return new Series(bars, () => value);\n }\n\n /**\n * Create series from array of values\n * @param bars - Bar data (Bar[] or BarData) for time alignment\n * @param values - Array of values\n * @returns Series\n * @throws When read on other bars with a different length than `values` (e.g. a series computed on the\n * chart bars and read inside a `request.security` expression, which runs on the higher-timeframe bars)\n */\n static fromArray(bars: Bar[] | BarData, values: number[]): Series {\n const origin = bars instanceof BarData ? bars.bars : bars;\n return new Series(bars, (_bar, i, data) => {\n if (data !== origin && data.length !== values.length) {\n throw new Error(\n `Series values were computed on other bars (${values.length} values, ${data.length} bars). ` +\n 'Inside request.security(), compute the series inside the expression, e.g. () => ta.ema(close, 10).'\n );\n }\n return values[i] ?? NaN;\n });\n }\n\n // ============================================\n // Arithmetic Operations\n // ============================================\n\n /**\n * Add two series or a series and a number\n * @param other - Series or number to add\n * @returns New Series representing the sum\n */\n add(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a + b;\n });\n }\n\n /**\n * Subtract two series or subtract a number from a series\n * @param other - Series or number to subtract\n * @returns New Series representing the difference\n */\n sub(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a - b;\n });\n }\n\n /**\n * Multiply two series or a series by a number\n * @param other - Series or number to multiply\n * @returns New Series representing the product\n */\n mul(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a * b;\n });\n }\n\n /**\n * Raise the series to a power (PineScript math.pow on a series)\n * @param exponent - Series or number exponent\n * @returns New Series representing base ** exponent\n */\n pow(exponent: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof exponent === 'number' ? exponent : exponent.extractor(bar, i, data);\n return Math.pow(a, b);\n });\n }\n\n /**\n * Divide two series or a series by a number\n * @param other - Series or number to divide by\n * @returns New Series representing the quotient\n */\n div(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a / b; // PineScript: x / 0 is +/-Infinity (na() is true for it), 0 / 0 is na\n });\n }\n\n /**\n * Modulo operation\n * @param other - Series or number for modulo\n * @returns New Series representing the remainder\n */\n mod(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return b !== 0 ? a % b : NaN;\n });\n }\n\n /**\n * Negation\n * @returns New Series with negated values\n */\n neg(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n return -this.extractor(bar, i, data);\n });\n }\n\n // ============================================\n // Comparison Operations (PineScript operators: tolerance 1e-10, false with na; see src/compare)\n // ============================================\n\n /**\n * Greater than comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n gt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.gt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Greater than or equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n gte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ge(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Less than comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n lt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.lt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Less than or equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n lte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.le(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Equality comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n eq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.eq(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Not equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n neq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ne(a, b) ? 1 : 0;\n });\n }\n\n // ============================================\n // Logical Operations (for boolean series)\n // ============================================\n\n /**\n * Logical AND\n * @param other - Series or number (truthy/falsy)\n * @returns New Series with 1 where both true, 0 otherwise\n */\n and(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a && b ? 1 : 0;\n });\n }\n\n /**\n * Logical OR\n * @param other - Series or number (truthy/falsy)\n * @returns New Series with 1 where either true, 0 otherwise\n */\n or(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a || b ? 1 : 0;\n });\n }\n\n /**\n * Logical NOT\n * @returns New Series with inverted boolean values\n */\n not(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n return !a ? 1 : 0;\n });\n }\n\n // ============================================\n // Conditional Selection\n // ============================================\n\n /**\n * Bar-by-bar conditional selection (ternary operator for Series)\n * Uses this Series as the condition (truthy = nonzero, falsy = zero/NaN)\n *\n * @param trueValue - Value or Series to use when condition is truthy\n * @param falseValue - Value or Series to use when condition is falsy\n * @returns New Series with bar-by-bar selected values\n *\n * @example\n * ```typescript\n * // PineScript: result = condition ? trueVal : falseVal\n * const result = condition.iff(trueVal, falseVal);\n *\n * // Example: RSI formula uses ternary for edge cases\n * // rsi = down == 0 ? 100 : up == 0 ? 0 : formula\n * const rsi = down.eq(0).iff(100, up.eq(0).iff(0, formula));\n * ```\n */\n iff(trueValue: Series | number, falseValue: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const condition = this.extractor(bar, i, data);\n // Truthy: nonzero and not NaN\n const isTruthy = condition !== 0 && !Number.isNaN(condition);\n\n if (isTruthy) {\n return typeof trueValue === 'number' ? trueValue : trueValue.extractor(bar, i, data);\n } else {\n return typeof falseValue === 'number' ? falseValue : falseValue.extractor(bar, i, data);\n }\n });\n }\n\n // ============================================\n // Offset/History\n // ============================================\n\n /**\n * Access previous bars (like close[1] in PineScript)\n * @param offset - Number of bars back (0 or more)\n * @returns New Series with offset values\n * @throws RangeError when `offset` is negative\n */\n offset(offset: number): Series {\n if (offset < 0) throw new RangeError(`Series.offset(${offset}): the offset cannot be negative (it would read a future bar).`);\n return new Series(this.dataSource, (_bar, i, data) => {\n const targetIndex = i - offset;\n if (targetIndex < 0 || targetIndex >= data.length) {\n return NaN;\n }\n return this.extractor(data[targetIndex]!, targetIndex, data);\n });\n }\n\n // ============================================\n // Computation & Access\n // ============================================\n\n /**\n * Compute all values for the series\n * \n * Now includes automatic cache invalidation:\n * - Checks if dataSource version has changed since cache was computed\n * - Recomputes if version mismatch detected\n * - Stores version when cache is created\n * \n * @returns Array of computed values\n */\n toArray(): number[] {\n // Check if cache is valid by comparing versions\n if (this.cached !== null && this.cachedVersion === this.dataSource.version) {\n return this.cached;\n }\n\n // Recompute and update cache\n const bars = this.dataSource.bars;\n this.cached = bars.map((bar, i) => this.extractor(bar, i, bars));\n this.cachedVersion = this.dataSource.version;\n return this.cached;\n }\n\n /**\n * Materialize this Series by eagerly computing values and breaking closure chain\n * \n * This method addresses the closure chain memory leak issue:\n * - Computes all values immediately\n * - Creates a new Series that stores values directly\n * - Breaks references to parent Series objects\n * - Useful for complex expressions to free intermediate Series memory\n * \n * @example\n * ```typescript\n * // Without materialize: keeps a, b, c, d in memory via closures\n * const result = a.add(b).mul(c).div(d).sub(e);\n * \n * // With materialize: breaks chain, frees a, b, c memory\n * const result = a.add(b).mul(c).materialize().div(d).sub(e);\n * ```\n * \n * @returns New Series with computed values and no closure dependencies\n */\n materialize(): Series {\n const values = this.toArray();\n // Create a copy of values to ensure no shared references\n const valuesCopy = [...values];\n return Series.fromArray(this.dataSource, valuesCopy);\n }\n\n /**\n * Invalidate cache (when data changes)\n * \n * Note: With BarData versioning, manual invalidation is rarely needed.\n * The cache is automatically invalidated when the underlying BarData changes.\n * This method is kept for backward compatibility and advanced use cases.\n * \n * @internal\n */\n _invalidate(): void {\n this.cached = null;\n this.cachedVersion = -1;\n }\n\n /**\n * Compute all values (alias for toArray)\n * @returns Array of computed values\n * @internal\n */\n _compute(): number[] {\n return this.toArray();\n }\n\n /**\n * Get value at specific index\n * @param index - Bar index\n * @returns Value at that index\n */\n get(index: number): number {\n const values = this.toArray();\n return values[index] ?? NaN;\n }\n\n /**\n * Get the last value (most recent bar)\n * @returns Most recent value\n */\n last(): number {\n const values = this.toArray();\n return values[values.length - 1] ?? NaN;\n }\n\n /**\n * Get number of values\n * @returns Length of series\n */\n length(): number {\n return this.dataSource.length;\n }\n\n /**\n * Convert series to time-value pairs for charting\n * @returns Array of { time, value } objects\n */\n toTimeValuePairs(): Array<{ time: any; value: number }> {\n const values = this.toArray();\n const bars = this.dataSource.bars;\n return bars.map((bar, i) => ({\n time: bar.time,\n value: values[i]!\n })).filter(point => !Number.isNaN(point.value));\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,cAAyB;AAyBlB,MAAM,QAAQ;AAAA,EACX;AAAA,EACA,WAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,YAAY,OAAc,CAAC,GAAG;AAC5B,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAc;AAChB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAiB;AACnB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,KAAgB;AACnB,SAAK,MAAM,KAAK,GAAG;AACnB,SAAK;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAuB;AACrB,UAAM,MAAM,KAAK,MAAM,IAAI;AAC3B,QAAI,QAAQ,QAAW;AACrB,WAAK;AAAA,IACP;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAe,KAAgB;AACjC,QAAI,SAAS,KAAK,QAAQ,KAAK,MAAM,QAAQ;AAC3C,WAAK,MAAM,KAAK,IAAI;AACpB,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,KAAgB;AACzB,QAAI,KAAK,MAAM,SAAS,GAAG;AACzB,WAAK,MAAM,KAAK,MAAM,SAAS,CAAC,IAAI;AACpC,WAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,MAAmB;AACxB,SAAK,QAAQ;AACb,SAAK;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAmB;AACjB,SAAK;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,GAAG,OAAgC;AACjC,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,KAAK,MAAsB;AAChC,WAAO,IAAI,QAAQ,IAAI;AAAA,EACzB;AACF;
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Simplified Series class for lazy time-series computation\n * Represents a time-series of values with lazy evaluation\n * @module runtime/series\n */\n\nimport * as compare from '../compare/index.js';\nimport type { Bar } from '../types/index.js';\n\n/**\n * Function that computes a value for each bar\n */\nexport type SeriesExtractor = (bar: Bar, index: number, data: Bar[]) => number;\n\n/**\n * BarData - Versioned wrapper around Bar[] array for cache invalidation\n * \n * This class wraps a Bar[] array and tracks a version number that increments\n * whenever the data is mutated. Series objects reference this to detect when\n * their cached values need to be recomputed.\n * \n * @example\n * ```typescript\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * \n * barData.push(newBar); // Increments version\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * ```\n */\nexport class BarData {\n private _bars: Bar[];\n private _version: number = 0;\n\n /**\n * Create a new BarData wrapper\n * @param bars - Initial bar data (defaults to empty array)\n */\n constructor(bars: Bar[] = []) {\n this._bars = bars;\n }\n\n /**\n * Get the current version number\n * Version increments whenever data is mutated\n */\n get version(): number {\n return this._version;\n }\n\n /**\n * Get the underlying bar array\n * Note: Direct mutations to this array will NOT increment version\n * Use the provided mutation methods instead\n */\n get bars(): Bar[] {\n return this._bars;\n }\n\n /**\n * Get the number of bars\n */\n get length(): number {\n return this._bars.length;\n }\n\n /**\n * Add a new bar to the end\n * @param bar - Bar to add\n */\n push(bar: Bar): void {\n this._bars.push(bar);\n this._version++;\n }\n\n /**\n * Remove and return the last bar\n * @returns The removed bar, or undefined if empty\n */\n pop(): Bar | undefined {\n const bar = this._bars.pop();\n if (bar !== undefined) {\n this._version++;\n }\n return bar;\n }\n\n /**\n * Replace a bar at a specific index\n * @param index - Index to update\n * @param bar - New bar data\n */\n set(index: number, bar: Bar): void {\n if (index >= 0 && index < this._bars.length) {\n this._bars[index] = bar;\n this._version++;\n }\n }\n\n /**\n * Update the last bar (useful for real-time/streaming updates)\n * @param bar - New bar data\n */\n updateLast(bar: Bar): void {\n if (this._bars.length > 0) {\n this._bars[this._bars.length - 1] = bar;\n this._version++;\n }\n }\n\n /**\n * Replace all bars with new data\n * @param bars - New bar array\n */\n setAll(bars: Bar[]): void {\n this._bars = bars;\n this._version++;\n }\n\n /**\n * Manually increment version (for advanced use cases)\n * Call this after direct mutations to the bars array\n */\n invalidate(): void {\n this._version++;\n }\n\n /**\n * Get a bar at a specific index\n * @param index - Bar index\n * @returns Bar at that index, or undefined\n */\n at(index: number): Bar | undefined {\n return this._bars[index];\n }\n\n /**\n * Create a BarData from an existing Bar array\n * @param bars - Bar array\n * @returns New BarData instance\n */\n static from(bars: Bar[]): BarData {\n return new BarData(bars);\n }\n}\n\n/**\n * Series - represents a time-series of values with lazy evaluation\n *\n * Series are lazy - they don't compute values until needed.\n * Operations on Series return new Series with composed extractors.\n *\n * Now supports automatic cache invalidation via BarData versioning\n * and memory-efficient closure chain breaking via materialize().\n *\n * @example\n * ```typescript\n * // Basic usage (backward compatible)\n * const close = Series.fromBars(bars, 'close');\n * const open = Series.fromBars(bars, 'open');\n * const range = close.sub(open); // Creates new Series, doesn't compute yet\n * const values = range.toArray(); // Now computes for all bars\n * \n * // With automatic cache invalidation\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * barData.push(newBar); // Version increments\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * \n * // Breaking closure chains for memory efficiency\n * const complex = a.add(b).mul(c).div(d).sub(e);\n * const materialized = complex.materialize(); // Breaks closure chain\n * ```\n */\n/** Largest history reference of a script series (PineScript max_bars_back limit). */\nexport const MAX_BARS_BACK = 5000;\n\n/** PineScript's runtime error RE10008 text. */\nexport function historyError(bar: number, barsBack: number): string {\n return (\n `Error on bar ${bar}: The script attempts to reference historical data that is too far from the current bar ` +\n `(${barsBack} bars back). The history-referencing length for the expression must be a value between 0 and ${MAX_BARS_BACK}.`\n );\n}\n\nexport class Series {\n private extractor: SeriesExtractor;\n private dataSource: BarData;\n private cached: number[] | null = null;\n private cachedVersion: number = -1;\n\n /**\n * Create a new Series\n *\n * @param data - Bar data (Bar[] or BarData)\n * @param extractor - Function to extract/compute value for each bar\n */\n /**\n * True for PineScript's built-in price variables (open, high, low, close, volume, hl2...): their history covers\n * every bar, so references further than 5000 bars back are allowed (measured: close[bar_index] runs).\n */\n fullHistory = false;\n\n constructor(data: Bar[] | BarData, extractor: SeriesExtractor) {\n // Support both Bar[] and BarData for backward compatibility\n this.dataSource = data instanceof BarData ? data : new BarData(data);\n this.extractor = extractor;\n }\n\n /**\n * Get the underlying bar data\n * @returns Bar array\n */\n get bars(): Bar[] {\n return this.dataSource.bars;\n }\n\n /**\n * Get the underlying BarData source\n * @returns BarData instance\n */\n get barData(): BarData {\n return this.dataSource;\n }\n\n // ============================================\n // Static Factory Methods\n // ============================================\n\n /**\n * Create Series from bar data by extracting a specific field\n * @param bars - Bar data (Bar[] or BarData)\n * @param field - Field to extract ('open', 'high', 'low', 'close', 'volume')\n * @returns Series with extracted field values\n */\n static fromBars(bars: Bar[] | BarData, field: 'open' | 'high' | 'low' | 'close' | 'volume'): Series {\n const series = new Series(bars, (bar) => bar[field] ?? NaN);\n series.fullHistory = true;\n return series;\n }\n\n /**\n * Create a constant series (same value for all bars)\n * @param bars - Bar data (Bar[] or BarData)\n * @param value - Constant value\n * @returns Series with constant value\n */\n static constant(bars: Bar[] | BarData, value: number): Series {\n return new Series(bars, () => value);\n }\n\n /**\n * Create series from array of values\n * @param bars - Bar data (Bar[] or BarData) for time alignment\n * @param values - Array of values\n * @returns Series\n * @throws When read on other bars with a different length than `values` (e.g. a series computed on the\n * chart bars and read inside a `request.security` expression, which runs on the higher-timeframe bars)\n */\n static fromArray(bars: Bar[] | BarData, values: number[]): Series {\n const origin = bars instanceof BarData ? bars.bars : bars;\n return new Series(bars, (_bar, i, data) => {\n if (data !== origin && data.length !== values.length) {\n throw new Error(\n `Series values were computed on other bars (${values.length} values, ${data.length} bars). ` +\n 'Inside request.security(), compute the series inside the expression, e.g. () => ta.ema(close, 10).'\n );\n }\n return values[i] ?? NaN;\n });\n }\n\n // ============================================\n // Arithmetic Operations\n // ============================================\n\n /**\n * Add two series or a series and a number\n * @param other - Series or number to add\n * @returns New Series representing the sum\n */\n add(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a + b;\n });\n }\n\n /**\n * Subtract two series or subtract a number from a series\n * @param other - Series or number to subtract\n * @returns New Series representing the difference\n */\n sub(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a - b;\n });\n }\n\n /**\n * Multiply two series or a series by a number\n * @param other - Series or number to multiply\n * @returns New Series representing the product\n */\n mul(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a * b;\n });\n }\n\n /**\n * Raise the series to a power (PineScript math.pow on a series)\n * @param exponent - Series or number exponent\n * @returns New Series representing base ** exponent\n */\n pow(exponent: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof exponent === 'number' ? exponent : exponent.extractor(bar, i, data);\n return Math.pow(a, b);\n });\n }\n\n /**\n * Divide two series or a series by a number\n * @param other - Series or number to divide by\n * @returns New Series representing the quotient\n */\n div(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a / b; // PineScript: x / 0 is +/-Infinity (na() is true for it), 0 / 0 is na\n });\n }\n\n /**\n * Modulo operation\n * @param other - Series or number for modulo\n * @returns New Series representing the remainder\n */\n mod(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return b !== 0 ? a % b : NaN;\n });\n }\n\n /**\n * Negation\n * @returns New Series with negated values\n */\n neg(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n return -this.extractor(bar, i, data);\n });\n }\n\n // ============================================\n // Comparison Operations (PineScript operators: tolerance 1e-10, false with na; see src/compare)\n // ============================================\n\n /**\n * Greater than comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n gt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.gt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Greater than or equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n gte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ge(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Less than comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n lt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.lt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Less than or equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n lte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.le(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Equality comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n eq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.eq(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Not equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n neq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ne(a, b) ? 1 : 0;\n });\n }\n\n // ============================================\n // Logical Operations (for boolean series)\n // ============================================\n\n /**\n * Logical AND\n * @param other - Series or number (truthy/falsy)\n * @returns New Series with 1 where both true, 0 otherwise\n */\n and(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a && b ? 1 : 0;\n });\n }\n\n /**\n * Logical OR\n * @param other - Series or number (truthy/falsy)\n * @returns New Series with 1 where either true, 0 otherwise\n */\n or(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a || b ? 1 : 0;\n });\n }\n\n /**\n * Logical NOT\n * @returns New Series with inverted boolean values\n */\n not(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n return !a ? 1 : 0;\n });\n }\n\n // ============================================\n // Conditional Selection\n // ============================================\n\n /**\n * Bar-by-bar conditional selection (ternary operator for Series)\n * Uses this Series as the condition (truthy = nonzero, falsy = zero/NaN)\n *\n * @param trueValue - Value or Series to use when condition is truthy\n * @param falseValue - Value or Series to use when condition is falsy\n * @returns New Series with bar-by-bar selected values\n *\n * @example\n * ```typescript\n * // PineScript: result = condition ? trueVal : falseVal\n * const result = condition.iff(trueVal, falseVal);\n *\n * // Example: RSI formula uses ternary for edge cases\n * // rsi = down == 0 ? 100 : up == 0 ? 0 : formula\n * const rsi = down.eq(0).iff(100, up.eq(0).iff(0, formula));\n * ```\n */\n iff(trueValue: Series | number, falseValue: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const condition = this.extractor(bar, i, data);\n // Truthy: nonzero and not NaN\n const isTruthy = condition !== 0 && !Number.isNaN(condition);\n\n if (isTruthy) {\n return typeof trueValue === 'number' ? trueValue : trueValue.extractor(bar, i, data);\n } else {\n return typeof falseValue === 'number' ? falseValue : falseValue.extractor(bar, i, data);\n }\n });\n }\n\n // ============================================\n // Offset/History\n // ============================================\n\n /**\n * Access previous bars (like close[1] in PineScript)\n * @param offset - Number of bars back (0 or more)\n * @returns New Series with offset values\n * @throws RangeError when `offset` is negative\n */\n offset(offset: number): Series {\n if (offset < 0) throw new RangeError(`Series.offset(${offset}): the offset cannot be negative (it would read a future bar).`);\n // PineScript runtime error RE10008: a script series keeps at most 5000 bars of history\n if (offset > MAX_BARS_BACK && !this.fullHistory) throw new Error(historyError(0, Math.floor(offset)));\n return new Series(this.dataSource, (_bar, i, data) => {\n const targetIndex = i - offset;\n if (targetIndex < 0 || targetIndex >= data.length) {\n return NaN;\n }\n return this.extractor(data[targetIndex]!, targetIndex, data);\n });\n }\n\n // ============================================\n // Computation & Access\n // ============================================\n\n /**\n * Compute all values for the series\n * \n * Now includes automatic cache invalidation:\n * - Checks if dataSource version has changed since cache was computed\n * - Recomputes if version mismatch detected\n * - Stores version when cache is created\n * \n * @returns Array of computed values\n */\n toArray(): number[] {\n // Check if cache is valid by comparing versions\n if (this.cached !== null && this.cachedVersion === this.dataSource.version) {\n return this.cached;\n }\n\n // Recompute and update cache\n const bars = this.dataSource.bars;\n this.cached = bars.map((bar, i) => this.extractor(bar, i, bars));\n this.cachedVersion = this.dataSource.version;\n return this.cached;\n }\n\n /**\n * Materialize this Series by eagerly computing values and breaking closure chain\n * \n * This method addresses the closure chain memory leak issue:\n * - Computes all values immediately\n * - Creates a new Series that stores values directly\n * - Breaks references to parent Series objects\n * - Useful for complex expressions to free intermediate Series memory\n * \n * @example\n * ```typescript\n * // Without materialize: keeps a, b, c, d in memory via closures\n * const result = a.add(b).mul(c).div(d).sub(e);\n * \n * // With materialize: breaks chain, frees a, b, c memory\n * const result = a.add(b).mul(c).materialize().div(d).sub(e);\n * ```\n * \n * @returns New Series with computed values and no closure dependencies\n */\n materialize(): Series {\n const values = this.toArray();\n // Create a copy of values to ensure no shared references\n const valuesCopy = [...values];\n return Series.fromArray(this.dataSource, valuesCopy);\n }\n\n /**\n * Invalidate cache (when data changes)\n * \n * Note: With BarData versioning, manual invalidation is rarely needed.\n * The cache is automatically invalidated when the underlying BarData changes.\n * This method is kept for backward compatibility and advanced use cases.\n * \n * @internal\n */\n _invalidate(): void {\n this.cached = null;\n this.cachedVersion = -1;\n }\n\n /**\n * Compute all values (alias for toArray)\n * @returns Array of computed values\n * @internal\n */\n _compute(): number[] {\n return this.toArray();\n }\n\n /**\n * Get value at specific index\n * @param index - Bar index\n * @returns Value at that index\n */\n get(index: number): number {\n const values = this.toArray();\n return values[index] ?? NaN;\n }\n\n /**\n * Get the last value (most recent bar)\n * @returns Most recent value\n */\n last(): number {\n const values = this.toArray();\n return values[values.length - 1] ?? NaN;\n }\n\n /**\n * Get number of values\n * @returns Length of series\n */\n length(): number {\n return this.dataSource.length;\n }\n\n /**\n * Convert series to time-value pairs for charting\n * @returns Array of { time, value } objects\n */\n toTimeValuePairs(): Array<{ time: any; value: number }> {\n const values = this.toArray();\n const bars = this.dataSource.bars;\n return bars.map((bar, i) => ({\n time: bar.time,\n value: values[i]!\n })).filter(point => !Number.isNaN(point.value));\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,cAAyB;AAyBlB,MAAM,QAAQ;AAAA,EACX;AAAA,EACA,WAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,YAAY,OAAc,CAAC,GAAG;AAC5B,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAc;AAChB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;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AAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,cAAoB;AAClB,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAqB;AACnB,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAuB;AACzB,UAAM,SAAS,KAAK,QAAQ;AAC5B,WAAO,OAAO,KAAK,KAAK;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAe;AACb,UAAM,SAAS,KAAK,QAAQ;AAC5B,WAAO,OAAO,OAAO,SAAS,CAAC,KAAK;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAiB;AACf,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,mBAAwD;AACtD,UAAM,SAAS,KAAK,QAAQ;AAC5B,UAAM,OAAO,KAAK,WAAW;AAC7B,WAAO,KAAK,IAAI,CAAC,KAAK,OAAO;AAAA,MAC3B,MAAM,IAAI;AAAA,MACV,OAAO,OAAO,CAAC;AAAA,IACjB,EAAE,EAAE,OAAO,WAAS,CAAC,OAAO,MAAM,MAAM,KAAK,CAAC;AAAA,EAChD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -134,6 +134,28 @@ export interface ArrowConfig {
|
|
|
134
134
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
135
135
|
forceOverlay?: boolean;
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Configuration of a PineScript `plotcandle()` (kind 'candle') or `plotbar()` (kind 'bar') declaration. The candles
|
|
139
|
+
* are in `result.plotCandles[id]`, the bars in `result.plotBars[id]`.
|
|
140
|
+
*/
|
|
141
|
+
export interface CandleConfig {
|
|
142
|
+
/** Unique identifier (key of the data in the result) */
|
|
143
|
+
id: string;
|
|
144
|
+
/** 'candle' for plotcandle, 'bar' for plotbar */
|
|
145
|
+
kind: 'candle' | 'bar';
|
|
146
|
+
/** Display title */
|
|
147
|
+
title?: string;
|
|
148
|
+
/** Static body colour (plotcandle) or bar colour (plotbar) */
|
|
149
|
+
color?: string;
|
|
150
|
+
/** Static wick colour (plotcandle only) */
|
|
151
|
+
wickColor?: string;
|
|
152
|
+
/** Static border colour (plotcandle only) */
|
|
153
|
+
borderColor?: string;
|
|
154
|
+
/** Display mode */
|
|
155
|
+
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
156
|
+
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
157
|
+
forceOverlay?: boolean;
|
|
158
|
+
}
|
|
137
159
|
/**
|
|
138
160
|
* Configuration for horizontal line outputs in generated indicators
|
|
139
161
|
* Matches PineScript hline() function parameters
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CAC7E;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAA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nB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,kBAAkB;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,KAAK,EAAE,YAAY,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,YAAY,CAAC;IACrB,kDAAkD;IAClD,KAAK,EAAE,SAAS,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Type definitions for OakScriptJS runtime\n * These types define the adapter interfaces and context structure for the runtime system\n * @module runtime/types\n */\n\nimport type { FillGradient } from '../types/metadata.js';\n\n/**\n * Handle returned by ChartAdapter.addSeries\n * Represents a series on the chart with ability to update data\n */\nexport interface SeriesHandle {\n /** Set the data for this series */\n setData(data: Array<{ time: number; value: number; color?: string }>): void;\n}\n\n/**\n * Options for creating a series on the chart\n */\nexport interface SeriesOptions {\n /** Series color */\n color?: string;\n /** Line width */\n lineWidth?: number;\n /** Line style (0 = solid, 1 = dotted, 2 = dashed, etc.) */\n lineStyle?: number;\n /** Price scale ID */\n priceScaleId?: string;\n /** Pane index */\n pane?: number;\n}\n\n/**\n * Chart adapter interface\n * Implementations translate library calls into chart library operations\n */\nexport interface ChartAdapter {\n /** Add a new series to the chart */\n addSeries(type: string, options?: SeriesOptions): SeriesHandle;\n /** Remove a series from the chart */\n removeSeries(series: SeriesHandle): void;\n /** Get the main price series (optional, may return undefined) */\n getMainSeries?(): SeriesHandle | undefined;\n /** Create a new pane and return its index (optional) */\n createPane?(): number;\n}\n\n/**\n * Configuration for registering an input\n */\nexport interface InputConfig {\n /** Unique identifier for the input */\n id: string;\n /**\n * Type of input. `timeframe` and `session` values are strings (\"60\", \"1D\", \"0930-1600:23456\";\n * an empty timeframe means the chart timeframe), `time` values are UNIX times in milliseconds.\n */\n type: 'int' | 'float' | 'bool' | 'string' | 'source' | 'color' | 'timeframe' | 'session' | 'time';\n /** Default value */\n defval: unknown;\n /** Display title */\n title?: string;\n /** Minimum value (for numeric inputs) */\n min?: number;\n /** Maximum value (for numeric inputs) */\n max?: number;\n /** Step size (for numeric inputs) */\n step?: number;\n /** Options for dropdown selection (for string, timeframe and session inputs) */\n options?: string[];\n /** Settings group header (PineScript `group`) */\n group?: string;\n /** Inputs with the same `inline` id are shown on one line (PineScript `inline`) */\n inline?: string;\n /** Info tooltip of the input (PineScript `tooltip`) */\n tooltip?: string;\n /** Ask for the value when the script is added to a chart (PineScript `confirm`) */\n confirm?: boolean;\n /**\n * Where the input value is shown (PineScript `display`); not set means the PineScript default: 'all', except\n * color inputs: 'none'\n */\n display?: 'all' | 'none' | 'data_window' | 'status_line';\n}\n\n/**\n * Configuration for plot outputs in generated indicators\n */\nexport interface PlotConfig {\n /** Unique identifier for the plot */\n id: string;\n /** Display title */\n title: string;\n /** Plot color */\n color: string;\n /** Line width in pixels */\n lineWidth?: number;\n /** Plot style */\n style?: 'line' | 'stepline' | 'histogram' | 'area' | 'circles' | 'columns' | 'cross' | 'areabr' | 'steplinebr' | 'linebr' | 'stepline_diamond';\n /** Whether the plot is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n /** Display mode: 'all', 'none', 'data_window', 'status_line', 'pane' */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Offset in bars (positive = future, negative = past) */\n offset?: number;\n /** Histogram base value */\n histbase?: number;\n /** Line style (PineScript `linestyle`); default solid. A constant or an input value, not per bar */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration of a PineScript `plotarrow()` declaration: an up arrow (below the bar) for a positive value, a down\n * arrow (above the bar) for a negative value, nothing for 0 / na. The arrow height scales with the absolute value\n * between `minheight` and `maxheight` pixels (drawn by the renderer).\n */\nexport interface ArrowConfig {\n /** Unique identifier (key of the arrow data in the result) */\n id: string;\n /** Display title */\n title?: string;\n /** Color of the up arrows (PineScript default #00FF00) */\n colorup: string;\n /** Color of the down arrows (PineScript default #FF0000) */\n colordown: string;\n /** Minimal arrow height in pixels (PineScript default 5) */\n minheight: number;\n /** Maximal arrow height in pixels (PineScript default 100) */\n maxheight: number;\n /** Offset in bars (applied to the emitted arrow times) */\n offset?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration for horizontal line outputs in generated indicators\n * Matches PineScript hline() function parameters\n */\nexport interface HLineConfig {\n /** Unique identifier for the hline */\n id: string;\n /** Price level for the horizontal line */\n price: number;\n /** Display title */\n title?: string;\n /** Line color */\n color?: string;\n /** Line style: solid, dashed, or dotted (PineScript default: dashed) */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Line width in pixels */\n linewidth?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n}\n\n/**\n * Configuration for fill between plots or hlines in generated indicators\n * Matches PineScript fill() function parameters\n */\nexport interface FillConfig {\n /** Unique identifier for the fill */\n id: string;\n /** ID of the first plot or hline */\n plot1: string;\n /** ID of the second plot or hline */\n plot2: string;\n /** Fill color */\n color?: string;\n /** Per-bar fill colors (overrides static color) */\n colors?: string[];\n /** Gradient fill (PineScript `fill(hline1, hline2, top_value, bottom_value, top_color, bottom_color)`) */\n gradient?: FillGradient;\n /** Display title */\n title?: string;\n /** Whether the fill is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n}\n\n/**\n * Configuration for plotshape/plotchar outputs in generated indicators\n * Matches PineScript plotshape()/plotchar() declarative parameters\n */\nexport interface ShapeConfig {\n /** Unique identifier for the shape declaration */\n id: string;\n /** 'shape' for plotshape, 'char' for plotchar */\n kind: 'shape' | 'char';\n /** Display title */\n title?: string;\n /** Shape style (plotshape only) */\n style?: 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' | 'arrowup' | 'arrowdown' | 'labelup' | 'labeldown' | 'square' | 'diamond';\n /** Character (plotchar only) */\n char?: string;\n /** Marker location relative to the bar */\n location: 'abovebar' | 'belowbar' | 'top' | 'bottom' | 'absolute';\n /** Marker color */\n color?: string;\n /** Text shown near the marker */\n text?: string;\n /** Text color */\n textcolor?: string;\n /** Marker size */\n size?: 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';\n /** Offset in bars (applied to the emitted marker times) */\n offset?: number;\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration for bgcolor/barcolor outputs in generated indicators\n */\nexport interface BarColorConfig {\n /** Unique identifier */\n id: string;\n /** 'bgcolor' or 'barcolor' */\n kind: 'bgcolor' | 'barcolor';\n /** Display title */\n title?: string;\n /** Offset in bars (bgcolor only, already baked into emitted data) */\n offset?: number;\n /** bgcolor only: drawn on the main chart pane even when the script is not an overlay (PineScript\n * `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Options for numeric inputs\n */\nexport interface InputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n}\n\n/**\n * Input adapter interface\n * Implementations handle input registration and value management\n */\nexport interface InputAdapter {\n /** Register an input, returns current value (possibly user-updated) */\n registerInput(config: InputConfig): unknown;\n /** Get current value of an input */\n getValue(id: string): unknown;\n /** Set value of an input */\n setValue(id: string, value: unknown): void;\n /** Register callback for input changes */\n onInputChange(callback: (id: string, value: unknown) => void): void;\n}\n\n/**\n * OHLCV data structure\n * Provides access to price and volume time series\n */\nexport interface OhlcvData {\n /** Timestamps for each bar */\n time: number[];\n /** Open prices */\n open: number[];\n /** High prices */\n high: number[];\n /** Low prices */\n low: number[];\n /** Close prices */\n close: number[];\n /** Volume data */\n volume: number[];\n}\n\n/**\n * Global context object for OakScriptJS runtime\n * Must be set by host application before calling any indicator calculate function\n */\nexport interface OakScriptContext {\n /** Chart adapter for plot operations */\n chart: ChartAdapter;\n /** Input adapter for managing indicator inputs */\n inputs: InputAdapter;\n /** OHLCV data for the current symbol/timeframe */\n ohlcv: OhlcvData;\n /** Current bar index (typically the last bar) */\n bar_index: number;\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Type definitions for OakScriptJS runtime\n * These types define the adapter interfaces and context structure for the runtime system\n * @module runtime/types\n */\n\nimport type { FillGradient } from '../types/metadata.js';\n\n/**\n * Handle returned by ChartAdapter.addSeries\n * Represents a series on the chart with ability to update data\n */\nexport interface SeriesHandle {\n /** Set the data for this series */\n setData(data: Array<{ time: number; value: number; color?: string }>): void;\n}\n\n/**\n * Options for creating a series on the chart\n */\nexport interface SeriesOptions {\n /** Series color */\n color?: string;\n /** Line width */\n lineWidth?: number;\n /** Line style (0 = solid, 1 = dotted, 2 = dashed, etc.) */\n lineStyle?: number;\n /** Price scale ID */\n priceScaleId?: string;\n /** Pane index */\n pane?: number;\n}\n\n/**\n * Chart adapter interface\n * Implementations translate library calls into chart library operations\n */\nexport interface ChartAdapter {\n /** Add a new series to the chart */\n addSeries(type: string, options?: SeriesOptions): SeriesHandle;\n /** Remove a series from the chart */\n removeSeries(series: SeriesHandle): void;\n /** Get the main price series (optional, may return undefined) */\n getMainSeries?(): SeriesHandle | undefined;\n /** Create a new pane and return its index (optional) */\n createPane?(): number;\n}\n\n/**\n * Configuration for registering an input\n */\nexport interface InputConfig {\n /** Unique identifier for the input */\n id: string;\n /**\n * Type of input. `timeframe` and `session` values are strings (\"60\", \"1D\", \"0930-1600:23456\";\n * an empty timeframe means the chart timeframe), `time` values are UNIX times in milliseconds.\n */\n type: 'int' | 'float' | 'bool' | 'string' | 'source' | 'color' | 'timeframe' | 'session' | 'time';\n /** Default value */\n defval: unknown;\n /** Display title */\n title?: string;\n /** Minimum value (for numeric inputs) */\n min?: number;\n /** Maximum value (for numeric inputs) */\n max?: number;\n /** Step size (for numeric inputs) */\n step?: number;\n /** Options for dropdown selection (for string, timeframe and session inputs) */\n options?: string[];\n /** Settings group header (PineScript `group`) */\n group?: string;\n /** Inputs with the same `inline` id are shown on one line (PineScript `inline`) */\n inline?: string;\n /** Info tooltip of the input (PineScript `tooltip`) */\n tooltip?: string;\n /** Ask for the value when the script is added to a chart (PineScript `confirm`) */\n confirm?: boolean;\n /**\n * Where the input value is shown (PineScript `display`); not set means the PineScript default: 'all', except\n * color inputs: 'none'\n */\n display?: 'all' | 'none' | 'data_window' | 'status_line';\n}\n\n/**\n * Configuration for plot outputs in generated indicators\n */\nexport interface PlotConfig {\n /** Unique identifier for the plot */\n id: string;\n /** Display title */\n title: string;\n /** Plot color */\n color: string;\n /** Line width in pixels */\n lineWidth?: number;\n /** Plot style */\n style?: 'line' | 'stepline' | 'histogram' | 'area' | 'circles' | 'columns' | 'cross' | 'areabr' | 'steplinebr' | 'linebr' | 'stepline_diamond';\n /** Whether the plot is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n /** Display mode: 'all', 'none', 'data_window', 'status_line', 'pane' */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Offset in bars (positive = future, negative = past) */\n offset?: number;\n /** Histogram base value */\n histbase?: number;\n /** Line style (PineScript `linestyle`); default solid. A constant or an input value, not per bar */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration of a PineScript `plotarrow()` declaration: an up arrow (below the bar) for a positive value, a down\n * arrow (above the bar) for a negative value, nothing for 0 / na. The arrow height scales with the absolute value\n * between `minheight` and `maxheight` pixels (drawn by the renderer).\n */\nexport interface ArrowConfig {\n /** Unique identifier (key of the arrow data in the result) */\n id: string;\n /** Display title */\n title?: string;\n /** Color of the up arrows (PineScript default #00FF00) */\n colorup: string;\n /** Color of the down arrows (PineScript default #FF0000) */\n colordown: string;\n /** Minimal arrow height in pixels (PineScript default 5) */\n minheight: number;\n /** Maximal arrow height in pixels (PineScript default 100) */\n maxheight: number;\n /** Offset in bars (applied to the emitted arrow times) */\n offset?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration of a PineScript `plotcandle()` (kind 'candle') or `plotbar()` (kind 'bar') declaration. The candles\n * are in `result.plotCandles[id]`, the bars in `result.plotBars[id]`.\n */\nexport interface CandleConfig {\n /** Unique identifier (key of the data in the result) */\n id: string;\n /** 'candle' for plotcandle, 'bar' for plotbar */\n kind: 'candle' | 'bar';\n /** Display title */\n title?: string;\n /** Static body colour (plotcandle) or bar colour (plotbar) */\n color?: string;\n /** Static wick colour (plotcandle only) */\n wickColor?: string;\n /** Static border colour (plotcandle only) */\n borderColor?: string;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration for horizontal line outputs in generated indicators\n * Matches PineScript hline() function parameters\n */\nexport interface HLineConfig {\n /** Unique identifier for the hline */\n id: string;\n /** Price level for the horizontal line */\n price: number;\n /** Display title */\n title?: string;\n /** Line color */\n color?: string;\n /** Line style: solid, dashed, or dotted (PineScript default: dashed) */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Line width in pixels */\n linewidth?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n}\n\n/**\n * Configuration for fill between plots or hlines in generated indicators\n * Matches PineScript fill() function parameters\n */\nexport interface FillConfig {\n /** Unique identifier for the fill */\n id: string;\n /** ID of the first plot or hline */\n plot1: string;\n /** ID of the second plot or hline */\n plot2: string;\n /** Fill color */\n color?: string;\n /** Per-bar fill colors (overrides static color) */\n colors?: string[];\n /** Gradient fill (PineScript `fill(hline1, hline2, top_value, bottom_value, top_color, bottom_color)`) */\n gradient?: FillGradient;\n /** Display title */\n title?: string;\n /** Whether the fill is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n}\n\n/**\n * Configuration for plotshape/plotchar outputs in generated indicators\n * Matches PineScript plotshape()/plotchar() declarative parameters\n */\nexport interface ShapeConfig {\n /** Unique identifier for the shape declaration */\n id: string;\n /** 'shape' for plotshape, 'char' for plotchar */\n kind: 'shape' | 'char';\n /** Display title */\n title?: string;\n /** Shape style (plotshape only) */\n style?: 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' | 'arrowup' | 'arrowdown' | 'labelup' | 'labeldown' | 'square' | 'diamond';\n /** Character (plotchar only) */\n char?: string;\n /** Marker location relative to the bar */\n location: 'abovebar' | 'belowbar' | 'top' | 'bottom' | 'absolute';\n /** Marker color */\n color?: string;\n /** Text shown near the marker */\n text?: string;\n /** Text color */\n textcolor?: string;\n /** Marker size */\n size?: 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';\n /** Offset in bars (applied to the emitted marker times) */\n offset?: number;\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Configuration for bgcolor/barcolor outputs in generated indicators\n */\nexport interface BarColorConfig {\n /** Unique identifier */\n id: string;\n /** 'bgcolor' or 'barcolor' */\n kind: 'bgcolor' | 'barcolor';\n /** Display title */\n title?: string;\n /** Offset in bars (bgcolor only, already baked into emitted data) */\n offset?: number;\n /** bgcolor only: drawn on the main chart pane even when the script is not an overlay (PineScript\n * `force_overlay`); default false */\n forceOverlay?: boolean;\n}\n\n/**\n * Options for numeric inputs\n */\nexport interface InputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n}\n\n/**\n * Input adapter interface\n * Implementations handle input registration and value management\n */\nexport interface InputAdapter {\n /** Register an input, returns current value (possibly user-updated) */\n registerInput(config: InputConfig): unknown;\n /** Get current value of an input */\n getValue(id: string): unknown;\n /** Set value of an input */\n setValue(id: string, value: unknown): void;\n /** Register callback for input changes */\n onInputChange(callback: (id: string, value: unknown) => void): void;\n}\n\n/**\n * OHLCV data structure\n * Provides access to price and volume time series\n */\nexport interface OhlcvData {\n /** Timestamps for each bar */\n time: number[];\n /** Open prices */\n open: number[];\n /** High prices */\n high: number[];\n /** Low prices */\n low: number[];\n /** Close prices */\n close: number[];\n /** Volume data */\n volume: number[];\n}\n\n/**\n * Global context object for OakScriptJS runtime\n * Must be set by host application before calling any indicator calculate function\n */\nexport interface OakScriptContext {\n /** Chart adapter for plot operations */\n chart: ChartAdapter;\n /** Input adapter for managing indicator inputs */\n inputs: InputAdapter;\n /** OHLCV data for the current symbol/timeframe */\n ohlcv: OhlcvData;\n /** Current bar index (typically the last bar) */\n bar_index: number;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|