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.
Files changed (61) hide show
  1. package/dist/cjs/array/index.d.ts +1 -1
  2. package/dist/cjs/array/index.d.ts.map +1 -1
  3. package/dist/cjs/array/index.js +2 -1
  4. package/dist/cjs/array/index.js.map +2 -2
  5. package/dist/cjs/callsite/index.d.ts +27 -0
  6. package/dist/cjs/callsite/index.d.ts.map +1 -1
  7. package/dist/cjs/callsite/index.js +47 -0
  8. package/dist/cjs/callsite/index.js.map +2 -2
  9. package/dist/cjs/color/index.d.ts +1 -0
  10. package/dist/cjs/color/index.d.ts.map +1 -1
  11. package/dist/cjs/color/index.js +9 -30
  12. package/dist/cjs/color/index.js.map +2 -2
  13. package/dist/cjs/color/parse.d.ts +29 -0
  14. package/dist/cjs/color/parse.d.ts.map +1 -0
  15. package/dist/cjs/color/parse.js +57 -0
  16. package/dist/cjs/color/parse.js.map +7 -0
  17. package/dist/cjs/index.d.ts +1 -1
  18. package/dist/cjs/index.js +1 -1
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/cjs/script/index.d.ts +4 -0
  21. package/dist/cjs/script/index.d.ts.map +1 -1
  22. package/dist/cjs/script/index.js +6 -1
  23. package/dist/cjs/script/index.js.map +2 -2
  24. package/dist/cjs/ta/index.d.ts +3 -0
  25. package/dist/cjs/ta/index.d.ts.map +1 -1
  26. package/dist/cjs/ta/index.js +6 -2
  27. package/dist/cjs/ta/index.js.map +2 -2
  28. package/dist/esm/array/index.d.ts +1 -1
  29. package/dist/esm/array/index.d.ts.map +1 -1
  30. package/dist/esm/array/index.js +3 -2
  31. package/dist/esm/array/index.js.map +1 -1
  32. package/dist/esm/callsite/index.d.ts +27 -0
  33. package/dist/esm/callsite/index.d.ts.map +1 -1
  34. package/dist/esm/callsite/index.js +79 -0
  35. package/dist/esm/callsite/index.js.map +1 -1
  36. package/dist/esm/color/index.d.ts +1 -0
  37. package/dist/esm/color/index.d.ts.map +1 -1
  38. package/dist/esm/color/index.js +13 -36
  39. package/dist/esm/color/index.js.map +1 -1
  40. package/dist/esm/color/parse.d.ts +29 -0
  41. package/dist/esm/color/parse.d.ts.map +1 -0
  42. package/dist/esm/color/parse.js +55 -0
  43. package/dist/esm/color/parse.js.map +1 -0
  44. package/dist/esm/index.d.ts +1 -1
  45. package/dist/esm/index.js +1 -1
  46. package/dist/esm/script/index.d.ts +4 -0
  47. package/dist/esm/script/index.d.ts.map +1 -1
  48. package/dist/esm/script/index.js +6 -1
  49. package/dist/esm/script/index.js.map +1 -1
  50. package/dist/esm/ta/index.d.ts +3 -0
  51. package/dist/esm/ta/index.d.ts.map +1 -1
  52. package/dist/esm/ta/index.js +11 -2
  53. package/dist/esm/ta/index.js.map +1 -1
  54. package/package.json +1 -1
  55. package/src/array/index.ts +3 -2
  56. package/src/callsite/index.ts +74 -0
  57. package/src/color/index.ts +14 -36
  58. package/src/color/parse.ts +56 -0
  59. package/src/index.ts +1 -1
  60. package/src/script/index.ts +6 -1
  61. 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.0';
167
+ export const VERSION = '0.9.1';
168
168
 
169
169
  /**
170
170
  * Library information
@@ -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]! === 0) {
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]!) || devValues[i]! === 0) {
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);