oakscriptjs 0.9.0 → 0.9.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/dist/cjs/array/index.d.ts +1 -1
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +2 -1
- package/dist/cjs/array/index.js.map +2 -2
- package/dist/cjs/callsite/index.d.ts +27 -0
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +47 -0
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts +1 -0
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +9 -30
- package/dist/cjs/color/index.js.map +2 -2
- package/dist/cjs/color/parse.d.ts +29 -0
- package/dist/cjs/color/parse.d.ts.map +1 -0
- package/dist/cjs/color/parse.js +57 -0
- package/dist/cjs/color/parse.js.map +7 -0
- 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/script/index.d.ts +4 -0
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +6 -1
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/ta/index.d.ts +3 -0
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +6 -2
- package/dist/cjs/ta/index.js.map +2 -2
- package/dist/esm/array/index.d.ts +1 -1
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +3 -2
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts +27 -0
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +79 -0
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/color/index.d.ts +1 -0
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +13 -36
- package/dist/esm/color/index.js.map +1 -1
- package/dist/esm/color/parse.d.ts +29 -0
- package/dist/esm/color/parse.d.ts.map +1 -0
- package/dist/esm/color/parse.js +55 -0
- package/dist/esm/color/parse.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/script/index.d.ts +4 -0
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +6 -1
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/ta/index.d.ts +3 -0
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +11 -2
- package/dist/esm/ta/index.js.map +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +3 -2
- package/src/callsite/index.ts +74 -0
- package/src/color/index.ts +14 -36
- package/src/color/parse.ts +56 -0
- package/src/index.ts +1 -1
- package/src/script/index.ts +6 -1
- package/src/ta/index.ts +9 -2
package/src/index.ts
CHANGED
|
@@ -164,7 +164,7 @@ export type { LightweightSeriesDefinitions } from './runtime/adapters/Lightweigh
|
|
|
164
164
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
165
165
|
|
|
166
166
|
// Version
|
|
167
|
-
export const VERSION = '0.9.
|
|
167
|
+
export const VERSION = '0.9.1';
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* Library information
|
package/src/script/index.ts
CHANGED
|
@@ -58,6 +58,7 @@ import type {
|
|
|
58
58
|
import { BarData, Series } from '../runtime/series.js';
|
|
59
59
|
import * as taSeries from '../ta-series.js';
|
|
60
60
|
import * as colorCore from '../color/index.js';
|
|
61
|
+
import { inputColorDefault } from '../color/parse.js';
|
|
61
62
|
import { fixnan as fixnanValues, isNA, nz } from '../utils/index.js';
|
|
62
63
|
import * as lineCore from '../line/index.js';
|
|
63
64
|
import * as labelCore from '../label/index.js';
|
|
@@ -404,8 +405,12 @@ export const input = {
|
|
|
404
405
|
string(defval: string, title?: string, opts: StringInputOptions = {}): string {
|
|
405
406
|
return registerInput<string>({ type: 'string', defval, title, options: opts.options, ...common(opts) }, 'input_string');
|
|
406
407
|
},
|
|
408
|
+
/**
|
|
409
|
+
* Declares a colour input. As in PineScript, the default keeps an alpha of 2 decimals: an input default
|
|
410
|
+
* `color.new(c, 90)` has the alpha byte 26 (25 in the script). A value given by the host is not changed.
|
|
411
|
+
*/
|
|
407
412
|
color(defval: string, title?: string, opts: InputOptions = {}): string {
|
|
408
|
-
return registerInput<string>({ type: 'color', defval, title, ...common(opts) }, 'input_color');
|
|
413
|
+
return registerInput<string>({ type: 'color', defval: inputColorDefault(defval), title, ...common(opts) }, 'input_color');
|
|
409
414
|
},
|
|
410
415
|
/** Declares a source input and returns it as a Series. */
|
|
411
416
|
source(defval: string = 'close', title?: string, opts: InputOptions = {}): Series {
|
package/src/ta/index.ts
CHANGED
|
@@ -127,6 +127,8 @@ export function ema(source: Source, length: simple_int): series_float {
|
|
|
127
127
|
* - RSI values below 30 typically indicate oversold conditions
|
|
128
128
|
* - Uses `ta.rma()` (Relative Moving Average) for smoothing, matching PineScript v6
|
|
129
129
|
* - Formula: RSI = 100 - (100 / (1 + RS)), where RS = Average Gain / Average Loss
|
|
130
|
+
* - As in PineScript (`down == 0 ? 100 : up == 0 ? 0 : ...`): 100 when the average loss is 0, else 0 when the
|
|
131
|
+
* average gain is 0, both with the 1e-10 tolerance of the comparison operators
|
|
130
132
|
* - Average Gain and Average Loss are calculated using RMA (alpha = 1 / length)
|
|
131
133
|
* - `na` values in the source series are ignored
|
|
132
134
|
*
|
|
@@ -158,8 +160,10 @@ export function rsi(source: Source, length: simple_int): series_float {
|
|
|
158
160
|
result.push(NaN); // First value is NaN
|
|
159
161
|
|
|
160
162
|
for (let i = 0; i < avgGains.length; i++) {
|
|
161
|
-
if (avgLosses[i]
|
|
163
|
+
if (eq(avgLosses[i]!, 0)) {
|
|
162
164
|
result.push(100);
|
|
165
|
+
} else if (eq(avgGains[i]!, 0)) {
|
|
166
|
+
result.push(0);
|
|
163
167
|
} else {
|
|
164
168
|
const rs = avgGains[i]! / avgLosses[i]!;
|
|
165
169
|
result.push(100 - (100 / (1 + rs)));
|
|
@@ -1476,6 +1480,7 @@ export function percentrank(source: Source, length: simple_int): series_float {
|
|
|
1476
1480
|
* - Typical Price = (High + Low + Close) / 3
|
|
1477
1481
|
* - Mean Deviation = Average of absolute differences from mean
|
|
1478
1482
|
* - Scaled by 0.015 to provide more readable numbers
|
|
1483
|
+
* - As in PineScript: when the mean deviation is 0 (1e-10 tolerance, a flat window), the CCI of the previous bar
|
|
1479
1484
|
* - Values above +100 indicate overbought conditions
|
|
1480
1485
|
* - Values below -100 indicate oversold conditions
|
|
1481
1486
|
* - \`na\` values in the source series are ignored
|
|
@@ -1493,8 +1498,10 @@ export function cci(source: Source, length: simple_int): series_float {
|
|
|
1493
1498
|
const devValues = dev(source, length);
|
|
1494
1499
|
|
|
1495
1500
|
for (let i = 0; i < source.length; i++) {
|
|
1496
|
-
if (isNaN(smaValues[i]!) || isNaN(devValues[i]!)
|
|
1501
|
+
if (isNaN(smaValues[i]!) || isNaN(devValues[i]!)) {
|
|
1497
1502
|
result.push(NaN);
|
|
1503
|
+
} else if (eq(devValues[i]!, 0)) {
|
|
1504
|
+
result.push(i > 0 ? result[i - 1]! : NaN);
|
|
1498
1505
|
} else {
|
|
1499
1506
|
const cci = (source[i]! - smaValues[i]!) / (0.015 * devValues[i]!);
|
|
1500
1507
|
result.push(cci);
|