openalgo-charts 2.5.2 → 2.5.4

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.
@@ -1,4 +1,5 @@
1
- import { IndicatorDescriptor, ChartDataContext, IndicatorSettings, Bar, IndicatorBarsRequest, IndicatorInput, IndicatorPlot, IndicatorValues, IndicatorStore, IndicatorCalcContext, IndicatorLevel } from 'openalgo-charts';
1
+ import { IndicatorDescriptor, ChartDataContext, IndicatorRequestState, IndicatorSettings, Bar, IndicatorBarsRequest, IndicatorInput, IndicatorPlot, IndicatorValues, IndicatorStore, IndicatorCalcContext, IndicatorLevel, RequestedBarsSnapshot, IndicatorSnapshotRequest } from 'openalgo-charts';
2
+ export { RequestedBarsSnapshot } from 'openalgo-charts';
2
3
 
3
4
  declare const SMA: IndicatorDescriptor;
4
5
  declare const WMA: IndicatorDescriptor;
@@ -973,6 +974,143 @@ declare const WAVETREND_INDICATORS: readonly IndicatorDescriptor[];
973
974
  declare const SEASONALITY: IndicatorDescriptor;
974
975
  declare const SEASONALITY_INDICATORS: readonly IndicatorDescriptor[];
975
976
 
977
+ /**
978
+ * Array-based statistics with explicit observation windows. Results keep the
979
+ * input length and never mutate inputs. NaN and infinities are missing values.
980
+ * Numeric warmup and undefined statistics are NaN; boolean warmup is false.
981
+ */
982
+ /** Missing-value policy shared by numerical statistics and predicates. */
983
+ interface NumericalWindowOptions {
984
+ /**
985
+ * `propagate` (default) uses chronological windows and rejects missing terms.
986
+ * `skip` uses finite observations, preserving their original order. Rolling
987
+ * numeric results hold across missing bars once the window is full.
988
+ * Predicates require a finite current observation and otherwise return false.
989
+ */
990
+ missing?: 'propagate' | 'skip';
991
+ }
992
+ /** Estimator choice for {@link rollingVariance}. */
993
+ interface RollingVarianceOptions extends NumericalWindowOptions {
994
+ /** Divide by period-1 for a sample, or period for the default population. */
995
+ sample?: boolean;
996
+ }
997
+ /**
998
+ * Rolling median, averaging the middle pair for even periods. Uses a full
999
+ * period including the current bar, with NaN until ready. Missing values
1000
+ * propagate by default; `skip` collects period finite observations and holds
1001
+ * across gaps. Equal values retain their multiplicity. Invalid periods throw
1002
+ * RangeError; an unknown missing policy throws TypeError.
1003
+ */
1004
+ declare function rollingMedian(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1005
+ /**
1006
+ * Most frequent value in a full period ending at the current bar; equal
1007
+ * frequencies choose the smallest value. Warmup is NaN. Missing values
1008
+ * propagate by default; `skip` collects period finite observations and holds
1009
+ * across gaps. Invalid periods throw RangeError; unknown policies TypeError.
1010
+ */
1011
+ declare function rollingMode(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1012
+ /**
1013
+ * Variance of a full period ending at the current bar. Population is the
1014
+ * default; `sample` divides by period-1 and gives NaN for period one. Ties are
1015
+ * repeated observations. Warmup is NaN. Missing values propagate by default;
1016
+ * `skip` collects period finite observations and holds across gaps. Invalid
1017
+ * periods throw RangeError; invalid policy or sample options throw TypeError.
1018
+ * A variance beyond the finite number range is Infinity.
1019
+ */
1020
+ declare function rollingVariance(values: readonly number[], period: number, options?: RollingVarianceOptions): number[];
1021
+ /**
1022
+ * Maximum minus minimum in a full period ending at the current bar. Repeated
1023
+ * extremes do not change the result. Warmup is NaN. Missing values propagate
1024
+ * by default; `skip` collects period finite observations and holds across gaps.
1025
+ * Invalid periods throw RangeError; unknown missing policies throw TypeError.
1026
+ */
1027
+ declare function rollingRange(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1028
+ /**
1029
+ * Sorted-window percentile at zero-based rank (period-1)*percentage/100,
1030
+ * interpolating its adjacent values. Ties retain multiplicity; endpoints are
1031
+ * the minimum and maximum. A full period includes the current bar; warmup is
1032
+ * NaN. Missing values propagate by default; `skip` collects finite observations
1033
+ * and holds across gaps. Invalid periods or percentages outside 0..100 throw
1034
+ * RangeError; unknown missing policies throw TypeError.
1035
+ */
1036
+ declare function percentileLinear(values: readonly number[], period: number, percentage: number, options?: NumericalWindowOptions): number[];
1037
+ /**
1038
+ * Spearman correlation of value ranks with chronological order, times 100.
1039
+ * Tied values receive their average rank. A constant or one-value window is
1040
+ * NaN, as is warmup before a full period including the current bar. Missing
1041
+ * values propagate by default; `skip` ranks the last period finite observations
1042
+ * and holds across gaps. Invalid periods throw RangeError; unknown policies
1043
+ * throw TypeError.
1044
+ */
1045
+ declare function rankCorrelation(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1046
+ /**
1047
+ * Negative weighted sum divided by the ordinary sum over a full period,
1048
+ * assigning weight one to the newest value and period to the oldest. Equal
1049
+ * values remain separate observations. A zero compensated ordinary sum and
1050
+ * warmup are NaN; a nonzero sum is never discarded using an epsilon cutoff.
1051
+ * Ratios beyond the finite number range yield signed Infinity.
1052
+ * Missing values propagate by default; `skip` weights the last period finite
1053
+ * observations and holds across gaps. Invalid periods throw RangeError;
1054
+ * unknown missing policies throw TypeError.
1055
+ */
1056
+ declare function centerOfGravity(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1057
+ /**
1058
+ * Minimum from the first bar through the current bar; equal minima retain the
1059
+ * existing value. There is no fixed warmup. Default `propagate` makes the
1060
+ * entire remaining history NaN after any missing term. `skip` holds the last
1061
+ * finite minimum, with NaN before the first finite term. Unknown policies
1062
+ * throw TypeError; empty input returns an empty array.
1063
+ */
1064
+ declare function runningMin(values: readonly number[], options?: NumericalWindowOptions): number[];
1065
+ /**
1066
+ * Maximum from the first bar through the current bar; equal maxima retain the
1067
+ * existing value. There is no fixed warmup. Default `propagate` makes the
1068
+ * remaining history NaN after any missing term. `skip` holds the last finite
1069
+ * maximum, with NaN before the first finite term. Unknown policies throw
1070
+ * TypeError; empty input returns an empty array.
1071
+ */
1072
+ declare function runningMax(values: readonly number[], options?: NumericalWindowOptions): number[];
1073
+ /**
1074
+ * Current a>b after previous a<=b. Current equality is false; prior equality
1075
+ * qualifies. Default `propagate` requires finite pairs on adjacent bars;
1076
+ * `skip` compares with the most recent jointly finite pair. Missing current
1077
+ * pairs and the first pair return false. Unequal array lengths throw
1078
+ * RangeError; unknown missing policies throw TypeError.
1079
+ */
1080
+ declare function crossesAbove(a: readonly number[], b: readonly number[], options?: NumericalWindowOptions): boolean[];
1081
+ /**
1082
+ * Current a<b after previous a>=b. Current equality is false; prior equality
1083
+ * qualifies. Default `propagate` requires finite adjacent pairs; `skip` uses
1084
+ * the most recent jointly finite pair. Missing current pairs and the first
1085
+ * pair return false. Unequal lengths throw RangeError; unknown policies
1086
+ * throw TypeError.
1087
+ */
1088
+ declare function crossesBelow(a: readonly number[], b: readonly number[], options?: NumericalWindowOptions): boolean[];
1089
+ /**
1090
+ * Crossing in either direction, with strict current inequality and inclusive
1091
+ * prior inequality. Default `propagate` requires finite adjacent pairs;
1092
+ * `skip` compares with the most recent jointly finite pair. Missing current
1093
+ * pairs and the first pair are false. Unequal lengths throw RangeError;
1094
+ * unknown missing policies throw TypeError.
1095
+ */
1096
+ declare function crosses(a: readonly number[], b: readonly number[], options?: NumericalWindowOptions): boolean[];
1097
+ /**
1098
+ * Whether the finite current value strictly exceeds every one of period prior
1099
+ * observations, excluding the current bar. Equality fails. Default `propagate`
1100
+ * uses prior chronological bars; `skip` collects prior finite observations.
1101
+ * Missing current values, gaps in required history, and insufficient history
1102
+ * return false. Invalid periods throw RangeError; unknown policies TypeError.
1103
+ */
1104
+ declare function rising(values: readonly number[], period: number, options?: NumericalWindowOptions): boolean[];
1105
+ /**
1106
+ * Whether the finite current value is strictly below every one of period prior
1107
+ * observations, excluding the current bar. Equality fails. Default `propagate`
1108
+ * uses prior chronological bars; `skip` collects prior finite observations.
1109
+ * Missing current values, gaps in required history, and insufficient history
1110
+ * return false. Invalid periods throw RangeError; unknown policies TypeError.
1111
+ */
1112
+ declare function falling(values: readonly number[], period: number, options?: NumericalWindowOptions): boolean[];
1113
+
976
1114
  /**
977
1115
  * Pure calculation helpers shared by the Tier-1 indicator descriptors
978
1116
  * (`openalgo-charts/indicators`). Every function returns an array the same
@@ -982,59 +1120,161 @@ declare const SEASONALITY_INDICATORS: readonly IndicatorDescriptor[];
982
1120
  *
983
1121
  * `ema`, `rsi`, `atr`, `trueRange`, and `supertrend` are NOT re-implemented
984
1122
  * here — they ship in the base bundle and the tier imports them from it.
1123
+ *
1124
+ * For helpers accepting missing-value options, omitted options use each
1125
+ * helper's documented default. Supplied options treat NaN and infinities as
1126
+ * missing. An empty options object selects chronological propagation.
1127
+ *
1128
+ * Varying window lengths must align with the source. Each bar uses its own
1129
+ * positive safe-integer length; NaN lengths produce gaps without discarding
1130
+ * source history. Other invalid numeric lengths throw RangeError, malformed
1131
+ * elements throw TypeError, and unequal array lengths throw RangeError.
1132
+ * Array lengths default to chronological propagation. With `skip`, changed
1133
+ * lengths reevaluate finite history even on missing source bars. These paths
1134
+ * use O(n + sum of evaluated window lengths) time and O(n) working storage.
985
1135
  */
986
- /** Simple moving average. First value lands at index `period - 1`. */
987
- declare function sma(values: readonly number[], period: number): number[];
988
- /** Linearly weighted moving average (most recent bar carries weight `period`). */
989
- declare function wma(values: readonly number[], period: number): number[];
990
- /**
991
- * Wilder's smoothing (RMA): seed with the SMA of the first `period` values,
992
- * then `(prev * (period - 1) + v) / period`. The basis of RSI, ATR, and ADX.
993
- */
994
- declare function rma(values: readonly number[], period: number): number[];
995
- /** Rolling population standard deviation over `period`. */
996
- declare function stdev(values: readonly number[], period: number): number[];
997
- /** Rolling maximum over `period` bars. */
998
- declare function highest(values: readonly number[], period: number): number[];
999
- /** Rolling minimum over `period` bars. */
1000
- declare function lowest(values: readonly number[], period: number): number[];
1136
+
1137
+ /**
1138
+ * Simple moving average. Valid scalar windows without options sum oldest first
1139
+ * afresh, then divide once. Missing or overflowing sums produce NaN and recover
1140
+ * when they expire. This uses O(n * period) time and O(1) extra working storage.
1141
+ * Unsupported scalar periods retain their historical behavior.
1142
+ * Supplied `skip` collects period finite observations and holds across gaps;
1143
+ * `propagate` (also the default for {}) requires a complete chronological
1144
+ * window. Warmup is NaN. Option-path periods must be positive safe integers;
1145
+ * invalid periods throw RangeError and malformed options throw TypeError.
1146
+ */
1147
+ declare function sma(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1148
+ /** Bar-aligned lengths use each current window; NaN lengths give gaps. Arrays default to propagation. */
1149
+ declare function sma(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1150
+ /**
1151
+ * Linearly weighted average, newest observation carrying weight period.
1152
+ * Valid scalar defaults sum weighted terms oldest first and omit nonfinite
1153
+ * results. Supplied `skip` weights period
1154
+ * finite observations and holds across gaps; `propagate` requires a full
1155
+ * chronological window. Warmup is NaN. The option path validates a positive
1156
+ * safe-integer period and a missing policy, throwing RangeError or TypeError.
1157
+ */
1158
+ declare function wma(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1159
+ /** Bar-aligned lengths weight the newest selected observation most; NaN lengths give gaps. */
1160
+ declare function wma(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1161
+ /**
1162
+ * Wilder's smoothing (RMA): seed from the first complete finite window,
1163
+ * then `(prev * (period - 1) + v) / period`. Valid scalar defaults retry
1164
+ * nonfinite seeds, leave a gap for missing inputs and retain seeded state.
1165
+ * Running overflow is unavailable without restarting. Supplied `skip` seeds from period
1166
+ * finite observations and holds state across gaps. `propagate` clears state on
1167
+ * a missing input and reseeds after period consecutive finite observations.
1168
+ * Warmup is NaN. The option path requires a positive safe-integer period and
1169
+ * valid policy, throwing RangeError or TypeError respectively.
1170
+ */
1171
+ declare function rma(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1172
+ /**
1173
+ * Population standard deviation. Valid scalar defaults accumulate squared
1174
+ * deviations oldest first and omit nonfinite results.
1175
+ * Supplied `skip` uses period finite observations and holds across gaps;
1176
+ * `propagate` requires a full chronological window. Ties retain multiplicity;
1177
+ * warmup is NaN. Invalid option-path periods throw RangeError, malformed
1178
+ * options TypeError. A period must be a positive safe integer.
1179
+ */
1180
+ declare function stdev(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1181
+ /** Bar-aligned lengths select the current population; NaN lengths give gaps. Arrays default to propagation. */
1182
+ declare function stdev(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1183
+ /**
1184
+ * Rolling maximum. Omitted options preserve legacy warmup and gap behavior.
1185
+ * Supplied `skip` searches period finite observations and holds across gaps;
1186
+ * `propagate` requires period chronological finite bars. Insufficient or
1187
+ * all-missing history is NaN. Invalid option-path periods throw RangeError;
1188
+ * malformed policies throw TypeError. Periods must be positive safe integers.
1189
+ */
1190
+ declare function highest(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1191
+ /** Bar-aligned lengths select the current maximum window; NaN lengths give gaps. */
1192
+ declare function highest(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1193
+ /**
1194
+ * Rolling minimum. Omitted options preserve legacy warmup and gap behavior.
1195
+ * Supplied `skip` searches period finite observations and holds across gaps;
1196
+ * `propagate` requires period chronological finite bars. Insufficient or
1197
+ * all-missing history is NaN. Invalid option-path periods throw RangeError;
1198
+ * malformed policies throw TypeError. Periods must be positive safe integers.
1199
+ */
1200
+ declare function lowest(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1201
+ /** Bar-aligned lengths select the current minimum window; NaN lengths give gaps. */
1202
+ declare function lowest(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1001
1203
  /** NaN → null, so a warmup slot serialises as an explicit gap. */
1002
1204
  declare function nulls(values: readonly number[]): (number | null)[];
1003
1205
  /**
1004
- * the reference `ema`: seeded with the **SMA of the first `period` values**, NaN
1005
- * before that. The base bundle's `ema` seeds from `values[0]` and emits from
1006
- * index 0 instead, so the two disagree for roughly the first `period` bars and
1007
- * converge after. Anything reproducing a reference platform plot needs this one.
1008
- */
1009
- declare function smaSeededEma(values: readonly number[], period: number): number[];
1206
+ * EMA seeded with an SMA, then smoothed with alpha=2/(period+1). Valid scalar
1207
+ * defaults seed from the first complete finite window, retry nonfinite seeds,
1208
+ * and emit gaps for missing inputs while retaining seeded state. A nonfinite
1209
+ * running update stays committed, without restarting. Supplied
1210
+ * `skip` seeds from period finite observations and holds state across gaps.
1211
+ * `propagate` clears state on any missing input and reseeds with period
1212
+ * consecutive finite observations. Warmup is NaN. Invalid option-path
1213
+ * periods throw RangeError; malformed options throw TypeError. Periods must
1214
+ * be positive safe integers.
1215
+ */
1216
+ declare function smaSeededEma(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1010
1217
  /** the reference `change(src, n)`: `src - src[n]`. NaN for the first `n` bars. */
1011
1218
  declare function change(values: readonly number[], n?: number): number[];
1012
1219
  /** the reference `roc`: `100 * (src - src[n]) / src[n]`. NaN for the first `n` bars. */
1013
1220
  declare function roc(values: readonly number[], n: number): number[];
1014
1221
  /**
1015
- * the reference `dev`: mean **absolute** deviation from the SMA over `period` — not
1016
- * a standard deviation. CCI's 0.015 constant is calibrated against this.
1017
- */
1018
- declare function dev(values: readonly number[], period: number): number[];
1019
- /**
1020
- * the reference `percentrank`: the percentage of the **previous** `period` values
1021
- * that are less than or equal to the current one. The current bar is the
1022
- * subject of the comparison, not part of the window, so the first answer lands
1023
- * at index `period`.
1024
- */
1025
- declare function percentRank(values: readonly number[], period: number): number[];
1222
+ * Mean absolute deviation from the average. Valid scalar defaults accumulate
1223
+ * deviations oldest first and omit nonfinite results.
1224
+ * Supplied `skip` uses period finite observations and holds across
1225
+ * gaps; `propagate` requires a full chronological window. Ties retain their
1226
+ * multiplicity and warmup is NaN. Invalid option-path periods throw RangeError,
1227
+ * malformed options TypeError. Periods must be positive safe integers.
1228
+ */
1229
+ declare function dev(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1230
+ /** Bar-aligned lengths select the current deviation window; NaN lengths give gaps. */
1231
+ declare function dev(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1232
+ /**
1233
+ * Percentage of period previous values less than or equal to the current
1234
+ * subject, excluding the subject itself. Omitted options preserve legacy
1235
+ * behavior. Supplied `skip` collects previous finite observations; `propagate`
1236
+ * requires a full previous chronological window. A missing subject or
1237
+ * insufficient history produces NaN under either policy. Equality counts.
1238
+ * Invalid option-path periods throw RangeError; malformed policies throw
1239
+ * TypeError. Periods must be positive safe integers.
1240
+ */
1241
+ declare function percentRank(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1242
+ /** Bar-aligned lengths count previous observations. A missing current subject or length gives NaN. */
1243
+ declare function percentRank(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1026
1244
  /** the reference `alma`: Gaussian-weighted MA, `offset` 0..1 and `sigma` > 0. */
1027
1245
  declare function alma(values: readonly number[], period: number, offset: number, sigma: number): number[];
1028
1246
  /** the reference `vwma`: `sma(src * volume, len) / sma(volume, len)`. */
1029
1247
  declare function vwma(values: readonly number[], volumes: readonly number[], period: number): number[];
1030
1248
  /**
1031
- * the reference `highestbars` / `lowestbars`: the **offset** to the extreme bar
1032
- * in the window, `0` for the current bar and `-(period - 1)` for the oldest.
1033
- * Aroon is built entirely out of these, and the sign convention is why.
1249
+ * Highest-value bar offset, zero for current and negative into history; ties
1250
+ * choose the latest bar. Omitted options preserve legacy behavior. Supplied
1251
+ * `skip` searches period finite observations and retains original bar indices,
1252
+ * so an offset can extend beyond period-1 and ages across missing current bars.
1253
+ * `propagate` requires period chronological finite bars. Warmup and all-missing
1254
+ * history are NaN. Invalid option-path periods throw RangeError; malformed
1255
+ * policies throw TypeError. Periods must be positive safe integers.
1256
+ */
1257
+ declare function highestBars(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1258
+ /** Bar-aligned lengths retain original offsets and latest ties; NaN lengths give gaps. */
1259
+ declare function highestBars(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1260
+ /**
1261
+ * Lowest-value bar offset, zero for current and negative into history; ties
1262
+ * choose the latest bar. Omitted options preserve legacy behavior. Supplied
1263
+ * `skip` searches period finite observations using their original indices;
1264
+ * offsets age across gaps. `propagate` requires a full chronological window.
1265
+ * Warmup and all-missing history are NaN. Invalid option-path periods throw
1266
+ * RangeError; malformed policies throw TypeError. Periods must be positive
1267
+ * safe integers.
1268
+ */
1269
+ declare function lowestBars(values: readonly number[], period: number, options?: NumericalWindowOptions): number[];
1270
+ /** Bar-aligned lengths retain original offsets and latest ties; NaN lengths give gaps. */
1271
+ declare function lowestBars(values: readonly number[], period: number | readonly number[], options?: NumericalWindowOptions): number[];
1272
+ /**
1273
+ * Fresh oldest-first sum over each complete finite window; NaN on warmup or
1274
+ * overflow. Missing values expire with the window. Valid integer periods use
1275
+ * O(n * period) time and O(1) extra working storage, excluding the result.
1276
+ * Unsupported scalar periods retain their historical behavior.
1034
1277
  */
1035
- declare function highestBars(values: readonly number[], period: number): number[];
1036
- declare function lowestBars(values: readonly number[], period: number): number[];
1037
- /** the reference `sum`: rolling sum over `period` bars. NaN during warmup. */
1038
1278
  declare function rollingSum(values: readonly number[], period: number): number[];
1039
1279
  /** the reference `cum`: running total from the first bar. Non-finite terms count as 0. */
1040
1280
  declare function cumulative(values: readonly number[]): number[];
@@ -1074,7 +1314,22 @@ declare function cci(values: readonly number[], period: number): number[];
1074
1314
  * not a pivot.
1075
1315
  */
1076
1316
  declare function pivotHigh(values: readonly number[], left: number, right: number): number[];
1317
+ /**
1318
+ * Array widths align with the source and are read on the confirmation bar.
1319
+ * NaN array elements give gaps; scalar companions and other array elements
1320
+ * must be nonnegative safe integers. Mismatched array lengths throw RangeError.
1321
+ * Zero widths are valid. Finite neighbors and strict comparisons are required.
1322
+ * Results stay on confirmation bars, including repeated confirmations of one
1323
+ * candidate. Invalid numbers throw RangeError; malformed elements TypeError.
1324
+ */
1325
+ declare function pivotHigh(values: readonly number[], left: number | readonly number[], right: number | readonly number[]): number[];
1077
1326
  declare function pivotLow(values: readonly number[], left: number, right: number): number[];
1327
+ /**
1328
+ * Array widths follow pivotHigh's validation and confirmation placement, with
1329
+ * strictly lower candidates. Missing widths or neighbors give NaN. Both widths
1330
+ * are read from the current confirmation bar, even if the candidate repeats.
1331
+ */
1332
+ declare function pivotLow(values: readonly number[], left: number | readonly number[], right: number | readonly number[]): number[];
1078
1333
  /** the reference `barssince`: bars elapsed since `cond` was last true, NaN before the first. */
1079
1334
  declare function barsSince(cond: readonly boolean[]): number[];
1080
1335
  /**
@@ -1110,6 +1365,10 @@ interface Tier2Point {
1110
1365
  interface Tier2Context {
1111
1366
  /** Host identity when supplied. Indicator settings remain independent. */
1112
1367
  dataContext?: Readonly<ChartDataContext>;
1368
+ /** Native source, provider and external-data revisions, when supplied. */
1369
+ requestState?: Readonly<IndicatorRequestState>;
1370
+ /** Inclusive availability cutoff during opted-in native timed replay. */
1371
+ asOf?: number;
1113
1372
  /** Cancelled when this request is obsolete or the instance is removed. */
1114
1373
  signal?: AbortSignal;
1115
1374
  settings: Readonly<IndicatorSettings>;
@@ -1152,6 +1411,13 @@ interface Tier2Descriptor {
1152
1411
  supports?(ctx: Tier2Context): boolean;
1153
1412
  /** Load the series for the current window. */
1154
1413
  fetch(ctx: Tier2Context): Promise<readonly Tier2Point[]>;
1414
+ /**
1415
+ * Opt into native timed replay. fetch must honor finite ctx.asOf, return the
1416
+ * values known then, and use point.time as availability time. Raw requestBars
1417
+ * does not supply historical value versions automatically. Native legacy
1418
+ * replay without an availability clock remains unsupported. Defaults false.
1419
+ */
1420
+ supportsReplay?: boolean;
1155
1421
  /**
1156
1422
  * Optional live subscription. Call `push` with each incoming point; return an
1157
1423
  * unsubscribe function.
@@ -1187,12 +1453,9 @@ declare function createTier2Indicator(d: Tier2Descriptor): IndicatorDescriptor;
1187
1453
  /**
1188
1454
  * A higher-timeframe view of the chart's own bars, one value per source bar.
1189
1455
  *
1190
- * A study written for a script language asks for the daily high on a 5-minute
1191
- * chart and gets a column the same length as the chart. The engine has no
1192
- * such call, and every port that needed one folded the bars by hand, each a
1193
- * little differently: some anchored an hourly bucket to midnight and some to
1194
- * the session open, some read the bucket as it stood and some read its final
1195
- * values. This is the one fold, with the three readings named:
1456
+ * securitySeries aligns aggregate OHLC values. securityExpression calculates
1457
+ * on aggregate bars before alignment, so a rolling window counts requested
1458
+ * bars rather than repeated aligned values. securitySeries names its readings:
1196
1459
  *
1197
1460
  * - `offset: 0` (the default) reads the bucket **as it stood at that bar**:
1198
1461
  * its open so far, high and low so far, the bar's own close, volume so far.
@@ -1211,6 +1474,16 @@ declare function createTier2Indicator(d: Tier2Descriptor): IndicatorDescriptor;
1211
1474
  * its hourly bars.
1212
1475
  */
1213
1476
 
1477
+ interface SecurityExpressionOptions {
1478
+ timezone?: string;
1479
+ session?: string;
1480
+ /**
1481
+ * confirmed (default) holds the previous observed bucket's result once the
1482
+ * next bucket starts. developing calculates with the current partial bucket.
1483
+ * lookahead aligns the current bucket's final result onto its earlier bars.
1484
+ */
1485
+ mode?: 'confirmed' | 'developing' | 'lookahead';
1486
+ }
1214
1487
  interface SecurityOptions {
1215
1488
  /** The calendar the buckets are cut in. Defaults to the shipped default zone. */
1216
1489
  timezone?: string;
@@ -1244,6 +1517,124 @@ interface SecuritySeries {
1244
1517
  isNew: boolean[];
1245
1518
  }
1246
1519
  declare function securitySeries(bars: readonly Bar[], interval: string, options?: SecurityOptions): SecuritySeries;
1520
+ /**
1521
+ * Evaluate on aggregated bars first, then align named columns to source bars.
1522
+ * This differs from applying a rolling formula to already aligned OHLC values,
1523
+ * which counts each repeated requested value as another observation.
1524
+ *
1525
+ * The expression must be pure and causal, returning one value per requested
1526
+ * bar in each column. Confirmed and lookahead modes evaluate the folded history
1527
+ * once; developing mode evaluates every source prefix, with no future source
1528
+ * bars, so its cost includes one expression call per source bar. Completed
1529
+ * buckets are inferred only when the next observed bucket starts. Missing
1530
+ * buckets are not fabricated and the last bucket is never clock-confirmed.
1531
+ *
1532
+ * Supply bars finer than or equal to the requested interval. This function
1533
+ * cannot manufacture lower-timeframe observations from coarser source bars.
1534
+ * Source timestamps must increase strictly. Empty data returns {} without
1535
+ * invoking the expression. Non-finite expression results become null.
1536
+ */
1537
+ declare function securityExpression(bars: readonly Bar[], interval: string, expression: (bars: readonly Readonly<Bar>[]) => IndicatorValues, options?: SecurityExpressionOptions): IndicatorValues;
1538
+
1539
+ /**
1540
+ * A pure, causal calculation with one value per requested bar in each named
1541
+ * column. Output at index i may depend only on input through i. Helpers cannot
1542
+ * prove callback causality. Inputs are copied and frozen, including each bar.
1543
+ */
1544
+ type RequestedExpression = (bars: readonly Readonly<Bar>[]) => IndicatorValues;
1545
+ interface RequestedAlignmentOptions {
1546
+ /**
1547
+ * carry retains the latest eligible row, including null values. missing emits
1548
+ * only when the selected row changes; the first target is an initial reading.
1549
+ */
1550
+ gaps?: 'carry' | 'missing';
1551
+ }
1552
+ /** Opening-time membership is [start, end); availability may equal end. */
1553
+ interface RequestedTimeWindow {
1554
+ start: number;
1555
+ end: number;
1556
+ }
1557
+ interface RequestedIntrabarOptions {
1558
+ /** Inclusive UTC availability cutoff in addition to each window's end. */
1559
+ asOf?: number;
1560
+ }
1561
+ /** Arrays retain requested row order, including missing expression values. */
1562
+ interface RequestedIntrabarValues {
1563
+ times: number[][];
1564
+ values: Record<string, (number | null)[][]>;
1565
+ }
1566
+ /**
1567
+ * Calculate once on the whole requested history, then align to finite, strictly
1568
+ * increasing UTC evaluation times. The confirmed prefix ends at the first
1569
+ * unconfirmed bar or unknown availability; that bar and all later bars remain
1570
+ * in expression input but cannot emit. Availability is the cumulative maximum
1571
+ * across each prefix. Simultaneously available rows select the latest one.
1572
+ *
1573
+ * Missing/nonfinite results become null and replace older readings. An empty
1574
+ * snapshot returns {} without invoking the expression; an empty target with
1575
+ * nonempty requested history still evaluates to obtain named empty columns.
1576
+ * Invalid timestamps, metadata, options or output shapes throw IndicatorInputError.
1577
+ * Inputs are fully validated before the callback. Runtime is O((n + targets) *
1578
+ * columns), plus expression cost. No transport, aggregation or clock inference.
1579
+ */
1580
+ declare function alignRequestedExpression(targetTimes: readonly number[], snapshot: RequestedBarsSnapshot, expression: RequestedExpression, options?: RequestedAlignmentOptions): IndicatorValues;
1581
+ /**
1582
+ * Calculate once across all requested observations, then group by nonoverlapping
1583
+ * ordered windows. Windows must have finite start < end; gaps are allowed.
1584
+ * An observation belongs by its opening in [start, end), and emits only when
1585
+ * its confirmed prefix is available by end and by optional finite asOf.
1586
+ * Delayed observations never move to a later window. Expression history never
1587
+ * restarts at window boundaries. Empty windows return empty arrays.
1588
+ *
1589
+ * Uses the same prefix, missing-value, validation and empty-snapshot rules as
1590
+ * alignRequestedExpression. Result times are openings, not availability times.
1591
+ * Runtime is O(n * columns + windows * columns), plus expression cost.
1592
+ */
1593
+ declare function requestedIntrabars(targetWindows: readonly RequestedTimeWindow[], snapshot: RequestedBarsSnapshot, expression: RequestedExpression, options?: RequestedIntrabarOptions): RequestedIntrabarValues;
1594
+
1595
+ /** Source and settings visible to request selection and requested calculation. */
1596
+ interface RequestedIndicatorContext {
1597
+ bars: readonly Bar[];
1598
+ settings: Readonly<IndicatorSettings>;
1599
+ dataContext?: Readonly<ChartDataContext>;
1600
+ requestState?: Readonly<IndicatorRequestState>;
1601
+ calculation?: IndicatorCalcContext;
1602
+ }
1603
+ /** A requested expression with an instance-owned snapshot lifecycle. */
1604
+ interface RequestedIndicatorDescriptor extends Pick<IndicatorDescriptor, 'id' | 'name' | 'category' | 'placement' | 'inputs' | 'plots' | 'levels' | 'range'> {
1605
+ /**
1606
+ * Select a complete history window, including expression warmup. null means
1607
+ * unsupported. The helper owns cancellation; signal is not a selector input.
1608
+ * Symbol, exchange, interval and explicit asOf changes start a new generation.
1609
+ * Window changes refresh the complete selection without merging partial pages.
1610
+ */
1611
+ request(ctx: RequestedIndicatorContext): Omit<IndicatorSnapshotRequest, 'signal'> | null;
1612
+ /**
1613
+ * Calculate on copied, frozen requested bars before alignment. Each result at
1614
+ * i must depend only on requested observations through i. Return every plot's
1615
+ * named column with one value per requested bar. Nonfinite values become null.
1616
+ * Under asOf, only the known, confirmed prefix available by that cutoff is
1617
+ * supplied. Provider correctness for historical value versions remains required.
1618
+ */
1619
+ expression(bars: readonly Readonly<Bar>[], settings: Readonly<IndicatorSettings>, ctx: RequestedIndicatorContext): IndicatorValues;
1620
+ /** carry retains the latest eligible row, including null; missing emits a newly selected row only. */
1621
+ gaps?: RequestedAlignmentOptions['gaps'];
1622
+ /**
1623
+ * Strictly increasing finite availability query times, one per source bar.
1624
+ * Defaults to source opening times. Use an explicit final playhead time when
1625
+ * a forming source bar should observe requested data available after opening.
1626
+ */
1627
+ targetTimes?(ctx: RequestedIndicatorContext): readonly number[];
1628
+ }
1629
+ /**
1630
+ * Manage one requested snapshot per instance. Changes are observed through the
1631
+ * optional native request hooks, or through data notifications on older hosts.
1632
+ * There is at most one active request and one latest pending refresh. Provider,
1633
+ * source, history or market changes and backward replay cancel obsolete work.
1634
+ * Synchronous style reattachment retains pending work when its selection is
1635
+ * unchanged. Calculation performs no requests and never prealigns cached values.
1636
+ */
1637
+ declare function createRequestedIndicator(d: RequestedIndicatorDescriptor): IndicatorDescriptor;
1247
1638
 
1248
1639
  declare const INDICATORS_TIER: "indicators";
1249
1640
  /** Every built-in descriptor, in picker order. */
@@ -1255,4 +1646,4 @@ declare const BUILTIN_INDICATORS: readonly IndicatorDescriptor[];
1255
1646
  */
1256
1647
  declare function registerBuiltinIndicators(): void;
1257
1648
 
1258
- export { ADAPTIVE_INDICATORS, ADL, ADX, ALLIGATOR, ALMA, ALPHATREND, AROON, AROON_OSCILLATOR, ATR, AVERAGE_DAILY_RANGE, AVERAGE_INDICATORS, AWESOME_OSCILLATOR, BALANCE_OF_POWER, BB_TREND, BOLLINGER, BOLLINGER_BANDWIDTH, BOLLINGER_PERCENT_B, BUILTIN_INDICATORS, CCI, CHAIKIN_MONEY_FLOW, CHAIKIN_OSCILLATOR, CHAIKIN_VOLATILITY, CHANDELIER_EXIT, CHANDE_KROLL_STOP, CHANDE_MOMENTUM, CHOPPINESS_INDEX, CHOP_ZONE, CONNORS_RSI, CONSOLIDATION_BREAKOUT, COPPOCK_CURVE, CPR, DEMA, DONCHIAN, DPO, EASE_OF_MOVEMENT, ELDER_FORCE_INDEX, EMA, ENVELOPE, FISHER_TRANSFORM, FLOW_INDICATORS, HALFTREND, HISTORICAL_VOLATILITY, HMA, HULL_SUITE, ICHIMOKU, INDEX_INDICATORS, INDICATORS_TIER, KAMA, KELTNER_CHANNEL, KLINGER_OSCILLATOR, KNOW_SURE_THING, LINREG_SLOPE, LSMA, MACD, MASS_INDEX, MA_CHANNEL, MA_CROSS, MA_RIBBON, MCGINLEY_DYNAMIC, MEDIAN, MFI, MOMENTUM, NET_VOLUME, NVI, OBV, OPEN_INTEREST, OPEN_INTEREST_BUILDUP, OPEN_INTEREST_CHANGE, OSCILLATOR_INDICATORS, OVERLAY_INDICATORS, PARABOLIC_SAR, PPO, PVI, PVO, PVT, RANGE_ANALYSIS, RANGE_INDICATORS, RELATIVE_VIGOR_INDEX, RELATIVE_VOLATILITY_INDEX, ROC, RSI, RSI_DIVERGENCE, SEASONALITY, SEASONALITY_INDICATORS, SIGNAL_INDICATORS, SMA, SMI, SMI_ERGODIC_INDICATOR, SMI_ERGODIC_OSCILLATOR, SMMA, SPECIAL_K, STANDARD_DEVIATION, STANDARD_ERROR, STANDARD_ERROR_BANDS, STOCHASTIC, STOCHASTIC_RSI, STRENGTH_INDICATORS, STUDY_INDICATORS, SUPERTREND, type SecurityOptions, type SecuritySeries, T3, TEMA, TREND_STRENGTH_INDEX, TRIX, TSI, TWAP, type Tier2Context, type Tier2Descriptor, type Tier2Point, ULCER_INDEX, ULTIMATE_OSCILLATOR, VOLATILITY_INDICATORS, VOLATILITY_STOP, VOLUME, VORTEX, VWAP, VWMA, WAVETREND, WAVETREND_INDICATORS, WILLIAMS_FRACTALS, WILLIAMS_PERCENT_R, WILLIAMS_VIX_FIX, WMA, WOODIES_CCI, alma, barsSince, cci, change, connorsStreak, correlation, createTier2Indicator, cumulative, dev, highest, highestBars, linreg, lowest, lowestBars, nulls, percentRank, percentileNearestRank, pivotHigh, pivotLow, registerBuiltinIndicators, rma, roc, rollingSum, securitySeries, sma, smaSeededEma, stdev, stoch, swma, valueWhen, vwma, wma };
1649
+ export { ADAPTIVE_INDICATORS, ADL, ADX, ALLIGATOR, ALMA, ALPHATREND, AROON, AROON_OSCILLATOR, ATR, AVERAGE_DAILY_RANGE, AVERAGE_INDICATORS, AWESOME_OSCILLATOR, BALANCE_OF_POWER, BB_TREND, BOLLINGER, BOLLINGER_BANDWIDTH, BOLLINGER_PERCENT_B, BUILTIN_INDICATORS, CCI, CHAIKIN_MONEY_FLOW, CHAIKIN_OSCILLATOR, CHAIKIN_VOLATILITY, CHANDELIER_EXIT, CHANDE_KROLL_STOP, CHANDE_MOMENTUM, CHOPPINESS_INDEX, CHOP_ZONE, CONNORS_RSI, CONSOLIDATION_BREAKOUT, COPPOCK_CURVE, CPR, DEMA, DONCHIAN, DPO, EASE_OF_MOVEMENT, ELDER_FORCE_INDEX, EMA, ENVELOPE, FISHER_TRANSFORM, FLOW_INDICATORS, HALFTREND, HISTORICAL_VOLATILITY, HMA, HULL_SUITE, ICHIMOKU, INDEX_INDICATORS, INDICATORS_TIER, KAMA, KELTNER_CHANNEL, KLINGER_OSCILLATOR, KNOW_SURE_THING, LINREG_SLOPE, LSMA, MACD, MASS_INDEX, MA_CHANNEL, MA_CROSS, MA_RIBBON, MCGINLEY_DYNAMIC, MEDIAN, MFI, MOMENTUM, NET_VOLUME, NVI, type NumericalWindowOptions, OBV, OPEN_INTEREST, OPEN_INTEREST_BUILDUP, OPEN_INTEREST_CHANGE, OSCILLATOR_INDICATORS, OVERLAY_INDICATORS, PARABOLIC_SAR, PPO, PVI, PVO, PVT, RANGE_ANALYSIS, RANGE_INDICATORS, RELATIVE_VIGOR_INDEX, RELATIVE_VOLATILITY_INDEX, ROC, RSI, RSI_DIVERGENCE, type RequestedAlignmentOptions, type RequestedExpression, type RequestedIndicatorContext, type RequestedIndicatorDescriptor, type RequestedIntrabarOptions, type RequestedIntrabarValues, type RequestedTimeWindow, type RollingVarianceOptions, SEASONALITY, SEASONALITY_INDICATORS, SIGNAL_INDICATORS, SMA, SMI, SMI_ERGODIC_INDICATOR, SMI_ERGODIC_OSCILLATOR, SMMA, SPECIAL_K, STANDARD_DEVIATION, STANDARD_ERROR, STANDARD_ERROR_BANDS, STOCHASTIC, STOCHASTIC_RSI, STRENGTH_INDICATORS, STUDY_INDICATORS, SUPERTREND, type SecurityExpressionOptions, type SecurityOptions, type SecuritySeries, T3, TEMA, TREND_STRENGTH_INDEX, TRIX, TSI, TWAP, type Tier2Context, type Tier2Descriptor, type Tier2Point, ULCER_INDEX, ULTIMATE_OSCILLATOR, VOLATILITY_INDICATORS, VOLATILITY_STOP, VOLUME, VORTEX, VWAP, VWMA, WAVETREND, WAVETREND_INDICATORS, WILLIAMS_FRACTALS, WILLIAMS_PERCENT_R, WILLIAMS_VIX_FIX, WMA, WOODIES_CCI, alignRequestedExpression, alma, barsSince, cci, centerOfGravity, change, connorsStreak, correlation, createRequestedIndicator, createTier2Indicator, crosses, crossesAbove, crossesBelow, cumulative, dev, falling, highest, highestBars, linreg, lowest, lowestBars, nulls, percentRank, percentileLinear, percentileNearestRank, pivotHigh, pivotLow, rankCorrelation, registerBuiltinIndicators, requestedIntrabars, rising, rma, roc, rollingMedian, rollingMode, rollingRange, rollingSum, rollingVariance, runningMax, runningMin, securityExpression, securitySeries, sma, smaSeededEma, stdev, stoch, swma, valueWhen, vwma, wma };