oakscriptjs 0.24.0 → 0.25.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 +25 -1
- package/bin/oakscript.mjs +10 -3
- package/dist/cjs/box/index.d.ts +348 -289
- package/dist/cjs/box/index.d.ts.map +1 -1
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/check/node.d.ts.map +1 -1
- package/dist/cjs/check/node.js +1 -0
- package/dist/cjs/check/node.js.map +2 -2
- package/dist/cjs/check/preview.d.ts +31 -0
- package/dist/cjs/check/preview.d.ts.map +1 -0
- package/dist/cjs/check/preview.js +303 -0
- package/dist/cjs/check/preview.js.map +7 -0
- package/dist/cjs/color/index.d.ts +11 -11
- package/dist/cjs/color/index.js.map +1 -1
- package/dist/cjs/color/parse.d.ts +2 -0
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +6 -0
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/compare/index.d.ts +76 -12
- package/dist/cjs/compare/index.d.ts.map +1 -1
- package/dist/cjs/compare/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +28 -5
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +14 -0
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/label/index.d.ts +265 -187
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +1 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +247 -207
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +61 -89
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +49 -40
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +57 -78
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/input-active.d.ts +2 -2
- package/dist/cjs/runtime/input-active.js.map +1 -1
- package/dist/cjs/runtime/series.d.ts +241 -161
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +223 -127
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/api/alert.d.ts +37 -0
- package/dist/cjs/script/api/alert.d.ts.map +1 -0
- package/dist/cjs/script/api/alert.js +17 -0
- package/dist/cjs/script/api/alert.js.map +7 -0
- package/dist/cjs/script/api/calc.d.ts +232 -0
- package/dist/cjs/script/api/calc.d.ts.map +1 -0
- package/dist/cjs/script/api/calc.js +17 -0
- package/dist/cjs/script/api/calc.js.map +7 -0
- package/dist/cjs/script/api/color.d.ts +213 -0
- package/dist/cjs/script/api/color.d.ts.map +1 -0
- package/dist/cjs/script/api/color.js +17 -0
- package/dist/cjs/script/api/color.js.map +7 -0
- package/dist/cjs/script/api/context.d.ts +764 -0
- package/dist/cjs/script/api/context.d.ts.map +1 -0
- package/dist/cjs/script/api/context.js +17 -0
- package/dist/cjs/script/api/context.js.map +7 -0
- package/dist/cjs/script/api/log.d.ts +58 -0
- package/dist/cjs/script/api/log.d.ts.map +1 -0
- package/dist/cjs/script/api/log.js +17 -0
- package/dist/cjs/script/api/log.js.map +7 -0
- package/dist/cjs/script/api/strategy.d.ts +391 -0
- package/dist/cjs/script/api/strategy.d.ts.map +1 -0
- package/dist/cjs/script/api/strategy.js +17 -0
- package/dist/cjs/script/api/strategy.js.map +7 -0
- package/dist/cjs/script/api/ta.d.ts +1012 -0
- package/dist/cjs/script/api/ta.d.ts.map +1 -0
- package/dist/cjs/script/api/ta.js +17 -0
- package/dist/cjs/script/api/ta.js.map +7 -0
- package/dist/cjs/script/api/table.d.ts +479 -0
- package/dist/cjs/script/api/table.d.ts.map +1 -0
- package/dist/cjs/script/api/table.js +17 -0
- package/dist/cjs/script/api/table.js.map +7 -0
- package/dist/cjs/script/constants.d.ts +228 -83
- package/dist/cjs/script/constants.d.ts.map +1 -1
- package/dist/cjs/script/constants.js +87 -0
- package/dist/cjs/script/constants.js.map +2 -2
- package/dist/cjs/script/define.d.ts +94 -0
- package/dist/cjs/script/define.d.ts.map +1 -0
- package/dist/cjs/script/define.js +127 -0
- package/dist/cjs/script/define.js.map +7 -0
- package/dist/cjs/script/drawing-args.d.ts.map +1 -1
- package/dist/cjs/script/drawing-args.js +1 -1
- package/dist/cjs/script/drawing-args.js.map +2 -2
- package/dist/cjs/script/formula.d.ts +53 -0
- package/dist/cjs/script/formula.d.ts.map +1 -0
- package/dist/cjs/script/formula.js +402 -0
- package/dist/cjs/script/formula.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +10 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/index.d.ts +1065 -1006
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +530 -60
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/script/json.d.ts +117 -0
- package/dist/cjs/script/json.d.ts.map +1 -0
- package/dist/cjs/script/json.js +321 -0
- package/dist/cjs/script/json.js.map +7 -0
- package/dist/cjs/str/index.d.ts +50 -75
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +2 -2
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +102 -1
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +2 -2
- package/dist/cjs/table/index.d.ts +330 -49
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +55 -27
- package/dist/cjs/table/index.js.map +2 -2
- package/dist/cjs/text/index.d.ts +12 -14
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/types/index.d.ts +15 -8
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -3
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/esm/box/index.d.ts +348 -289
- package/dist/esm/box/index.d.ts.map +1 -1
- package/dist/esm/box/index.js +276 -276
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/check/node.d.ts.map +1 -1
- package/dist/esm/check/node.js +1 -0
- package/dist/esm/check/node.js.map +1 -1
- package/dist/esm/check/preview.d.ts +31 -0
- package/dist/esm/check/preview.d.ts.map +1 -0
- package/dist/esm/check/preview.js +296 -0
- package/dist/esm/check/preview.js.map +1 -0
- package/dist/esm/color/index.d.ts +11 -11
- package/dist/esm/color/index.js +11 -11
- package/dist/esm/color/parse.d.ts +2 -0
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +7 -0
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/compare/index.d.ts +76 -12
- package/dist/esm/compare/index.d.ts.map +1 -1
- package/dist/esm/compare/index.js +76 -12
- package/dist/esm/compare/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +28 -5
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +39 -3
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/label/index.d.ts +265 -187
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +207 -177
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +247 -207
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +202 -194
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +61 -89
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +61 -89
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +49 -40
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +22 -9
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +57 -78
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +57 -78
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/input-active.d.ts +2 -2
- package/dist/esm/runtime/input-active.js +2 -2
- package/dist/esm/runtime/series.d.ts +241 -161
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +241 -161
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/api/alert.d.ts +37 -0
- package/dist/esm/script/api/alert.d.ts.map +1 -0
- package/dist/esm/script/api/alert.js +7 -0
- package/dist/esm/script/api/alert.js.map +1 -0
- package/dist/esm/script/api/calc.d.ts +232 -0
- package/dist/esm/script/api/calc.d.ts.map +1 -0
- package/dist/esm/script/api/calc.js +6 -0
- package/dist/esm/script/api/calc.js.map +1 -0
- package/dist/esm/script/api/color.d.ts +213 -0
- package/dist/esm/script/api/color.d.ts.map +1 -0
- package/dist/esm/script/api/color.js +6 -0
- package/dist/esm/script/api/color.js.map +1 -0
- package/dist/esm/script/api/context.d.ts +764 -0
- package/dist/esm/script/api/context.d.ts.map +1 -0
- package/dist/esm/script/api/context.js +7 -0
- package/dist/esm/script/api/context.js.map +1 -0
- package/dist/esm/script/api/log.d.ts +58 -0
- package/dist/esm/script/api/log.d.ts.map +1 -0
- package/dist/esm/script/api/log.js +6 -0
- package/dist/esm/script/api/log.js.map +1 -0
- package/dist/esm/script/api/strategy.d.ts +391 -0
- package/dist/esm/script/api/strategy.d.ts.map +1 -0
- package/dist/esm/script/api/strategy.js +7 -0
- package/dist/esm/script/api/strategy.js.map +1 -0
- package/dist/esm/script/api/ta.d.ts +1012 -0
- package/dist/esm/script/api/ta.d.ts.map +1 -0
- package/dist/esm/script/api/ta.js +6 -0
- package/dist/esm/script/api/ta.js.map +1 -0
- package/dist/esm/script/api/table.d.ts +479 -0
- package/dist/esm/script/api/table.d.ts.map +1 -0
- package/dist/esm/script/api/table.js +7 -0
- package/dist/esm/script/api/table.js.map +1 -0
- package/dist/esm/script/constants.d.ts +228 -83
- package/dist/esm/script/constants.d.ts.map +1 -1
- package/dist/esm/script/constants.js +110 -24
- package/dist/esm/script/constants.js.map +1 -1
- package/dist/esm/script/define.d.ts +94 -0
- package/dist/esm/script/define.d.ts.map +1 -0
- package/dist/esm/script/define.js +136 -0
- package/dist/esm/script/define.js.map +1 -0
- package/dist/esm/script/drawing-args.d.ts.map +1 -1
- package/dist/esm/script/drawing-args.js +2 -1
- package/dist/esm/script/drawing-args.js.map +1 -1
- package/dist/esm/script/formula.d.ts +53 -0
- package/dist/esm/script/formula.d.ts.map +1 -0
- package/dist/esm/script/formula.js +408 -0
- package/dist/esm/script/formula.js.map +1 -0
- package/dist/esm/script/globals.d.ts +10 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/index.d.ts +1065 -1006
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +1096 -151
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/script/json.d.ts +117 -0
- package/dist/esm/script/json.d.ts.map +1 -0
- package/dist/esm/script/json.js +375 -0
- package/dist/esm/script/json.js.map +1 -0
- package/dist/esm/str/index.d.ts +50 -75
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +51 -76
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +102 -1
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/strategy/index.js +1 -1
- package/dist/esm/strategy/index.js.map +1 -1
- package/dist/esm/table/index.d.ts +330 -49
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +372 -61
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/text/index.d.ts +12 -14
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +12 -14
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +15 -8
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +15 -8
- package/dist/esm/types/index.js.map +1 -1
- package/docs/first-indicator.md +152 -0
- package/docs/guide.md +1185 -0
- package/docs/inventory.md +772 -0
- package/docs/no-code.md +207 -0
- package/docs/recipes.md +202 -0
- package/package.json +2 -1
- package/skills/oakscript/SKILL.md +8 -0
- package/skills/oakscript/reference/errors.md +3 -2
- package/src/box/index.ts +348 -289
- package/src/check/node.ts +1 -0
- package/src/check/preview.ts +307 -0
- package/src/color/index.ts +11 -11
- package/src/color/parse.ts +7 -0
- package/src/compare/index.ts +76 -12
- package/src/drawing/registry.ts +44 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +267 -189
- package/src/line/index.ts +248 -208
- package/src/linefill/index.ts +61 -89
- package/src/math/index.ts +51 -42
- package/src/polyline/index.ts +57 -78
- package/src/runtime/input-active.ts +2 -2
- package/src/runtime/series.ts +243 -163
- package/src/script/api/alert.ts +43 -0
- package/src/script/api/calc.ts +250 -0
- package/src/script/api/color.ts +245 -0
- package/src/script/api/context.ts +944 -0
- package/src/script/api/log.ts +60 -0
- package/src/script/api/strategy.ts +410 -0
- package/src/script/api/ta.ts +1115 -0
- package/src/script/api/table.ts +538 -0
- package/src/script/constants.ts +229 -25
- package/src/script/define.ts +221 -0
- package/src/script/drawing-args.ts +2 -1
- package/src/script/formula.ts +438 -0
- package/src/script/globals.ts +10 -0
- package/src/script/index.ts +1517 -239
- package/src/script/json.ts +457 -0
- package/src/str/index.ts +51 -76
- package/src/strategy/index.ts +102 -1
- package/src/table/index.ts +388 -62
- package/src/text/index.ts +12 -14
- package/src/types/index.ts +15 -8
package/dist/cjs/script/index.js
CHANGED
|
@@ -31,12 +31,15 @@ __export(script_exports, {
|
|
|
31
31
|
BarData: () => import_series.BarData,
|
|
32
32
|
DEFAULT_CANDLE_COLORS: () => DEFAULT_CANDLE_COLORS,
|
|
33
33
|
DEFAULT_OUTPUT_TITLES: () => DEFAULT_OUTPUT_TITLES,
|
|
34
|
+
DEFAULT_PALETTE: () => DEFAULT_PALETTE,
|
|
35
|
+
FORMULA_FUNCTIONS: () => import_formula.FORMULA_FUNCTIONS,
|
|
34
36
|
MAX_LOG_ENTRIES: () => MAX_LOG_ENTRIES,
|
|
35
37
|
MissingSymbolDataError: () => MissingSymbolDataError,
|
|
36
38
|
STRATEGY_DEFAULTS: () => import_strategy2.STRATEGY_DEFAULTS,
|
|
39
|
+
ScriptError: () => ScriptError,
|
|
37
40
|
Series: () => import_series.Series,
|
|
38
41
|
StrategyRecorder: () => StrategyRecorder,
|
|
39
|
-
adjustment: () => adjustment,
|
|
42
|
+
adjustment: () => import_constants.adjustment,
|
|
40
43
|
alert: () => alert,
|
|
41
44
|
alertcondition: () => alertcondition,
|
|
42
45
|
bar_index: () => bar_index,
|
|
@@ -45,26 +48,32 @@ __export(script_exports, {
|
|
|
45
48
|
barstate: () => barstate,
|
|
46
49
|
bgcolor: () => bgcolor,
|
|
47
50
|
box: () => box,
|
|
51
|
+
calc: () => calc,
|
|
48
52
|
chart: () => chart,
|
|
53
|
+
checkIndicatorJson: () => import_json.checkIndicatorJson,
|
|
49
54
|
close: () => close,
|
|
50
55
|
color: () => color,
|
|
51
56
|
compare: () => compare,
|
|
52
57
|
createScriptRun: () => createScriptRun,
|
|
53
|
-
currency: () => currency,
|
|
58
|
+
currency: () => import_constants.currency,
|
|
54
59
|
dayofmonth: () => dayofmonth,
|
|
55
60
|
dayofweek: () => dayofweek,
|
|
56
61
|
defineEnum: () => defineEnum,
|
|
57
|
-
|
|
62
|
+
defineIndicator: () => import_define.defineIndicator,
|
|
63
|
+
defineIndicatorFromJson: () => import_json.defineIndicatorFromJson,
|
|
64
|
+
display: () => import_constants.display,
|
|
58
65
|
dividends: () => dividends,
|
|
59
66
|
eachBar: () => eachBar,
|
|
60
67
|
earnings: () => earnings,
|
|
68
|
+
evaluateFormula: () => import_formula.evaluateFormula,
|
|
61
69
|
executeIntrabar: () => executeIntrabar,
|
|
62
70
|
executeScript: () => executeScript,
|
|
63
|
-
extend: () => extend,
|
|
71
|
+
extend: () => import_constants.extend,
|
|
64
72
|
fill: () => fill,
|
|
65
73
|
fixnan: () => fixnan,
|
|
66
|
-
font: () => font,
|
|
67
|
-
format: () => format,
|
|
74
|
+
font: () => import_constants.font,
|
|
75
|
+
format: () => import_constants.format,
|
|
76
|
+
formula: () => import_formula.formula,
|
|
68
77
|
high: () => high,
|
|
69
78
|
hl2: () => hl2,
|
|
70
79
|
hlc3: () => hlc3,
|
|
@@ -74,13 +83,14 @@ __export(script_exports, {
|
|
|
74
83
|
hour: () => hour,
|
|
75
84
|
inSession: () => inSession,
|
|
76
85
|
indicator: () => indicator,
|
|
86
|
+
indicatorBodyFromJson: () => import_json.indicatorBodyFromJson,
|
|
77
87
|
input: () => input,
|
|
78
88
|
isInputActive: () => import_input_active.isInputActive,
|
|
79
89
|
label: () => label,
|
|
80
90
|
last_bar_index: () => last_bar_index,
|
|
81
91
|
line: () => line,
|
|
82
92
|
linefill: () => linefill,
|
|
83
|
-
location: () => location,
|
|
93
|
+
location: () => import_constants.location,
|
|
84
94
|
log: () => log,
|
|
85
95
|
low: () => low,
|
|
86
96
|
math: () => math,
|
|
@@ -90,7 +100,7 @@ __export(script_exports, {
|
|
|
90
100
|
nz: () => nz,
|
|
91
101
|
ohlc4: () => ohlc4,
|
|
92
102
|
open: () => open,
|
|
93
|
-
order: () => order,
|
|
103
|
+
order: () => import_constants.order,
|
|
94
104
|
persist: () => persist,
|
|
95
105
|
plot: () => plot,
|
|
96
106
|
plotarrow: () => plotarrow,
|
|
@@ -102,13 +112,13 @@ __export(script_exports, {
|
|
|
102
112
|
position: () => import_types.position,
|
|
103
113
|
releaseDrawing: () => import_registry2.releaseDrawing,
|
|
104
114
|
request: () => request,
|
|
105
|
-
scale: () => scale,
|
|
115
|
+
scale: () => import_constants.scale,
|
|
106
116
|
second: () => second,
|
|
107
117
|
seriesOf: () => seriesOf,
|
|
108
118
|
session: () => session,
|
|
109
119
|
setLogLineResolver: () => setLogLineResolver,
|
|
110
|
-
shape: () => shape,
|
|
111
|
-
size: () => size,
|
|
120
|
+
shape: () => import_constants.shape,
|
|
121
|
+
size: () => import_constants.size,
|
|
112
122
|
splits: () => splits,
|
|
113
123
|
str: () => str,
|
|
114
124
|
strategy: () => strategy,
|
|
@@ -127,9 +137,9 @@ __export(script_exports, {
|
|
|
127
137
|
varip: () => varip,
|
|
128
138
|
volume: () => volume,
|
|
129
139
|
weekofyear: () => weekofyear,
|
|
130
|
-
xloc: () => xloc,
|
|
140
|
+
xloc: () => import_constants.xloc,
|
|
131
141
|
year: () => year,
|
|
132
|
-
yloc: () => yloc
|
|
142
|
+
yloc: () => import_constants.yloc
|
|
133
143
|
});
|
|
134
144
|
module.exports = __toCommonJS(script_exports);
|
|
135
145
|
var import_series = require("../runtime/series.js");
|
|
@@ -140,6 +150,7 @@ var import_closure_writes = require("./closure-writes.js");
|
|
|
140
150
|
var pineConstants = __toESM(require("./constants.js"), 1);
|
|
141
151
|
var import_drawing_args = require("./drawing-args.js");
|
|
142
152
|
var colorCore = __toESM(require("../color/index.js"), 1);
|
|
153
|
+
var compareCore = __toESM(require("../compare/index.js"), 1);
|
|
143
154
|
var import_parse = require("../color/parse.js");
|
|
144
155
|
var import_utils = require("../utils/index.js");
|
|
145
156
|
var import_source_resolver = require("../utils/source-resolver.js");
|
|
@@ -168,9 +179,12 @@ var import_events = require("../security/events.js");
|
|
|
168
179
|
var import_types = require("../types/index.js");
|
|
169
180
|
var import_strategy = require("../strategy/index.js");
|
|
170
181
|
var import_context = require("../session/context.js");
|
|
182
|
+
var import_constants = require("./constants.js");
|
|
171
183
|
var import_strategy2 = require("../strategy/index.js");
|
|
172
|
-
var compare = __toESM(require("../compare/index.js"), 1);
|
|
173
184
|
var import_input_active = require("../runtime/input-active.js");
|
|
185
|
+
var import_define = require("./define.js");
|
|
186
|
+
var import_formula = require("./formula.js");
|
|
187
|
+
var import_json = require("./json.js");
|
|
174
188
|
function varDrawing(initial) {
|
|
175
189
|
const box2 = persist(initial ? (0, import_registry.holdDrawing)(initial) : void 0);
|
|
176
190
|
return {
|
|
@@ -195,8 +209,9 @@ function collector() {
|
|
|
195
209
|
}
|
|
196
210
|
return ctx;
|
|
197
211
|
}
|
|
198
|
-
function freshCollector(inputValues) {
|
|
212
|
+
function freshCollector(inputValues, strict = false) {
|
|
199
213
|
return {
|
|
214
|
+
strict,
|
|
200
215
|
title: "Untitled",
|
|
201
216
|
overlay: false,
|
|
202
217
|
inputValues,
|
|
@@ -235,6 +250,137 @@ function slugId(title, fallback, taken) {
|
|
|
235
250
|
taken.add(id);
|
|
236
251
|
return id;
|
|
237
252
|
}
|
|
253
|
+
function shown(v) {
|
|
254
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
255
|
+
if (typeof v === "number" || typeof v === "boolean" || v === null || v === void 0) return String(v);
|
|
256
|
+
return Array.isArray(v) ? "a list" : typeof v === "object" ? "an object" : typeof v;
|
|
257
|
+
}
|
|
258
|
+
function closeNames(name, names) {
|
|
259
|
+
const bare = (x) => x.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
260
|
+
const same = names.filter((k) => bare(k) === bare(name));
|
|
261
|
+
if (same.length) return same;
|
|
262
|
+
const n = name.toLowerCase();
|
|
263
|
+
const dist = (a, b) => {
|
|
264
|
+
const row = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
265
|
+
for (let i = 1; i <= a.length; i++) {
|
|
266
|
+
let diag = row[0];
|
|
267
|
+
row[0] = i;
|
|
268
|
+
for (let j = 1; j <= b.length; j++) {
|
|
269
|
+
const up = row[j];
|
|
270
|
+
row[j] = Math.min(up + 1, row[j - 1] + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
271
|
+
diag = up;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return row[b.length];
|
|
275
|
+
};
|
|
276
|
+
return names.map((k) => ({ k, d: dist(n, k.toLowerCase()) })).filter(({ k, d }) => d <= Math.max(2, Math.floor(name.length / 3)) || k.toLowerCase().includes(n) || n.includes(k.toLowerCase())).sort((a, b) => a.d - b.d).slice(0, 3).map(({ k }) => k);
|
|
277
|
+
}
|
|
278
|
+
function checkInputNames(c, inputs) {
|
|
279
|
+
const names = c.inputConfig.map((i) => i.id);
|
|
280
|
+
for (const key of Object.keys(inputs)) {
|
|
281
|
+
if (c.inputIds.has(key)) continue;
|
|
282
|
+
const near = closeNames(key, names);
|
|
283
|
+
throw new ScriptError(
|
|
284
|
+
`There is no input "${key}".` + (near.length ? ` Did you mean "${near.join('", "')}"?` : "") + (names.length ? ` The inputs are: ${names.join(", ")}.` : " The script has no inputs.")
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function checkInputValue(config, id, value) {
|
|
289
|
+
const name = config.title ? `"${config.title}" (${id})` : `"${id}"`;
|
|
290
|
+
const fail = (why) => {
|
|
291
|
+
throw new ScriptError(`Input ${name}: ${why}`);
|
|
292
|
+
};
|
|
293
|
+
switch (config.type) {
|
|
294
|
+
case "int":
|
|
295
|
+
case "float":
|
|
296
|
+
case "price":
|
|
297
|
+
case "time":
|
|
298
|
+
if (typeof value !== "number" || Number.isNaN(value)) fail(`${shown(value)} is not a number.`);
|
|
299
|
+
if (config.type === "int" && !Number.isInteger(value)) fail(`${value} is not a whole number.`);
|
|
300
|
+
if (config.min !== void 0 && value < config.min) fail(`${value} is below the minimum, ${config.min}.`);
|
|
301
|
+
if (config.max !== void 0 && value > config.max) fail(`${value} is above the maximum, ${config.max}.`);
|
|
302
|
+
break;
|
|
303
|
+
case "bool":
|
|
304
|
+
if (typeof value !== "boolean") fail(`${shown(value)} is not true or false.`);
|
|
305
|
+
break;
|
|
306
|
+
case "color":
|
|
307
|
+
if (!(0, import_parse.isColorText)(value)) fail(`${shown(value)} is not a colour. Write it as "#ff0000" or "rgba(255, 0, 0, 0.5)".`);
|
|
308
|
+
break;
|
|
309
|
+
case "source":
|
|
310
|
+
if (typeof value !== "string" || !SOURCES[value] && !(0, import_source_resolver.externalSource)(value)) {
|
|
311
|
+
fail(`${shown(value)} is not a price source. The sources are: ${Object.keys(SOURCES).join(", ")}.`);
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
default:
|
|
315
|
+
if (typeof value !== "string") fail(`${shown(value)} is not a text.`);
|
|
316
|
+
}
|
|
317
|
+
if (config.options && !config.options.includes(value)) {
|
|
318
|
+
fail(`${shown(value)} is not one of the choices: ${config.options.map(shown).join(", ")}.`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function checkOptions(fn, options, keys, colorKeys = ["color"]) {
|
|
322
|
+
if (!ctx?.strict || options === void 0) return;
|
|
323
|
+
if (!(0, import_drawing_args.isPlainObject)(options)) throw new ScriptError(`${fn}(): the options are an object, e.g. { color: color.red }.`);
|
|
324
|
+
for (const [key, v] of Object.entries(options)) {
|
|
325
|
+
if (!keys.includes(key)) {
|
|
326
|
+
const near = closeNames(key, keys);
|
|
327
|
+
throw new ScriptError(
|
|
328
|
+
`${fn}(): there is no option "${key}".` + (near.length ? ` Did you mean "${near.join('", "')}"?` : "") + ` The options are: ${keys.join(", ")}.`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
if (colorKeys.includes(key)) checkColor(`${fn}(): the ${key}`, v);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function checkColor(what, v) {
|
|
335
|
+
if (v === void 0 || v === null) return;
|
|
336
|
+
const bad = Array.isArray(v) ? v.find((x) => x !== void 0 && x !== null && x !== "" && !(0, import_parse.isColorText)(x)) : (0, import_parse.isColorText)(v) ? void 0 : v;
|
|
337
|
+
if (bad !== void 0) {
|
|
338
|
+
const name = typeof bad === "string" ? bad.trim().toLowerCase() : "";
|
|
339
|
+
if (/^[a-z]+$/.test(name) && typeof colorCore[name] === "string") {
|
|
340
|
+
throw new ScriptError(`${what} ${shown(bad)} is a colour name: write color.${name} (without quotes).`);
|
|
341
|
+
}
|
|
342
|
+
throw new ScriptError(`${what} ${shown(bad)} is not a colour. Write a colour as color.red, "#ff0000" or "rgba(255, 0, 0, 0.5)".`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function runWarnings() {
|
|
346
|
+
const out = [];
|
|
347
|
+
const option = { line: "max_lines_count", label: "max_labels_count", box: "max_boxes_count", polyline: "max_polylines_count", linefill: "max_lines_count" };
|
|
348
|
+
for (const [kind, n] of Object.entries((0, import_registry.droppedDrawings)())) {
|
|
349
|
+
if (!n || kind === "table") continue;
|
|
350
|
+
out.push(
|
|
351
|
+
`${n} ${kind}${n > 1 ? "s were" : " was"} deleted because the script made more than the maximum number of ${kind}s; the oldest go first. To keep more, raise ${option[kind]} in indicator(), e.g. indicator("...", { ${option[kind]}: 500 }).`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
function plotsOnPrices(c) {
|
|
357
|
+
const b = ctxBars.bars;
|
|
358
|
+
let lo = Infinity;
|
|
359
|
+
let hi = -Infinity;
|
|
360
|
+
for (const bar of b) {
|
|
361
|
+
if (bar.low < lo) lo = bar.low;
|
|
362
|
+
if (bar.high > hi) hi = bar.high;
|
|
363
|
+
}
|
|
364
|
+
if (!(hi >= lo)) return true;
|
|
365
|
+
const margin = (hi - lo) * 0.25;
|
|
366
|
+
let inside = 0;
|
|
367
|
+
let total = 0;
|
|
368
|
+
const shown2 = c.plotConfig.filter((p) => p.display !== "none").map((p) => c.plots[p.id] ?? []);
|
|
369
|
+
for (const points of shown2) {
|
|
370
|
+
for (const p of points) {
|
|
371
|
+
total++;
|
|
372
|
+
if (p.value >= lo - margin && p.value <= hi + margin) inside++;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return total === 0 || inside >= total * 0.9;
|
|
376
|
+
}
|
|
377
|
+
const DEFAULT_PALETTE = ["#2962FF", "#FF6D00", "#00897B", "#AB47BC", "#F23645", "#43A047", "#FBC02D", "#8D6E63"];
|
|
378
|
+
class ScriptError extends Error {
|
|
379
|
+
constructor(message) {
|
|
380
|
+
super(message);
|
|
381
|
+
this.name = "ScriptError";
|
|
382
|
+
}
|
|
383
|
+
}
|
|
238
384
|
let scriptOptions = {};
|
|
239
385
|
const NO_VARIP = [];
|
|
240
386
|
let intrabarRun = null;
|
|
@@ -294,7 +440,7 @@ function runBody(body, barsInput, inputs, chart2, options, inc) {
|
|
|
294
440
|
chartCtx = { ...chart2 };
|
|
295
441
|
runNow = chart2.now ?? Date.now();
|
|
296
442
|
scriptOptions = options;
|
|
297
|
-
ctx = freshCollector(inputs);
|
|
443
|
+
ctx = freshCollector(inputs, options.strict === true);
|
|
298
444
|
intrabarRun = null;
|
|
299
445
|
varipRun = { slot: 0, recorder: options.recorder ?? null, mode: "live", scratch: null };
|
|
300
446
|
currentBar = -1;
|
|
@@ -309,6 +455,8 @@ function runBody(body, barsInput, inputs, chart2, options, inc) {
|
|
|
309
455
|
throw err;
|
|
310
456
|
}
|
|
311
457
|
if (missingSymbols.length) throw new MissingSymbolDataError(missingSymbols);
|
|
458
|
+
if (ctx.strict) checkInputNames(ctx, inputs);
|
|
459
|
+
if (ctx.paneAuto) ctx.overlay = plotsOnPrices(ctx);
|
|
312
460
|
if (inc) incremental.bodyDone();
|
|
313
461
|
const c = ctx;
|
|
314
462
|
return {
|
|
@@ -318,7 +466,8 @@ function runBody(body, barsInput, inputs, chart2, options, inc) {
|
|
|
318
466
|
overlay: c.overlay,
|
|
319
467
|
precision: c.precision,
|
|
320
468
|
format: c.format,
|
|
321
|
-
...c.scale ? { scale: c.scale } : {}
|
|
469
|
+
...c.scale ? { scale: c.scale } : {},
|
|
470
|
+
...c.pane ? { pane: c.pane } : {}
|
|
322
471
|
},
|
|
323
472
|
inputConfig: c.inputConfig,
|
|
324
473
|
plotConfig: c.plotConfig,
|
|
@@ -351,7 +500,8 @@ function runBody(body, barsInput, inputs, chart2, options, inc) {
|
|
|
351
500
|
logs: c.logs.length ? [...c.logs].sort((x, y) => x.bar - y.bar).slice(-MAX_LOG_ENTRIES) : void 0
|
|
352
501
|
},
|
|
353
502
|
hasAlertFunction: c.hasAlertFunction,
|
|
354
|
-
usesVisibleRange: c.usesVisibleRange
|
|
503
|
+
usesVisibleRange: c.usesVisibleRange,
|
|
504
|
+
warnings: runWarnings()
|
|
355
505
|
};
|
|
356
506
|
} finally {
|
|
357
507
|
ctx = null;
|
|
@@ -700,7 +850,15 @@ function indicator(title, options = {}) {
|
|
|
700
850
|
declare(c, "indicator");
|
|
701
851
|
c.title = title;
|
|
702
852
|
c.shortTitle = options.shorttitle;
|
|
703
|
-
|
|
853
|
+
if (options.pane !== void 0) {
|
|
854
|
+
if (!["price", "separate", "auto"].includes(options.pane)) {
|
|
855
|
+
throw new ScriptError(`indicator(): pane is 'price', 'separate' or 'auto', got ${shown(options.pane)}.`);
|
|
856
|
+
}
|
|
857
|
+
if (options.overlay !== void 0) throw new ScriptError("indicator(): give overlay or pane, not both.");
|
|
858
|
+
}
|
|
859
|
+
c.overlay = options.pane === "price" ? true : options.pane === void 0 ? options.overlay ?? false : false;
|
|
860
|
+
c.paneAuto = options.pane === "auto";
|
|
861
|
+
c.pane = options.pane;
|
|
704
862
|
c.precision = options.precision;
|
|
705
863
|
c.format = options.format;
|
|
706
864
|
c.scale = options.scale;
|
|
@@ -753,14 +911,27 @@ function common(opts) {
|
|
|
753
911
|
if (opts.confirm !== void 0) out.confirm = opts.confirm;
|
|
754
912
|
if (opts.display !== void 0) out.display = opts.display;
|
|
755
913
|
if (opts.active !== void 0) out.active = opts.active;
|
|
914
|
+
if (opts.id !== void 0) out.id = opts.id;
|
|
756
915
|
return out;
|
|
757
916
|
}
|
|
758
917
|
function registerInput(config, fallbackId) {
|
|
759
918
|
const c = collector();
|
|
760
|
-
const
|
|
761
|
-
|
|
919
|
+
const wanted = config.id;
|
|
920
|
+
let id;
|
|
921
|
+
if (wanted !== void 0) {
|
|
922
|
+
if (typeof wanted !== "string" || !/^[A-Za-z_]\w*$/.test(wanted)) {
|
|
923
|
+
throw new ScriptError(`input id ${shown(wanted)}: letters, digits and _ only, not starting with a digit, e.g. "fast_length".`);
|
|
924
|
+
}
|
|
925
|
+
if (c.inputIds.has(wanted)) throw new ScriptError(`Two inputs have the id "${wanted}": give each its own.`);
|
|
926
|
+
c.inputIds.add(wanted);
|
|
927
|
+
id = wanted;
|
|
928
|
+
} else {
|
|
929
|
+
id = slugId(config.title, fallbackId, c.inputIds);
|
|
930
|
+
}
|
|
931
|
+
c.inputConfig.push({ ...config, id });
|
|
762
932
|
c.defaultInputs[id] = config.defval;
|
|
763
933
|
const value = c.inputValues[id];
|
|
934
|
+
if (c.strict && value !== void 0) checkInputValue({ id, ...config }, id, value);
|
|
764
935
|
return value === void 0 ? config.defval : value;
|
|
765
936
|
}
|
|
766
937
|
function registerNumeric(type, defval, title, opts = {}, idKind = type) {
|
|
@@ -770,7 +941,7 @@ function registerNumeric(type, defval, title, opts = {}, idKind = type) {
|
|
|
770
941
|
);
|
|
771
942
|
return typeof v === "number" ? v : defval;
|
|
772
943
|
}
|
|
773
|
-
const COMMON_INPUT_KEYS = ["tooltip", "inline", "group", "confirm", "display", "active"];
|
|
944
|
+
const COMMON_INPUT_KEYS = ["tooltip", "inline", "group", "confirm", "display", "active", "id"];
|
|
774
945
|
const INPUT_KEYS = {
|
|
775
946
|
int: ["defval", "title", "minval", "maxval", "step", "options", ...COMMON_INPUT_KEYS],
|
|
776
947
|
float: ["defval", "title", "minval", "maxval", "step", "options", ...COMMON_INPUT_KEYS],
|
|
@@ -816,67 +987,207 @@ function inputArgs(kind, defvalOrArgs, titleOrArgs, opts) {
|
|
|
816
987
|
};
|
|
817
988
|
}
|
|
818
989
|
const input = strictNamespace("input", {
|
|
990
|
+
/**
|
|
991
|
+
* Declares a whole-number setting (a length, a count) and returns its value, rounded to an integer.
|
|
992
|
+
* @param defval - Default value, or every argument by name (`{ defval, title, minval... }`).
|
|
993
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_int`).
|
|
994
|
+
* @param opts - `minval`, `maxval`, `step`, `options` (a choice list) and the common input options.
|
|
995
|
+
* @returns The current value: the user's value, else `defval`.
|
|
996
|
+
* @example
|
|
997
|
+
* ```js
|
|
998
|
+
* const length = input.int(14, "Length", { minval: 1, maxval: 500 });
|
|
999
|
+
* plot(ta.rsi(close, length), "RSI");
|
|
1000
|
+
* ```
|
|
1001
|
+
*/
|
|
819
1002
|
int(defval, title, opts) {
|
|
820
1003
|
const a = inputArgs("int", defval, title, opts);
|
|
821
1004
|
return Math.round(registerNumeric("int", a.defval, a.title, a.opts));
|
|
822
1005
|
},
|
|
1006
|
+
/**
|
|
1007
|
+
* Declares a decimal-number setting (a multiplier, a percent, a level) and returns its value.
|
|
1008
|
+
* @param defval - Default value, or every argument by name (`{ defval, title, minval... }`).
|
|
1009
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_float`).
|
|
1010
|
+
* @param opts - `minval`, `maxval`, `step`, `options` (a choice list) and the common input options.
|
|
1011
|
+
* @returns The current value: the user's value, else `defval`.
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```js
|
|
1014
|
+
* const mult = input.float(2.0, "Multiplier", { minval: 0.1, step: 0.1 });
|
|
1015
|
+
* const [basis, upper, lower] = ta.bb(close, 20, mult);
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
823
1018
|
float(defval, title, opts) {
|
|
824
1019
|
const a = inputArgs("float", defval, title, opts);
|
|
825
1020
|
return registerNumeric("float", a.defval, a.title, a.opts);
|
|
826
1021
|
},
|
|
1022
|
+
/**
|
|
1023
|
+
* Declares an on / off setting (a checkbox) and returns its value. Shown only in the settings by default.
|
|
1024
|
+
* @param defval - Default value, or every argument by name (`{ defval, title... }`).
|
|
1025
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_bool`).
|
|
1026
|
+
* @param opts - The common input options (`group`, `inline`, `tooltip`, `confirm`, `display`, `active`, `id`).
|
|
1027
|
+
* @returns The current value: the user's value, else `defval`.
|
|
1028
|
+
* @example
|
|
1029
|
+
* ```js
|
|
1030
|
+
* const showMa = input.bool(true, "Show MA");
|
|
1031
|
+
* plot(ta.sma(close, 20), "MA", { display: showMa ? display.all : display.none });
|
|
1032
|
+
* ```
|
|
1033
|
+
*/
|
|
827
1034
|
bool(defval, title, opts) {
|
|
828
1035
|
const a = inputArgs("bool", defval, title, opts);
|
|
829
1036
|
return registerInput({ type: "bool", defval: a.defval, title: a.title, ...common(a.opts) }, "input_bool");
|
|
830
1037
|
},
|
|
1038
|
+
/**
|
|
1039
|
+
* Declares a text setting and returns its value; with `options`, a drop-down list of choices.
|
|
1040
|
+
* @param defval - Default value (one of `options` when they are given), or every argument by name.
|
|
1041
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_string`).
|
|
1042
|
+
* @param opts - `options` (a choice list) and the common input options.
|
|
1043
|
+
* @returns The current value: the user's value, else `defval`.
|
|
1044
|
+
* @example
|
|
1045
|
+
* ```js
|
|
1046
|
+
* const maType = input.string("EMA", "MA type", { options: ["SMA", "EMA"] });
|
|
1047
|
+
* const ma = maType === "SMA" ? ta.sma(close, 20) : ta.ema(close, 20);
|
|
1048
|
+
* ```
|
|
1049
|
+
*/
|
|
831
1050
|
string(defval, title, opts) {
|
|
832
1051
|
const a = inputArgs("string", defval, title, opts);
|
|
833
1052
|
return registerInput({ type: "string", defval: a.defval, title: a.title, options: a.opts.options, ...common(a.opts) }, "input_string");
|
|
834
1053
|
},
|
|
835
|
-
/**
|
|
1054
|
+
/**
|
|
1055
|
+
* Declares a multi-line text setting (lines separated by a newline) and returns its value, e.g. a list of levels
|
|
1056
|
+
* the script parses. Shown only in the settings by default.
|
|
1057
|
+
* @param defval - Default text, or every argument by name.
|
|
1058
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_text_area`).
|
|
1059
|
+
* @param opts - The common input options.
|
|
1060
|
+
* @returns The current text: the user's text, else `defval`.
|
|
1061
|
+
* @example
|
|
1062
|
+
* ```js
|
|
1063
|
+
* const text = input.text_area("100\n105\n110", "Levels");
|
|
1064
|
+
* for (const lvl of text.split("\n")) hline(Number(lvl), "Level " + lvl);
|
|
1065
|
+
* ```
|
|
1066
|
+
*/
|
|
836
1067
|
text_area(defval, title, opts) {
|
|
837
1068
|
const a = inputArgs("text_area", defval, title, opts);
|
|
838
1069
|
return registerInput({ type: "text_area", defval: a.defval, title: a.title, ...common(a.opts) }, "input_text_area");
|
|
839
1070
|
},
|
|
840
1071
|
/**
|
|
841
|
-
* Declares a colour
|
|
842
|
-
* `color.new(c, 90)`
|
|
1072
|
+
* Declares a colour setting (a colour picker) and returns its value. The default's transparency is kept to 2
|
|
1073
|
+
* decimals (`color.new(c, 90)` gives the alpha byte 26); a value given by the host is used as it is. Shown only in
|
|
1074
|
+
* the settings by default.
|
|
1075
|
+
* @param defval - Default colour (`color.blue`, `"#2962FF"`, `color.new(...)`), or every argument by name.
|
|
1076
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_color`).
|
|
1077
|
+
* @param opts - The common input options.
|
|
1078
|
+
* @returns The current colour string: the user's colour, else `defval`.
|
|
1079
|
+
* @example
|
|
1080
|
+
* ```js
|
|
1081
|
+
* const lineColor = input.color(color.teal, "Line colour");
|
|
1082
|
+
* plot(ta.ema(close, 20), "EMA", { color: lineColor });
|
|
1083
|
+
* ```
|
|
843
1084
|
*/
|
|
844
1085
|
color(defval, title, opts) {
|
|
845
1086
|
const a = inputArgs("color", defval, title, opts);
|
|
846
1087
|
return registerInput({ type: "color", defval: (0, import_parse.inputColorDefault)(a.defval), title: a.title, ...common(a.opts) }, "input_color");
|
|
847
1088
|
},
|
|
848
|
-
/**
|
|
1089
|
+
/**
|
|
1090
|
+
* Declares a source setting (the price a calculation reads) and returns it as a Series. The choices are `open`,
|
|
1091
|
+
* `high`, `low`, `close`, `volume`, `hl2`, `hlc3`, `ohlc4`, `hlcc4`, and the outputs of other scripts on the chart
|
|
1092
|
+
* when the host allows it (an unknown source gives `close`).
|
|
1093
|
+
* @param defval - Default source, by name (`"close"`) or as the built-in Series (`close`), or every argument by
|
|
1094
|
+
* name. Default: `"close"`.
|
|
1095
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_source`).
|
|
1096
|
+
* @param opts - The common input options.
|
|
1097
|
+
* @returns The chosen source as a Series.
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```js
|
|
1100
|
+
* const src = input.source(close, "Source");
|
|
1101
|
+
* plot(ta.sma(src, 20), "SMA");
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
849
1104
|
source(defval = "close", title, opts) {
|
|
850
1105
|
const a = inputArgs("source", defval, title, opts);
|
|
851
1106
|
const name = registerInput({ type: "source", defval: sourceName(a.defval ?? "close"), title: a.title, ...common(a.opts) }, "input_source");
|
|
852
1107
|
return sourceSeries(name);
|
|
853
1108
|
},
|
|
854
|
-
/**
|
|
1109
|
+
/**
|
|
1110
|
+
* Declares a timeframe setting (a timeframe picker) and returns its value, for `request.security()` or
|
|
1111
|
+
* `timeframe.change()`.
|
|
1112
|
+
* @param defval - Default timeframe: `"60"` (60 minutes), `"D"`, `"W"`, `"M"`...; `""` is the chart's timeframe.
|
|
1113
|
+
* Or every argument by name.
|
|
1114
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_timeframe`).
|
|
1115
|
+
* @param opts - `options` (a choice list of timeframes) and the common input options.
|
|
1116
|
+
* @returns The current timeframe string (`""`: the chart's timeframe).
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```js
|
|
1119
|
+
* const tf = input.timeframe("D", "Higher timeframe");
|
|
1120
|
+
* const htfClose = request.security("", tf, () => close);
|
|
1121
|
+
* ```
|
|
1122
|
+
*/
|
|
855
1123
|
timeframe(defval, title, opts) {
|
|
856
1124
|
const a = inputArgs("timeframe", defval, title, opts);
|
|
857
1125
|
return registerInput({ type: "timeframe", defval: a.defval, title: a.title, options: a.opts.options, ...common(a.opts) }, "input_timeframe");
|
|
858
1126
|
},
|
|
859
|
-
/**
|
|
1127
|
+
/**
|
|
1128
|
+
* Declares a trading-hours setting and returns its value, a session string for `time()` or `inSession()`.
|
|
1129
|
+
* @param defval - Default session: `"HHMM-HHMM"`, optionally followed by `:` and the days (1 = Sunday ...
|
|
1130
|
+
* 7 = Saturday), e.g. `"0930-1600"` or `"0930-1600:23456"`. Or every argument by name.
|
|
1131
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_session`).
|
|
1132
|
+
* @param opts - `options` (a choice list of sessions) and the common input options.
|
|
1133
|
+
* @returns The current session string.
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```js
|
|
1136
|
+
* const sess = input.session("0930-1600", "Session");
|
|
1137
|
+
* bgcolor(color.when(na(time("", sess)).not(), color.new(color.blue, 90)));
|
|
1138
|
+
* ```
|
|
1139
|
+
*/
|
|
860
1140
|
session(defval, title, opts) {
|
|
861
1141
|
const a = inputArgs("session", defval, title, opts);
|
|
862
1142
|
return registerInput({ type: "session", defval: a.defval, title: a.title, options: a.opts.options, ...common(a.opts) }, "input_session");
|
|
863
1143
|
},
|
|
864
|
-
/**
|
|
1144
|
+
/**
|
|
1145
|
+
* Declares a symbol setting (a symbol search) and returns its value, a ticker id for `request.security()` of
|
|
1146
|
+
* another symbol.
|
|
1147
|
+
* @param defval - Default ticker id, `"EXCHANGE:TICKER"` (`"NASDAQ:MSFT"`), or every argument by name.
|
|
1148
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_symbol`).
|
|
1149
|
+
* @param opts - `options` (a choice list of symbols) and the common input options.
|
|
1150
|
+
* @returns The current ticker id.
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```js
|
|
1153
|
+
* const other = input.symbol("NASDAQ:MSFT", "Compare with");
|
|
1154
|
+
* plot(request.security(other, "", () => close), "Other close");
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
865
1157
|
symbol(defval, title, opts) {
|
|
866
1158
|
const a = inputArgs("symbol", defval, title, opts);
|
|
867
1159
|
return registerInput({ type: "symbol", defval: a.defval, title: a.title, options: a.opts.options, ...common(a.opts) }, "input_symbol");
|
|
868
1160
|
},
|
|
869
1161
|
/**
|
|
870
|
-
*
|
|
871
|
-
*
|
|
1162
|
+
* Declares a price-level setting (a number field) and returns its value. With `confirm: true` the host can ask the
|
|
1163
|
+
* user to pick it on the chart; an `inline` id shared with an `input.time()` makes one chart point of both.
|
|
1164
|
+
* @param defval - Default price, or every argument by name.
|
|
1165
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_float`).
|
|
1166
|
+
* @param opts - The common input options.
|
|
1167
|
+
* @returns The current price: the user's value, else `defval`.
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```js
|
|
1170
|
+
* const level = input.price(100, "Level", { confirm: true });
|
|
1171
|
+
* hline(level, "Level");
|
|
1172
|
+
* ```
|
|
872
1173
|
*/
|
|
873
1174
|
price(defval, title, opts) {
|
|
874
1175
|
const a = inputArgs("price", defval, title, opts);
|
|
875
1176
|
return registerNumeric("price", a.defval, a.title, a.opts, "float");
|
|
876
1177
|
},
|
|
877
1178
|
/**
|
|
878
|
-
*
|
|
879
|
-
*
|
|
1179
|
+
* Declares a choice among the fields of an enum made with `defineEnum()` and returns the chosen field. The
|
|
1180
|
+
* settings list the fields by title; the host stores the field's name.
|
|
1181
|
+
* @param defval - Default field (`MaType.sma`), or every argument by name. It must be one of `options`.
|
|
1182
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_enum`).
|
|
1183
|
+
* @param opts - `options` (only these fields of the enum) and the common input options.
|
|
1184
|
+
* @returns The chosen field; compare it with `===`.
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```js
|
|
1187
|
+
* const MaType = defineEnum({ sma: "Simple", ema: "Exponential" });
|
|
1188
|
+
* const maType = input.enum(MaType.sma, "Average");
|
|
1189
|
+
* const ma = maType === MaType.ema ? ta.ema(close, 20) : ta.sma(close, 20);
|
|
1190
|
+
* ```
|
|
880
1191
|
*/
|
|
881
1192
|
enum(defval, title, opts) {
|
|
882
1193
|
const a = inputArgs("enum", defval, title, opts);
|
|
@@ -900,7 +1211,19 @@ const input = strictNamespace("input", {
|
|
|
900
1211
|
);
|
|
901
1212
|
return choices.find((f) => f.name === name) ?? a.defval;
|
|
902
1213
|
},
|
|
903
|
-
/**
|
|
1214
|
+
/**
|
|
1215
|
+
* Declares a date-and-time setting and returns it as a UNIX time in milliseconds. With `confirm: true` the host
|
|
1216
|
+
* can ask the user to pick it on the chart. Shown only in the settings by default.
|
|
1217
|
+
* @param defval - Default time in ms, usually from `timestamp()`, or every argument by name.
|
|
1218
|
+
* @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_time`).
|
|
1219
|
+
* @param opts - The common input options.
|
|
1220
|
+
* @returns The current time in ms: the user's value, else `defval`.
|
|
1221
|
+
* @example
|
|
1222
|
+
* ```js
|
|
1223
|
+
* const start = input.time(timestamp("2024-01-01"), "Start");
|
|
1224
|
+
* bgcolor(color.when(time.gte(start), color.new(color.green, 90)));
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
904
1227
|
time(defval, title, opts) {
|
|
905
1228
|
const a = inputArgs("time", defval, title, opts);
|
|
906
1229
|
const v = registerInput({ type: "time", defval: a.defval, title: a.title, ...common(a.opts) }, "input_time");
|
|
@@ -967,6 +1290,8 @@ function editDistance(a, b) {
|
|
|
967
1290
|
return row[b.length];
|
|
968
1291
|
}
|
|
969
1292
|
const PROBED_NAMES = /* @__PURE__ */ new Set(["then", "toJSON", "asymmetricMatch", "nodeType", "tagName", "inspect", "default"]);
|
|
1293
|
+
function sameKeys(_same) {
|
|
1294
|
+
}
|
|
970
1295
|
function strictNamespace(name, members) {
|
|
971
1296
|
return new Proxy(members, {
|
|
972
1297
|
get(target, prop, receiver) {
|
|
@@ -985,7 +1310,7 @@ function strictNamespace(name, members) {
|
|
|
985
1310
|
}
|
|
986
1311
|
});
|
|
987
1312
|
}
|
|
988
|
-
function outsideBarLoops(members) {
|
|
1313
|
+
function outsideBarLoops(members, ns = "ta") {
|
|
989
1314
|
const out = {};
|
|
990
1315
|
for (const [key, value] of Object.entries(members)) {
|
|
991
1316
|
if (typeof value !== "function") {
|
|
@@ -996,7 +1321,7 @@ function outsideBarLoops(members) {
|
|
|
996
1321
|
out[key] = function(...args) {
|
|
997
1322
|
if (currentBar >= 0) {
|
|
998
1323
|
throw new Error(
|
|
999
|
-
|
|
1324
|
+
`${ns}.${key}() was called inside eachBar(): a ${ns}.* call computes the whole Series at once. Compute it before the loop (const x = ${ns}.${key}(...)) and read the bar's value with c.get(x). For a Pine ta.* call inside an if block or a for loop, use the callsite.* call sites.`
|
|
1000
1325
|
);
|
|
1001
1326
|
}
|
|
1002
1327
|
return fn.apply(this, args);
|
|
@@ -1096,8 +1421,10 @@ const steppedTa = {
|
|
|
1096
1421
|
() => taSeries.stoch(source, highSource, lowSource, length)
|
|
1097
1422
|
)
|
|
1098
1423
|
};
|
|
1099
|
-
const ta =
|
|
1100
|
-
|
|
1424
|
+
const { ta: _libraryTa, ...taFunctions } = taSeries;
|
|
1425
|
+
void _libraryTa;
|
|
1426
|
+
const taMembers = strictNamespace("ta", outsideBarLoops({
|
|
1427
|
+
...taFunctions,
|
|
1101
1428
|
...steppedTa,
|
|
1102
1429
|
tr: (handleNa = false) => stepped("tr", () => import_step.taStep.tr(handleNa), [high, low, close], (v, i) => [at(v, 0, i), at(v, 1, i), at(v, 2, i)], 1, () => taSeries.tr(bars(), handleNa)),
|
|
1103
1430
|
atr: (length) => stepped("atr", () => import_step.taStep.atr(length), [high, low, close], (v, i) => [at(v, 0, i), at(v, 1, i), at(v, 2, i)], 1, () => taSeries.atr(bars(), length)),
|
|
@@ -1163,8 +1490,11 @@ const ta = strictNamespace("ta", outsideBarLoops({
|
|
|
1163
1490
|
pvi: barsSeries(taSeries.pvi),
|
|
1164
1491
|
iii: barsSeries(taSeries.iii),
|
|
1165
1492
|
wad: barsSeries(taSeries.wad),
|
|
1166
|
-
wvad: barsSeries(taSeries.wvad)
|
|
1493
|
+
wvad: barsSeries(taSeries.wvad),
|
|
1494
|
+
zigzag: (deviation, depth, backstep) => taSeries.zigzag(bars(), deviation, depth, backstep)
|
|
1167
1495
|
}));
|
|
1496
|
+
const ta = taMembers;
|
|
1497
|
+
sameKeys(true);
|
|
1168
1498
|
function fixnan(source) {
|
|
1169
1499
|
if (source instanceof import_series.Series) return import_series.Series.fromArray(ctxBars, (0, import_utils.fixnan)(source.toArray()));
|
|
1170
1500
|
return withPalette((0, import_utils.fixnan)(source), colorPalettes.get(source));
|
|
@@ -1208,31 +1538,68 @@ function fromGradient(value, bottom_value, top_value, bottom_color, top_color) {
|
|
|
1208
1538
|
(_, i) => colorCore.from_gradient(at2(v, value, i), at2(lo, bottom_value, i), at2(hi, top_value, i), colorAt(bottom_color, i), colorAt(top_color, i))
|
|
1209
1539
|
);
|
|
1210
1540
|
}
|
|
1211
|
-
const
|
|
1541
|
+
const colorMembers = strictNamespace("color", {
|
|
1212
1542
|
...colorCore,
|
|
1213
1543
|
new: colorCore.new_color,
|
|
1214
1544
|
from_gradient: fromGradient,
|
|
1215
|
-
when: colorWhen
|
|
1545
|
+
when: colorWhen,
|
|
1546
|
+
/**
|
|
1547
|
+
* Not in PineScript: the colour faded by `amount`, from 0 (unchanged) to 1 (invisible): `color.fade(color.red, 0.8)`
|
|
1548
|
+
* is `color.new(color.red, 80)`.
|
|
1549
|
+
*/
|
|
1550
|
+
fade: (c, amount) => {
|
|
1551
|
+
if (typeof amount !== "number" || !(amount >= 0 && amount <= 1)) {
|
|
1552
|
+
throw new ScriptError(`color.fade(): the amount is from 0 (unchanged) to 1 (invisible), got ${shown(amount)}.`);
|
|
1553
|
+
}
|
|
1554
|
+
return colorCore.new_color(c, amount * 100);
|
|
1555
|
+
}
|
|
1216
1556
|
});
|
|
1557
|
+
const color = colorMembers;
|
|
1558
|
+
sameKeys(true);
|
|
1217
1559
|
const DEFAULT_OUTPUT_TITLES = {
|
|
1560
|
+
/** Title of a `plot()` without one. */
|
|
1218
1561
|
plot: "Plot",
|
|
1562
|
+
/** Title of an `hline()` without one. */
|
|
1219
1563
|
hline: "Level",
|
|
1564
|
+
/** Title of a `fill()` between two plots without one. */
|
|
1220
1565
|
plotFill: "Plots Background",
|
|
1566
|
+
/** Title of a `fill()` between two hlines without one. */
|
|
1221
1567
|
hlineFill: "Hlines Background",
|
|
1568
|
+
/** Title of a `plotshape()` without one. */
|
|
1222
1569
|
shape: "Shapes",
|
|
1570
|
+
/** Title of a `plotchar()` without one. */
|
|
1223
1571
|
char: "Chars",
|
|
1572
|
+
/** Title of a `plotarrow()` without one. */
|
|
1224
1573
|
arrow: "Arrows",
|
|
1574
|
+
/** Title of a `bgcolor()` without one. */
|
|
1225
1575
|
bgcolor: "Background Color",
|
|
1576
|
+
/** Title of a `barcolor()` without one. */
|
|
1226
1577
|
barcolor: "Bar Color",
|
|
1578
|
+
/** Title of a `plotcandle()` without one. */
|
|
1227
1579
|
candle: "PlotCandle",
|
|
1580
|
+
/** Title of a `plotbar()` without one. */
|
|
1228
1581
|
bar: "PlotBar"
|
|
1229
1582
|
};
|
|
1230
|
-
|
|
1583
|
+
const PLOT_OPTION_KEYS = ["offset", "color", "linewidth", "style", "linestyle", "display", "histbase", "force_overlay", "editable"];
|
|
1584
|
+
function plotImpl(source, title = DEFAULT_OUTPUT_TITLES.plot, options = {}) {
|
|
1231
1585
|
if (intrabarRun) return { id: "", kind: "plot" };
|
|
1232
1586
|
const c = collector();
|
|
1233
|
-
|
|
1587
|
+
if (c.strict && typeof title !== "string") throw new ScriptError(`plot(): the title is a text, e.g. plot(rsi, "RSI"), got ${shown(title)}.`);
|
|
1588
|
+
checkOptions("plot", options, PLOT_OPTION_KEYS);
|
|
1589
|
+
const series = typeof source === "number" ? new import_series.Series(ctxBars, () => source) : source;
|
|
1590
|
+
if (!(series instanceof import_series.Series)) {
|
|
1591
|
+
throw new TypeError(`plot(): the value to plot is a series (close, ta.sma(close, 14)...) or a number, got ${shown(source)}.`);
|
|
1592
|
+
}
|
|
1593
|
+
const id = scriptOptions.plotIds === "title" ? slugId(title, `plot${c.plotConfig.length}`, c.plotIdsTaken ??= /* @__PURE__ */ new Set()) : `plot${c.plotConfig.length}`;
|
|
1234
1594
|
const perBar2 = Array.isArray(options.color) ? options.color : void 0;
|
|
1235
|
-
const
|
|
1595
|
+
const palette = scriptOptions.palette === true ? DEFAULT_PALETTE : Array.isArray(scriptOptions.palette) && scriptOptions.palette.length ? scriptOptions.palette : null;
|
|
1596
|
+
let fallback = "#2962FF";
|
|
1597
|
+
if (palette && options.color === void 0) {
|
|
1598
|
+
const k = c.paletteUsed ?? 0;
|
|
1599
|
+
c.paletteUsed = k + 1;
|
|
1600
|
+
fallback = palette[k % palette.length];
|
|
1601
|
+
}
|
|
1602
|
+
const staticColor2 = typeof options.color === "string" ? options.color : perBar2?.[perBar2.length - 1] ?? fallback;
|
|
1236
1603
|
c.plotConfig.push({
|
|
1237
1604
|
id,
|
|
1238
1605
|
title,
|
|
@@ -1298,6 +1665,7 @@ const plot = Object.assign(plotImpl, {
|
|
|
1298
1665
|
});
|
|
1299
1666
|
function hlineImpl(price, title = DEFAULT_OUTPUT_TITLES.hline, options = {}) {
|
|
1300
1667
|
const c = collector();
|
|
1668
|
+
checkOptions("hline", options, ["color", "linestyle", "linewidth", "editable"]);
|
|
1301
1669
|
const id = `hline${c.hlineConfig.length}`;
|
|
1302
1670
|
c.hlineConfig.push({
|
|
1303
1671
|
id,
|
|
@@ -1477,10 +1845,13 @@ function emitMarkers(kind, condition, title, options) {
|
|
|
1477
1845
|
c.markers.push(location2 === "absolute" ? { time: time2, ...template, price: v } : { time: time2, ...template });
|
|
1478
1846
|
}
|
|
1479
1847
|
}
|
|
1848
|
+
const SHAPE_OPTION_KEYS = ["style", "location", "color", "text", "textcolor", "size", "offset", "tooltip", "force_overlay", "editable"];
|
|
1480
1849
|
function plotshape(condition, title, options = {}) {
|
|
1850
|
+
checkOptions("plotshape", options, SHAPE_OPTION_KEYS, ["color", "textcolor"]);
|
|
1481
1851
|
emitMarkers("shape", condition, title, options);
|
|
1482
1852
|
}
|
|
1483
1853
|
function plotchar(condition, title, options = {}) {
|
|
1854
|
+
checkOptions("plotchar", options, [...SHAPE_OPTION_KEYS.filter((k) => k !== "style"), "char"], ["color", "textcolor"]);
|
|
1484
1855
|
emitMarkers("char", condition, title, options);
|
|
1485
1856
|
}
|
|
1486
1857
|
function plotarrow(series, title, options = {}) {
|
|
@@ -1546,9 +1917,13 @@ function emitBarColors(kind, colors, options) {
|
|
|
1546
1917
|
}
|
|
1547
1918
|
}
|
|
1548
1919
|
function bgcolor(colors, options = {}) {
|
|
1920
|
+
if (ctx?.strict) checkColor("bgcolor(): the colour", colors);
|
|
1921
|
+
checkOptions("bgcolor", options, ["offset", "title", "force_overlay", "editable"]);
|
|
1549
1922
|
emitBarColors("bgcolor", colors, options);
|
|
1550
1923
|
}
|
|
1551
1924
|
function barcolor(colors, options = {}) {
|
|
1925
|
+
if (ctx?.strict) checkColor("barcolor(): the colour", colors);
|
|
1926
|
+
checkOptions("barcolor", options, ["title", "editable"]);
|
|
1552
1927
|
emitBarColors("barcolor", colors, options);
|
|
1553
1928
|
}
|
|
1554
1929
|
function candleColor(col, i) {
|
|
@@ -1568,7 +1943,14 @@ function ohlcRows(o, h, l, cl) {
|
|
|
1568
1943
|
return rows;
|
|
1569
1944
|
}
|
|
1570
1945
|
const staticColor = (col) => typeof col === "string" ? col : void 0;
|
|
1571
|
-
const DEFAULT_CANDLE_COLORS = {
|
|
1946
|
+
const DEFAULT_CANDLE_COLORS = {
|
|
1947
|
+
/** Body colour (and the colour of `plotbar()` bars). */
|
|
1948
|
+
color: "#2962FF",
|
|
1949
|
+
/** Wick colour. */
|
|
1950
|
+
wickColor: "#737375",
|
|
1951
|
+
/** Border colour. */
|
|
1952
|
+
borderColor: "#000000"
|
|
1953
|
+
};
|
|
1572
1954
|
function candlePalettes(cols) {
|
|
1573
1955
|
const palettes = {};
|
|
1574
1956
|
for (const k of ["color", "wickColor", "borderColor"]) {
|
|
@@ -2017,6 +2399,8 @@ const strategy = Object.defineProperties(
|
|
|
2017
2399
|
Object.assign((title, options) => declareStrategy(title, options), strategyMembers),
|
|
2018
2400
|
variableGetters
|
|
2019
2401
|
);
|
|
2402
|
+
sameKeys(true);
|
|
2403
|
+
sameKeys(true);
|
|
2020
2404
|
const SYMBOL_INFO_KEYS = [
|
|
2021
2405
|
"timezone",
|
|
2022
2406
|
"session",
|
|
@@ -2084,7 +2468,8 @@ const timeframe = {
|
|
|
2084
2468
|
return chartTimeframe().period;
|
|
2085
2469
|
},
|
|
2086
2470
|
get main_period() {
|
|
2087
|
-
|
|
2471
|
+
const main = chartCtx.mainTimeframe;
|
|
2472
|
+
return main ? timeframeCore.info(main).period : chartTimeframe().period;
|
|
2088
2473
|
},
|
|
2089
2474
|
get multiplier() {
|
|
2090
2475
|
return chartTimeframe().multiplier;
|
|
@@ -2349,12 +2734,9 @@ const str = strictNamespace("str", {
|
|
|
2349
2734
|
...strCore,
|
|
2350
2735
|
// format.mintick uses the chart symbol's tick and price scale (syminfo.mintick, syminfo.pricescale)
|
|
2351
2736
|
tostring: ((value, format2, mintick, pricescale) => format2 === "mintick" && mintick === void 0 ? strCore.tostring(value, format2, syminfo.mintick, pricescale ?? syminfo.pricescale) : strCore.tostring(value, format2, mintick, pricescale)),
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
format(pattern, ...args) {
|
|
2356
|
-
return (0, import_messageformat.formatMessage)(pattern, args, exchangeTimezone);
|
|
2357
|
-
}
|
|
2737
|
+
// the exchange time zone by default; the documentation is the library function's
|
|
2738
|
+
format_time: ((time2, format2 = "yyyy-MM-dd'T'HH:mm:ssZ", timezone) => strCore.format_time(time2, format2, timezone ?? exchangeTimezone())),
|
|
2739
|
+
format: ((pattern, ...args) => (0, import_messageformat.formatMessage)(pattern, args, exchangeTimezone))
|
|
2358
2740
|
});
|
|
2359
2741
|
function barTime(bar) {
|
|
2360
2742
|
return bar.time * (chartCtx.timeUnit === "ms" ? 1 : 1e3);
|
|
@@ -2580,7 +2962,7 @@ function security(symbol, timeframe2, expression, gaps = barmerge.gaps_off, look
|
|
|
2580
2962
|
let result;
|
|
2581
2963
|
let values;
|
|
2582
2964
|
ctxBars.setAll(htf);
|
|
2583
|
-
chartCtx = { ...chartCtx, timeframe: tf };
|
|
2965
|
+
chartCtx = { ...chartCtx, timeframe: tf, mainTimeframe: chartCtx.mainTimeframe ?? chartCtx.timeframe };
|
|
2584
2966
|
try {
|
|
2585
2967
|
result = expression();
|
|
2586
2968
|
const parts = Array.isArray(result) ? result : [result];
|
|
@@ -2609,7 +2991,13 @@ function runExternal(symbol, heikin, tf, expression, ignoreInvalid, own) {
|
|
|
2609
2991
|
let result;
|
|
2610
2992
|
let values;
|
|
2611
2993
|
ctxBars.setAll(bars2);
|
|
2612
|
-
const seen = {
|
|
2994
|
+
const seen = {
|
|
2995
|
+
...chartCtx,
|
|
2996
|
+
tickerid: symbol,
|
|
2997
|
+
timeframe: tf,
|
|
2998
|
+
mainTickerid: chartCtx.mainTickerid ?? chartCtx.tickerid,
|
|
2999
|
+
mainTimeframe: chartCtx.mainTimeframe ?? chartCtx.timeframe
|
|
3000
|
+
};
|
|
2613
3001
|
for (const key of SYMBOL_INFO_KEYS) seen[key] = info[key];
|
|
2614
3002
|
chartCtx = seen;
|
|
2615
3003
|
try {
|
|
@@ -2803,7 +3191,7 @@ function earningsCall(...args) {
|
|
|
2803
3191
|
const list = (symbolEvents(ticker2).earnings ?? []).filter((e) => e.time <= runNow);
|
|
2804
3192
|
return eventSeries(list.map((e) => e.time), eventField(list, field, "request.earnings", ticker2), a[2], a[3]);
|
|
2805
3193
|
}
|
|
2806
|
-
const
|
|
3194
|
+
const requestMembers = strictNamespace("request", {
|
|
2807
3195
|
security: securityCall,
|
|
2808
3196
|
security_lower_tf: securityLowerTfCall,
|
|
2809
3197
|
seed: seedCall,
|
|
@@ -2811,14 +3199,24 @@ const request = strictNamespace("request", {
|
|
|
2811
3199
|
splits: splitsCall,
|
|
2812
3200
|
earnings: earningsCall
|
|
2813
3201
|
});
|
|
3202
|
+
const request = requestMembers;
|
|
3203
|
+
sameKeys(true);
|
|
2814
3204
|
const loopBar = () => currentBar;
|
|
2815
3205
|
function drawings(name, members, all) {
|
|
2816
3206
|
const out = (0, import_drawing_args.drawingNamespace)(name, members, loopBar);
|
|
2817
3207
|
return Object.defineProperty(out, "all", { get: all, enumerable: true });
|
|
2818
3208
|
}
|
|
2819
|
-
const lineNs = drawings(
|
|
3209
|
+
const lineNs = drawings(
|
|
3210
|
+
"line",
|
|
3211
|
+
{ ...lineCore, ...pineConstants.lineStyles },
|
|
3212
|
+
() => lineCore.all()
|
|
3213
|
+
);
|
|
2820
3214
|
const line = lineNs;
|
|
2821
|
-
const labelNs = drawings(
|
|
3215
|
+
const labelNs = drawings(
|
|
3216
|
+
"label",
|
|
3217
|
+
{ ...labelCore, ...pineConstants.labelStyles },
|
|
3218
|
+
() => labelCore.all()
|
|
3219
|
+
);
|
|
2822
3220
|
const label = labelNs;
|
|
2823
3221
|
const boxNs = drawings("box", { ...boxCore }, () => boxCore.all());
|
|
2824
3222
|
const box = boxNs;
|
|
@@ -2828,8 +3226,8 @@ const polylineNs = drawings("polyline", { ...polylineCore }, () => polylineCore.
|
|
|
2828
3226
|
const polyline = polylineNs;
|
|
2829
3227
|
const tableNs = drawings("table", { ...tableCore }, () => tableCore.all());
|
|
2830
3228
|
const table = tableNs;
|
|
3229
|
+
sameKeys(true);
|
|
2831
3230
|
const text = { ...textCore };
|
|
2832
|
-
const { shape, location, size, xloc, yloc, extend, display, format, font, scale, order, currency, adjustment } = pineConstants;
|
|
2833
3231
|
const chart = {
|
|
2834
3232
|
/** Chart foreground colour (PineScript `chart.fg_color`), from the chart context. */
|
|
2835
3233
|
get fg_color() {
|
|
@@ -2918,11 +3316,13 @@ function alertImpl(message, freq = "once_per_bar") {
|
|
|
2918
3316
|
if (currentBar >= 0) call(currentBar);
|
|
2919
3317
|
else for (let i = 0; i < b.length; i++) call(i);
|
|
2920
3318
|
}
|
|
2921
|
-
const
|
|
3319
|
+
const alertMembers = Object.assign(alertImpl, {
|
|
2922
3320
|
freq_all: "all",
|
|
2923
3321
|
freq_once_per_bar: "once_per_bar",
|
|
2924
3322
|
freq_once_per_bar_close: "once_per_bar_close"
|
|
2925
3323
|
});
|
|
3324
|
+
const alert = alertMembers;
|
|
3325
|
+
sameKeys(true);
|
|
2926
3326
|
const MAX_LOG_ENTRIES = 1e4;
|
|
2927
3327
|
let logLineResolver = null;
|
|
2928
3328
|
function setLogLineResolver(resolver) {
|
|
@@ -2949,7 +3349,7 @@ function logImpl(level, message, args) {
|
|
|
2949
3349
|
else for (let i = 0; i < b.length; i++) add(i);
|
|
2950
3350
|
if (c.logs.length > MAX_LOG_ENTRIES * 2) c.logs.splice(0, c.logs.length - MAX_LOG_ENTRIES);
|
|
2951
3351
|
}
|
|
2952
|
-
const
|
|
3352
|
+
const logMembers = strictNamespace("log", {
|
|
2953
3353
|
info(message, ...args) {
|
|
2954
3354
|
logImpl("info", message, args);
|
|
2955
3355
|
},
|
|
@@ -2960,6 +3360,8 @@ const log = strictNamespace("log", {
|
|
|
2960
3360
|
logImpl("error", message, args);
|
|
2961
3361
|
}
|
|
2962
3362
|
});
|
|
3363
|
+
const log = logMembers;
|
|
3364
|
+
sameKeys(true);
|
|
2963
3365
|
function resumedLogs(before, now, from) {
|
|
2964
3366
|
const kept = (before ?? []).filter((e) => e.bar < from);
|
|
2965
3367
|
const logs = kept.concat((now ?? []).filter((e) => e.bar >= from));
|
|
@@ -2980,4 +3382,72 @@ const math = strictNamespace("math", {
|
|
|
2980
3382
|
return number instanceof import_series.Series ? mathCore.round_to_mintick(number, tick) : mathCore.round_to_mintick(number, tick);
|
|
2981
3383
|
})
|
|
2982
3384
|
});
|
|
3385
|
+
const asSeries = (v) => typeof v === "number" ? import_series.Series.constant(ctxBars, v) : v;
|
|
3386
|
+
const AVERAGE_KINDS = {
|
|
3387
|
+
simple: (s, n) => taSeries.sma(s, n),
|
|
3388
|
+
exponential: (s, n) => taSeries.ema(s, n),
|
|
3389
|
+
weighted: (s, n) => taSeries.wma(s, n),
|
|
3390
|
+
smoothed: (s, n) => taSeries.rma(s, n),
|
|
3391
|
+
hull: (s, n) => taSeries.hma(s, n),
|
|
3392
|
+
"volume-weighted": (s, n) => ta.vwma(s, n)
|
|
3393
|
+
};
|
|
3394
|
+
function checkLength(fn, length) {
|
|
3395
|
+
if (typeof length !== "number" || !Number.isInteger(length) || length < 1) {
|
|
3396
|
+
throw new ScriptError(`calc.${fn}(): the length is a whole number of bars, 1 or more, got ${shown(length)}.`);
|
|
3397
|
+
}
|
|
3398
|
+
return length;
|
|
3399
|
+
}
|
|
3400
|
+
function conditionsOf(name, conditions) {
|
|
3401
|
+
if (!conditions.length) throw new ScriptError(`${name}(): give at least one condition, e.g. ${name}(close.gt(open), volume.gt(0)).`);
|
|
3402
|
+
return conditions.map(asSeries);
|
|
3403
|
+
}
|
|
3404
|
+
const calcMembers = strictNamespace("calc", outsideBarLoops({
|
|
3405
|
+
/** Moving average of the last `length` values: kind 'simple' (default), 'exponential', 'weighted', 'smoothed', 'hull' or 'volume-weighted'. */
|
|
3406
|
+
average(source, length, kind = "simple") {
|
|
3407
|
+
const fn = AVERAGE_KINDS[kind];
|
|
3408
|
+
if (!fn) throw new ScriptError(`calc.average(): the kind is one of ${Object.keys(AVERAGE_KINDS).map((k) => `'${k}'`).join(", ")}, got ${shown(kind)}.`);
|
|
3409
|
+
return fn(asSeries(source), checkLength("average", length));
|
|
3410
|
+
},
|
|
3411
|
+
/** 1 on the bar where `a` crosses above `b`. */
|
|
3412
|
+
crossesAbove: (a, b) => ta.crossover(asSeries(a), b),
|
|
3413
|
+
/** 1 on the bar where `a` crosses below `b`. */
|
|
3414
|
+
crossesBelow: (a, b) => ta.crossunder(asSeries(a), b),
|
|
3415
|
+
/** 1 on the bar where `a` and `b` cross, either way. */
|
|
3416
|
+
crosses: (a, b) => ta.cross(asSeries(a), asSeries(b)),
|
|
3417
|
+
/** 1 where `a` is above `b`. */
|
|
3418
|
+
above: (a, b) => asSeries(a).gt(b),
|
|
3419
|
+
/** 1 where `a` is below `b`. */
|
|
3420
|
+
below: (a, b) => asSeries(a).lt(b),
|
|
3421
|
+
/** 1 where `value` is between `low` and `high` (both included). */
|
|
3422
|
+
between: (value, lowLimit, highLimit) => asSeries(value).gte(lowLimit).and(asSeries(value).lte(highLimit)),
|
|
3423
|
+
/** The value `bars` bars before (1: the previous bar). */
|
|
3424
|
+
previous: (source, bars2 = 1) => asSeries(source).offset(checkLength("previous", bars2)),
|
|
3425
|
+
/** The difference with the value `bars` bars before. */
|
|
3426
|
+
change: (source, bars2 = 1) => taSeries.change(asSeries(source), checkLength("change", bars2)),
|
|
3427
|
+
/** The change in percent since `bars` bars before. */
|
|
3428
|
+
percentChange: (source, bars2 = 1) => {
|
|
3429
|
+
const s = asSeries(source);
|
|
3430
|
+
const before = s.offset(checkLength("percentChange", bars2));
|
|
3431
|
+
return s.sub(before).div(before).mul(100);
|
|
3432
|
+
},
|
|
3433
|
+
/** The highest value of the last `length` bars. */
|
|
3434
|
+
highest: (source, length) => ta.highest(asSeries(source), checkLength("highest", length)),
|
|
3435
|
+
/** The lowest value of the last `length` bars. */
|
|
3436
|
+
lowest: (source, length) => ta.lowest(asSeries(source), checkLength("lowest", length)),
|
|
3437
|
+
/** 1 when the value rose on each of the last `bars` bars. */
|
|
3438
|
+
isRising: (source, bars2 = 1) => taSeries.rising(asSeries(source), checkLength("isRising", bars2)),
|
|
3439
|
+
/** 1 when the value fell on each of the last `bars` bars. */
|
|
3440
|
+
isFalling: (source, bars2 = 1) => taSeries.falling(asSeries(source), checkLength("isFalling", bars2)),
|
|
3441
|
+
/** Standard deviation of the last `length` values. */
|
|
3442
|
+
standardDeviation: (source, length) => taSeries.stdev(asSeries(source), checkLength("standardDeviation", length)),
|
|
3443
|
+
/** `whenTrue` where the condition holds, else `whenFalse`. */
|
|
3444
|
+
ifElse: (condition, whenTrue, whenFalse) => asSeries(condition).iff(whenTrue, whenFalse),
|
|
3445
|
+
/** 1 where every condition holds. */
|
|
3446
|
+
all: (...conditions) => conditionsOf("calc.all", conditions).reduce((x, y) => x.and(y)),
|
|
3447
|
+
/** 1 where one of the conditions holds. */
|
|
3448
|
+
any: (...conditions) => conditionsOf("calc.any", conditions).reduce((x, y) => x.or(y))
|
|
3449
|
+
}, "calc"));
|
|
3450
|
+
const calc = calcMembers;
|
|
3451
|
+
sameKeys(true);
|
|
3452
|
+
const compare = compareCore;
|
|
2983
3453
|
//# sourceMappingURL=index.js.map
|