oakscriptjs 0.24.0 → 0.25.1
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 +1067 -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 +1067 -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 +1519 -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
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as compare from '../compare/index.js';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This class wraps a Bar[] array and tracks a version number that increments
|
|
11
|
-
* whenever the data is mutated. Series objects reference this to detect when
|
|
12
|
-
* their cached values need to be recomputed.
|
|
8
|
+
* Host-side: an array of bars with a version number that grows on every change, so the Series made on it know when
|
|
9
|
+
* their cached values are stale. Scripts do not use it: their Series are made on the chart's bars.
|
|
13
10
|
*
|
|
14
11
|
* @example
|
|
15
12
|
* ```typescript
|
|
@@ -124,35 +121,6 @@ export class BarData {
|
|
|
124
121
|
return new BarData(bars);
|
|
125
122
|
}
|
|
126
123
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Series - represents a time-series of values with lazy evaluation
|
|
129
|
-
*
|
|
130
|
-
* Series are lazy - they don't compute values until needed.
|
|
131
|
-
* Operations on Series return new Series with composed extractors.
|
|
132
|
-
*
|
|
133
|
-
* Now supports automatic cache invalidation via BarData versioning
|
|
134
|
-
* and memory-efficient closure chain breaking via materialize().
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* // Basic usage (backward compatible)
|
|
139
|
-
* const close = Series.fromBars(bars, 'close');
|
|
140
|
-
* const open = Series.fromBars(bars, 'open');
|
|
141
|
-
* const range = close.sub(open); // Creates new Series, doesn't compute yet
|
|
142
|
-
* const values = range.toArray(); // Now computes for all bars
|
|
143
|
-
*
|
|
144
|
-
* // With automatic cache invalidation
|
|
145
|
-
* const barData = new BarData(bars);
|
|
146
|
-
* const close = Series.fromBars(barData, 'close');
|
|
147
|
-
* const values1 = close.toArray(); // Computes and caches
|
|
148
|
-
* barData.push(newBar); // Version increments
|
|
149
|
-
* const values2 = close.toArray(); // Detects stale cache, recomputes
|
|
150
|
-
*
|
|
151
|
-
* // Breaking closure chains for memory efficiency
|
|
152
|
-
* const complex = a.add(b).mul(c).div(d).sub(e);
|
|
153
|
-
* const materialized = complex.materialize(); // Breaks closure chain
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
124
|
/** Largest history reference of a script series (PineScript max_bars_back limit). */
|
|
157
125
|
export const MAX_BARS_BACK = 5000;
|
|
158
126
|
/** PineScript's runtime error RE10008 text. */
|
|
@@ -165,39 +133,53 @@ let runHooks = null;
|
|
|
165
133
|
export function setSeriesRunHooks(hooks) {
|
|
166
134
|
runHooks = hooks;
|
|
167
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* A series: one number per bar, oldest bar first, NaN where the value is missing (na). `close`, `open`, `high`,
|
|
138
|
+
* `low`, `volume`, the `ta.*` results and `input.source()` are Series.
|
|
139
|
+
*
|
|
140
|
+
* JavaScript operators do not work on a Series (`close - open` throws): use its methods, which work on all the bars
|
|
141
|
+
* at once and return a new Series. The other operand can be a Series or a plain number. Comparisons and logic give
|
|
142
|
+
* a Series of 1 (true) and 0 (false). Inside `eachBar()`, read the number of the current bar with `c.get(series)`.
|
|
143
|
+
* Values are computed when first read, then kept.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```js
|
|
147
|
+
* const body = close.sub(open);
|
|
148
|
+
* const up = close.gt(open);
|
|
149
|
+
* plot(up.iff(body, body.neg()), "Body size");
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
168
152
|
export class Series {
|
|
169
153
|
extractor;
|
|
170
154
|
dataSource;
|
|
171
155
|
cached = null;
|
|
172
156
|
cachedVersion = -1;
|
|
173
157
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* @param data - Bar data (Bar[] or BarData)
|
|
177
|
-
* @param extractor - Function to extract/compute value for each bar
|
|
158
|
+
* True for the built-in price series (`open`, `high`, `low`, `close`, `volume`, `hl2`...): their history covers
|
|
159
|
+
* every bar, so `offset()` may reach further than 5000 bars back.
|
|
178
160
|
*/
|
|
161
|
+
fullHistory = false;
|
|
179
162
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
163
|
+
* Makes a Series that computes its value on each bar with a function. Scripts rarely need it: Series come from the
|
|
164
|
+
* builtins, `ta.*` and the Series methods.
|
|
165
|
+
* @param data - The bars the series is aligned to (an array of bars, or a {@link BarData}).
|
|
166
|
+
* @param extractor - Gives the value of bar `index`: `(bar, index, bars) => number`; NaN for na.
|
|
167
|
+
* @example
|
|
168
|
+
* ```js
|
|
169
|
+
* const range = new Series(close.bars, (bar) => bar.high - bar.low);
|
|
170
|
+
* ```
|
|
182
171
|
*/
|
|
183
|
-
fullHistory = false;
|
|
184
172
|
constructor(data, extractor) {
|
|
185
173
|
// Support both Bar[] and BarData for backward compatibility
|
|
186
174
|
this.dataSource = data instanceof BarData ? data : new BarData(data);
|
|
187
175
|
this.extractor = extractor;
|
|
188
176
|
runHooks?.created(this);
|
|
189
177
|
}
|
|
190
|
-
/**
|
|
191
|
-
* Get the underlying bar data
|
|
192
|
-
* @returns Bar array
|
|
193
|
-
*/
|
|
178
|
+
/** The bars this series is aligned to (`{ time, open, high, low, close, volume }`, oldest first). */
|
|
194
179
|
get bars() {
|
|
195
180
|
return this.dataSource.bars;
|
|
196
181
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Get the underlying BarData source
|
|
199
|
-
* @returns BarData instance
|
|
200
|
-
*/
|
|
182
|
+
/** The {@link BarData} holding the bars this series is aligned to. */
|
|
201
183
|
get barData() {
|
|
202
184
|
return this.dataSource;
|
|
203
185
|
}
|
|
@@ -205,10 +187,15 @@ export class Series {
|
|
|
205
187
|
// Static Factory Methods
|
|
206
188
|
// ============================================
|
|
207
189
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* @param
|
|
211
|
-
* @
|
|
190
|
+
* Makes the Series of one field of the bars (the price series). In a script, use the globals `open`, `high`, `low`,
|
|
191
|
+
* `close`, `volume` instead.
|
|
192
|
+
* @param bars - The bars (an array of bars, or a {@link BarData}).
|
|
193
|
+
* @param field - `'open'`, `'high'`, `'low'`, `'close'` or `'volume'`.
|
|
194
|
+
* @returns A Series of that field; NaN where a bar does not have it.
|
|
195
|
+
* @example
|
|
196
|
+
* ```js
|
|
197
|
+
* const myClose = Series.fromBars(close.bars, "close");
|
|
198
|
+
* ```
|
|
212
199
|
*/
|
|
213
200
|
static fromBars(bars, field) {
|
|
214
201
|
const series = new Series(bars, (bar) => bar[field] ?? NaN);
|
|
@@ -216,21 +203,31 @@ export class Series {
|
|
|
216
203
|
return series;
|
|
217
204
|
}
|
|
218
205
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* @param
|
|
222
|
-
* @
|
|
206
|
+
* Makes a Series with the same value on every bar. The Series methods also take plain numbers, so a script seldom
|
|
207
|
+
* needs it.
|
|
208
|
+
* @param bars - The bars to align to (an array of bars, or a {@link BarData}).
|
|
209
|
+
* @param value - The value of every bar (NaN for na).
|
|
210
|
+
* @returns A Series of `value`.
|
|
211
|
+
* @example
|
|
212
|
+
* ```js
|
|
213
|
+
* const level = Series.constant(close.bars, 50);
|
|
214
|
+
* ```
|
|
223
215
|
*/
|
|
224
216
|
static constant(bars, value) {
|
|
225
217
|
return new Series(bars, () => value);
|
|
226
218
|
}
|
|
227
219
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* @param
|
|
231
|
-
* @
|
|
220
|
+
* Makes a Series from an array with one value per bar, oldest first. In a script, `seriesOf(values)` does the same
|
|
221
|
+
* on the chart bars.
|
|
222
|
+
* @param bars - The bars the values belong to (an array of bars, or a {@link BarData}).
|
|
223
|
+
* @param values - One number per bar, oldest first; a missing value reads as NaN.
|
|
224
|
+
* @returns A Series of the values.
|
|
232
225
|
* @throws When read on other bars with a different length than `values` (e.g. a series computed on the
|
|
233
|
-
* chart bars and read inside a `request.security` expression, which runs on the
|
|
226
|
+
* chart bars and read inside a `request.security` expression, which runs on the other timeframe's bars).
|
|
227
|
+
* @example
|
|
228
|
+
* ```js
|
|
229
|
+
* const doubled = Series.fromArray(close.bars, close.toArray().map((v) => v * 2));
|
|
230
|
+
* ```
|
|
234
231
|
*/
|
|
235
232
|
static fromArray(bars, values) {
|
|
236
233
|
const origin = bars instanceof BarData ? bars.bars : bars;
|
|
@@ -246,9 +243,13 @@ export class Series {
|
|
|
246
243
|
// Arithmetic Operations
|
|
247
244
|
// ============================================
|
|
248
245
|
/**
|
|
249
|
-
*
|
|
250
|
-
* @param other - Series or number to add
|
|
251
|
-
* @returns
|
|
246
|
+
* Adds a Series or a number to this series, bar by bar (the `+` of two values). NaN on either side gives NaN.
|
|
247
|
+
* @param other - Series or number to add.
|
|
248
|
+
* @returns A Series of the sums.
|
|
249
|
+
* @example
|
|
250
|
+
* ```js
|
|
251
|
+
* const mid = high.add(low).div(2);
|
|
252
|
+
* ```
|
|
252
253
|
*/
|
|
253
254
|
add(other) {
|
|
254
255
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -258,9 +259,13 @@ export class Series {
|
|
|
258
259
|
});
|
|
259
260
|
}
|
|
260
261
|
/**
|
|
261
|
-
*
|
|
262
|
-
* @param other - Series or number to subtract
|
|
263
|
-
* @returns
|
|
262
|
+
* Subtracts a Series or a number from this series, bar by bar (the `-` of two values). NaN on either side gives NaN.
|
|
263
|
+
* @param other - Series or number to subtract.
|
|
264
|
+
* @returns A Series of the differences.
|
|
265
|
+
* @example
|
|
266
|
+
* ```js
|
|
267
|
+
* const body = close.sub(open);
|
|
268
|
+
* ```
|
|
264
269
|
*/
|
|
265
270
|
sub(other) {
|
|
266
271
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -270,9 +275,13 @@ export class Series {
|
|
|
270
275
|
});
|
|
271
276
|
}
|
|
272
277
|
/**
|
|
273
|
-
*
|
|
274
|
-
* @param other - Series or number to multiply
|
|
275
|
-
* @returns
|
|
278
|
+
* Multiplies this series by a Series or a number, bar by bar (the `*` of two values). NaN on either side gives NaN.
|
|
279
|
+
* @param other - Series or number to multiply by.
|
|
280
|
+
* @returns A Series of the products.
|
|
281
|
+
* @example
|
|
282
|
+
* ```js
|
|
283
|
+
* const upper = ta.sma(close, 20).mul(1.02);
|
|
284
|
+
* ```
|
|
276
285
|
*/
|
|
277
286
|
mul(other) {
|
|
278
287
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -282,9 +291,14 @@ export class Series {
|
|
|
282
291
|
});
|
|
283
292
|
}
|
|
284
293
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* @
|
|
294
|
+
* Raises this series to a power, bar by bar (`math.pow` on a series). NaN on either side gives NaN; a negative base
|
|
295
|
+
* with a fractional exponent gives NaN.
|
|
296
|
+
* @param exponent - Series or number exponent.
|
|
297
|
+
* @returns A Series of `this ** exponent`.
|
|
298
|
+
* @example
|
|
299
|
+
* ```js
|
|
300
|
+
* const squared = close.sub(ta.sma(close, 20)).pow(2);
|
|
301
|
+
* ```
|
|
288
302
|
*/
|
|
289
303
|
pow(exponent) {
|
|
290
304
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -294,9 +308,15 @@ export class Series {
|
|
|
294
308
|
});
|
|
295
309
|
}
|
|
296
310
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* @
|
|
311
|
+
* Divides this series by a Series or a number, bar by bar (the `/` of two values). A division by 0 gives
|
|
312
|
+
* +/-Infinity (which `na()` treats as na), 0 / 0 and NaN on either side give NaN.
|
|
313
|
+
* @param other - Series or number to divide by.
|
|
314
|
+
* @returns A Series of the quotients.
|
|
315
|
+
* @example
|
|
316
|
+
* ```js
|
|
317
|
+
* const range = high.sub(low);
|
|
318
|
+
* const ratio = range.gt(0).iff(close.sub(open).div(range), 0);
|
|
319
|
+
* ```
|
|
300
320
|
*/
|
|
301
321
|
div(other) {
|
|
302
322
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -306,9 +326,14 @@ export class Series {
|
|
|
306
326
|
});
|
|
307
327
|
}
|
|
308
328
|
/**
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
* @
|
|
329
|
+
* Remainder of the division of this series by a Series or a number, bar by bar (the `%` of two values). The
|
|
330
|
+
* remainder has the sign of this series; a divisor of 0 and NaN on either side give NaN.
|
|
331
|
+
* @param other - Series or number to divide by.
|
|
332
|
+
* @returns A Series of the remainders.
|
|
333
|
+
* @example
|
|
334
|
+
* ```js
|
|
335
|
+
* const everyFifth = bar_index.mod(5).eq(0);
|
|
336
|
+
* ```
|
|
312
337
|
*/
|
|
313
338
|
mod(other) {
|
|
314
339
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -318,8 +343,12 @@ export class Series {
|
|
|
318
343
|
});
|
|
319
344
|
}
|
|
320
345
|
/**
|
|
321
|
-
*
|
|
322
|
-
* @returns
|
|
346
|
+
* Changes the sign of every value (the unary `-`). NaN stays NaN.
|
|
347
|
+
* @returns A Series of the opposite values.
|
|
348
|
+
* @example
|
|
349
|
+
* ```js
|
|
350
|
+
* const drop = close.sub(close.offset(1)).neg();
|
|
351
|
+
* ```
|
|
323
352
|
*/
|
|
324
353
|
neg() {
|
|
325
354
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -330,9 +359,14 @@ export class Series {
|
|
|
330
359
|
// Comparison Operations (PineScript operators: tolerance 1e-10, false with na; see src/compare)
|
|
331
360
|
// ============================================
|
|
332
361
|
/**
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* @
|
|
362
|
+
* Tests whether this series is above a Series or a number, bar by bar (`a > b`).
|
|
363
|
+
* Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.
|
|
364
|
+
* @param other - Series or number to compare with.
|
|
365
|
+
* @returns A Series of 1 where it is true, 0 where it is false.
|
|
366
|
+
* @example
|
|
367
|
+
* ```js
|
|
368
|
+
* const up = close.gt(open);
|
|
369
|
+
* ```
|
|
336
370
|
*/
|
|
337
371
|
gt(other) {
|
|
338
372
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -342,9 +376,14 @@ export class Series {
|
|
|
342
376
|
});
|
|
343
377
|
}
|
|
344
378
|
/**
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
* @
|
|
379
|
+
* Tests whether this series is above or equal to a Series or a number, bar by bar (`a >= b`).
|
|
380
|
+
* Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.
|
|
381
|
+
* @param other - Series or number to compare with.
|
|
382
|
+
* @returns A Series of 1 where it is true, 0 where it is false.
|
|
383
|
+
* @example
|
|
384
|
+
* ```js
|
|
385
|
+
* const atOrAbove = close.gte(ta.sma(close, 50));
|
|
386
|
+
* ```
|
|
348
387
|
*/
|
|
349
388
|
gte(other) {
|
|
350
389
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -354,9 +393,14 @@ export class Series {
|
|
|
354
393
|
});
|
|
355
394
|
}
|
|
356
395
|
/**
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* @
|
|
396
|
+
* Tests whether this series is below a Series or a number, bar by bar (`a < b`).
|
|
397
|
+
* Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.
|
|
398
|
+
* @param other - Series or number to compare with.
|
|
399
|
+
* @returns A Series of 1 where it is true, 0 where it is false.
|
|
400
|
+
* @example
|
|
401
|
+
* ```js
|
|
402
|
+
* const oversold = ta.rsi(close, 14).lt(30);
|
|
403
|
+
* ```
|
|
360
404
|
*/
|
|
361
405
|
lt(other) {
|
|
362
406
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -366,9 +410,14 @@ export class Series {
|
|
|
366
410
|
});
|
|
367
411
|
}
|
|
368
412
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* @
|
|
413
|
+
* Tests whether this series is below or equal to a Series or a number, bar by bar (`a <= b`).
|
|
414
|
+
* Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.
|
|
415
|
+
* @param other - Series or number to compare with.
|
|
416
|
+
* @returns A Series of 1 where it is true, 0 where it is false.
|
|
417
|
+
* @example
|
|
418
|
+
* ```js
|
|
419
|
+
* const atOrBelow = low.lte(ta.lowest(low, 20).offset(1));
|
|
420
|
+
* ```
|
|
372
421
|
*/
|
|
373
422
|
lte(other) {
|
|
374
423
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -378,9 +427,14 @@ export class Series {
|
|
|
378
427
|
});
|
|
379
428
|
}
|
|
380
429
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* @
|
|
430
|
+
* Tests whether this series equals a Series or a number, bar by bar (`a == b`).
|
|
431
|
+
* Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.
|
|
432
|
+
* @param other - Series or number to compare with.
|
|
433
|
+
* @returns A Series of 1 where it is true, 0 where it is false.
|
|
434
|
+
* @example
|
|
435
|
+
* ```js
|
|
436
|
+
* const doji = close.eq(open);
|
|
437
|
+
* ```
|
|
384
438
|
*/
|
|
385
439
|
eq(other) {
|
|
386
440
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -390,9 +444,14 @@ export class Series {
|
|
|
390
444
|
});
|
|
391
445
|
}
|
|
392
446
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
* @
|
|
447
|
+
* Tests whether this series differs from a Series or a number, bar by bar (`a != b`).
|
|
448
|
+
* Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.
|
|
449
|
+
* @param other - Series or number to compare with.
|
|
450
|
+
* @returns A Series of 1 where it is true, 0 where it is false.
|
|
451
|
+
* @example
|
|
452
|
+
* ```js
|
|
453
|
+
* const moved = close.neq(close.offset(1));
|
|
454
|
+
* ```
|
|
396
455
|
*/
|
|
397
456
|
neq(other) {
|
|
398
457
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -405,9 +464,13 @@ export class Series {
|
|
|
405
464
|
// Logical Operations (for boolean series)
|
|
406
465
|
// ============================================
|
|
407
466
|
/**
|
|
408
|
-
* Logical
|
|
409
|
-
* @param other - Series or number
|
|
410
|
-
* @returns
|
|
467
|
+
* Logical "and" of two conditions, bar by bar. A value is true when it is not 0 and not NaN.
|
|
468
|
+
* @param other - The other condition: a Series or a number.
|
|
469
|
+
* @returns A Series of 1 where both are true, 0 elsewhere.
|
|
470
|
+
* @example
|
|
471
|
+
* ```js
|
|
472
|
+
* const strongUp = close.gt(open).and(volume.gt(ta.sma(volume, 20)));
|
|
473
|
+
* ```
|
|
411
474
|
*/
|
|
412
475
|
and(other) {
|
|
413
476
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -417,9 +480,13 @@ export class Series {
|
|
|
417
480
|
});
|
|
418
481
|
}
|
|
419
482
|
/**
|
|
420
|
-
* Logical
|
|
421
|
-
* @param other - Series or number
|
|
422
|
-
* @returns
|
|
483
|
+
* Logical "or" of two conditions, bar by bar. A value is true when it is not 0 and not NaN.
|
|
484
|
+
* @param other - The other condition: a Series or a number.
|
|
485
|
+
* @returns A Series of 1 where at least one is true, 0 elsewhere.
|
|
486
|
+
* @example
|
|
487
|
+
* ```js
|
|
488
|
+
* const extreme = ta.rsi(close, 14).gt(70).or(ta.rsi(close, 14).lt(30));
|
|
489
|
+
* ```
|
|
423
490
|
*/
|
|
424
491
|
or(other) {
|
|
425
492
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -429,8 +496,12 @@ export class Series {
|
|
|
429
496
|
});
|
|
430
497
|
}
|
|
431
498
|
/**
|
|
432
|
-
* Logical
|
|
433
|
-
* @returns
|
|
499
|
+
* Logical "not" of a condition, bar by bar: true (not 0, not NaN) becomes 0, and 0 or NaN becomes 1.
|
|
500
|
+
* @returns A Series of 1 where this series is false, 0 where it is true.
|
|
501
|
+
* @example
|
|
502
|
+
* ```js
|
|
503
|
+
* const notUp = close.gt(open).not();
|
|
504
|
+
* ```
|
|
434
505
|
*/
|
|
435
506
|
not() {
|
|
436
507
|
return new Series(this.dataSource, (bar, i, data) => {
|
|
@@ -442,21 +513,16 @@ export class Series {
|
|
|
442
513
|
// Conditional Selection
|
|
443
514
|
// ============================================
|
|
444
515
|
/**
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* @param
|
|
449
|
-
* @
|
|
450
|
-
* @returns New Series with bar-by-bar selected values
|
|
451
|
-
*
|
|
516
|
+
* Picks one of two values on each bar, with this series as the condition (the `cond ? x : y` of a series). The
|
|
517
|
+
* condition is true when it is not 0 and not NaN; 0 and NaN pick `falseValue`.
|
|
518
|
+
* @param trueValue - Series or number used where the condition is true.
|
|
519
|
+
* @param falseValue - Series or number used where the condition is false.
|
|
520
|
+
* @returns A Series of the picked values.
|
|
452
521
|
* @example
|
|
453
|
-
* ```
|
|
454
|
-
*
|
|
455
|
-
* const
|
|
456
|
-
*
|
|
457
|
-
* // Example: RSI formula uses ternary for edge cases
|
|
458
|
-
* // rsi = down == 0 ? 100 : up == 0 ? 0 : formula
|
|
459
|
-
* const rsi = down.eq(0).iff(100, up.eq(0).iff(0, formula));
|
|
522
|
+
* ```js
|
|
523
|
+
* const range = high.sub(low);
|
|
524
|
+
* const ratio = range.gt(0).iff(close.sub(open).div(range), 0);
|
|
525
|
+
* plot(ratio, "Body / range");
|
|
460
526
|
* ```
|
|
461
527
|
*/
|
|
462
528
|
iff(trueValue, falseValue) {
|
|
@@ -476,10 +542,17 @@ export class Series {
|
|
|
476
542
|
// Offset/History
|
|
477
543
|
// ============================================
|
|
478
544
|
/**
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
* @
|
|
482
|
-
*
|
|
545
|
+
* Shifts the series back in time: on each bar, the value `offset` bars earlier (`close.offset(1)` is the previous
|
|
546
|
+
* close). The first `offset` bars, which have no earlier bar, get NaN.
|
|
547
|
+
* @param offset - Number of bars back: 0 (the series itself) or more, a whole number. A series computed by the
|
|
548
|
+
* script can look back at most 5000 bars; the price series (`close`, `high`...) any number.
|
|
549
|
+
* @returns A Series of the earlier values.
|
|
550
|
+
* @throws RangeError when `offset` is negative (it would read a future bar); an error past 5000 bars.
|
|
551
|
+
* @example
|
|
552
|
+
* ```js
|
|
553
|
+
* const change = close.sub(close.offset(1));
|
|
554
|
+
* const higherHigh = high.gt(high.offset(1));
|
|
555
|
+
* ```
|
|
483
556
|
*/
|
|
484
557
|
offset(offset) {
|
|
485
558
|
if (offset < 0)
|
|
@@ -499,14 +572,14 @@ export class Series {
|
|
|
499
572
|
// Computation & Access
|
|
500
573
|
// ============================================
|
|
501
574
|
/**
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
575
|
+
* Gives the values of all the bars as a plain array, oldest bar first (NaN for na). The values are computed on the
|
|
576
|
+
* first read and kept until the bars change; the array is shared, so copy it before changing it.
|
|
577
|
+
* @returns One number per bar, oldest first.
|
|
578
|
+
* @example
|
|
579
|
+
* ```js
|
|
580
|
+
* const values = ta.sma(close, 20).toArray();
|
|
581
|
+
* const shifted = seriesOf(values.map((v) => v * 1.01));
|
|
582
|
+
* ```
|
|
510
583
|
*/
|
|
511
584
|
toArray() {
|
|
512
585
|
// Check if cache is valid by comparing versions
|
|
@@ -534,24 +607,13 @@ export class Series {
|
|
|
534
607
|
return this.cached;
|
|
535
608
|
}
|
|
536
609
|
/**
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
* - Computes all values immediately
|
|
541
|
-
* - Creates a new Series that stores values directly
|
|
542
|
-
* - Breaks references to parent Series objects
|
|
543
|
-
* - Useful for complex expressions to free intermediate Series memory
|
|
544
|
-
*
|
|
610
|
+
* Computes the values now and returns a Series that stores them, without links to the series it was built from.
|
|
611
|
+
* Use it on a long chain of methods to compute it once and free the steps in between.
|
|
612
|
+
* @returns A Series of the same values, stored.
|
|
545
613
|
* @example
|
|
546
|
-
* ```
|
|
547
|
-
*
|
|
548
|
-
* const result = a.add(b).mul(c).div(d).sub(e);
|
|
549
|
-
*
|
|
550
|
-
* // With materialize: breaks chain, frees a, b, c memory
|
|
551
|
-
* const result = a.add(b).mul(c).materialize().div(d).sub(e);
|
|
614
|
+
* ```js
|
|
615
|
+
* const spread = high.sub(low).div(close).mul(100).materialize();
|
|
552
616
|
* ```
|
|
553
|
-
*
|
|
554
|
-
* @returns New Series with computed values and no closure dependencies
|
|
555
617
|
*/
|
|
556
618
|
materialize() {
|
|
557
619
|
const values = this.toArray();
|
|
@@ -581,33 +643,43 @@ export class Series {
|
|
|
581
643
|
return this.toArray();
|
|
582
644
|
}
|
|
583
645
|
/**
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
646
|
+
* Reads the value of one bar by its position: 0 is the oldest bar, `bar_index` counts the same way. This is not
|
|
647
|
+
* the "bars back" of `offset()`: inside a bar loop, read the current bar with `c.get(series)` and earlier bars with
|
|
648
|
+
* `c.get(series, k)`.
|
|
649
|
+
* @param index - Bar position, 0 for the oldest bar.
|
|
650
|
+
* @returns The value of that bar; NaN when there is no such bar.
|
|
651
|
+
* @example
|
|
652
|
+
* ```js
|
|
653
|
+
* const firstClose = close.get(0);
|
|
654
|
+
* ```
|
|
587
655
|
*/
|
|
588
656
|
get(index) {
|
|
589
657
|
const values = this.toArray();
|
|
590
658
|
return values[index] ?? NaN;
|
|
591
659
|
}
|
|
592
660
|
/**
|
|
593
|
-
*
|
|
594
|
-
* @returns
|
|
661
|
+
* Reads the value of the newest bar.
|
|
662
|
+
* @returns The value of the last bar; NaN when there are no bars.
|
|
663
|
+
* @example
|
|
664
|
+
* ```js
|
|
665
|
+
* const lastRsi = ta.rsi(close, 14).last();
|
|
666
|
+
* ```
|
|
595
667
|
*/
|
|
596
668
|
last() {
|
|
597
669
|
const values = this.toArray();
|
|
598
670
|
return values[values.length - 1] ?? NaN;
|
|
599
671
|
}
|
|
600
672
|
/**
|
|
601
|
-
*
|
|
602
|
-
* @returns
|
|
673
|
+
* Gives the number of bars of the series (a method, not a property).
|
|
674
|
+
* @returns The number of bars.
|
|
675
|
+
* @example
|
|
676
|
+
* ```js
|
|
677
|
+
* const bars = close.length();
|
|
678
|
+
* ```
|
|
603
679
|
*/
|
|
604
680
|
length() {
|
|
605
681
|
return this.dataSource.length;
|
|
606
682
|
}
|
|
607
|
-
/**
|
|
608
|
-
* Convert series to time-value pairs for charting
|
|
609
|
-
* @returns Array of { time, value } objects
|
|
610
|
-
*/
|
|
611
683
|
/**
|
|
612
684
|
* A Series holds the values of all the bars, so JavaScript operators cannot use it: without this guard
|
|
613
685
|
* `close - open` is NaN, `close > open` false and `` `${rsi}` `` "[object Object]", with no error. The
|
|
@@ -622,6 +694,14 @@ export class Series {
|
|
|
622
694
|
'a.add(b) a.sub(b) a.mul(b) a.div(b) a.mod(b) a.pow(b) a.neg(), a.gt(b) a.gte(b) a.lt(b) a.lte(b) a.eq(b) a.neq(b), ' +
|
|
623
695
|
'a.and(b) a.or(b) a.not(), cond.iff(x, y), a.offset(1) for a[1]; or read numbers inside eachBar() with c.get(a).');
|
|
624
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* Gives the values as `{ time, value }` points for a chart line, oldest first, leaving out the NaN bars.
|
|
699
|
+
* @returns The points; `time` is the bar time, in the unit of the bars.
|
|
700
|
+
* @example
|
|
701
|
+
* ```js
|
|
702
|
+
* const points = ta.sma(close, 20).toTimeValuePairs();
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
625
705
|
toTimeValuePairs() {
|
|
626
706
|
const values = this.toArray();
|
|
627
707
|
const bars = this.dataSource.bars;
|