oakscriptjs 0.11.6 → 0.12.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/dist/cjs/drawing/registry.d.ts +2 -0
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +7 -0
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/runtime/inputs.d.ts.map +1 -1
- package/dist/cjs/runtime/inputs.js +6 -2
- package/dist/cjs/runtime/inputs.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +69 -0
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/index.d.ts +24 -2
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +58 -21
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +8 -0
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +13 -2
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/source-resolver.d.ts +17 -0
- package/dist/cjs/utils/source-resolver.d.ts.map +1 -0
- package/dist/cjs/utils/source-resolver.js +45 -0
- package/dist/cjs/utils/source-resolver.js.map +7 -0
- package/dist/esm/drawing/registry.d.ts +2 -0
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +8 -0
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/runtime/inputs.d.ts.map +1 -1
- package/dist/esm/runtime/inputs.js +8 -2
- package/dist/esm/runtime/inputs.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +69 -0
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +24 -2
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +57 -15
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +8 -0
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +18 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/source-resolver.d.ts +17 -0
- package/dist/esm/utils/source-resolver.d.ts.map +1 -0
- package/dist/esm/utils/source-resolver.js +24 -0
- package/dist/esm/utils/source-resolver.js.map +1 -0
- package/package.json +1 -1
- package/src/drawing/registry.ts +10 -0
- package/src/index.ts +6 -1
- package/src/runtime/inputs.ts +7 -2
- package/src/runtime/types.ts +65 -0
- package/src/script/index.ts +80 -21
- package/src/types/metadata.ts +8 -0
- package/src/utils/index.ts +15 -1
- package/src/utils/source-resolver.ts +29 -0
package/dist/esm/utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { sma, ema, wma, rma } from '../ta/index.js';
|
|
6
6
|
import { Series } from '../runtime/series.js';
|
|
7
7
|
import { isDeleted } from '../drawing/registry.js';
|
|
8
|
+
import { externalSource } from './source-resolver.js';
|
|
8
9
|
/**
|
|
9
10
|
* Validates that a series has sufficient data for a given length
|
|
10
11
|
*/
|
|
@@ -170,6 +171,10 @@ export function getSource(data, source = 'close') {
|
|
|
170
171
|
case 'hlcc4': return ohlc.high.map((h, i) => (h + ohlc.low[i] + ohlc.close[i] + ohlc.close[i]) / 4);
|
|
171
172
|
case 'volume': return ohlc.volume ?? ohlc.close.map(() => NaN);
|
|
172
173
|
}
|
|
174
|
+
const ext = externalSource(source);
|
|
175
|
+
if (!ext)
|
|
176
|
+
return ohlc.close;
|
|
177
|
+
return ohlc.close.map((_, i) => ext[i] ?? NaN);
|
|
173
178
|
}
|
|
174
179
|
else {
|
|
175
180
|
const bars = data;
|
|
@@ -184,6 +189,11 @@ export function getSource(data, source = 'close') {
|
|
|
184
189
|
case 'hlcc4': return bars.map(b => (b.high + b.low + b.close + b.close) / 4);
|
|
185
190
|
case 'volume': return bars.map(b => b.volume ?? NaN);
|
|
186
191
|
}
|
|
192
|
+
// Another source (study on study), else close.
|
|
193
|
+
const ext = externalSource(source);
|
|
194
|
+
if (!ext)
|
|
195
|
+
return bars.map(b => b.close);
|
|
196
|
+
return bars.map((_, i) => ext[i] ?? NaN);
|
|
187
197
|
}
|
|
188
198
|
}
|
|
189
199
|
/**
|
|
@@ -217,7 +227,14 @@ export function getSourceSeries(bars, source = 'close') {
|
|
|
217
227
|
case 'ohlc4': return open.add(high).add(low).add(close).div(4);
|
|
218
228
|
case 'hlcc4': return high.add(low).add(close).add(close).div(4);
|
|
219
229
|
case 'volume': return Series.fromBars(bars, 'volume');
|
|
220
|
-
default:
|
|
230
|
+
default: {
|
|
231
|
+
// Another source (study on study), else close.
|
|
232
|
+
const ext = externalSource(source);
|
|
233
|
+
if (!ext)
|
|
234
|
+
return close;
|
|
235
|
+
const values = Array.from({ length: bars.length }, (_, i) => ext[i] ?? NaN);
|
|
236
|
+
return new Series(bars, (_bar, i) => values[i] ?? NaN);
|
|
237
|
+
}
|
|
221
238
|
}
|
|
222
239
|
}
|
|
223
240
|
// ===== Series Manipulation Utilities =====
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
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C,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CACpB,MAAoB,EACpB,MAAqC,EACrC,MAAW;IAEX,QAAQ,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;QAC7B,KAAK,KAAK,CAAC,CAAC,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,KAAK,KAAK,CAAC,CAAC,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,KAAK,KAAK,CAAC,CAAC,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,KAAK,KAAK,CAAC,CAAC,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAoB,EACpB,UAAqB;IAErB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACnC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC,KAAK;QAC7C,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;KACnC,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sources other than the bar fields: a study calculated on another study's output (PineScript hosts call it "study
|
|
3
|
+
* on study"). A source input then holds a host name such as `"<sourceId>$<plotIndex>"`; the host resolves it to
|
|
4
|
+
* values aligned with the bars it passes to the calculation (`NaN` where there is no value).
|
|
5
|
+
*
|
|
6
|
+
* The host sets the resolver around a calculation and clears it after; a name it does not know falls back to
|
|
7
|
+
* `close`, as before.
|
|
8
|
+
*/
|
|
9
|
+
/** Values of a source by name, aligned with the bars of the calculation; null/undefined = unknown name. */
|
|
10
|
+
export type SourceResolver = (name: string) => ArrayLike<number> | null | undefined;
|
|
11
|
+
/** Built-in sources (bar fields and their averages). */
|
|
12
|
+
export declare const BUILTIN_SOURCES: ReadonlySet<string>;
|
|
13
|
+
/** Set (or clear with null) how source names other than the built-ins are read. */
|
|
14
|
+
export declare function setSourceResolver(fn: SourceResolver | null): void;
|
|
15
|
+
/** Values of a non built-in source name, or null when no resolver knows it. */
|
|
16
|
+
export declare function externalSource(name: string): ArrayLike<number> | null;
|
|
17
|
+
//# sourceMappingURL=source-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-resolver.d.ts","sourceRoot":"","sources":["../../../src/utils/source-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,2GAA2G;AAC3G,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAIpF,wDAAwD;AACxD,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,CAE9C,CAAC;AAEH,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAEjE;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAGrE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sources other than the bar fields: a study calculated on another study's output (PineScript hosts call it "study
|
|
3
|
+
* on study"). A source input then holds a host name such as `"<sourceId>$<plotIndex>"`; the host resolves it to
|
|
4
|
+
* values aligned with the bars it passes to the calculation (`NaN` where there is no value).
|
|
5
|
+
*
|
|
6
|
+
* The host sets the resolver around a calculation and clears it after; a name it does not know falls back to
|
|
7
|
+
* `close`, as before.
|
|
8
|
+
*/
|
|
9
|
+
let resolver = null;
|
|
10
|
+
/** Built-in sources (bar fields and their averages). */
|
|
11
|
+
export const BUILTIN_SOURCES = new Set([
|
|
12
|
+
'open', 'high', 'low', 'close', 'hl2', 'hlc3', 'ohlc4', 'hlcc4', 'volume',
|
|
13
|
+
]);
|
|
14
|
+
/** Set (or clear with null) how source names other than the built-ins are read. */
|
|
15
|
+
export function setSourceResolver(fn) {
|
|
16
|
+
resolver = fn;
|
|
17
|
+
}
|
|
18
|
+
/** Values of a non built-in source name, or null when no resolver knows it. */
|
|
19
|
+
export function externalSource(name) {
|
|
20
|
+
if (!resolver || BUILTIN_SOURCES.has(name))
|
|
21
|
+
return null;
|
|
22
|
+
return resolver(name) ?? null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=source-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-resolver.js","sourceRoot":"","sources":["../../../src/utils/source-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,IAAI,QAAQ,GAA0B,IAAI,CAAC;AAE3C,wDAAwD;AACxD,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC1D,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ;CAC1E,CAAC,CAAC;AAEH,mFAAmF;AACnF,MAAM,UAAU,iBAAiB,CAAC,EAAyB;IACzD,QAAQ,GAAG,EAAE,CAAC;AAChB,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,CAAC,QAAQ,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACxD,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
package/src/drawing/registry.ts
CHANGED
|
@@ -303,9 +303,18 @@ function cutOldest<K extends DrawingKind>(
|
|
|
303
303
|
return cut;
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
+
/** Kinds of the objects created since the last reset (a table counts too), in no order. */
|
|
307
|
+
const created = new Set<DrawingKind>();
|
|
308
|
+
|
|
309
|
+
/** The kinds of drawing objects created since the last {@link resetDrawings}, even when none is alive any more. */
|
|
310
|
+
export function createdDrawingKinds(): DrawingKind[] {
|
|
311
|
+
return [...created];
|
|
312
|
+
}
|
|
313
|
+
|
|
306
314
|
/** Records a new object and deletes the oldest objects of its kind when the count is too high. */
|
|
307
315
|
export function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {
|
|
308
316
|
const list = live[kind];
|
|
317
|
+
created.add(kind);
|
|
309
318
|
if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);
|
|
310
319
|
if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;
|
|
311
320
|
list.push(obj);
|
|
@@ -368,6 +377,7 @@ export function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[K]> {
|
|
|
368
377
|
/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */
|
|
369
378
|
export function resetDrawings(newLimits: DrawingLimits = {}): void {
|
|
370
379
|
for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;
|
|
380
|
+
created.clear();
|
|
371
381
|
held = new WeakMap();
|
|
372
382
|
releasedAt = new WeakMap();
|
|
373
383
|
heldAt = new WeakMap();
|
package/src/index.ts
CHANGED
|
@@ -51,6 +51,8 @@ export {
|
|
|
51
51
|
holdDrawing,
|
|
52
52
|
releaseDrawing,
|
|
53
53
|
varDrawing,
|
|
54
|
+
createdDrawingKinds,
|
|
55
|
+
type DrawingKind,
|
|
54
56
|
type DrawingLimits,
|
|
55
57
|
type DrawingVariable,
|
|
56
58
|
} from './drawing/registry.js';
|
|
@@ -124,6 +126,7 @@ export { rgb, from_hex as color_from_hex, new_color } from './color/index.js';
|
|
|
124
126
|
|
|
125
127
|
// Export chart data utilities
|
|
126
128
|
export { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';
|
|
129
|
+
export { setSourceResolver, externalSource, BUILTIN_SOURCES, type SourceResolver } from './utils/source-resolver.js';
|
|
127
130
|
|
|
128
131
|
// Export libraries (ZigZag, etc.)
|
|
129
132
|
export * from './lib/index.js';
|
|
@@ -203,6 +206,8 @@ export type {
|
|
|
203
206
|
FillConfig,
|
|
204
207
|
ArrowConfig,
|
|
205
208
|
CandleConfig,
|
|
209
|
+
ShapeConfig,
|
|
210
|
+
BarColorConfig,
|
|
206
211
|
} from './runtime/types.js';
|
|
207
212
|
|
|
208
213
|
// Strategy types and constants (the script API forwards strategy.* calls to a host engine)
|
|
@@ -219,7 +224,7 @@ export type { LightweightSeriesDefinitions } from './runtime/adapters/Lightweigh
|
|
|
219
224
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
220
225
|
|
|
221
226
|
// Version
|
|
222
|
-
export const VERSION = '0.
|
|
227
|
+
export const VERSION = '0.12.0';
|
|
223
228
|
|
|
224
229
|
/**
|
|
225
230
|
* Library information
|
package/src/runtime/inputs.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { InputConfig, InputOptions } from './types.js';
|
|
10
10
|
import { getContext, recalculate } from './runtime.js';
|
|
11
|
+
import { externalSource } from '../utils/source-resolver.js';
|
|
11
12
|
|
|
12
13
|
// Track registered inputs for idempotent registration
|
|
13
14
|
const registeredInputs = new Map<string, boolean>();
|
|
@@ -403,7 +404,11 @@ function getSourceData(
|
|
|
403
404
|
const c = ohlcv.close[i];
|
|
404
405
|
return h !== undefined && l !== undefined && c !== undefined ? (o + h + l + c) / 4 : NaN;
|
|
405
406
|
});
|
|
406
|
-
default:
|
|
407
|
-
|
|
407
|
+
default: {
|
|
408
|
+
// Another source (study on study), else close.
|
|
409
|
+
const ext = externalSource(sourceName);
|
|
410
|
+
if (!ext) return ohlcv.close;
|
|
411
|
+
return ohlcv.close.map((_, i) => (ext as ArrayLike<number>)[i] ?? NaN);
|
|
412
|
+
}
|
|
408
413
|
}
|
|
409
414
|
}
|
package/src/runtime/types.ts
CHANGED
|
@@ -134,6 +134,11 @@ export interface PlotConfig {
|
|
|
134
134
|
linestyle?: 'solid' | 'dashed' | 'dotted';
|
|
135
135
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
136
136
|
forceOverlay?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
139
|
+
* drawn. Default true
|
|
140
|
+
*/
|
|
141
|
+
editable?: boolean;
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
/**
|
|
@@ -160,6 +165,11 @@ export interface ArrowConfig {
|
|
|
160
165
|
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
161
166
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
162
167
|
forceOverlay?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
170
|
+
* drawn. Default true
|
|
171
|
+
*/
|
|
172
|
+
editable?: boolean;
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
/**
|
|
@@ -183,6 +193,17 @@ export interface CandleConfig {
|
|
|
183
193
|
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
184
194
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
185
195
|
forceOverlay?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
198
|
+
* drawn. Default true
|
|
199
|
+
*/
|
|
200
|
+
editable?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* The colours the study chooses from per bar (the PineScript palette of the body / wick / border colour), when they
|
|
203
|
+
* are a fixed set: a user can change each of them. Unset: a single colour (`color` / `wickColor` / `borderColor`)
|
|
204
|
+
* or colours computed per bar
|
|
205
|
+
*/
|
|
206
|
+
palettes?: { color?: string[]; wickColor?: string[]; borderColor?: string[] };
|
|
186
207
|
}
|
|
187
208
|
|
|
188
209
|
/**
|
|
@@ -204,6 +225,11 @@ export interface HLineConfig {
|
|
|
204
225
|
linewidth?: number;
|
|
205
226
|
/** Display mode */
|
|
206
227
|
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
228
|
+
/**
|
|
229
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
230
|
+
* drawn. Default true
|
|
231
|
+
*/
|
|
232
|
+
editable?: boolean;
|
|
207
233
|
}
|
|
208
234
|
|
|
209
235
|
/**
|
|
@@ -227,6 +253,20 @@ export interface FillConfig {
|
|
|
227
253
|
title?: string;
|
|
228
254
|
/** Whether the fill is visible (can be boolean or expression string for dynamic visibility) */
|
|
229
255
|
visible?: boolean | string;
|
|
256
|
+
/**
|
|
257
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
258
|
+
* drawn. Default true
|
|
259
|
+
*/
|
|
260
|
+
editable?: boolean;
|
|
261
|
+
/** Gradient fill: its colour at the top value when it is the same on every bar */
|
|
262
|
+
topColor?: string;
|
|
263
|
+
/** Gradient fill: its colour at the bottom value when it is the same on every bar */
|
|
264
|
+
bottomColor?: string;
|
|
265
|
+
/**
|
|
266
|
+
* The colours the fill chooses from per bar when they are a fixed set (PineScript palette): a user can change each
|
|
267
|
+
* of them. Unset: `color` (one colour) or colours computed per bar
|
|
268
|
+
*/
|
|
269
|
+
palette?: string[];
|
|
230
270
|
}
|
|
231
271
|
|
|
232
272
|
/**
|
|
@@ -258,6 +298,16 @@ export interface ShapeConfig {
|
|
|
258
298
|
offset?: number;
|
|
259
299
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
260
300
|
forceOverlay?: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
303
|
+
* drawn. Default true
|
|
304
|
+
*/
|
|
305
|
+
editable?: boolean;
|
|
306
|
+
/**
|
|
307
|
+
* The colours the output chooses from per bar when they are a fixed set (PineScript palette): a user can change
|
|
308
|
+
* each of them. Unset: `color` (one colour) or colours computed per bar
|
|
309
|
+
*/
|
|
310
|
+
palette?: string[];
|
|
261
311
|
}
|
|
262
312
|
|
|
263
313
|
/**
|
|
@@ -275,6 +325,21 @@ export interface BarColorConfig {
|
|
|
275
325
|
/** bgcolor only: drawn on the main chart pane even when the script is not an overlay (PineScript
|
|
276
326
|
* `force_overlay`); default false */
|
|
277
327
|
forceOverlay?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
330
|
+
* drawn. Default true
|
|
331
|
+
*/
|
|
332
|
+
editable?: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* The colours the output chooses from per bar (PineScript palette): a user can change each of them. A colour given
|
|
335
|
+
* as a constant is a palette of one colour. Unset: colours computed per bar
|
|
336
|
+
*/
|
|
337
|
+
palette?: string[];
|
|
338
|
+
/**
|
|
339
|
+
* Where the output comes among the plot / shape / character / arrow / candle outputs (`outputs` of the script): it
|
|
340
|
+
* was declared after the first `outputIndex` of them. The Style settings list it there. Unset: after all of them
|
|
341
|
+
*/
|
|
342
|
+
outputIndex?: number;
|
|
278
343
|
}
|
|
279
344
|
|
|
280
345
|
/**
|
package/src/script/index.ts
CHANGED
|
@@ -78,6 +78,7 @@ import * as taSeries from '../ta-series.js';
|
|
|
78
78
|
import * as colorCore from '../color/index.js';
|
|
79
79
|
import { inputColorDefault } from '../color/parse.js';
|
|
80
80
|
import { fixnan as fixnanValues, isNA, nz } from '../utils/index.js';
|
|
81
|
+
import { externalSource } from '../utils/source-resolver.js';
|
|
81
82
|
import * as lineCore from '../line/index.js';
|
|
82
83
|
import * as labelCore from '../label/index.js';
|
|
83
84
|
import * as boxCore from '../box/index.js';
|
|
@@ -87,7 +88,7 @@ import * as tableCore from '../table/index.js';
|
|
|
87
88
|
import * as chartPointCore from '../chartpoint/index.js';
|
|
88
89
|
import * as textCore from '../text/index.js';
|
|
89
90
|
import * as mathCore from '../math/index.js';
|
|
90
|
-
import { resetDrawings, setDrawingBar, setDrawingLimits } from '../drawing/registry.js';
|
|
91
|
+
import { createdDrawingKinds, resetDrawings, setDrawingBar, setDrawingLimits, type DrawingKind } from '../drawing/registry.js';
|
|
91
92
|
export { holdDrawing, releaseDrawing, varDrawing, type DrawingVariable } from '../drawing/registry.js';
|
|
92
93
|
import { drawingOutputs } from '../drawing/output.js';
|
|
93
94
|
import * as timeframeCore from '../timeframe/index.js';
|
|
@@ -136,6 +137,11 @@ export interface ScriptRunResult {
|
|
|
136
137
|
barColorConfig: BarColorConfig[];
|
|
137
138
|
/** plotcandle() / plotbar() declarations */
|
|
138
139
|
candleConfig: CandleConfig[];
|
|
140
|
+
/**
|
|
141
|
+
* The kinds of drawing objects (label.new, line.new, box.new, linefill.new, polyline.new, table.new) the run
|
|
142
|
+
* created, even the ones deleted since: the drawing groups a user can show or hide.
|
|
143
|
+
*/
|
|
144
|
+
drawingKinds: DrawingKind[];
|
|
139
145
|
/**
|
|
140
146
|
* The plot(), plotshape(), plotchar(), plotarrow(), plotcandle() and plotbar() declarations in the order the
|
|
141
147
|
* script made them (the id of each in its own config). PineScript numbers a script's outputs in this order.
|
|
@@ -361,6 +367,7 @@ export function executeScript(
|
|
|
361
367
|
arrowConfig: c.arrowConfig,
|
|
362
368
|
barColorConfig: c.barColorConfig,
|
|
363
369
|
candleConfig: c.candleConfig,
|
|
370
|
+
drawingKinds: createdDrawingKinds(),
|
|
364
371
|
outputs: c.outputs,
|
|
365
372
|
defaultInputs: c.defaultInputs,
|
|
366
373
|
alertConfig: c.alertConfig,
|
|
@@ -557,7 +564,13 @@ for (const s of [hl2, hlc3, ohlc4, hlcc4]) s.fullHistory = true;
|
|
|
557
564
|
const SOURCES: Record<string, Series> = { open, high, low, close, volume, hl2, hlc3, ohlc4, hlcc4 };
|
|
558
565
|
|
|
559
566
|
function sourceSeries(name: string): Series {
|
|
560
|
-
|
|
567
|
+
const builtin = SOURCES[name];
|
|
568
|
+
if (builtin) return builtin;
|
|
569
|
+
// Another source (study on study): its values as the host gives them now, aligned with the bars.
|
|
570
|
+
const ext = externalSource(name);
|
|
571
|
+
if (!ext) return close;
|
|
572
|
+
const values = Array.from(ext);
|
|
573
|
+
return new Series(ctxBars, (_bar, i) => values[i] ?? NaN);
|
|
561
574
|
}
|
|
562
575
|
|
|
563
576
|
// ── Bound ta namespace ───────────────────────────────────────────────────────
|
|
@@ -691,6 +704,8 @@ export interface ScriptPlotOptions {
|
|
|
691
704
|
histbase?: number;
|
|
692
705
|
/** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
|
|
693
706
|
force_overlay?: boolean;
|
|
707
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
708
|
+
editable?: boolean;
|
|
694
709
|
}
|
|
695
710
|
|
|
696
711
|
/** PineScript `plot()` — declares the plot and supplies its data in one call. */
|
|
@@ -709,6 +724,7 @@ function plotImpl(series: Series, title?: string, options: ScriptPlotOptions = {
|
|
|
709
724
|
display: options.display,
|
|
710
725
|
histbase: options.histbase,
|
|
711
726
|
forceOverlay: options.force_overlay,
|
|
727
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
712
728
|
});
|
|
713
729
|
c.outputs.push({ kind: 'plot', id, title: title ?? id });
|
|
714
730
|
const values = series.toArray();
|
|
@@ -749,6 +765,8 @@ export interface ScriptHLineOptions {
|
|
|
749
765
|
/** Line style; default dashed (PineScript). */
|
|
750
766
|
linestyle?: HLineConfig['linestyle'];
|
|
751
767
|
linewidth?: number;
|
|
768
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
769
|
+
editable?: boolean;
|
|
752
770
|
}
|
|
753
771
|
|
|
754
772
|
/** PineScript `hline()` — a static horizontal level. Default line style: dashed (PineScript). */
|
|
@@ -762,6 +780,7 @@ function hlineImpl(price: number, title?: string, options: ScriptHLineOptions =
|
|
|
762
780
|
color: options.color,
|
|
763
781
|
linestyle: options.linestyle ?? 'dashed',
|
|
764
782
|
linewidth: options.linewidth,
|
|
783
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
765
784
|
});
|
|
766
785
|
return { id, kind: 'hline' };
|
|
767
786
|
}
|
|
@@ -777,6 +796,8 @@ export interface ScriptFillOptions {
|
|
|
777
796
|
/** Static color, or a per-bar color array from color.when(). */
|
|
778
797
|
color?: string | string[];
|
|
779
798
|
title?: string;
|
|
799
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
800
|
+
editable?: boolean;
|
|
780
801
|
}
|
|
781
802
|
|
|
782
803
|
/** A fill colour argument: a colour, na (null / undefined), or a per-bar array from color.when(). */
|
|
@@ -794,14 +815,20 @@ function perBarColors(c: ScriptFillColor, n: number): Array<string | null> {
|
|
|
794
815
|
return new Array<string | null>(n).fill(c ?? null);
|
|
795
816
|
}
|
|
796
817
|
|
|
818
|
+
/** The colour of every bar when it is the same on all of them (and not na). */
|
|
819
|
+
function sameColor(colors: Array<string | null>): string | undefined {
|
|
820
|
+
const first = colors[0];
|
|
821
|
+
return first && colors.every((x) => x === first) ? first : undefined;
|
|
822
|
+
}
|
|
823
|
+
|
|
797
824
|
/**
|
|
798
825
|
* PineScript `fill()`, with the three PineScript overloads (positional arguments), for two plots or two hlines:
|
|
799
826
|
* - `fill(p1, p2, color?, title?, ...)`
|
|
800
827
|
* - `fill(p1, p2, top_value, bottom_value, top_color, bottom_color, title?, ...)`: gradient fill; values and colours
|
|
801
828
|
* can change per bar (a Series / a color.when() array)
|
|
802
829
|
* - `fill(p1, p2, { color, title })`: options object (oakscriptjs form, kept for existing scripts)
|
|
803
|
-
*
|
|
804
|
-
*
|
|
830
|
+
* `editable = false` keeps the fill out of the Style settings; `show_last`, `fillgaps` and `display` are accepted
|
|
831
|
+
* and not used. Every fill has an id in `fillConfig` (the fills between plots also list it on their data).
|
|
805
832
|
*/
|
|
806
833
|
export function fill(a: PlotHandle, b: PlotHandle, options?: ScriptFillOptions): void;
|
|
807
834
|
export function fill(a: PlotHandle, b: PlotHandle, color: ScriptFillColor, title?: string, ...rest: unknown[]): void;
|
|
@@ -822,6 +849,7 @@ export function fill(a: PlotHandle, b: PlotHandle, ...args: unknown[]): void {
|
|
|
822
849
|
let staticColor: string | undefined;
|
|
823
850
|
let title: string | undefined;
|
|
824
851
|
let gradient: FillGradient | undefined;
|
|
852
|
+
let editable: unknown;
|
|
825
853
|
if (typeof third === 'number' || third instanceof Series) {
|
|
826
854
|
const n = ctxBars.bars.length;
|
|
827
855
|
gradient = {
|
|
@@ -831,30 +859,39 @@ export function fill(a: PlotHandle, b: PlotHandle, ...args: unknown[]): void {
|
|
|
831
859
|
bottomColor: perBarColors(args[3] as ScriptFillColor, n),
|
|
832
860
|
};
|
|
833
861
|
title = args[4] as string | undefined;
|
|
862
|
+
editable = args[5];
|
|
834
863
|
} else if (third !== null && typeof third === 'object' && !Array.isArray(third)) {
|
|
835
864
|
const options = third as ScriptFillOptions;
|
|
836
865
|
perBar = Array.isArray(options.color) ? options.color : undefined;
|
|
837
866
|
staticColor = typeof options.color === 'string' ? options.color : undefined;
|
|
838
867
|
title = options.title;
|
|
868
|
+
editable = options.editable;
|
|
839
869
|
} else {
|
|
840
870
|
const color = third as ScriptFillColor;
|
|
841
871
|
perBar = Array.isArray(color) ? color.map((x) => x ?? '') : undefined;
|
|
842
872
|
staticColor = typeof color === 'string' ? color : undefined;
|
|
843
873
|
title = args[1] as string | undefined;
|
|
874
|
+
editable = args[2];
|
|
844
875
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
876
|
+
const id = `fill${c.fillConfig.length}`;
|
|
877
|
+
const topColor = gradient && sameColor(gradient.topColor);
|
|
878
|
+
const bottomColor = gradient && sameColor(gradient.bottomColor);
|
|
879
|
+
const hlines = a.kind === 'hline' && b.kind === 'hline';
|
|
880
|
+
c.fillConfig.push({
|
|
881
|
+
id,
|
|
882
|
+
plot1: a.id,
|
|
883
|
+
plot2: b.id,
|
|
884
|
+
color: staticColor,
|
|
885
|
+
// the per-bar data of a fill between plots is in the result
|
|
886
|
+
...(hlines ? { colors: perBar, gradient } : {}),
|
|
887
|
+
title,
|
|
888
|
+
...(topColor ? { topColor } : {}),
|
|
889
|
+
...(bottomColor ? { bottomColor } : {}),
|
|
890
|
+
...(editable === false ? { editable: false } : {}),
|
|
891
|
+
});
|
|
892
|
+
if (hlines) return;
|
|
857
893
|
c.fills.push({
|
|
894
|
+
id,
|
|
858
895
|
plot1: a.id,
|
|
859
896
|
plot2: b.id,
|
|
860
897
|
options: { color: staticColor, title },
|
|
@@ -876,6 +913,8 @@ export interface PlotShapeOptions {
|
|
|
876
913
|
tooltip?: string;
|
|
877
914
|
/** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
|
|
878
915
|
force_overlay?: boolean;
|
|
916
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
917
|
+
editable?: boolean;
|
|
879
918
|
}
|
|
880
919
|
|
|
881
920
|
export interface PlotCharOptions extends Omit<PlotShapeOptions, 'style'> {
|
|
@@ -958,6 +997,7 @@ function emitMarkers(
|
|
|
958
997
|
size: options.size,
|
|
959
998
|
offset: options.offset,
|
|
960
999
|
forceOverlay: options.force_overlay,
|
|
1000
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
961
1001
|
});
|
|
962
1002
|
c.outputs.push({ kind, id, title });
|
|
963
1003
|
const shapeStyle = kind === 'shape' ? (style as ShapeStyle) : undefined;
|
|
@@ -1011,6 +1051,8 @@ export interface PlotArrowOptions {
|
|
|
1011
1051
|
display?: ArrowConfig['display'];
|
|
1012
1052
|
/** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
|
|
1013
1053
|
force_overlay?: boolean;
|
|
1054
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
1055
|
+
editable?: boolean;
|
|
1014
1056
|
}
|
|
1015
1057
|
|
|
1016
1058
|
/**
|
|
@@ -1035,6 +1077,7 @@ export function plotarrow(series: Series, title?: string, options: PlotArrowOpti
|
|
|
1035
1077
|
offset: options.offset,
|
|
1036
1078
|
display: options.display,
|
|
1037
1079
|
forceOverlay: options.force_overlay,
|
|
1080
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
1038
1081
|
});
|
|
1039
1082
|
c.outputs.push({ kind: 'arrow', id, title });
|
|
1040
1083
|
const values = series.toArray();
|
|
@@ -1058,11 +1101,21 @@ export function plotarrow(series: Series, title?: string, options: PlotArrowOpti
|
|
|
1058
1101
|
function emitBarColors(
|
|
1059
1102
|
kind: 'bgcolor' | 'barcolor',
|
|
1060
1103
|
colors: string | Array<string | undefined>,
|
|
1061
|
-
options: { offset?: number; title?: string; force_overlay?: boolean }
|
|
1104
|
+
options: { offset?: number; title?: string; force_overlay?: boolean; editable?: boolean }
|
|
1062
1105
|
): void {
|
|
1063
1106
|
const c = collector();
|
|
1064
1107
|
const id = `${kind}${c.barColorConfig.filter((x) => x.kind === kind).length}`;
|
|
1065
|
-
c.barColorConfig.push({
|
|
1108
|
+
c.barColorConfig.push({
|
|
1109
|
+
id,
|
|
1110
|
+
kind,
|
|
1111
|
+
title: options.title,
|
|
1112
|
+
offset: options.offset,
|
|
1113
|
+
forceOverlay: options.force_overlay,
|
|
1114
|
+
// a constant colour is a palette of one colour (PineScript)
|
|
1115
|
+
...(typeof colors === 'string' ? { palette: [colors] } : {}),
|
|
1116
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
1117
|
+
outputIndex: c.outputs.length,
|
|
1118
|
+
});
|
|
1066
1119
|
const b = bars();
|
|
1067
1120
|
const off = options.offset ?? 0;
|
|
1068
1121
|
const target: BgColorData[] = kind === 'bgcolor' ? c.bgColors : c.barColors;
|
|
@@ -1072,7 +1125,7 @@ function emitBarColors(
|
|
|
1072
1125
|
if (!col) continue;
|
|
1073
1126
|
const j = i + off;
|
|
1074
1127
|
if (j < 0 || j >= b.length) continue;
|
|
1075
|
-
target.push(forceOverlay ? { time: b[j]!.time, color: col, forceOverlay } : { time: b[j]!.time, color: col });
|
|
1128
|
+
target.push(forceOverlay ? { time: b[j]!.time, color: col, id, forceOverlay } : { time: b[j]!.time, color: col, id });
|
|
1076
1129
|
}
|
|
1077
1130
|
}
|
|
1078
1131
|
|
|
@@ -1082,7 +1135,7 @@ function emitBarColors(
|
|
|
1082
1135
|
*/
|
|
1083
1136
|
export function bgcolor(
|
|
1084
1137
|
colors: string | Array<string | undefined>,
|
|
1085
|
-
options: { offset?: number; title?: string; force_overlay?: boolean } = {}
|
|
1138
|
+
options: { offset?: number; title?: string; force_overlay?: boolean; editable?: boolean } = {}
|
|
1086
1139
|
): void {
|
|
1087
1140
|
emitBarColors('bgcolor', colors, options);
|
|
1088
1141
|
}
|
|
@@ -1090,7 +1143,7 @@ export function bgcolor(
|
|
|
1090
1143
|
/** PineScript `barcolor()` — per-bar candle color override. */
|
|
1091
1144
|
export function barcolor(
|
|
1092
1145
|
colors: string | Array<string | undefined>,
|
|
1093
|
-
options: { title?: string } = {}
|
|
1146
|
+
options: { title?: string; editable?: boolean } = {}
|
|
1094
1147
|
): void {
|
|
1095
1148
|
emitBarColors('barcolor', colors, options);
|
|
1096
1149
|
}
|
|
@@ -1108,6 +1161,8 @@ export interface PlotCandleOptions {
|
|
|
1108
1161
|
display?: CandleConfig['display'];
|
|
1109
1162
|
/** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
|
|
1110
1163
|
force_overlay?: boolean;
|
|
1164
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
1165
|
+
editable?: boolean;
|
|
1111
1166
|
}
|
|
1112
1167
|
|
|
1113
1168
|
export interface PlotBarOptions {
|
|
@@ -1116,6 +1171,8 @@ export interface PlotBarOptions {
|
|
|
1116
1171
|
display?: CandleConfig['display'];
|
|
1117
1172
|
/** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
|
|
1118
1173
|
force_overlay?: boolean;
|
|
1174
|
+
/** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
|
|
1175
|
+
editable?: boolean;
|
|
1119
1176
|
}
|
|
1120
1177
|
|
|
1121
1178
|
/** Colour of bar i: undefined when the argument is not given, 'transparent' for an na entry. */
|
|
@@ -1171,6 +1228,7 @@ export function plotcandle(
|
|
|
1171
1228
|
borderColor: staticColor(options.bordercolor),
|
|
1172
1229
|
display: options.display,
|
|
1173
1230
|
forceOverlay: options.force_overlay,
|
|
1231
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
1174
1232
|
});
|
|
1175
1233
|
c.outputs.push({ kind: 'candle', id, title });
|
|
1176
1234
|
const b = bars();
|
|
@@ -1208,6 +1266,7 @@ export function plotbar(
|
|
|
1208
1266
|
color: staticColor(options.color),
|
|
1209
1267
|
display: options.display,
|
|
1210
1268
|
forceOverlay: options.force_overlay,
|
|
1269
|
+
...(options.editable === false ? { editable: false } : {}),
|
|
1211
1270
|
});
|
|
1212
1271
|
c.outputs.push({ kind: 'bar', id, title });
|
|
1213
1272
|
const b = bars();
|