oakscriptjs 0.11.1 → 0.11.3
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/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +5 -2
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/drawing/output.d.ts +2 -1
- package/dist/cjs/drawing/output.d.ts.map +1 -1
- package/dist/cjs/drawing/output.js +5 -0
- package/dist/cjs/drawing/output.js.map +2 -2
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/script/index.d.ts +1 -1
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +6 -51
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +1 -0
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/session/context.d.ts +20 -4
- package/dist/cjs/session/context.d.ts.map +1 -1
- package/dist/cjs/session/context.js +65 -5
- package/dist/cjs/session/context.js.map +2 -2
- package/dist/cjs/ta/index.d.ts +31 -29
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +10 -12
- package/dist/cjs/ta/index.js.map +3 -3
- package/dist/cjs/table/index.d.ts +10 -5
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +11 -2
- package/dist/cjs/table/index.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +16 -0
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +5 -2
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/drawing/output.d.ts +2 -1
- package/dist/esm/drawing/output.d.ts.map +1 -1
- package/dist/esm/drawing/output.js +8 -1
- package/dist/esm/drawing/output.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/script/index.d.ts +1 -1
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +7 -62
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +4 -0
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/session/context.d.ts +20 -4
- package/dist/esm/session/context.d.ts.map +1 -1
- package/dist/esm/session/context.js +81 -7
- package/dist/esm/session/context.js.map +1 -1
- package/dist/esm/ta/index.d.ts +31 -29
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +45 -45
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/table/index.d.ts +10 -5
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +23 -8
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +16 -0
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/callsite/index.ts +5 -2
- package/src/drawing/output.ts +9 -1
- package/src/index.ts +6 -3
- package/src/script/index.ts +7 -65
- package/src/session/calendar.ts +3 -0
- package/src/session/context.ts +99 -7
- package/src/ta/index.ts +46 -45
- package/src/table/index.ts +22 -6
- package/src/types/metadata.ts +16 -0
package/src/ta/index.ts
CHANGED
|
@@ -138,7 +138,8 @@ export function rsi(source: Source, length: simple_int): series_float;
|
|
|
138
138
|
/**
|
|
139
139
|
* PineScript v4 `rsi(x, y)` with two series (#180): `x` and `y` are the averages of the upward and downward changes,
|
|
140
140
|
* already computed. As in PineScript: 100 when `y` is within 1e-10 of zero (also with an na `x`), else 0 when `x` is,
|
|
141
|
-
* else `100 - 100 / (1 + x / y)
|
|
141
|
+
* else `100 - 100 / (1 + x / y)`: -Infinity when `x == -y` (#182), which `na()` and `nz()` treat as na while comparisons
|
|
142
|
+
* see it (`r < 30` is true). Versions 5 and 6 have the length form only.
|
|
142
143
|
*/
|
|
143
144
|
export function rsi(x: Source, y: Source): series_float;
|
|
144
145
|
export function rsi(source: Source, length: simple_int | Source): series_float {
|
|
@@ -148,8 +149,7 @@ export function rsi(source: Source, length: simple_int | Source): series_float {
|
|
|
148
149
|
const y = length[i] ?? NaN;
|
|
149
150
|
if (eq(y, 0)) return 100;
|
|
150
151
|
if (eq(x, 0)) return 0;
|
|
151
|
-
|
|
152
|
-
return Number.isFinite(r) ? r : NaN;
|
|
152
|
+
return 100 - 100 / (1 + x / y);
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
checkPositiveLength('rsi', length, 0, 'y');
|
|
@@ -293,14 +293,14 @@ export function stdev(
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
/**
|
|
296
|
-
* The last `length` non-na values up to bar `i` (the bar itself may be na), or null when fewer exist.
|
|
297
|
-
*
|
|
296
|
+
* The last `length` non-na values up to bar `i` (the bar itself may be na), or null when fewer exist. +/-Infinity
|
|
297
|
+
* counts as na (#183).
|
|
298
298
|
*/
|
|
299
299
|
function lastValues(source: Source, i: number, length: number): number[] | null {
|
|
300
300
|
const values: number[] = [];
|
|
301
301
|
for (let j = i; j >= 0 && values.length < length; j--) {
|
|
302
302
|
const x = source[j]!;
|
|
303
|
-
if (
|
|
303
|
+
if (Number.isFinite(x)) values.push(x);
|
|
304
304
|
}
|
|
305
305
|
return values.length === length ? values : null;
|
|
306
306
|
}
|
|
@@ -361,7 +361,7 @@ function windowExtremes(
|
|
|
361
361
|
/**
|
|
362
362
|
* The non-na values of `source` with their bars, and for each bar the position of its last non-na value (-1 when
|
|
363
363
|
* there is none yet). PineScript's ta.highest / ta.lowest / ta.highestbars / ta.lowestbars / ta.pivothigh /
|
|
364
|
-
* ta.pivotlow keep the non-na values they receive and nothing else.
|
|
364
|
+
* ta.pivotlow keep the non-na values they receive and nothing else; +/-Infinity is skipped like na (#183).
|
|
365
365
|
*/
|
|
366
366
|
function keptValues(source: Source): { values: number[]; bars: number[]; last: Int32Array } {
|
|
367
367
|
const values: number[] = [];
|
|
@@ -369,7 +369,7 @@ function keptValues(source: Source): { values: number[]; bars: number[]; last: I
|
|
|
369
369
|
const last = new Int32Array(source.length);
|
|
370
370
|
for (let i = 0; i < source.length; i++) {
|
|
371
371
|
const x = source[i]!;
|
|
372
|
-
if (
|
|
372
|
+
if (Number.isFinite(x)) {
|
|
373
373
|
values.push(x);
|
|
374
374
|
bars.push(i);
|
|
375
375
|
}
|
|
@@ -910,9 +910,9 @@ export function wma(source: Source, length: simple_int | ArrayLike<number>): ser
|
|
|
910
910
|
* @returns Highest value series (na on the first `length - 1` bars)
|
|
911
911
|
*
|
|
912
912
|
* @remarks
|
|
913
|
-
* As in PineScript: `na` values are skipped. The result is the highest of the last `length`
|
|
914
|
-
* of them when there are fewer), also on a bar whose own value is `na`; `na` before bar
|
|
915
|
-
* value was received. A fractional length is truncated (7.5 is 7 bars).
|
|
913
|
+
* As in PineScript: `na` values (also +/-Infinity, #183) are skipped. The result is the highest of the last `length`
|
|
914
|
+
* non-na values (of all of them when there are fewer), also on a bar whose own value is `na`; `na` before bar
|
|
915
|
+
* `length - 1` and while no value was received. A fractional length is truncated (7.5 is 7 bars).
|
|
916
916
|
* `length` can be an array (a length per bar, PineScript series length), also for `ta.lowest`, `ta.highestbars`
|
|
917
917
|
* and `ta.lowestbars`: each bar uses its own length.
|
|
918
918
|
* A length above 15,000 throws the PineScript runtime error (also `ta.lowest`, `ta.highestbars`, `ta.lowestbars`).
|
|
@@ -930,9 +930,9 @@ export function highest(source: Source, length: simple_int | ArrayLike<number>):
|
|
|
930
930
|
* @returns Lowest value series (na on the first `length - 1` bars)
|
|
931
931
|
*
|
|
932
932
|
* @remarks
|
|
933
|
-
* As in PineScript: `na` values are skipped. The result is the lowest of the last `length`
|
|
934
|
-
* of them when there are fewer), also on a bar whose own value is `na`; `na` before bar
|
|
935
|
-
* value was received.
|
|
933
|
+
* As in PineScript: `na` values (also +/-Infinity, #183) are skipped. The result is the lowest of the last `length`
|
|
934
|
+
* non-na values (of all of them when there are fewer), also on a bar whose own value is `na`; `na` before bar
|
|
935
|
+
* `length - 1` and while no value was received.
|
|
936
936
|
*/
|
|
937
937
|
export function lowest(source: Source, length: simple_int | ArrayLike<number>): series_float {
|
|
938
938
|
return extremeValue(source, length, true);
|
|
@@ -1018,7 +1018,7 @@ function monotonic(source: Source, length: simple_int, step: (newer: number, old
|
|
|
1018
1018
|
for (let i = 0; i < source.length; i++) {
|
|
1019
1019
|
const v = source[i]!;
|
|
1020
1020
|
const prev = i > 0 ? source[i - 1]! : NaN;
|
|
1021
|
-
if (
|
|
1021
|
+
if (Number.isFinite(v) && Number.isFinite(prev)) count = step(v, prev) ? count + 1 : 0;
|
|
1022
1022
|
result.push(count >= length);
|
|
1023
1023
|
}
|
|
1024
1024
|
return result;
|
|
@@ -1035,8 +1035,8 @@ function monotonic(source: Source, length: simple_int, step: (newer: number, old
|
|
|
1035
1035
|
* PineScript rules:
|
|
1036
1036
|
* - a counter of rises from the previous bar (a rise is larger than the 1e-10 tolerance); a step that is not a rise
|
|
1037
1037
|
* resets it to 0
|
|
1038
|
-
* - a step from or to an `na` bar leaves the counter unchanged (so an `na` bar, and the bar after
|
|
1039
|
-
* result of the bar before the `na`)
|
|
1038
|
+
* - a step from or to an `na` (or +/-Infinity) bar leaves the counter unchanged (so an `na` bar, and the bar after
|
|
1039
|
+
* it, keep the result of the bar before the `na`)
|
|
1040
1040
|
* - true when the counter is at least `length` (false at the start)
|
|
1041
1041
|
*
|
|
1042
1042
|
* @example
|
|
@@ -1061,8 +1061,8 @@ export function rising(source: Source, length: simple_int): series_bool {
|
|
|
1061
1061
|
* PineScript rules:
|
|
1062
1062
|
* - a counter of falls from the previous bar (a fall is larger than the 1e-10 tolerance); a step that is not a fall
|
|
1063
1063
|
* resets it to 0
|
|
1064
|
-
* - a step from or to an `na` bar leaves the counter unchanged (so an `na` bar, and the bar after
|
|
1065
|
-
* result of the bar before the `na`)
|
|
1064
|
+
* - a step from or to an `na` (or +/-Infinity) bar leaves the counter unchanged (so an `na` bar, and the bar after
|
|
1065
|
+
* it, keep the result of the bar before the `na`)
|
|
1066
1066
|
* - true when the counter is at least `length` (false at the start)
|
|
1067
1067
|
*
|
|
1068
1068
|
* @example
|
|
@@ -1251,7 +1251,7 @@ function varianceOf(
|
|
|
1251
1251
|
* @remarks
|
|
1252
1252
|
* - Returns the middle value when values are sorted
|
|
1253
1253
|
* - For an even length, returns the average of the two middle values
|
|
1254
|
-
* - As in PineScript: `na` values are skipped, the window holds the last `length` non-na values
|
|
1254
|
+
* - As in PineScript: `na` values (also +/-Infinity) are skipped, the window holds the last `length` non-na values
|
|
1255
1255
|
* (going back as many bars as needed), and a bar whose own value is `na` still gets a result
|
|
1256
1256
|
* - Returns NaN until `length` non-na values exist
|
|
1257
1257
|
* - More robust to outliers than mean (SMA)
|
|
@@ -1287,7 +1287,7 @@ export function median(source: Source, length: simple_int): series_float {
|
|
|
1287
1287
|
const mid = Math.floor(len / 2);
|
|
1288
1288
|
for (let i = 0; i < n; i++) {
|
|
1289
1289
|
const x = source[i]!;
|
|
1290
|
-
if (
|
|
1290
|
+
if (Number.isFinite(x)) {
|
|
1291
1291
|
kept[count++] = x;
|
|
1292
1292
|
sorted.splice(bound(x, false), 0, x); // before the equal values: the newest first
|
|
1293
1293
|
// the value leaving the window is the oldest, so the last of its equal values
|
|
@@ -1601,8 +1601,9 @@ export function cci(source: Source, length: simple_int): series_float {
|
|
|
1601
1601
|
* - Measures where close is relative to the high-low range
|
|
1602
1602
|
* - Values above 80 typically indicate overbought
|
|
1603
1603
|
* - Values below 20 typically indicate oversold
|
|
1604
|
-
* - As PineScript: when the source, \`highest(high, length)\` or \`lowest(low, length)\` is \`na\`, or the range
|
|
1605
|
-
* result is the previous result of the call (\`na\` until a first value)
|
|
1604
|
+
* - As PineScript: when the source, \`highest(high, length)\` or \`lowest(low, length)\` is \`na\`, or the range and
|
|
1605
|
+
* \`source - lowest\` are both 0, the result is the previous result of the call (\`na\` until a first value); a zero
|
|
1606
|
+
* range with another source value gives +/-Infinity (plotted as \`na\`)
|
|
1606
1607
|
*
|
|
1607
1608
|
* @example
|
|
1608
1609
|
* \`\`\`typescript
|
|
@@ -1617,13 +1618,13 @@ export function stoch(source: Source, high: Source, low: Source, length: simple_
|
|
|
1617
1618
|
const lowestValues = lowest(low, length);
|
|
1618
1619
|
const highestValues = highest(high, length);
|
|
1619
1620
|
|
|
1620
|
-
// PineScript: an na input or a zero range
|
|
1621
|
+
// PineScript: an na (NaN) result keeps the previous one: an na input, or 0 / 0 on a zero range; a non-zero value
|
|
1622
|
+
// over a zero range gives +/-Infinity (#183)
|
|
1621
1623
|
let previous = NaN;
|
|
1622
1624
|
for (let i = 0; i < source.length; i++) {
|
|
1623
|
-
const value = source[i]!;
|
|
1624
1625
|
const lo = lowestValues[i]!;
|
|
1625
|
-
const
|
|
1626
|
-
if (!Number.isNaN(
|
|
1626
|
+
const k = (100 * (source[i]! - lo)) / (highestValues[i]! - lo);
|
|
1627
|
+
if (!Number.isNaN(k)) previous = k;
|
|
1627
1628
|
result.push(previous);
|
|
1628
1629
|
}
|
|
1629
1630
|
|
|
@@ -1898,8 +1899,8 @@ function pivot(source: Source, leftbars: PivotLength, rightbars: PivotLength, is
|
|
|
1898
1899
|
* - As in PineScript, the value appears `rightbars` bars after the pivot bar: the pivot bar
|
|
1899
1900
|
* index is `i - rightbars`
|
|
1900
1901
|
* - A pivot high may equal values on its left but must be higher than all values on its right
|
|
1901
|
-
* - `na` values are skipped: the window is the last `leftbars + rightbars + 1` non-na values,
|
|
1902
|
-
* them must be on the bar `rightbars` bars back
|
|
1902
|
+
* - `na` values (also +/-Infinity) are skipped: the window is the last `leftbars + rightbars + 1` non-na values,
|
|
1903
|
+
* and the highest of them must be on the bar `rightbars` bars back
|
|
1903
1904
|
* - `leftbars` / `rightbars` can be arrays (a length per bar, PineScript series length), also for `ta.pivotlow`:
|
|
1904
1905
|
* each bar uses its own lengths
|
|
1905
1906
|
*
|
|
@@ -1938,8 +1939,8 @@ export function pivothigh(
|
|
|
1938
1939
|
* - As in PineScript, the value appears `rightbars` bars after the pivot bar: the pivot bar
|
|
1939
1940
|
* index is `i - rightbars`
|
|
1940
1941
|
* - A pivot low may equal values on its left but must be lower than all values on its right
|
|
1941
|
-
* - `na` values are skipped: the window is the last `leftbars + rightbars + 1` non-na values,
|
|
1942
|
-
* them must be on the bar `rightbars` bars back
|
|
1942
|
+
* - `na` values (also +/-Infinity) are skipped: the window is the last `leftbars + rightbars + 1` non-na values,
|
|
1943
|
+
* and the lowest of them must be on the bar `rightbars` bars back
|
|
1943
1944
|
*
|
|
1944
1945
|
* @example
|
|
1945
1946
|
* ```typescript
|
|
@@ -2529,7 +2530,7 @@ export function kcw(
|
|
|
2529
2530
|
* (PineScript `ta.range(source, length)`).
|
|
2530
2531
|
*
|
|
2531
2532
|
* @remarks
|
|
2532
|
-
* As in PineScript: `na` values are skipped (the window holds the last `length` non-na
|
|
2533
|
+
* As in PineScript: `na` values (also +/-Infinity) are skipped (the window holds the last `length` non-na
|
|
2533
2534
|
* values), and a bar whose own value is `na` still gets a result.
|
|
2534
2535
|
*/
|
|
2535
2536
|
export function range(source: Source, length: simple_int): series_float {
|
|
@@ -2545,9 +2546,9 @@ export function range(source: Source, length: simple_int): series_float {
|
|
|
2545
2546
|
* -1 for the previous bar, and so on (as in PineScript, the offset is negative).
|
|
2546
2547
|
*
|
|
2547
2548
|
* @remarks
|
|
2548
|
-
* As in PineScript: the best of the last `length` non-na values, the newest one on equal
|
|
2549
|
-
* distance in bars to its bar, so it is below `-(length - 1)` when `na` values were
|
|
2550
|
-
* `length - 1` and while no value was received; a fractional length is truncated.
|
|
2549
|
+
* As in PineScript: the best of the last `length` non-na values (+/-Infinity skipped), the newest one on equal
|
|
2550
|
+
* values; the offset is the distance in bars to its bar, so it is below `-(length - 1)` when `na` values were
|
|
2551
|
+
* skipped. `na` before bar `length - 1` and while no value was received; a fractional length is truncated.
|
|
2551
2552
|
*/
|
|
2552
2553
|
export function highestbars(source: Source, length: simple_int | ArrayLike<number>): series_int {
|
|
2553
2554
|
return extremeOffset(source, length, false);
|
|
@@ -2558,9 +2559,9 @@ export function highestbars(source: Source, length: simple_int | ArrayLike<numbe
|
|
|
2558
2559
|
* -1 for the previous bar, and so on (as in PineScript, the offset is negative).
|
|
2559
2560
|
*
|
|
2560
2561
|
* @remarks
|
|
2561
|
-
* As in PineScript: the best of the last `length` non-na values, the newest one on equal
|
|
2562
|
-
* distance in bars to its bar, so it is below `-(length - 1)` when `na` values were
|
|
2563
|
-
* `length - 1` and while no value was received; a fractional length is truncated.
|
|
2562
|
+
* As in PineScript: the best of the last `length` non-na values (+/-Infinity skipped), the newest one on equal
|
|
2563
|
+
* values; the offset is the distance in bars to its bar, so it is below `-(length - 1)` when `na` values were
|
|
2564
|
+
* skipped. `na` before bar `length - 1` and while no value was received; a fractional length is truncated.
|
|
2564
2565
|
*/
|
|
2565
2566
|
export function lowestbars(source: Source, length: simple_int | ArrayLike<number>): series_int {
|
|
2566
2567
|
return extremeOffset(source, length, true);
|
|
@@ -2570,13 +2571,13 @@ export function lowestbars(source: Source, length: simple_int | ArrayLike<number
|
|
|
2570
2571
|
* All-time highest value of `source` up to each bar (PineScript `ta.max(source)`).
|
|
2571
2572
|
*
|
|
2572
2573
|
* @remarks
|
|
2573
|
-
* As in PineScript: `na` values are skipped, the value carries over `na` bars, and the
|
|
2574
|
+
* As in PineScript: `na` values (also +/-Infinity) are skipped, the value carries over `na` bars, and the
|
|
2574
2575
|
* result is `na` until the first non-na value.
|
|
2575
2576
|
*/
|
|
2576
2577
|
export function max(source: Source): series_float {
|
|
2577
2578
|
let best = NaN;
|
|
2578
2579
|
return source.map((x) => {
|
|
2579
|
-
if (
|
|
2580
|
+
if (Number.isFinite(x) && !(x <= best)) best = x;
|
|
2580
2581
|
return best;
|
|
2581
2582
|
});
|
|
2582
2583
|
}
|
|
@@ -2585,13 +2586,13 @@ export function max(source: Source): series_float {
|
|
|
2585
2586
|
* All-time lowest value of `source` up to each bar (PineScript `ta.min(source)`).
|
|
2586
2587
|
*
|
|
2587
2588
|
* @remarks
|
|
2588
|
-
* As in PineScript: `na` values are skipped, the value carries over `na` bars, and the
|
|
2589
|
+
* As in PineScript: `na` values (also +/-Infinity) are skipped, the value carries over `na` bars, and the
|
|
2589
2590
|
* result is `na` until the first non-na value.
|
|
2590
2591
|
*/
|
|
2591
2592
|
export function min(source: Source): series_float {
|
|
2592
2593
|
let best = NaN;
|
|
2593
2594
|
return source.map((x) => {
|
|
2594
|
-
if (
|
|
2595
|
+
if (Number.isFinite(x) && !(x >= best)) best = x;
|
|
2595
2596
|
return best;
|
|
2596
2597
|
});
|
|
2597
2598
|
}
|
|
@@ -2647,8 +2648,8 @@ export function cog(source: Source, length: simple_int = 10): series_float {
|
|
|
2647
2648
|
*
|
|
2648
2649
|
* @remarks
|
|
2649
2650
|
* PineScript rules:
|
|
2650
|
-
* - the window is the last `length` non-`na` values (an `na` bar does not enter it, and gets the mode
|
|
2651
|
-
* window it keeps)
|
|
2651
|
+
* - the window is the last `length` non-`na` values (an `na` or +/-Infinity bar does not enter it, and gets the mode
|
|
2652
|
+
* of the window it keeps)
|
|
2652
2653
|
* - NaN until `length` non-`na` values exist
|
|
2653
2654
|
* - If no mode exists, returns the smallest value
|
|
2654
2655
|
*/
|
|
@@ -2660,7 +2661,7 @@ export function mode(source: Source, length: simple_int): series_float {
|
|
|
2660
2661
|
|
|
2661
2662
|
for (let i = 0; i < source.length; i++) {
|
|
2662
2663
|
const v = source[i]!;
|
|
2663
|
-
if (
|
|
2664
|
+
if (Number.isFinite(v)) seen.push(v);
|
|
2664
2665
|
if (seen.length < len) {
|
|
2665
2666
|
result.push(NaN);
|
|
2666
2667
|
continue;
|
package/src/table/index.ts
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* - `table.cell_set_*` changes one property of a cell (a cell that was not defined is created)
|
|
13
13
|
* - a column or row outside the table is a runtime error
|
|
14
14
|
* - a deleted table is `na`: its functions do nothing
|
|
15
|
-
* - one live table per position: `table.new` at the position of a live table
|
|
15
|
+
* - one live table per position and pane: `table.new` or `table.set_position` at the position of a live table with
|
|
16
|
+
* the same `force_overlay` deletes that table (#176, #182); a table with `force_overlay = true` and one without
|
|
17
|
+
* keep each their own position, also in an overlay script
|
|
16
18
|
*
|
|
17
19
|
* @version 6
|
|
18
20
|
*/
|
|
@@ -25,9 +27,16 @@ type HAlign = 'left' | 'center' | 'right';
|
|
|
25
27
|
type VAlign = 'top' | 'center' | 'bottom';
|
|
26
28
|
type FontFamily = 'default' | 'monospace';
|
|
27
29
|
|
|
30
|
+
/** Deletes the live tables other than `keep` at `position` with the same `force_overlay` (#176, #182). */
|
|
31
|
+
function freePosition(position: TablePosition, force_overlay: boolean, keep?: Table): void {
|
|
32
|
+
for (const old of allDrawings('table')) {
|
|
33
|
+
if (old !== keep && old.position === position && (old.force_overlay ?? false) === force_overlay) remove('table', old);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
/**
|
|
29
|
-
* Creates a new table (PineScript `table.new`). A live table at the same position
|
|
30
|
-
* one table per position (#176).
|
|
38
|
+
* Creates a new table (PineScript `table.new`). A live table at the same position with the same `force_overlay` is
|
|
39
|
+
* deleted, as PineScript keeps one table per position and pane (#176, #182).
|
|
31
40
|
*
|
|
32
41
|
* @example
|
|
33
42
|
* ```typescript
|
|
@@ -46,7 +55,7 @@ export function new_table(
|
|
|
46
55
|
border_width?: number,
|
|
47
56
|
force_overlay?: boolean
|
|
48
57
|
): Table {
|
|
49
|
-
|
|
58
|
+
freePosition(position, force_overlay ?? false);
|
|
50
59
|
return register('table', {
|
|
51
60
|
position,
|
|
52
61
|
columns,
|
|
@@ -196,8 +205,15 @@ function setTable<K extends keyof Table>(field: K) {
|
|
|
196
205
|
};
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
/**
|
|
200
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Moves the table to another position (`position.*`). A live table at that position with the same `force_overlay` is
|
|
210
|
+
* deleted (#182).
|
|
211
|
+
*/
|
|
212
|
+
export function set_position(table_id: Table, position: TablePosition): void {
|
|
213
|
+
if (isDeleted(table_id)) return;
|
|
214
|
+
freePosition(position, table_id.force_overlay ?? false, table_id);
|
|
215
|
+
table_id.position = position;
|
|
216
|
+
}
|
|
201
217
|
/** Sets the background colour of the table. */
|
|
202
218
|
export const set_bgcolor = setTable('bgcolor');
|
|
203
219
|
/** Sets the colour of the outer frame. */
|
package/src/types/metadata.ts
CHANGED
|
@@ -428,6 +428,10 @@ export type LabelStyle =
|
|
|
428
428
|
*/
|
|
429
429
|
export interface LabelData {
|
|
430
430
|
time: number;
|
|
431
|
+
/** 'bar_time': the x coordinates are times given by the script (xloc.bar_time). A time after the last bar is
|
|
432
|
+
* drawn on the future bar that holds it, on the chart's calendar (trading sessions). Omitted: bar indexes (a
|
|
433
|
+
* future bar index k bars after the last bar has the time lastTime + k * interval). */
|
|
434
|
+
xloc?: 'bar_time';
|
|
431
435
|
/** Price; not used with yloc 'abovebar' / 'belowbar' */
|
|
432
436
|
price: number;
|
|
433
437
|
text: string;
|
|
@@ -462,6 +466,10 @@ export interface LineDrawingData {
|
|
|
462
466
|
price1: number;
|
|
463
467
|
time2: number;
|
|
464
468
|
price2: number;
|
|
469
|
+
/** 'bar_time': the x coordinates are times given by the script (xloc.bar_time). A time after the last bar is
|
|
470
|
+
* drawn on the future bar that holds it, on the chart's calendar (trading sessions). Omitted: bar indexes (a
|
|
471
|
+
* future bar index k bars after the last bar has the time lastTime + k * interval). */
|
|
472
|
+
xloc?: 'bar_time';
|
|
465
473
|
/** Omitted: #2962FF (color.blue; #2196F3 in a v4 script) */
|
|
466
474
|
color?: string;
|
|
467
475
|
/** Omitted: 1. A width of 0 is kept (PineScript `width = 0`) */
|
|
@@ -481,6 +489,10 @@ export interface BoxData {
|
|
|
481
489
|
price1: number;
|
|
482
490
|
time2: number;
|
|
483
491
|
price2: number;
|
|
492
|
+
/** 'bar_time': the x coordinates are times given by the script (xloc.bar_time). A time after the last bar is
|
|
493
|
+
* drawn on the future bar that holds it, on the chart's calendar (trading sessions). Omitted: bar indexes (a
|
|
494
|
+
* future bar index k bars after the last bar has the time lastTime + k * interval). */
|
|
495
|
+
xloc?: 'bar_time';
|
|
484
496
|
/** Omitted: #2962FF (color.blue; #2196F3 in a v4 script) */
|
|
485
497
|
bgColor?: string;
|
|
486
498
|
/** Omitted: #2962FF (color.blue; #2196F3 in a v4 script) */
|
|
@@ -522,6 +534,10 @@ export interface LinefillData {
|
|
|
522
534
|
*/
|
|
523
535
|
export interface PolylineData {
|
|
524
536
|
points: Array<{ time: number; price: number }>;
|
|
537
|
+
/** 'bar_time': the x coordinates are times given by the script (xloc.bar_time). A time after the last bar is
|
|
538
|
+
* drawn on the future bar that holds it, on the chart's calendar (trading sessions). Omitted: bar indexes (a
|
|
539
|
+
* future bar index k bars after the last bar has the time lastTime + k * interval). */
|
|
540
|
+
xloc?: 'bar_time';
|
|
525
541
|
/** Curved segments between the points */
|
|
526
542
|
curved?: boolean;
|
|
527
543
|
/** The last point is connected to the first */
|