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
package/dist/cjs/script/index.js
CHANGED
|
@@ -69,9 +69,12 @@ __export(script_exports, {
|
|
|
69
69
|
open: () => open,
|
|
70
70
|
plot: () => plot,
|
|
71
71
|
plotarrow: () => plotarrow,
|
|
72
|
+
plotbar: () => plotbar,
|
|
73
|
+
plotcandle: () => plotcandle,
|
|
72
74
|
plotchar: () => plotchar,
|
|
73
75
|
plotshape: () => plotshape,
|
|
74
76
|
polyline: () => polyline,
|
|
77
|
+
position: () => import_types.position,
|
|
75
78
|
request: () => request,
|
|
76
79
|
second: () => second,
|
|
77
80
|
seriesOf: () => seriesOf,
|
|
@@ -80,6 +83,7 @@ __export(script_exports, {
|
|
|
80
83
|
strategy: () => strategy,
|
|
81
84
|
syminfo: () => syminfo,
|
|
82
85
|
ta: () => ta,
|
|
86
|
+
table: () => table,
|
|
83
87
|
text: () => text,
|
|
84
88
|
ticker: () => ticker,
|
|
85
89
|
time: () => time,
|
|
@@ -102,10 +106,12 @@ var labelCore = __toESM(require("../label/index.js"), 1);
|
|
|
102
106
|
var boxCore = __toESM(require("../box/index.js"), 1);
|
|
103
107
|
var linefillCore = __toESM(require("../linefill/index.js"), 1);
|
|
104
108
|
var polylineCore = __toESM(require("../polyline/index.js"), 1);
|
|
109
|
+
var tableCore = __toESM(require("../table/index.js"), 1);
|
|
105
110
|
var chartPointCore = __toESM(require("../chartpoint/index.js"), 1);
|
|
106
111
|
var textCore = __toESM(require("../text/index.js"), 1);
|
|
107
112
|
var mathCore = __toESM(require("../math/index.js"), 1);
|
|
108
113
|
var import_registry = require("../drawing/registry.js");
|
|
114
|
+
var import_output = require("../drawing/output.js");
|
|
109
115
|
var timeframeCore = __toESM(require("../timeframe/index.js"), 1);
|
|
110
116
|
var timeCore = __toESM(require("../time/index.js"), 1);
|
|
111
117
|
var strCore = __toESM(require("../str/index.js"), 1);
|
|
@@ -113,7 +119,9 @@ var import_messageformat = require("../str/messageformat.js");
|
|
|
113
119
|
var import_calendar = require("../session/calendar.js");
|
|
114
120
|
var import_bars = require("../session/bars.js");
|
|
115
121
|
var import_resample = require("../security/resample.js");
|
|
122
|
+
var import_types = require("../types/index.js");
|
|
116
123
|
var import_strategy = require("../strategy/index.js");
|
|
124
|
+
var import_session = require("../time/session.js");
|
|
117
125
|
var import_strategy2 = require("../strategy/index.js");
|
|
118
126
|
var compare = __toESM(require("../compare/index.js"), 1);
|
|
119
127
|
const ctxBars = new import_series.BarData([]);
|
|
@@ -144,8 +152,11 @@ function freshCollector(inputValues) {
|
|
|
144
152
|
arrowConfig: [],
|
|
145
153
|
arrows: [],
|
|
146
154
|
barColorConfig: [],
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
bgColors: [],
|
|
156
|
+
barColors: [],
|
|
157
|
+
candleConfig: [],
|
|
158
|
+
plotCandles: {},
|
|
159
|
+
plotBars: {},
|
|
149
160
|
alertConfig: [],
|
|
150
161
|
alerts: []
|
|
151
162
|
};
|
|
@@ -164,6 +175,7 @@ function executeScript(body, barsInput, inputs = {}, chart2 = {}, options = {})
|
|
|
164
175
|
scriptOptions = options;
|
|
165
176
|
ctx = freshCollector(inputs);
|
|
166
177
|
(0, import_registry.resetDrawings)();
|
|
178
|
+
mathCore.resetRandom();
|
|
167
179
|
try {
|
|
168
180
|
body();
|
|
169
181
|
const c = ctx;
|
|
@@ -182,6 +194,7 @@ function executeScript(body, barsInput, inputs = {}, chart2 = {}, options = {})
|
|
|
182
194
|
shapeConfig: c.shapeConfig,
|
|
183
195
|
arrowConfig: c.arrowConfig,
|
|
184
196
|
barColorConfig: c.barColorConfig,
|
|
197
|
+
candleConfig: c.candleConfig,
|
|
185
198
|
defaultInputs: c.defaultInputs,
|
|
186
199
|
alertConfig: c.alertConfig,
|
|
187
200
|
strategyConfig: c.strategy?.properties,
|
|
@@ -191,8 +204,11 @@ function executeScript(body, barsInput, inputs = {}, chart2 = {}, options = {})
|
|
|
191
204
|
fills: c.fills.length ? c.fills : void 0,
|
|
192
205
|
markers: c.markers.length ? c.markers : void 0,
|
|
193
206
|
arrows: c.arrows.length ? c.arrows : void 0,
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
bgColors: c.bgColors.length ? c.bgColors : void 0,
|
|
208
|
+
barColors: c.barColors.length ? c.barColors : void 0,
|
|
209
|
+
plotCandles: Object.keys(c.plotCandles).length ? c.plotCandles : void 0,
|
|
210
|
+
plotBars: Object.keys(c.plotBars).length ? c.plotBars : void 0,
|
|
211
|
+
...(0, import_output.drawingOutputs)(ctxBars.bars, chartCtx.timeUnit),
|
|
196
212
|
alerts: c.alerts.length ? c.alerts : void 0
|
|
197
213
|
}
|
|
198
214
|
};
|
|
@@ -299,6 +315,7 @@ const hl2 = new import_series.Series(ctxBars, (b) => (b.high + b.low) / 2);
|
|
|
299
315
|
const hlc3 = new import_series.Series(ctxBars, (b) => (b.high + b.low + b.close) / 3);
|
|
300
316
|
const ohlc4 = new import_series.Series(ctxBars, (b) => (b.open + b.high + b.low + b.close) / 4);
|
|
301
317
|
const hlcc4 = new import_series.Series(ctxBars, (b) => (b.high + b.low + b.close + b.close) / 4);
|
|
318
|
+
for (const s of [hl2, hlc3, ohlc4, hlcc4]) s.fullHistory = true;
|
|
302
319
|
const SOURCES = { open, high, low, close, volume, hl2, hlc3, ohlc4, hlcc4 };
|
|
303
320
|
function sourceSeries(name) {
|
|
304
321
|
return SOURCES[name] ?? close;
|
|
@@ -372,11 +389,11 @@ function plotImpl(series, title, options = {}) {
|
|
|
372
389
|
const c = collector();
|
|
373
390
|
const id = `plot${c.plotConfig.length}`;
|
|
374
391
|
const perBar2 = Array.isArray(options.color) ? options.color : void 0;
|
|
375
|
-
const
|
|
392
|
+
const staticColor2 = typeof options.color === "string" ? options.color : perBar2?.[perBar2.length - 1] ?? "#2962FF";
|
|
376
393
|
c.plotConfig.push({
|
|
377
394
|
id,
|
|
378
395
|
title: title ?? id,
|
|
379
|
-
color:
|
|
396
|
+
color: staticColor2,
|
|
380
397
|
lineWidth: options.linewidth,
|
|
381
398
|
style: options.style,
|
|
382
399
|
linestyle: options.linestyle,
|
|
@@ -440,7 +457,7 @@ function fill(a, b, ...args) {
|
|
|
440
457
|
const c = collector();
|
|
441
458
|
const third = args[0];
|
|
442
459
|
let perBar2;
|
|
443
|
-
let
|
|
460
|
+
let staticColor2;
|
|
444
461
|
let title;
|
|
445
462
|
let gradient;
|
|
446
463
|
if (typeof third === "number" || third instanceof import_series.Series) {
|
|
@@ -455,12 +472,12 @@ function fill(a, b, ...args) {
|
|
|
455
472
|
} else if (third !== null && typeof third === "object" && !Array.isArray(third)) {
|
|
456
473
|
const options = third;
|
|
457
474
|
perBar2 = Array.isArray(options.color) ? options.color : void 0;
|
|
458
|
-
|
|
475
|
+
staticColor2 = typeof options.color === "string" ? options.color : void 0;
|
|
459
476
|
title = options.title;
|
|
460
477
|
} else {
|
|
461
478
|
const color2 = third;
|
|
462
479
|
perBar2 = Array.isArray(color2) ? color2.map((x) => x ?? "") : void 0;
|
|
463
|
-
|
|
480
|
+
staticColor2 = typeof color2 === "string" ? color2 : void 0;
|
|
464
481
|
title = args[1];
|
|
465
482
|
}
|
|
466
483
|
if (a.kind === "hline" && b.kind === "hline") {
|
|
@@ -468,7 +485,7 @@ function fill(a, b, ...args) {
|
|
|
468
485
|
id: `fill${c.fillConfig.length}`,
|
|
469
486
|
plot1: a.id,
|
|
470
487
|
plot2: b.id,
|
|
471
|
-
color:
|
|
488
|
+
color: staticColor2,
|
|
472
489
|
colors: perBar2,
|
|
473
490
|
gradient,
|
|
474
491
|
title
|
|
@@ -478,11 +495,40 @@ function fill(a, b, ...args) {
|
|
|
478
495
|
c.fills.push({
|
|
479
496
|
plot1: a.id,
|
|
480
497
|
plot2: b.id,
|
|
481
|
-
options: { color:
|
|
498
|
+
options: { color: staticColor2, title },
|
|
482
499
|
colors: perBar2,
|
|
483
500
|
gradient
|
|
484
501
|
});
|
|
485
502
|
}
|
|
503
|
+
const MARKER_SHAPES = {
|
|
504
|
+
xcross: "xcross",
|
|
505
|
+
cross: "cross",
|
|
506
|
+
triangleup: "triangleUp",
|
|
507
|
+
triangledown: "triangleDown",
|
|
508
|
+
flag: "flag",
|
|
509
|
+
circle: "circle",
|
|
510
|
+
arrowup: "arrowUp",
|
|
511
|
+
arrowdown: "arrowDown",
|
|
512
|
+
labelup: "labelUp",
|
|
513
|
+
labeldown: "labelDown",
|
|
514
|
+
square: "square",
|
|
515
|
+
diamond: "diamond"
|
|
516
|
+
};
|
|
517
|
+
function markerPosition(location, shape) {
|
|
518
|
+
switch (location) {
|
|
519
|
+
case "abovebar":
|
|
520
|
+
return "aboveBar";
|
|
521
|
+
case "belowbar":
|
|
522
|
+
return "belowBar";
|
|
523
|
+
case "top":
|
|
524
|
+
return "top";
|
|
525
|
+
case "bottom":
|
|
526
|
+
return "bottom";
|
|
527
|
+
case "absolute":
|
|
528
|
+
return shape === "labeldown" ? "atPriceTop" : shape === "labelup" ? "atPriceBottom" : "atPriceMiddle";
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const MARKER_COLOR = "#2962FF";
|
|
486
532
|
function emitMarkers(kind, condition, title, options) {
|
|
487
533
|
const c = collector();
|
|
488
534
|
const id = `${kind}${c.shapeConfig.filter((s) => s.kind === kind).length}`;
|
|
@@ -503,6 +549,19 @@ function emitMarkers(kind, condition, title, options) {
|
|
|
503
549
|
offset: options.offset,
|
|
504
550
|
forceOverlay: options.force_overlay
|
|
505
551
|
});
|
|
552
|
+
const shapeStyle = kind === "shape" ? style : void 0;
|
|
553
|
+
const template = {
|
|
554
|
+
position: markerPosition(location, shapeStyle),
|
|
555
|
+
shape: shapeStyle ? MARKER_SHAPES[shapeStyle] : "circle",
|
|
556
|
+
color: options.color ?? MARKER_COLOR,
|
|
557
|
+
id
|
|
558
|
+
};
|
|
559
|
+
if (char !== void 0) template.char = char;
|
|
560
|
+
if (options.text !== void 0) template.text = options.text;
|
|
561
|
+
if (options.textcolor !== void 0) template.textColor = options.textcolor;
|
|
562
|
+
if (options.size !== void 0) template.size = options.size;
|
|
563
|
+
if (options.tooltip !== void 0) template.tooltip = options.tooltip;
|
|
564
|
+
if (options.force_overlay) template.forceOverlay = true;
|
|
506
565
|
const values = condition.toArray();
|
|
507
566
|
const b = bars();
|
|
508
567
|
const off = options.offset ?? 0;
|
|
@@ -511,19 +570,8 @@ function emitMarkers(kind, condition, title, options) {
|
|
|
511
570
|
if (v === void 0 || Number.isNaN(v) || v === 0) continue;
|
|
512
571
|
const j = i + off;
|
|
513
572
|
if (j < 0 || j >= b.length) continue;
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
id,
|
|
517
|
-
location,
|
|
518
|
-
style,
|
|
519
|
-
char,
|
|
520
|
-
color: options.color,
|
|
521
|
-
text: options.text,
|
|
522
|
-
textcolor: options.textcolor,
|
|
523
|
-
size: options.size,
|
|
524
|
-
tooltip: options.tooltip,
|
|
525
|
-
price: location === "absolute" ? v : void 0
|
|
526
|
-
});
|
|
573
|
+
const time2 = b[j].time;
|
|
574
|
+
c.markers.push(location === "absolute" ? { time: time2, ...template, price: v } : { time: time2, ...template });
|
|
527
575
|
}
|
|
528
576
|
}
|
|
529
577
|
function plotshape(condition, title, options = {}) {
|
|
@@ -568,13 +616,14 @@ function emitBarColors(kind, colors, options) {
|
|
|
568
616
|
c.barColorConfig.push({ id, kind, title: options.title, offset: options.offset, forceOverlay: options.force_overlay });
|
|
569
617
|
const b = bars();
|
|
570
618
|
const off = options.offset ?? 0;
|
|
571
|
-
const target = kind === "bgcolor" ? c.
|
|
619
|
+
const target = kind === "bgcolor" ? c.bgColors : c.barColors;
|
|
620
|
+
const forceOverlay = kind === "bgcolor" && options.force_overlay === true;
|
|
572
621
|
for (let i = 0; i < b.length; i++) {
|
|
573
622
|
const col = typeof colors === "string" ? colors : colors[i];
|
|
574
623
|
if (!col) continue;
|
|
575
624
|
const j = i + off;
|
|
576
625
|
if (j < 0 || j >= b.length) continue;
|
|
577
|
-
target.push({ time: b[j].time, color: col });
|
|
626
|
+
target.push(forceOverlay ? { time: b[j].time, color: col, forceOverlay } : { time: b[j].time, color: col });
|
|
578
627
|
}
|
|
579
628
|
}
|
|
580
629
|
function bgcolor(colors, options = {}) {
|
|
@@ -583,11 +632,78 @@ function bgcolor(colors, options = {}) {
|
|
|
583
632
|
function barcolor(colors, options = {}) {
|
|
584
633
|
emitBarColors("barcolor", colors, options);
|
|
585
634
|
}
|
|
635
|
+
function candleColor(col, i) {
|
|
636
|
+
if (col === void 0) return void 0;
|
|
637
|
+
if (typeof col === "string") return col;
|
|
638
|
+
return col[i] ?? "transparent";
|
|
639
|
+
}
|
|
640
|
+
function ohlcRows(o, h, l, cl) {
|
|
641
|
+
const [ov, hv, lv, cv] = [o.toArray(), h.toArray(), l.toArray(), cl.toArray()];
|
|
642
|
+
const rows = [];
|
|
643
|
+
for (let i = 0; i < bars().length; i++) {
|
|
644
|
+
const [open2, high2, low2, close2] = [ov[i], hv[i], lv[i], cv[i]];
|
|
645
|
+
if (Number.isFinite(open2) && Number.isFinite(high2) && Number.isFinite(low2) && Number.isFinite(close2)) {
|
|
646
|
+
rows.push({ i, open: open2, high: high2, low: low2, close: close2 });
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return rows;
|
|
650
|
+
}
|
|
651
|
+
const staticColor = (col) => typeof col === "string" ? col : void 0;
|
|
652
|
+
function plotcandle(open2, high2, low2, close2, title, options = {}) {
|
|
653
|
+
const c = collector();
|
|
654
|
+
const id = `plotcandle${c.candleConfig.filter((x) => x.kind === "candle").length}`;
|
|
655
|
+
c.candleConfig.push({
|
|
656
|
+
id,
|
|
657
|
+
kind: "candle",
|
|
658
|
+
title,
|
|
659
|
+
color: staticColor(options.color),
|
|
660
|
+
wickColor: staticColor(options.wickcolor),
|
|
661
|
+
borderColor: staticColor(options.bordercolor),
|
|
662
|
+
display: options.display,
|
|
663
|
+
forceOverlay: options.force_overlay
|
|
664
|
+
});
|
|
665
|
+
const b = bars();
|
|
666
|
+
c.plotCandles[id] = ohlcRows(open2, high2, low2, close2).map(({ i, ...ohlc }) => {
|
|
667
|
+
const candle = { time: b[i].time, ...ohlc };
|
|
668
|
+
const color2 = candleColor(options.color, i);
|
|
669
|
+
const wickColor = candleColor(options.wickcolor, i);
|
|
670
|
+
const borderColor = candleColor(options.bordercolor, i);
|
|
671
|
+
if (color2 !== void 0) candle.color = color2;
|
|
672
|
+
if (wickColor !== void 0) candle.wickColor = wickColor;
|
|
673
|
+
if (borderColor !== void 0) candle.borderColor = borderColor;
|
|
674
|
+
if (options.force_overlay) candle.forceOverlay = true;
|
|
675
|
+
return candle;
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
function plotbar(open2, high2, low2, close2, title, options = {}) {
|
|
679
|
+
const c = collector();
|
|
680
|
+
const id = `plotbar${c.candleConfig.filter((x) => x.kind === "bar").length}`;
|
|
681
|
+
c.candleConfig.push({
|
|
682
|
+
id,
|
|
683
|
+
kind: "bar",
|
|
684
|
+
title,
|
|
685
|
+
color: staticColor(options.color),
|
|
686
|
+
display: options.display,
|
|
687
|
+
forceOverlay: options.force_overlay
|
|
688
|
+
});
|
|
689
|
+
const b = bars();
|
|
690
|
+
c.plotBars[id] = ohlcRows(open2, high2, low2, close2).map(({ i, ...ohlc }) => {
|
|
691
|
+
const bar = { time: b[i].time, ...ohlc };
|
|
692
|
+
const color2 = candleColor(options.color, i);
|
|
693
|
+
if (color2 !== void 0) bar.color = color2;
|
|
694
|
+
if (options.force_overlay) bar.forceOverlay = true;
|
|
695
|
+
return bar;
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
const HISTORY_START = 242;
|
|
699
|
+
const HISTORY_GROWTH = 1.618034;
|
|
586
700
|
function eachBar(fn) {
|
|
587
701
|
collector();
|
|
588
702
|
const b = bars();
|
|
589
703
|
const out = new Array(b.length).fill(NaN);
|
|
590
704
|
const cache = /* @__PURE__ */ new Map();
|
|
705
|
+
const buffers = /* @__PURE__ */ new Map();
|
|
706
|
+
let pendingError = null;
|
|
591
707
|
let idx = 0;
|
|
592
708
|
const ctx2 = {
|
|
593
709
|
get i() {
|
|
@@ -614,6 +730,13 @@ function eachBar(fn) {
|
|
|
614
730
|
},
|
|
615
731
|
get(src, offset = 0) {
|
|
616
732
|
if (offset < 0) throw new RangeError(`c.get(): the offset cannot be negative (${offset} would read a future bar).`);
|
|
733
|
+
if (!src.fullHistory && offset > 0) {
|
|
734
|
+
const k = Math.floor(offset);
|
|
735
|
+
if (k > import_series.MAX_BARS_BACK) throw new Error((0, import_series.historyError)(idx, k));
|
|
736
|
+
let buffer = buffers.get(src);
|
|
737
|
+
if (!buffer) buffers.set(src, buffer = { size: HISTORY_START, previous: 0, barMax: 0 });
|
|
738
|
+
if (k > buffer.barMax) buffer.barMax = k;
|
|
739
|
+
}
|
|
617
740
|
let vals = cache.get(src);
|
|
618
741
|
if (!vals) {
|
|
619
742
|
vals = src.toArray();
|
|
@@ -629,9 +752,20 @@ function eachBar(fn) {
|
|
|
629
752
|
};
|
|
630
753
|
try {
|
|
631
754
|
for (idx = 0; idx < b.length; idx++) {
|
|
755
|
+
if (pendingError && pendingError.bar === idx) throw new Error((0, import_series.historyError)(idx, pendingError.barsBack));
|
|
632
756
|
currentBar = idx;
|
|
633
757
|
const r = fn(ctx2);
|
|
634
758
|
out[idx] = typeof r === "number" ? r : typeof r === "boolean" ? r ? 1 : 0 : NaN;
|
|
759
|
+
for (const buffer of buffers.values()) {
|
|
760
|
+
const k = buffer.barMax;
|
|
761
|
+
if (k > buffer.size) {
|
|
762
|
+
const next = k - buffer.previous > 1 ? k : Math.round(buffer.size * HISTORY_GROWTH);
|
|
763
|
+
if (next > import_series.MAX_BARS_BACK && !pendingError) pendingError = { bar: idx + 1, barsBack: next };
|
|
764
|
+
buffer.size = next;
|
|
765
|
+
}
|
|
766
|
+
buffer.previous = k;
|
|
767
|
+
buffer.barMax = 0;
|
|
768
|
+
}
|
|
635
769
|
}
|
|
636
770
|
} finally {
|
|
637
771
|
currentBar = -1;
|
|
@@ -900,6 +1034,8 @@ function inSession(time2, session2, timezone) {
|
|
|
900
1034
|
}
|
|
901
1035
|
const str = {
|
|
902
1036
|
...strCore,
|
|
1037
|
+
// format.mintick rounds to the chart symbol's tick (syminfo.mintick)
|
|
1038
|
+
tostring: ((value, format, mintick) => strCore.tostring(value, format, format === "mintick" ? mintick ?? syminfo.mintick : mintick)),
|
|
903
1039
|
format_time(time2, format = "yyyy-MM-dd'T'HH:mm:ssZ", timezone) {
|
|
904
1040
|
return strCore.format_time(time2, format, timezone ?? exchangeTimezone());
|
|
905
1041
|
},
|
|
@@ -933,6 +1069,11 @@ function calendarFor(session2, timezone) {
|
|
|
933
1069
|
const { bars: bars2 } = sessionBars();
|
|
934
1070
|
if (!session2 && !timezone) return { bars: bars2, test: false };
|
|
935
1071
|
const tz = timezone ?? exchangeTimezone();
|
|
1072
|
+
if (session2 !== void 0 && (0, import_session.parsePineSession)(session2) === null) {
|
|
1073
|
+
const name = session2.trim();
|
|
1074
|
+
const symbol = name === "regular" && chartCtx.regularSession ? chartCtx.regularSession : chartCtx.session;
|
|
1075
|
+
return { bars: new import_bars.SessionBars(new import_calendar.TradingCalendar(tz, { session: toSpec(symbol).session }, "symbol"), bars2.chart.period), test: true };
|
|
1076
|
+
}
|
|
936
1077
|
const spec = session2 ? { session: session2 } : { session: toSpec(chartCtx.session).session };
|
|
937
1078
|
return { bars: new import_bars.SessionBars(new import_calendar.TradingCalendar(tz, spec, session2 ? "pine" : "symbol"), bars2.chart.period), test: true };
|
|
938
1079
|
}
|
|
@@ -1139,6 +1280,12 @@ const polyline = {
|
|
|
1139
1280
|
return polylineCore.all();
|
|
1140
1281
|
}
|
|
1141
1282
|
};
|
|
1283
|
+
const table = {
|
|
1284
|
+
...tableCore,
|
|
1285
|
+
get all() {
|
|
1286
|
+
return tableCore.all();
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1142
1289
|
const text = { ...textCore };
|
|
1143
1290
|
const chart = {
|
|
1144
1291
|
point: {
|