nexustrade 2.1.1 → 3.0.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/README.md CHANGED
@@ -1171,9 +1171,13 @@ Other brokers need a live T1 evidence adapter. Existing owner approval and trade
1171
1171
  limits apply. Native strategy/indicator runtime uses the existing checkpoint
1172
1172
  path; its verification does not establish live broker execution.
1173
1173
 
1174
- ConsecutiveTrue retains optional distinct session checks at a configured
1175
- cadence; missing/stale quotes reset the count. These are reusable components,
1176
- not a verified complete ftr445 strategy or evidence of profitable returns.
1174
+ `ConsecutiveTrue` measures elapsed time while its ordinary condition stays true.
1175
+ `CountTrue` counts matching intervals inside a time lookback. For example, a
1176
+ 20 `TradingDay` lookback with `countInterval: {length: 5, interval: "Minute"}`
1177
+ counts at most one match per five-minute interval across twenty exchange sessions.
1178
+ Omitting `countInterval` means one unit of the lookback interval. Comparisons and
1179
+ visit/crossing events belong in the ordinary `condition`, including `Then`.
1180
+ There are no sampled-comparison, distinct, cadence-count or clock modes.
1177
1181
 
1178
1182
  `PortfolioValue` keeps its existing cash-plus-positions semantics during warmup
1179
1183
  and trading. Backtesting and paper trading do not depend on the selected pricing
@@ -1183,6 +1187,14 @@ reconciliation path. Porting a T1 strategy preserves its settlement policy.
1183
1187
 
1184
1188
  For conditional capture, expiry runs from the retained observation's capture
1185
1189
  time. Minimum/Maximum with expiry is not a sliding-window minimum/maximum.
1186
- Sampled CountTrue retains at most 10000 observations; its sorted runtime index
1187
- is rebuilt when samples change and omitted from checkpoints. Moving references
1188
- use binary-search queries, following the existing SortedIvWindow design.
1190
+ `IndicatorMinimum` and `IndicatorMaximum` provide rolling extrema of one numeric
1191
+ operand. `CurrentValue(operand)` explicitly binds today's reference inside a
1192
+ historical CountTrue condition; historical operands retain their observed values.
1193
+ Outside that query it returns its operand. Bind the complete stateful operand,
1194
+ rather than inserting a reference inside its recurrence.
1195
+
1196
+ `TradingDay` windows use observed exchange sessions, including holidays and early
1197
+ closes. Elapsed Day/Hour/Minute windows keep their calendar meaning.
1198
+ `IndicatorWindowAgo` with `TradingDay` reads the confirmed value at the end of the
1199
+ reference session. Missing session evidence returns no value. `CurrentTimestamp`
1200
+ returns the evaluation time in Unix seconds, for ordinary candle-age comparisons.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.screenTop = exports.screenAny = exports.screenAll = exports.screenCompare = exports.screenDisclosure = exports.screenBarDollarVolume = exports.screenBarVolume = exports.screenPrice = exports.screenColumn = exports.updateScreenerWatchlist = exports.updateInsiderWatchlist = exports.updateInstitutionalWatchlist = exports.updateWatchlist = exports.launchAgent = exports.alert = exports.sellHoldings = exports.sell = exports.buy = exports.watchlistUniverse = exports.selectPercentile = exports.selectTop = exports.filter = exports.RebalanceNetBenefit = exports.RebalanceExpectedBenefit = exports.RebalanceEstimatedCost = exports.RebalancePlannedTurnover = exports.RebalanceAllocationDrift = exports.volatilityTarget = exports.maximumDiversificationAllocation = exports.riskParityAllocation = exports.meanVarianceAllocation = exports.always = exports.andThen = exports.multi = exports.exactly = exports.fewerThan = exports.atMost = exports.atLeast = exports.or = exports.and = exports.neq = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.cryptoAsset = exports.stockAsset = exports.PORTFOLIO_WIDE = exports.CANDIDATE = void 0;
4
- exports.geneStructureKind = exports.geneStopLossPct = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationDollars = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneConditionThreshold = exports.geneConditionWindowLength = exports.geneEntryCooldownDays = exports.geneReplaceExitCondition = exports.geneExitCondition = exports.geneReplaceEntryCondition = exports.geneEntryCondition = exports.geneSubject = exports.optimization = exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = exports.portfolio = exports.sessionFlatten = exports.strategy = exports.goodForMinutes = exports.goodForDay = exports.minimumNetCredit = exports.maximumNetDebit = exports.unitPriceLimit = exports.currentLimit = exports.limitOrder = exports.closeOption = exports.greeksTrigger = exports.daysHeldTrigger = exports.dteTrigger = exports.pnlTrigger = exports.rebalanceOption = exports.sleeve = exports.structureTemplate = exports.openOption = exports.againstParent = exports.optionsBuilder = exports.leg = exports.dynamicRebalance = exports.screenPercentile = void 0;
5
- exports.geneAppendUniversePipelineFilter = exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = exports.geneAllocationPolicy = void 0;
3
+ exports.screenPercentile = exports.screenTop = exports.screenAny = exports.screenAll = exports.screenCompare = exports.screenDisclosure = exports.screenBarDollarVolume = exports.screenBarVolume = exports.screenPrice = exports.screenColumn = exports.updateScreenerWatchlist = exports.updateInsiderWatchlist = exports.updateInstitutionalWatchlist = exports.updateWatchlist = exports.launchAgent = exports.alert = exports.sellHoldings = exports.sell = exports.buy = exports.watchlistUniverse = exports.selectPercentile = exports.selectTop = exports.filter = exports.RebalanceNetBenefit = exports.RebalanceExpectedBenefit = exports.RebalanceEstimatedCost = exports.RebalancePlannedTurnover = exports.RebalanceAllocationDrift = exports.volatilityTarget = exports.maximumDiversificationAllocation = exports.riskParityAllocation = exports.meanVarianceAllocation = exports.always = exports.multi = exports.exactly = exports.fewerThan = exports.atMost = exports.atLeast = exports.or = exports.and = exports.neq = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.cryptoAsset = exports.stockAsset = exports.PORTFOLIO_WIDE = exports.CANDIDATE = void 0;
4
+ exports.geneAllocationPolicy = exports.geneStructureKind = exports.geneStopLossPct = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationDollars = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneConditionThreshold = exports.geneConditionWindowLength = exports.geneEntryCooldownDays = exports.geneReplaceExitCondition = exports.geneExitCondition = exports.geneReplaceEntryCondition = exports.geneEntryCondition = exports.geneSubject = exports.optimization = exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = exports.portfolio = exports.sessionFlatten = exports.strategy = exports.goodForMinutes = exports.goodForDay = exports.minimumNetCredit = exports.maximumNetDebit = exports.unitPriceLimit = exports.currentLimit = exports.limitOrder = exports.closeOption = exports.greeksTrigger = exports.daysHeldTrigger = exports.dteTrigger = exports.pnlTrigger = exports.rebalanceOption = exports.sleeve = exports.structureTemplate = exports.openOption = exports.againstParent = exports.optionsBuilder = exports.leg = exports.dynamicRebalance = void 0;
5
+ exports.geneAppendUniversePipelineFilter = exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = void 0;
6
+ exports.andThen = andThen;
6
7
  exports.universe = universe;
7
8
  exports.AbsoluteValue = AbsoluteValue;
8
9
  exports.AccumulationDistribution = AccumulationDistribution;
@@ -26,6 +27,8 @@ exports.CrossBelow = CrossBelow;
26
27
  exports.CurrentTimeHours = CurrentTimeHours;
27
28
  exports.CurrentTimeMinutes = CurrentTimeMinutes;
28
29
  exports.CurrentTimeSeconds = CurrentTimeSeconds;
30
+ exports.CurrentTimestamp = CurrentTimestamp;
31
+ exports.CurrentValue = CurrentValue;
29
32
  exports.CustomIndicator = CustomIndicator;
30
33
  exports.Date = Date;
31
34
  exports.Day = Day;
@@ -55,7 +58,9 @@ exports.IndicatorAtCondition = IndicatorAtCondition;
55
58
  exports.IndicatorAtEntry = IndicatorAtEntry;
56
59
  exports.IndicatorAtMinutesAfterOpen = IndicatorAtMinutesAfterOpen;
57
60
  exports.IndicatorExponentialMovingAverage = IndicatorExponentialMovingAverage;
61
+ exports.IndicatorMaximum = IndicatorMaximum;
58
62
  exports.IndicatorMeanAbsoluteDeviation = IndicatorMeanAbsoluteDeviation;
63
+ exports.IndicatorMinimum = IndicatorMinimum;
59
64
  exports.IndicatorRateOfChange = IndicatorRateOfChange;
60
65
  exports.IndicatorSimpleMovingAverage = IndicatorSimpleMovingAverage;
61
66
  exports.IndicatorStandardDeviation = IndicatorStandardDeviation;
@@ -298,25 +303,11 @@ exports.exactly = exactly;
298
303
  /** Multi with an explicit Comparator (same wire shape as YAML Multi). */
299
304
  const multi = (count, comparison, ...conditions) => ({ type: "Multi", comparison, value: count, conditions });
300
305
  exports.multi = multi;
301
- /**
302
- * Sequence. `andThen(30, "Minute", A, B)` is true at tick t when B is true at t
303
- * and A was true at some STRICTLY EARLIER tick in the preceding 30 minutes.
304
- *
305
- * Simultaneous A and B does not fire — that is `and`. The window applies per
306
- * transition, so with three or more steps each one must occur within the window
307
- * of the step before it. Nesting is legal and means something different:
308
- * `andThen(W, andThen(W, A, B), C)` is not `andThen(W, A, B, C)`.
309
- *
310
- * `interval` is REQUIRED and has no default. An omitted interval would fall
311
- * back to Day and silently kill an intraday setup.
312
- *
313
- * Named `andThen` rather than `then`: a module namespace with a callable
314
- * `then` export is assimilated as a thenable, so `await import("nexustrade")`
315
- * would call it with resolve/reject and never settle. Emits wire type "Then",
316
- * the same way atLeast/atMost/exactly emit "Multi".
317
- */
318
- const andThen = (length, interval, ...conditions) => ({ type: "Then", conditions, window: { length, interval } });
319
- exports.andThen = andThen;
306
+ function andThen(timing, first, ...rest) {
307
+ return (typeof timing === "number"
308
+ ? { type: "Then", conditions: rest, window: { length: timing, interval: first } }
309
+ : { type: "Then", ...timing, conditions: [first, ...rest] });
310
+ }
320
311
  /** Always-true gate for strategies whose cadence lives in the pipeline. */
321
312
  const always = () => compare(Value(1), Value(0), "greaterThan");
322
313
  exports.always = always;
@@ -757,17 +748,14 @@ function ConsecutiveIncrease(indicator, period, lookback) {
757
748
  return d;
758
749
  }
759
750
  /**
760
- * ConsecutiveTrue indicator.
751
+ * Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
761
752
  * @param condition Condition evaluated over the window.
762
753
  * @param length Length of time
763
754
  * @param interval Unit of time
764
- * @param checkCadenceMinutes Optional. Counts completed regular-session checks instead of elapsed time. Window length is the required count; resets each session. Missing checks reset the count.
765
755
  */
766
- function ConsecutiveTrue(condition, length = 1, interval = "Day", checkCadenceMinutes) {
756
+ function ConsecutiveTrue(condition, length = 1, interval = "Day") {
767
757
  const d = { type: "ConsecutiveTrue" };
768
758
  d.condition = condition;
769
- if (checkCadenceMinutes !== undefined)
770
- d["checkCadenceMinutes"] = checkCadenceMinutes;
771
759
  d.window = { length: length, interval: interval };
772
760
  return d;
773
761
  }
@@ -784,14 +772,17 @@ function Correlation(operands, length = 60, interval = "Day") {
784
772
  return d;
785
773
  }
786
774
  /**
787
- * CountTrue indicator.
788
- * @param condition Condition evaluated over the window.
789
- * @param length Length of time
790
- * @param interval Unit of time
775
+ * Count matching intervals inside a time lookback. The ordinary condition owns comparisons/events. countInterval contributes at most one match per interval; omitted means one unit of the lookback interval. TradingDay skips closed exchange dates.
776
+ * @param condition Ordinary condition whose matching intervals are counted.
777
+ * @param length Lookback length.
778
+ * @param interval Lookback time unit; TradingDay uses observed exchange sessions.
779
+ * @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
791
780
  */
792
- function CountTrue(condition, length = 1, interval = "Day") {
781
+ function CountTrue(condition, length = 1, interval = "Day", countInterval) {
793
782
  const d = { type: "CountTrue" };
794
783
  d.condition = condition;
784
+ if (countInterval !== undefined)
785
+ d["countInterval"] = countInterval;
795
786
  d.window = { length: length, interval: interval };
796
787
  return d;
797
788
  }
@@ -832,6 +823,21 @@ function CurrentTimeSeconds() {
832
823
  const d = { type: "CurrentTimeSeconds" };
833
824
  return d;
834
825
  }
826
+ /**
827
+ * Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
828
+ */
829
+ function CurrentTimestamp() {
830
+ const d = { type: "CurrentTimestamp" };
831
+ return d;
832
+ }
833
+ /**
834
+ * Inside a CountTrue historical condition, bind this operand at its value now while other operands use their historical observations. Elsewhere return the operand normally. Wrap a complete stateful operand, not an expression inside its recurrence.
835
+ */
836
+ function CurrentValue(operand) {
837
+ const d = { type: "CurrentValue" };
838
+ d.indicators = [operand];
839
+ return d;
840
+ }
835
841
  /**
836
842
  * CustomIndicator indicator.
837
843
  * @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
@@ -1091,7 +1097,7 @@ function Index(metric = "VIX") {
1091
1097
  return d;
1092
1098
  }
1093
1099
  /**
1094
- * IndicatorAtCondition indicator.
1100
+ * Retain the operand from matching observations: First, Latest, Maximum, or Minimum. Ordinary conditions decide when to capture. An optional window expires observations; TradingDay skips closed exchange dates. Use this to freeze a qualified setup before entry or ratchet a numeric level, not IndicatorAtEntry when no fill exists yet.
1095
1101
  * @param condition Condition evaluated over the window.
1096
1102
  */
1097
1103
  function IndicatorAtCondition(operand, condition, selection = "First", clock = "Calendar", initialValue, length, interval) {
@@ -1142,6 +1148,17 @@ function IndicatorExponentialMovingAverage(operand, length = 30, interval = "Day
1142
1148
  d.window = { length: length, interval: interval };
1143
1149
  return d;
1144
1150
  }
1151
+ /**
1152
+ * Rolling maximum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
1153
+ * @param length Length of time
1154
+ * @param interval Unit of time
1155
+ */
1156
+ function IndicatorMaximum(operand, length = 30, interval = "Day") {
1157
+ const d = { type: "IndicatorMaximum" };
1158
+ d.indicators = [operand];
1159
+ d.window = { length: length, interval: interval };
1160
+ return d;
1161
+ }
1145
1162
  /**
1146
1163
  * IndicatorMeanAbsoluteDeviation indicator.
1147
1164
  * @param length Length of time
@@ -1153,6 +1170,17 @@ function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval = "Day")
1153
1170
  d.window = { length: length, interval: interval };
1154
1171
  return d;
1155
1172
  }
1173
+ /**
1174
+ * Rolling minimum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
1175
+ * @param length Length of time
1176
+ * @param interval Unit of time
1177
+ */
1178
+ function IndicatorMinimum(operand, length = 30, interval = "Day") {
1179
+ const d = { type: "IndicatorMinimum" };
1180
+ d.indicators = [operand];
1181
+ d.window = { length: length, interval: interval };
1182
+ return d;
1183
+ }
1156
1184
  /**
1157
1185
  * IndicatorRateOfChange indicator.
1158
1186
  * @param length Length of time
@@ -1187,14 +1215,12 @@ function IndicatorStandardDeviation(operand, length = 30, interval = "Day") {
1187
1215
  return d;
1188
1216
  }
1189
1217
  /**
1190
- * IndicatorWindowAgo indicator.
1218
+ * Value at an elapsed time in the past. TradingDay instead reads the confirmed closing value of the reference exchange session, including early closes. Missing session evidence returns no value; initialValue applies before enough history exists.
1191
1219
  * @param length Length of time
1192
1220
  * @param interval Unit of time
1193
1221
  */
1194
- function IndicatorWindowAgo(operand, length, interval, sampling, initialValue) {
1222
+ function IndicatorWindowAgo(operand, length, interval, initialValue) {
1195
1223
  const d = { type: "IndicatorWindowAgo" };
1196
- if (sampling !== undefined)
1197
- d["sampling"] = sampling;
1198
1224
  if (initialValue !== undefined)
1199
1225
  d["initialValue"] = initialValue;
1200
1226
  d.indicators = [operand];
@@ -1959,7 +1985,7 @@ function PortfolioValue() {
1959
1985
  return d;
1960
1986
  }
1961
1987
  /**
1962
- * PositionEntryPrice indicator.
1988
+ * Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
1963
1989
  * @param asset Ticker name (ex. SPY, BTC)
1964
1990
  */
1965
1991
  function PositionEntryPrice(asset) {
@@ -1986,7 +2012,7 @@ function PositionMaxDrawup(asset) {
1986
2012
  return d;
1987
2013
  }
1988
2014
  /**
1989
- * PositionMinutesSinceHigh indicator.
2015
+ * Exchange trading minutes since the current holding's last new high. Closed-market minutes do not count. Added shares preserve the holding's observation path.
1990
2016
  * @param asset Ticker name (ex. SPY, BTC)
1991
2017
  */
1992
2018
  function PositionMinutesSinceHigh(asset) {
@@ -1995,7 +2021,7 @@ function PositionMinutesSinceHigh(asset) {
1995
2021
  return d;
1996
2022
  }
1997
2023
  /**
1998
- * PositionPeakPrice indicator.
2024
+ * Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
1999
2025
  * @param asset Ticker name (ex. SPY, BTC)
2000
2026
  */
2001
2027
  function PositionPeakPrice(asset) {
@@ -41,6 +41,17 @@ export interface Condition {
41
41
  readonly [nodeKind]: "Condition (true/false, not an indicator)";
42
42
  [key: string]: unknown;
43
43
  }
44
+ /** Existing native Then timing: optional maximum window and trading-time wait. */
45
+ export interface ThenTiming {
46
+ window?: {
47
+ length: number;
48
+ interval: Interval;
49
+ };
50
+ transition: {
51
+ minimumTradingMinutes: number;
52
+ waiting: boolean;
53
+ };
54
+ }
44
55
  declare const candidateBound: unique symbol;
45
56
  /** Indicator bound to the pipeline candidate (Price(CANDIDATE), …). */
46
57
  export type CandidateIndicator = Indicator & {
@@ -595,7 +606,7 @@ export interface Portfolio {
595
606
  }
596
607
  export type DividendPolicy = "cash" | "reinvest";
597
608
  export type AssetType = "Stock" | "Cryptocurrency" | "Option" | "Other";
598
- export type Interval = "Day" | "Hour" | "Minute";
609
+ export type Interval = "Day" | "Hour" | "Minute" | "TradingDay";
599
610
  export type Comparator = "lessThan" | "greaterThan" | "lessThanOrEqual" | "greaterThanOrEqual" | "equal" | "notEqual";
600
611
  export type SelectDirection = "Highest" | "Lowest";
601
612
  export type UniverseSource = "ALL_US_STOCKS" | "SP500" | "NASDAQ100" | "DJIA" | "CRYPTO" | "SPECIFIC_ASSETS" | "WATCHLIST";
@@ -667,7 +678,8 @@ export declare const multi: (count: number, comparison: Comparator, ...condition
667
678
  * would call it with resolve/reject and never settle. Emits wire type "Then",
668
679
  * the same way atLeast/atMost/exactly emit "Multi".
669
680
  */
670
- export declare const andThen: (length: number, interval: Interval, ...conditions: Condition[]) => Condition;
681
+ export declare function andThen(length: number, interval: Interval, ...conditions: Condition[]): Condition;
682
+ export declare function andThen(timing: ThenTiming, ...conditions: Condition[]): Condition;
671
683
  /** Always-true gate for strategies whose cadence lives in the pipeline. */
672
684
  export declare const always: () => Condition;
673
685
  export declare const meanVarianceAllocation: (config?: Partial<Omit<MeanVarianceAllocationPolicy, "type">>) => MeanVarianceAllocationPolicy;
@@ -978,13 +990,12 @@ export declare function ConsecutiveDecrease(indicator: Indicator, period: Period
978
990
  */
979
991
  export declare function ConsecutiveIncrease(indicator: Indicator, period: Period, lookback: number): Indicator;
980
992
  /**
981
- * ConsecutiveTrue indicator.
993
+ * Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
982
994
  * @param condition Condition evaluated over the window.
983
995
  * @param length Length of time
984
996
  * @param interval Unit of time
985
- * @param checkCadenceMinutes Optional. Counts completed regular-session checks instead of elapsed time. Window length is the required count; resets each session. Missing checks reset the count.
986
997
  */
987
- export declare function ConsecutiveTrue(condition: Condition, length?: number, interval?: Interval, checkCadenceMinutes?: number): Indicator;
998
+ export declare function ConsecutiveTrue(condition: Condition, length?: number, interval?: Interval): Indicator;
988
999
  /**
989
1000
  * Correlation indicator.
990
1001
  * @param operands Sub-indicators this compound operates on.
@@ -993,12 +1004,16 @@ export declare function ConsecutiveTrue(condition: Condition, length?: number, i
993
1004
  */
994
1005
  export declare function Correlation(operands: Indicator[], length?: number, interval?: Interval): Indicator;
995
1006
  /**
996
- * CountTrue indicator.
997
- * @param condition Condition evaluated over the window.
998
- * @param length Length of time
999
- * @param interval Unit of time
1007
+ * Count matching intervals inside a time lookback. The ordinary condition owns comparisons/events. countInterval contributes at most one match per interval; omitted means one unit of the lookback interval. TradingDay skips closed exchange dates.
1008
+ * @param condition Ordinary condition whose matching intervals are counted.
1009
+ * @param length Lookback length.
1010
+ * @param interval Lookback time unit; TradingDay uses observed exchange sessions.
1011
+ * @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
1000
1012
  */
1001
- export declare function CountTrue(condition: Condition, length?: number, interval?: Interval): Indicator;
1013
+ export declare function CountTrue(condition: Condition, length?: number, interval?: Interval, countInterval?: {
1014
+ length: number;
1015
+ interval: Interval;
1016
+ }): Indicator;
1002
1017
  /**
1003
1018
  * CrossAbove indicator.
1004
1019
  */
@@ -1019,6 +1034,14 @@ export declare function CurrentTimeMinutes(): Indicator;
1019
1034
  * CurrentTimeSeconds indicator.
1020
1035
  */
1021
1036
  export declare function CurrentTimeSeconds(): Indicator;
1037
+ /**
1038
+ * Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
1039
+ */
1040
+ export declare function CurrentTimestamp(): Indicator;
1041
+ /**
1042
+ * Inside a CountTrue historical condition, bind this operand at its value now while other operands use their historical observations. Elsewhere return the operand normally. Wrap a complete stateful operand, not an expression inside its recurrence.
1043
+ */
1044
+ export declare function CurrentValue(operand: Indicator): Indicator;
1022
1045
  /**
1023
1046
  * CustomIndicator indicator.
1024
1047
  * @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
@@ -1162,10 +1185,10 @@ export declare function ImpliedVolatility(asset: AssetArg, dte?: number): Indica
1162
1185
  */
1163
1186
  export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "USDBROAD" | "TNX"): Indicator;
1164
1187
  /**
1165
- * IndicatorAtCondition indicator.
1188
+ * Retain the operand from matching observations: First, Latest, Maximum, or Minimum. Ordinary conditions decide when to capture. An optional window expires observations; TradingDay skips closed exchange dates. Use this to freeze a qualified setup before entry or ratchet a numeric level, not IndicatorAtEntry when no fill exists yet.
1166
1189
  * @param condition Condition evaluated over the window.
1167
1190
  */
1168
- export declare function IndicatorAtCondition(operand: Indicator, condition: Condition, selection?: "First" | "Latest" | "Maximum" | "Minimum", clock?: Clock, initialValue?: number, length?: number, interval?: "Minute" | "Day"): Indicator;
1191
+ export declare function IndicatorAtCondition(operand: Indicator, condition: Condition, selection?: "First" | "Latest" | "Maximum" | "Minimum", clock?: Clock, initialValue?: number, length?: number, interval?: Interval): Indicator;
1169
1192
  /**
1170
1193
  * IndicatorAtEntry indicator.
1171
1194
  * @param asset Ticker name (ex. SPY, BTC)
@@ -1184,12 +1207,24 @@ export declare function IndicatorAtMinutesAfterOpen(operand: Indicator, minutesA
1184
1207
  * @param interval Unit of time
1185
1208
  */
1186
1209
  export declare function IndicatorExponentialMovingAverage(operand: Indicator, length?: number, interval?: Interval): Indicator;
1210
+ /**
1211
+ * Rolling maximum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
1212
+ * @param length Length of time
1213
+ * @param interval Unit of time
1214
+ */
1215
+ export declare function IndicatorMaximum(operand: Indicator, length?: number, interval?: Interval): Indicator;
1187
1216
  /**
1188
1217
  * IndicatorMeanAbsoluteDeviation indicator.
1189
1218
  * @param length Length of time
1190
1219
  * @param interval Unit of time
1191
1220
  */
1192
1221
  export declare function IndicatorMeanAbsoluteDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
1222
+ /**
1223
+ * Rolling minimum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
1224
+ * @param length Length of time
1225
+ * @param interval Unit of time
1226
+ */
1227
+ export declare function IndicatorMinimum(operand: Indicator, length?: number, interval?: Interval): Indicator;
1193
1228
  /**
1194
1229
  * IndicatorRateOfChange indicator.
1195
1230
  * @param length Length of time
@@ -1209,11 +1244,11 @@ export declare function IndicatorSimpleMovingAverage(operand: Indicator, length?
1209
1244
  */
1210
1245
  export declare function IndicatorStandardDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
1211
1246
  /**
1212
- * IndicatorWindowAgo indicator.
1247
+ * Value at an elapsed time in the past. TradingDay instead reads the confirmed closing value of the reference exchange session, including early closes. Missing session evidence returns no value; initialValue applies before enough history exists.
1213
1248
  * @param length Length of time
1214
1249
  * @param interval Unit of time
1215
1250
  */
1216
- export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval, sampling?: "Calendar" | "Observation" | "Session", initialValue?: number): Indicator;
1251
+ export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval, initialValue?: number): Indicator;
1217
1252
  /**
1218
1253
  * News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. The value is the same for every asset: it takes no target asset.
1219
1254
  * @param industry Canonical industry tag whose news to read, as IsIndustry lists it. Legacy aliases are separate news series and are rejected, never mapped.
@@ -1619,7 +1654,7 @@ export declare function PoliticalTrades(asset: AssetArg, filer: string, metric?:
1619
1654
  */
1620
1655
  export declare function PortfolioValue(): Indicator;
1621
1656
  /**
1622
- * PositionEntryPrice indicator.
1657
+ * Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
1623
1658
  * @param asset Ticker name (ex. SPY, BTC)
1624
1659
  */
1625
1660
  export declare function PositionEntryPrice(asset: AssetArg): Indicator;
@@ -1634,12 +1669,12 @@ export declare function PositionMaxDrawdown(asset: AssetArg): Indicator;
1634
1669
  */
1635
1670
  export declare function PositionMaxDrawup(asset: AssetArg): Indicator;
1636
1671
  /**
1637
- * PositionMinutesSinceHigh indicator.
1672
+ * Exchange trading minutes since the current holding's last new high. Closed-market minutes do not count. Added shares preserve the holding's observation path.
1638
1673
  * @param asset Ticker name (ex. SPY, BTC)
1639
1674
  */
1640
1675
  export declare function PositionMinutesSinceHigh(asset: AssetArg): Indicator;
1641
1676
  /**
1642
- * PositionPeakPrice indicator.
1677
+ * Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
1643
1678
  * @param asset Ticker name (ex. SPY, BTC)
1644
1679
  */
1645
1680
  export declare function PositionPeakPrice(asset: AssetArg): Indicator;
@@ -128,24 +128,11 @@ export const fewerThan = (count, ...conditions) => ({ type: "Multi", comparison:
128
128
  export const exactly = (count, ...conditions) => ({ type: "Multi", comparison: "equal", value: count, conditions });
129
129
  /** Multi with an explicit Comparator (same wire shape as YAML Multi). */
130
130
  export const multi = (count, comparison, ...conditions) => ({ type: "Multi", comparison, value: count, conditions });
131
- /**
132
- * Sequence. `andThen(30, "Minute", A, B)` is true at tick t when B is true at t
133
- * and A was true at some STRICTLY EARLIER tick in the preceding 30 minutes.
134
- *
135
- * Simultaneous A and B does not fire — that is `and`. The window applies per
136
- * transition, so with three or more steps each one must occur within the window
137
- * of the step before it. Nesting is legal and means something different:
138
- * `andThen(W, andThen(W, A, B), C)` is not `andThen(W, A, B, C)`.
139
- *
140
- * `interval` is REQUIRED and has no default. An omitted interval would fall
141
- * back to Day and silently kill an intraday setup.
142
- *
143
- * Named `andThen` rather than `then`: a module namespace with a callable
144
- * `then` export is assimilated as a thenable, so `await import("nexustrade")`
145
- * would call it with resolve/reject and never settle. Emits wire type "Then",
146
- * the same way atLeast/atMost/exactly emit "Multi".
147
- */
148
- export const andThen = (length, interval, ...conditions) => ({ type: "Then", conditions, window: { length, interval } });
131
+ export function andThen(timing, first, ...rest) {
132
+ return (typeof timing === "number"
133
+ ? { type: "Then", conditions: rest, window: { length: timing, interval: first } }
134
+ : { type: "Then", ...timing, conditions: [first, ...rest] });
135
+ }
149
136
  /** Always-true gate for strategies whose cadence lives in the pipeline. */
150
137
  export const always = () => compare(Value(1), Value(0), "greaterThan");
151
138
  export const meanVarianceAllocation = (config = {}) => ({
@@ -530,17 +517,14 @@ export function ConsecutiveIncrease(indicator, period, lookback) {
530
517
  return d;
531
518
  }
532
519
  /**
533
- * ConsecutiveTrue indicator.
520
+ * Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
534
521
  * @param condition Condition evaluated over the window.
535
522
  * @param length Length of time
536
523
  * @param interval Unit of time
537
- * @param checkCadenceMinutes Optional. Counts completed regular-session checks instead of elapsed time. Window length is the required count; resets each session. Missing checks reset the count.
538
524
  */
539
- export function ConsecutiveTrue(condition, length = 1, interval = "Day", checkCadenceMinutes) {
525
+ export function ConsecutiveTrue(condition, length = 1, interval = "Day") {
540
526
  const d = { type: "ConsecutiveTrue" };
541
527
  d.condition = condition;
542
- if (checkCadenceMinutes !== undefined)
543
- d["checkCadenceMinutes"] = checkCadenceMinutes;
544
528
  d.window = { length: length, interval: interval };
545
529
  return d;
546
530
  }
@@ -557,14 +541,17 @@ export function Correlation(operands, length = 60, interval = "Day") {
557
541
  return d;
558
542
  }
559
543
  /**
560
- * CountTrue indicator.
561
- * @param condition Condition evaluated over the window.
562
- * @param length Length of time
563
- * @param interval Unit of time
544
+ * Count matching intervals inside a time lookback. The ordinary condition owns comparisons/events. countInterval contributes at most one match per interval; omitted means one unit of the lookback interval. TradingDay skips closed exchange dates.
545
+ * @param condition Ordinary condition whose matching intervals are counted.
546
+ * @param length Lookback length.
547
+ * @param interval Lookback time unit; TradingDay uses observed exchange sessions.
548
+ * @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
564
549
  */
565
- export function CountTrue(condition, length = 1, interval = "Day") {
550
+ export function CountTrue(condition, length = 1, interval = "Day", countInterval) {
566
551
  const d = { type: "CountTrue" };
567
552
  d.condition = condition;
553
+ if (countInterval !== undefined)
554
+ d["countInterval"] = countInterval;
568
555
  d.window = { length: length, interval: interval };
569
556
  return d;
570
557
  }
@@ -605,6 +592,21 @@ export function CurrentTimeSeconds() {
605
592
  const d = { type: "CurrentTimeSeconds" };
606
593
  return d;
607
594
  }
595
+ /**
596
+ * Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
597
+ */
598
+ export function CurrentTimestamp() {
599
+ const d = { type: "CurrentTimestamp" };
600
+ return d;
601
+ }
602
+ /**
603
+ * Inside a CountTrue historical condition, bind this operand at its value now while other operands use their historical observations. Elsewhere return the operand normally. Wrap a complete stateful operand, not an expression inside its recurrence.
604
+ */
605
+ export function CurrentValue(operand) {
606
+ const d = { type: "CurrentValue" };
607
+ d.indicators = [operand];
608
+ return d;
609
+ }
608
610
  /**
609
611
  * CustomIndicator indicator.
610
612
  * @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
@@ -864,7 +866,7 @@ export function Index(metric = "VIX") {
864
866
  return d;
865
867
  }
866
868
  /**
867
- * IndicatorAtCondition indicator.
869
+ * Retain the operand from matching observations: First, Latest, Maximum, or Minimum. Ordinary conditions decide when to capture. An optional window expires observations; TradingDay skips closed exchange dates. Use this to freeze a qualified setup before entry or ratchet a numeric level, not IndicatorAtEntry when no fill exists yet.
868
870
  * @param condition Condition evaluated over the window.
869
871
  */
870
872
  export function IndicatorAtCondition(operand, condition, selection = "First", clock = "Calendar", initialValue, length, interval) {
@@ -915,6 +917,17 @@ export function IndicatorExponentialMovingAverage(operand, length = 30, interval
915
917
  d.window = { length: length, interval: interval };
916
918
  return d;
917
919
  }
920
+ /**
921
+ * Rolling maximum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
922
+ * @param length Length of time
923
+ * @param interval Unit of time
924
+ */
925
+ export function IndicatorMaximum(operand, length = 30, interval = "Day") {
926
+ const d = { type: "IndicatorMaximum" };
927
+ d.indicators = [operand];
928
+ d.window = { length: length, interval: interval };
929
+ return d;
930
+ }
918
931
  /**
919
932
  * IndicatorMeanAbsoluteDeviation indicator.
920
933
  * @param length Length of time
@@ -926,6 +939,17 @@ export function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval =
926
939
  d.window = { length: length, interval: interval };
927
940
  return d;
928
941
  }
942
+ /**
943
+ * Rolling minimum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
944
+ * @param length Length of time
945
+ * @param interval Unit of time
946
+ */
947
+ export function IndicatorMinimum(operand, length = 30, interval = "Day") {
948
+ const d = { type: "IndicatorMinimum" };
949
+ d.indicators = [operand];
950
+ d.window = { length: length, interval: interval };
951
+ return d;
952
+ }
929
953
  /**
930
954
  * IndicatorRateOfChange indicator.
931
955
  * @param length Length of time
@@ -960,14 +984,12 @@ export function IndicatorStandardDeviation(operand, length = 30, interval = "Day
960
984
  return d;
961
985
  }
962
986
  /**
963
- * IndicatorWindowAgo indicator.
987
+ * Value at an elapsed time in the past. TradingDay instead reads the confirmed closing value of the reference exchange session, including early closes. Missing session evidence returns no value; initialValue applies before enough history exists.
964
988
  * @param length Length of time
965
989
  * @param interval Unit of time
966
990
  */
967
- export function IndicatorWindowAgo(operand, length, interval, sampling, initialValue) {
991
+ export function IndicatorWindowAgo(operand, length, interval, initialValue) {
968
992
  const d = { type: "IndicatorWindowAgo" };
969
- if (sampling !== undefined)
970
- d["sampling"] = sampling;
971
993
  if (initialValue !== undefined)
972
994
  d["initialValue"] = initialValue;
973
995
  d.indicators = [operand];
@@ -1732,7 +1754,7 @@ export function PortfolioValue() {
1732
1754
  return d;
1733
1755
  }
1734
1756
  /**
1735
- * PositionEntryPrice indicator.
1757
+ * Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
1736
1758
  * @param asset Ticker name (ex. SPY, BTC)
1737
1759
  */
1738
1760
  export function PositionEntryPrice(asset) {
@@ -1759,7 +1781,7 @@ export function PositionMaxDrawup(asset) {
1759
1781
  return d;
1760
1782
  }
1761
1783
  /**
1762
- * PositionMinutesSinceHigh indicator.
1784
+ * Exchange trading minutes since the current holding's last new high. Closed-market minutes do not count. Added shares preserve the holding's observation path.
1763
1785
  * @param asset Ticker name (ex. SPY, BTC)
1764
1786
  */
1765
1787
  export function PositionMinutesSinceHigh(asset) {
@@ -1768,7 +1790,7 @@ export function PositionMinutesSinceHigh(asset) {
1768
1790
  return d;
1769
1791
  }
1770
1792
  /**
1771
- * PositionPeakPrice indicator.
1793
+ * Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
1772
1794
  * @param asset Ticker name (ex. SPY, BTC)
1773
1795
  */
1774
1796
  export function PositionPeakPrice(asset) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexustrade",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "description": "Typed TypeScript SDK for NexusTrade portfolio authoring, backtesting, and optimization",
5
5
  "license": "MIT",
6
6
  "author": "Starks Technology",