oakscriptjs 0.16.0 → 0.17.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.
@@ -77,6 +77,16 @@ const upVolume = eachBar((c) => vols[c.i].reduce((sum, v) => sum + v, 0));
77
77
  plot(upVolume, "Up volume", { style: plot.style_columns, color: color.teal });
78
78
  ```
79
79
 
80
+ ### Seed data
81
+
82
+ `request.seed(source, symbol, expression)` reads a seed data series on the chart timeframe: it is
83
+ `request.security` of the symbol the host gives that series (by default `"<SOURCE>:<SYMBOL>"` upper-cased).
84
+
85
+ ```js
86
+ indicator("Seed value", { overlay: false });
87
+ plot(request.seed("seed_crypto_santiment", "BTC_DEV_ACTIVITY", () => close), "Dev activity");
88
+ ```
89
+
80
90
  ## Timeframe values
81
91
 
82
92
  - `timeframe.period` (`"60"`, `"1D"`...), `timeframe.multiplier`, `timeframe.isintraday`, `timeframe.isdaily`,
@@ -2944,6 +2944,11 @@ export interface ChartContext {
2944
2944
  * `request.security` merges on (#179), and the other fields its `syminfo.*` inside the expression.
2945
2945
  */
2946
2946
  symbolInfo?: (symbol: string) => SymbolInfo | undefined;
2947
+ /**
2948
+ * Ticker of a seed data series for `request.seed(source, symbol, ...)` (#205), whose bars then come from
2949
+ * {@link bars} like any other symbol. Default: `"<SOURCE>:<SYMBOL>"` upper-cased.
2950
+ */
2951
+ seedSymbol?: (source: string, symbol: string) => string;
2947
2952
  }
2948
2953
 
2949
2954
  /** Calendar and properties of a symbol, as in {@link ChartContext}. */
@@ -3666,10 +3671,26 @@ function security_lower_tf<T extends SecurityValue>(
3666
3671
  return (Array.isArray(result) ? mapped : mapped[0]) as T extends unknown[] ? number[][][] : number[][];
3667
3672
  }
3668
3673
 
3669
- /** PineScript `request.*`: `security` (issue #101, other symbols #179, lower timeframes #181) and `security_lower_tf`. */
3674
+ /**
3675
+ * PineScript `request.seed(source, symbol, expression, ignore_invalid_symbol)` (#205): `expression` on a seed data
3676
+ * series, on the chart timeframe. The series is the symbol `ChartContext.seedSymbol(source, symbol)` (default
3677
+ * `"<SOURCE>:<SYMBOL>"` upper-cased), read as `request.security(<that symbol>, "", expression)`.
3678
+ */
3679
+ function seed<T extends SecurityValue>(
3680
+ source: string,
3681
+ symbol: string,
3682
+ expression: () => T,
3683
+ ignore_invalid_symbol: boolean = false
3684
+ ): T extends unknown[] ? Series[] : Series {
3685
+ const ticker = chartCtx.seedSymbol?.(source, symbol) ?? `${source.toUpperCase()}:${symbol.toUpperCase()}`;
3686
+ return security(ticker, '', expression, barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol);
3687
+ }
3688
+
3689
+ /** PineScript `request.*`: `security` (issue #101, other symbols #179, lower timeframes #181), `security_lower_tf` and `seed` (#205). */
3670
3690
  /** PineScript parameters of `request.security` / `request.security_lower_tf`, in their positional order. */
3671
3691
  const SECURITY_PARAMETERS = ['symbol', 'timeframe', 'expression', 'gaps', 'lookahead', 'ignore_invalid_symbol', 'currency', 'calc_bars_count'] as const;
3672
3692
  const SECURITY_LOWER_TF_PARAMETERS = ['symbol', 'timeframe', 'expression', 'ignore_invalid_symbol', 'currency', 'ignore_invalid_timeframe', 'calc_bars_count'] as const;
3693
+ const SEED_PARAMETERS = ['source', 'symbol', 'expression', 'ignore_invalid_symbol', 'calc_bars_count'] as const;
3673
3694
 
3674
3695
  /** Named arguments of `request.security` (PineScript names). */
3675
3696
  export interface SecurityArgs<T extends SecurityValue = SecurityValue> {
@@ -3727,7 +3748,28 @@ function securityLowerTfCall<T extends SecurityValue>(
3727
3748
  return security_lower_tf(a[0] as string, a[1] as string, a[2] as () => T, a[3] as boolean | undefined);
3728
3749
  }
3729
3750
 
3730
- export const request = strictNamespace('request', { security: securityCall, security_lower_tf: securityLowerTfCall });
3751
+ /** Named arguments of `request.seed` (PineScript names). */
3752
+ export interface SeedArgs<T extends SecurityValue = SecurityValue> {
3753
+ source?: string;
3754
+ symbol?: string;
3755
+ expression?: () => T;
3756
+ ignore_invalid_symbol?: boolean;
3757
+ calc_bars_count?: number;
3758
+ }
3759
+
3760
+ /** `request.seed` with PineScript's named arguments. */
3761
+ function seedCall<T extends SecurityValue>(
3762
+ ...args:
3763
+ | [source: string, symbol: string, expression: () => T, ignore_invalid_symbol?: boolean]
3764
+ | [source: string, symbol: string, expression: () => T, args: SeedArgs<T>]
3765
+ | [args: SeedArgs<T> & { source: string; symbol: string; expression: () => T }]
3766
+ ): T extends unknown[] ? Series[] : Series {
3767
+ const a = namedArguments('request.seed', SEED_PARAMETERS, args);
3768
+ unsupportedSecurityArgs('request.seed', undefined, a[4]);
3769
+ return seed(a[0] as string, a[1] as string, a[2] as () => T, a[3] as boolean | undefined);
3770
+ }
3771
+
3772
+ export const request = strictNamespace('request', { security: securityCall, security_lower_tf: securityLowerTfCall, seed: seedCall });
3731
3773
 
3732
3774
  // ── Drawing objects ──────────────────────────────────────────────────────────
3733
3775
  // The drawing namespaces come from this bundle so that they share the registry that