nexustrade 2.1.1 → 3.1.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
|
@@ -1138,6 +1138,15 @@ fixed on later crossings unless an expiry was configured.
|
|
|
1138
1138
|
narrow position measurements. Reuse `MinutesSinceOrder` for purchase cadence.
|
|
1139
1139
|
Settlement accounting remains on the portfolio.
|
|
1140
1140
|
|
|
1141
|
+
`short` (Python `short`) sells one stock to open a short of exactly the sized
|
|
1142
|
+
shares; it defaults to `"number of assets"` and cannot be sized as a percent of
|
|
1143
|
+
current positions. `cover` buys the short back; its default is 100 percent of
|
|
1144
|
+
the open short, and every size is capped at the short, so it never goes long.
|
|
1145
|
+
A Short is refused while the book is long that stock, is capped by Reg-T initial
|
|
1146
|
+
margin, and is always whole shares. Backtests and paper books always support
|
|
1147
|
+
them; a live book needs a brokerage that can short stock (Alpaca, Tradier,
|
|
1148
|
+
TradeStation or Public, on a margin account).
|
|
1149
|
+
|
|
1141
1150
|
`sellHoldings` (Python `sell_holdings`) is a Sell action with a candidate-bound
|
|
1142
1151
|
holding condition. Its strategy condition supplies the account/market gate;
|
|
1143
1152
|
only actual qualifying stock holdings are sold. Ordinary fixed-asset Sell
|
|
@@ -1171,9 +1180,13 @@ Other brokers need a live T1 evidence adapter. Existing owner approval and trade
|
|
|
1171
1180
|
limits apply. Native strategy/indicator runtime uses the existing checkpoint
|
|
1172
1181
|
path; its verification does not establish live broker execution.
|
|
1173
1182
|
|
|
1174
|
-
ConsecutiveTrue
|
|
1175
|
-
|
|
1176
|
-
|
|
1183
|
+
`ConsecutiveTrue` measures elapsed time while its ordinary condition stays true.
|
|
1184
|
+
`CountTrue` counts matching intervals inside a time lookback. For example, a
|
|
1185
|
+
20 `TradingDay` lookback with `countInterval: {length: 5, interval: "Minute"}`
|
|
1186
|
+
counts at most one match per five-minute interval across twenty exchange sessions.
|
|
1187
|
+
Omitting `countInterval` means one unit of the lookback interval. Comparisons and
|
|
1188
|
+
visit/crossing events belong in the ordinary `condition`, including `Then`.
|
|
1189
|
+
There are no sampled-comparison, distinct, cadence-count or clock modes.
|
|
1177
1190
|
|
|
1178
1191
|
`PortfolioValue` keeps its existing cash-plus-positions semantics during warmup
|
|
1179
1192
|
and trading. Backtesting and paper trading do not depend on the selected pricing
|
|
@@ -1183,6 +1196,14 @@ reconciliation path. Porting a T1 strategy preserves its settlement policy.
|
|
|
1183
1196
|
|
|
1184
1197
|
For conditional capture, expiry runs from the retained observation's capture
|
|
1185
1198
|
time. Minimum/Maximum with expiry is not a sliding-window minimum/maximum.
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1199
|
+
`IndicatorMinimum` and `IndicatorMaximum` provide rolling extrema of one numeric
|
|
1200
|
+
operand. `CurrentValue(operand)` explicitly binds today's reference inside a
|
|
1201
|
+
historical CountTrue condition; historical operands retain their observed values.
|
|
1202
|
+
Outside that query it returns its operand. Bind the complete stateful operand,
|
|
1203
|
+
rather than inserting a reference inside its recurrence.
|
|
1204
|
+
|
|
1205
|
+
`TradingDay` windows use observed exchange sessions, including holidays and early
|
|
1206
|
+
closes. Elapsed Day/Hour/Minute windows keep their calendar meaning.
|
|
1207
|
+
`IndicatorWindowAgo` with `TradingDay` reads the confirmed value at the end of the
|
|
1208
|
+
reference session. Missing session evidence returns no value. `CurrentTimestamp`
|
|
1209
|
+
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.
|
|
4
|
-
exports.
|
|
5
|
-
exports.geneAppendUniversePipelineFilter = exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = exports.geneAllocationPolicy = void 0;
|
|
3
|
+
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.cover = exports.short = 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.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 = exports.screenTop = void 0;
|
|
5
|
+
exports.geneAppendUniversePipelineFilter = exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = exports.geneAllocationPolicy = exports.geneStructureKind = 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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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;
|
|
@@ -393,6 +384,20 @@ const buy = (target, amount, type = "percent of portfolio", options = {}) => ({
|
|
|
393
384
|
exports.buy = buy;
|
|
394
385
|
const sell = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
395
386
|
exports.sell = sell;
|
|
387
|
+
/**
|
|
388
|
+
* Sell-to-open one stock: hold a short of exactly the sized shares. Sizing is
|
|
389
|
+
* "number of assets" (shares), "dollars", "percent of portfolio" or "percent of
|
|
390
|
+
* buying power"; capped by Reg-T initial margin. Refused while the book is long
|
|
391
|
+
* the stock. Needs a brokerage that can short stock (backtests and paper can).
|
|
392
|
+
*/
|
|
393
|
+
const short = (target, amount, type = "number of assets", options = {}) => ({ type: "Short", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
394
|
+
exports.short = short;
|
|
395
|
+
/**
|
|
396
|
+
* Buy back an open stock short. "percent of current positions" is a percent of
|
|
397
|
+
* the open short; every size is capped at the short, so Cover never goes long.
|
|
398
|
+
*/
|
|
399
|
+
const cover = (target, amount = 100, type = "percent of current positions", options = {}) => ({ type: "Cover", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
400
|
+
exports.cover = cover;
|
|
396
401
|
/** Sell only actual holdings that pass a candidate-bound condition. */
|
|
397
402
|
const sellHoldings = (condition, amount = 100, type = "percent of current positions", options = {}) => ({ type: "Sell", targetAsset: (0, exports.stockAsset)("__PLACEHOLDER__"),
|
|
398
403
|
holdingCondition: condition, amount: { type, amount }, ...options });
|
|
@@ -757,17 +762,14 @@ function ConsecutiveIncrease(indicator, period, lookback) {
|
|
|
757
762
|
return d;
|
|
758
763
|
}
|
|
759
764
|
/**
|
|
760
|
-
*
|
|
765
|
+
* Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
|
|
761
766
|
* @param condition Condition evaluated over the window.
|
|
762
767
|
* @param length Length of time
|
|
763
768
|
* @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
769
|
*/
|
|
766
|
-
function ConsecutiveTrue(condition, length = 1, interval = "Day"
|
|
770
|
+
function ConsecutiveTrue(condition, length = 1, interval = "Day") {
|
|
767
771
|
const d = { type: "ConsecutiveTrue" };
|
|
768
772
|
d.condition = condition;
|
|
769
|
-
if (checkCadenceMinutes !== undefined)
|
|
770
|
-
d["checkCadenceMinutes"] = checkCadenceMinutes;
|
|
771
773
|
d.window = { length: length, interval: interval };
|
|
772
774
|
return d;
|
|
773
775
|
}
|
|
@@ -784,14 +786,17 @@ function Correlation(operands, length = 60, interval = "Day") {
|
|
|
784
786
|
return d;
|
|
785
787
|
}
|
|
786
788
|
/**
|
|
787
|
-
*
|
|
788
|
-
* @param condition
|
|
789
|
-
* @param length
|
|
790
|
-
* @param interval
|
|
789
|
+
* 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.
|
|
790
|
+
* @param condition Ordinary condition whose matching intervals are counted.
|
|
791
|
+
* @param length Lookback length.
|
|
792
|
+
* @param interval Lookback time unit; TradingDay uses observed exchange sessions.
|
|
793
|
+
* @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
|
|
791
794
|
*/
|
|
792
|
-
function CountTrue(condition, length = 1, interval = "Day") {
|
|
795
|
+
function CountTrue(condition, length = 1, interval = "Day", countInterval) {
|
|
793
796
|
const d = { type: "CountTrue" };
|
|
794
797
|
d.condition = condition;
|
|
798
|
+
if (countInterval !== undefined)
|
|
799
|
+
d["countInterval"] = countInterval;
|
|
795
800
|
d.window = { length: length, interval: interval };
|
|
796
801
|
return d;
|
|
797
802
|
}
|
|
@@ -832,6 +837,21 @@ function CurrentTimeSeconds() {
|
|
|
832
837
|
const d = { type: "CurrentTimeSeconds" };
|
|
833
838
|
return d;
|
|
834
839
|
}
|
|
840
|
+
/**
|
|
841
|
+
* Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
|
|
842
|
+
*/
|
|
843
|
+
function CurrentTimestamp() {
|
|
844
|
+
const d = { type: "CurrentTimestamp" };
|
|
845
|
+
return d;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* 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.
|
|
849
|
+
*/
|
|
850
|
+
function CurrentValue(operand) {
|
|
851
|
+
const d = { type: "CurrentValue" };
|
|
852
|
+
d.indicators = [operand];
|
|
853
|
+
return d;
|
|
854
|
+
}
|
|
835
855
|
/**
|
|
836
856
|
* CustomIndicator indicator.
|
|
837
857
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
|
|
@@ -1091,7 +1111,7 @@ function Index(metric = "VIX") {
|
|
|
1091
1111
|
return d;
|
|
1092
1112
|
}
|
|
1093
1113
|
/**
|
|
1094
|
-
*
|
|
1114
|
+
* 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
1115
|
* @param condition Condition evaluated over the window.
|
|
1096
1116
|
*/
|
|
1097
1117
|
function IndicatorAtCondition(operand, condition, selection = "First", clock = "Calendar", initialValue, length, interval) {
|
|
@@ -1142,6 +1162,17 @@ function IndicatorExponentialMovingAverage(operand, length = 30, interval = "Day
|
|
|
1142
1162
|
d.window = { length: length, interval: interval };
|
|
1143
1163
|
return d;
|
|
1144
1164
|
}
|
|
1165
|
+
/**
|
|
1166
|
+
* 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.
|
|
1167
|
+
* @param length Length of time
|
|
1168
|
+
* @param interval Unit of time
|
|
1169
|
+
*/
|
|
1170
|
+
function IndicatorMaximum(operand, length = 30, interval = "Day") {
|
|
1171
|
+
const d = { type: "IndicatorMaximum" };
|
|
1172
|
+
d.indicators = [operand];
|
|
1173
|
+
d.window = { length: length, interval: interval };
|
|
1174
|
+
return d;
|
|
1175
|
+
}
|
|
1145
1176
|
/**
|
|
1146
1177
|
* IndicatorMeanAbsoluteDeviation indicator.
|
|
1147
1178
|
* @param length Length of time
|
|
@@ -1153,6 +1184,17 @@ function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval = "Day")
|
|
|
1153
1184
|
d.window = { length: length, interval: interval };
|
|
1154
1185
|
return d;
|
|
1155
1186
|
}
|
|
1187
|
+
/**
|
|
1188
|
+
* 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.
|
|
1189
|
+
* @param length Length of time
|
|
1190
|
+
* @param interval Unit of time
|
|
1191
|
+
*/
|
|
1192
|
+
function IndicatorMinimum(operand, length = 30, interval = "Day") {
|
|
1193
|
+
const d = { type: "IndicatorMinimum" };
|
|
1194
|
+
d.indicators = [operand];
|
|
1195
|
+
d.window = { length: length, interval: interval };
|
|
1196
|
+
return d;
|
|
1197
|
+
}
|
|
1156
1198
|
/**
|
|
1157
1199
|
* IndicatorRateOfChange indicator.
|
|
1158
1200
|
* @param length Length of time
|
|
@@ -1187,14 +1229,12 @@ function IndicatorStandardDeviation(operand, length = 30, interval = "Day") {
|
|
|
1187
1229
|
return d;
|
|
1188
1230
|
}
|
|
1189
1231
|
/**
|
|
1190
|
-
*
|
|
1232
|
+
* 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
1233
|
* @param length Length of time
|
|
1192
1234
|
* @param interval Unit of time
|
|
1193
1235
|
*/
|
|
1194
|
-
function IndicatorWindowAgo(operand, length, interval,
|
|
1236
|
+
function IndicatorWindowAgo(operand, length, interval, initialValue) {
|
|
1195
1237
|
const d = { type: "IndicatorWindowAgo" };
|
|
1196
|
-
if (sampling !== undefined)
|
|
1197
|
-
d["sampling"] = sampling;
|
|
1198
1238
|
if (initialValue !== undefined)
|
|
1199
1239
|
d["initialValue"] = initialValue;
|
|
1200
1240
|
d.indicators = [operand];
|
|
@@ -1959,7 +1999,7 @@ function PortfolioValue() {
|
|
|
1959
1999
|
return d;
|
|
1960
2000
|
}
|
|
1961
2001
|
/**
|
|
1962
|
-
*
|
|
2002
|
+
* Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
|
|
1963
2003
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1964
2004
|
*/
|
|
1965
2005
|
function PositionEntryPrice(asset) {
|
|
@@ -1986,7 +2026,7 @@ function PositionMaxDrawup(asset) {
|
|
|
1986
2026
|
return d;
|
|
1987
2027
|
}
|
|
1988
2028
|
/**
|
|
1989
|
-
*
|
|
2029
|
+
* 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
2030
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1991
2031
|
*/
|
|
1992
2032
|
function PositionMinutesSinceHigh(asset) {
|
|
@@ -1995,7 +2035,7 @@ function PositionMinutesSinceHigh(asset) {
|
|
|
1995
2035
|
return d;
|
|
1996
2036
|
}
|
|
1997
2037
|
/**
|
|
1998
|
-
*
|
|
2038
|
+
* Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
|
|
1999
2039
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
2000
2040
|
*/
|
|
2001
2041
|
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 & {
|
|
@@ -273,7 +284,7 @@ export interface PurchaseFunding {
|
|
|
273
284
|
amount: Allocation;
|
|
274
285
|
}
|
|
275
286
|
export interface BuyOrSellAction {
|
|
276
|
-
type: "Buy" | "Sell";
|
|
287
|
+
type: "Buy" | "Sell" | "Short" | "Cover";
|
|
277
288
|
targetAsset: Asset;
|
|
278
289
|
amount: Allocation;
|
|
279
290
|
executionPriority?: ExecutionPriority;
|
|
@@ -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
|
|
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;
|
|
@@ -693,6 +705,22 @@ export declare const buy: (target: AssetArg, amount: number, type?: AllocationTy
|
|
|
693
705
|
export declare const sell: (target: AssetArg, amount: number, type?: AllocationType, options?: {
|
|
694
706
|
executionPriority?: ExecutionPriority;
|
|
695
707
|
}) => BuyOrSellAction;
|
|
708
|
+
/**
|
|
709
|
+
* Sell-to-open one stock: hold a short of exactly the sized shares. Sizing is
|
|
710
|
+
* "number of assets" (shares), "dollars", "percent of portfolio" or "percent of
|
|
711
|
+
* buying power"; capped by Reg-T initial margin. Refused while the book is long
|
|
712
|
+
* the stock. Needs a brokerage that can short stock (backtests and paper can).
|
|
713
|
+
*/
|
|
714
|
+
export declare const short: (target: AssetArg, amount: number, type?: AllocationType, options?: {
|
|
715
|
+
executionPriority?: ExecutionPriority;
|
|
716
|
+
}) => BuyOrSellAction;
|
|
717
|
+
/**
|
|
718
|
+
* Buy back an open stock short. "percent of current positions" is a percent of
|
|
719
|
+
* the open short; every size is capped at the short, so Cover never goes long.
|
|
720
|
+
*/
|
|
721
|
+
export declare const cover: (target: AssetArg, amount?: number, type?: AllocationType, options?: {
|
|
722
|
+
executionPriority?: ExecutionPriority;
|
|
723
|
+
}) => BuyOrSellAction;
|
|
696
724
|
/** Sell only actual holdings that pass a candidate-bound condition. */
|
|
697
725
|
export declare const sellHoldings: (condition: Condition, amount?: number, type?: AllocationType, options?: {
|
|
698
726
|
executionPriority?: ExecutionPriority;
|
|
@@ -978,13 +1006,12 @@ export declare function ConsecutiveDecrease(indicator: Indicator, period: Period
|
|
|
978
1006
|
*/
|
|
979
1007
|
export declare function ConsecutiveIncrease(indicator: Indicator, period: Period, lookback: number): Indicator;
|
|
980
1008
|
/**
|
|
981
|
-
*
|
|
1009
|
+
* Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
|
|
982
1010
|
* @param condition Condition evaluated over the window.
|
|
983
1011
|
* @param length Length of time
|
|
984
1012
|
* @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
1013
|
*/
|
|
987
|
-
export declare function ConsecutiveTrue(condition: Condition, length?: number, interval?: Interval
|
|
1014
|
+
export declare function ConsecutiveTrue(condition: Condition, length?: number, interval?: Interval): Indicator;
|
|
988
1015
|
/**
|
|
989
1016
|
* Correlation indicator.
|
|
990
1017
|
* @param operands Sub-indicators this compound operates on.
|
|
@@ -993,12 +1020,16 @@ export declare function ConsecutiveTrue(condition: Condition, length?: number, i
|
|
|
993
1020
|
*/
|
|
994
1021
|
export declare function Correlation(operands: Indicator[], length?: number, interval?: Interval): Indicator;
|
|
995
1022
|
/**
|
|
996
|
-
*
|
|
997
|
-
* @param condition
|
|
998
|
-
* @param length
|
|
999
|
-
* @param interval
|
|
1023
|
+
* 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.
|
|
1024
|
+
* @param condition Ordinary condition whose matching intervals are counted.
|
|
1025
|
+
* @param length Lookback length.
|
|
1026
|
+
* @param interval Lookback time unit; TradingDay uses observed exchange sessions.
|
|
1027
|
+
* @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
|
|
1000
1028
|
*/
|
|
1001
|
-
export declare function CountTrue(condition: Condition, length?: number, interval?: Interval
|
|
1029
|
+
export declare function CountTrue(condition: Condition, length?: number, interval?: Interval, countInterval?: {
|
|
1030
|
+
length: number;
|
|
1031
|
+
interval: Interval;
|
|
1032
|
+
}): Indicator;
|
|
1002
1033
|
/**
|
|
1003
1034
|
* CrossAbove indicator.
|
|
1004
1035
|
*/
|
|
@@ -1019,6 +1050,14 @@ export declare function CurrentTimeMinutes(): Indicator;
|
|
|
1019
1050
|
* CurrentTimeSeconds indicator.
|
|
1020
1051
|
*/
|
|
1021
1052
|
export declare function CurrentTimeSeconds(): Indicator;
|
|
1053
|
+
/**
|
|
1054
|
+
* Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
|
|
1055
|
+
*/
|
|
1056
|
+
export declare function CurrentTimestamp(): Indicator;
|
|
1057
|
+
/**
|
|
1058
|
+
* 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.
|
|
1059
|
+
*/
|
|
1060
|
+
export declare function CurrentValue(operand: Indicator): Indicator;
|
|
1022
1061
|
/**
|
|
1023
1062
|
* CustomIndicator indicator.
|
|
1024
1063
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
|
|
@@ -1162,10 +1201,10 @@ export declare function ImpliedVolatility(asset: AssetArg, dte?: number): Indica
|
|
|
1162
1201
|
*/
|
|
1163
1202
|
export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "USDBROAD" | "TNX"): Indicator;
|
|
1164
1203
|
/**
|
|
1165
|
-
*
|
|
1204
|
+
* 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
1205
|
* @param condition Condition evaluated over the window.
|
|
1167
1206
|
*/
|
|
1168
|
-
export declare function IndicatorAtCondition(operand: Indicator, condition: Condition, selection?: "First" | "Latest" | "Maximum" | "Minimum", clock?: Clock, initialValue?: number, length?: number, interval?:
|
|
1207
|
+
export declare function IndicatorAtCondition(operand: Indicator, condition: Condition, selection?: "First" | "Latest" | "Maximum" | "Minimum", clock?: Clock, initialValue?: number, length?: number, interval?: Interval): Indicator;
|
|
1169
1208
|
/**
|
|
1170
1209
|
* IndicatorAtEntry indicator.
|
|
1171
1210
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
@@ -1184,12 +1223,24 @@ export declare function IndicatorAtMinutesAfterOpen(operand: Indicator, minutesA
|
|
|
1184
1223
|
* @param interval Unit of time
|
|
1185
1224
|
*/
|
|
1186
1225
|
export declare function IndicatorExponentialMovingAverage(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1226
|
+
/**
|
|
1227
|
+
* 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.
|
|
1228
|
+
* @param length Length of time
|
|
1229
|
+
* @param interval Unit of time
|
|
1230
|
+
*/
|
|
1231
|
+
export declare function IndicatorMaximum(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1187
1232
|
/**
|
|
1188
1233
|
* IndicatorMeanAbsoluteDeviation indicator.
|
|
1189
1234
|
* @param length Length of time
|
|
1190
1235
|
* @param interval Unit of time
|
|
1191
1236
|
*/
|
|
1192
1237
|
export declare function IndicatorMeanAbsoluteDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1238
|
+
/**
|
|
1239
|
+
* 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.
|
|
1240
|
+
* @param length Length of time
|
|
1241
|
+
* @param interval Unit of time
|
|
1242
|
+
*/
|
|
1243
|
+
export declare function IndicatorMinimum(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1193
1244
|
/**
|
|
1194
1245
|
* IndicatorRateOfChange indicator.
|
|
1195
1246
|
* @param length Length of time
|
|
@@ -1209,11 +1260,11 @@ export declare function IndicatorSimpleMovingAverage(operand: Indicator, length?
|
|
|
1209
1260
|
*/
|
|
1210
1261
|
export declare function IndicatorStandardDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1211
1262
|
/**
|
|
1212
|
-
*
|
|
1263
|
+
* 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
1264
|
* @param length Length of time
|
|
1214
1265
|
* @param interval Unit of time
|
|
1215
1266
|
*/
|
|
1216
|
-
export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval,
|
|
1267
|
+
export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval, initialValue?: number): Indicator;
|
|
1217
1268
|
/**
|
|
1218
1269
|
* 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
1270
|
* @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 +1670,7 @@ export declare function PoliticalTrades(asset: AssetArg, filer: string, metric?:
|
|
|
1619
1670
|
*/
|
|
1620
1671
|
export declare function PortfolioValue(): Indicator;
|
|
1621
1672
|
/**
|
|
1622
|
-
*
|
|
1673
|
+
* Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
|
|
1623
1674
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1624
1675
|
*/
|
|
1625
1676
|
export declare function PositionEntryPrice(asset: AssetArg): Indicator;
|
|
@@ -1634,12 +1685,12 @@ export declare function PositionMaxDrawdown(asset: AssetArg): Indicator;
|
|
|
1634
1685
|
*/
|
|
1635
1686
|
export declare function PositionMaxDrawup(asset: AssetArg): Indicator;
|
|
1636
1687
|
/**
|
|
1637
|
-
*
|
|
1688
|
+
* 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
1689
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1639
1690
|
*/
|
|
1640
1691
|
export declare function PositionMinutesSinceHigh(asset: AssetArg): Indicator;
|
|
1641
1692
|
/**
|
|
1642
|
-
*
|
|
1693
|
+
* Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
|
|
1643
1694
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1644
1695
|
*/
|
|
1645
1696
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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 = {}) => ({
|
|
@@ -206,6 +193,18 @@ export const watchlistUniverse = (watchlistKey) => ({ source: "WATCHLIST", watch
|
|
|
206
193
|
// ---- equity + cash actions ----
|
|
207
194
|
export const buy = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
208
195
|
export const sell = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
196
|
+
/**
|
|
197
|
+
* Sell-to-open one stock: hold a short of exactly the sized shares. Sizing is
|
|
198
|
+
* "number of assets" (shares), "dollars", "percent of portfolio" or "percent of
|
|
199
|
+
* buying power"; capped by Reg-T initial margin. Refused while the book is long
|
|
200
|
+
* the stock. Needs a brokerage that can short stock (backtests and paper can).
|
|
201
|
+
*/
|
|
202
|
+
export const short = (target, amount, type = "number of assets", options = {}) => ({ type: "Short", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
203
|
+
/**
|
|
204
|
+
* Buy back an open stock short. "percent of current positions" is a percent of
|
|
205
|
+
* the open short; every size is capped at the short, so Cover never goes long.
|
|
206
|
+
*/
|
|
207
|
+
export const cover = (target, amount = 100, type = "percent of current positions", options = {}) => ({ type: "Cover", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
209
208
|
/** Sell only actual holdings that pass a candidate-bound condition. */
|
|
210
209
|
export const sellHoldings = (condition, amount = 100, type = "percent of current positions", options = {}) => ({ type: "Sell", targetAsset: stockAsset("__PLACEHOLDER__"),
|
|
211
210
|
holdingCondition: condition, amount: { type, amount }, ...options });
|
|
@@ -530,17 +529,14 @@ export function ConsecutiveIncrease(indicator, period, lookback) {
|
|
|
530
529
|
return d;
|
|
531
530
|
}
|
|
532
531
|
/**
|
|
533
|
-
*
|
|
532
|
+
* Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
|
|
534
533
|
* @param condition Condition evaluated over the window.
|
|
535
534
|
* @param length Length of time
|
|
536
535
|
* @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
536
|
*/
|
|
539
|
-
export function ConsecutiveTrue(condition, length = 1, interval = "Day"
|
|
537
|
+
export function ConsecutiveTrue(condition, length = 1, interval = "Day") {
|
|
540
538
|
const d = { type: "ConsecutiveTrue" };
|
|
541
539
|
d.condition = condition;
|
|
542
|
-
if (checkCadenceMinutes !== undefined)
|
|
543
|
-
d["checkCadenceMinutes"] = checkCadenceMinutes;
|
|
544
540
|
d.window = { length: length, interval: interval };
|
|
545
541
|
return d;
|
|
546
542
|
}
|
|
@@ -557,14 +553,17 @@ export function Correlation(operands, length = 60, interval = "Day") {
|
|
|
557
553
|
return d;
|
|
558
554
|
}
|
|
559
555
|
/**
|
|
560
|
-
*
|
|
561
|
-
* @param condition
|
|
562
|
-
* @param length
|
|
563
|
-
* @param interval
|
|
556
|
+
* 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.
|
|
557
|
+
* @param condition Ordinary condition whose matching intervals are counted.
|
|
558
|
+
* @param length Lookback length.
|
|
559
|
+
* @param interval Lookback time unit; TradingDay uses observed exchange sessions.
|
|
560
|
+
* @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
|
|
564
561
|
*/
|
|
565
|
-
export function CountTrue(condition, length = 1, interval = "Day") {
|
|
562
|
+
export function CountTrue(condition, length = 1, interval = "Day", countInterval) {
|
|
566
563
|
const d = { type: "CountTrue" };
|
|
567
564
|
d.condition = condition;
|
|
565
|
+
if (countInterval !== undefined)
|
|
566
|
+
d["countInterval"] = countInterval;
|
|
568
567
|
d.window = { length: length, interval: interval };
|
|
569
568
|
return d;
|
|
570
569
|
}
|
|
@@ -605,6 +604,21 @@ export function CurrentTimeSeconds() {
|
|
|
605
604
|
const d = { type: "CurrentTimeSeconds" };
|
|
606
605
|
return d;
|
|
607
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
|
|
609
|
+
*/
|
|
610
|
+
export function CurrentTimestamp() {
|
|
611
|
+
const d = { type: "CurrentTimestamp" };
|
|
612
|
+
return d;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* 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.
|
|
616
|
+
*/
|
|
617
|
+
export function CurrentValue(operand) {
|
|
618
|
+
const d = { type: "CurrentValue" };
|
|
619
|
+
d.indicators = [operand];
|
|
620
|
+
return d;
|
|
621
|
+
}
|
|
608
622
|
/**
|
|
609
623
|
* CustomIndicator indicator.
|
|
610
624
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
|
|
@@ -864,7 +878,7 @@ export function Index(metric = "VIX") {
|
|
|
864
878
|
return d;
|
|
865
879
|
}
|
|
866
880
|
/**
|
|
867
|
-
*
|
|
881
|
+
* 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
882
|
* @param condition Condition evaluated over the window.
|
|
869
883
|
*/
|
|
870
884
|
export function IndicatorAtCondition(operand, condition, selection = "First", clock = "Calendar", initialValue, length, interval) {
|
|
@@ -915,6 +929,17 @@ export function IndicatorExponentialMovingAverage(operand, length = 30, interval
|
|
|
915
929
|
d.window = { length: length, interval: interval };
|
|
916
930
|
return d;
|
|
917
931
|
}
|
|
932
|
+
/**
|
|
933
|
+
* 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.
|
|
934
|
+
* @param length Length of time
|
|
935
|
+
* @param interval Unit of time
|
|
936
|
+
*/
|
|
937
|
+
export function IndicatorMaximum(operand, length = 30, interval = "Day") {
|
|
938
|
+
const d = { type: "IndicatorMaximum" };
|
|
939
|
+
d.indicators = [operand];
|
|
940
|
+
d.window = { length: length, interval: interval };
|
|
941
|
+
return d;
|
|
942
|
+
}
|
|
918
943
|
/**
|
|
919
944
|
* IndicatorMeanAbsoluteDeviation indicator.
|
|
920
945
|
* @param length Length of time
|
|
@@ -926,6 +951,17 @@ export function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval =
|
|
|
926
951
|
d.window = { length: length, interval: interval };
|
|
927
952
|
return d;
|
|
928
953
|
}
|
|
954
|
+
/**
|
|
955
|
+
* 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.
|
|
956
|
+
* @param length Length of time
|
|
957
|
+
* @param interval Unit of time
|
|
958
|
+
*/
|
|
959
|
+
export function IndicatorMinimum(operand, length = 30, interval = "Day") {
|
|
960
|
+
const d = { type: "IndicatorMinimum" };
|
|
961
|
+
d.indicators = [operand];
|
|
962
|
+
d.window = { length: length, interval: interval };
|
|
963
|
+
return d;
|
|
964
|
+
}
|
|
929
965
|
/**
|
|
930
966
|
* IndicatorRateOfChange indicator.
|
|
931
967
|
* @param length Length of time
|
|
@@ -960,14 +996,12 @@ export function IndicatorStandardDeviation(operand, length = 30, interval = "Day
|
|
|
960
996
|
return d;
|
|
961
997
|
}
|
|
962
998
|
/**
|
|
963
|
-
*
|
|
999
|
+
* 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
1000
|
* @param length Length of time
|
|
965
1001
|
* @param interval Unit of time
|
|
966
1002
|
*/
|
|
967
|
-
export function IndicatorWindowAgo(operand, length, interval,
|
|
1003
|
+
export function IndicatorWindowAgo(operand, length, interval, initialValue) {
|
|
968
1004
|
const d = { type: "IndicatorWindowAgo" };
|
|
969
|
-
if (sampling !== undefined)
|
|
970
|
-
d["sampling"] = sampling;
|
|
971
1005
|
if (initialValue !== undefined)
|
|
972
1006
|
d["initialValue"] = initialValue;
|
|
973
1007
|
d.indicators = [operand];
|
|
@@ -1732,7 +1766,7 @@ export function PortfolioValue() {
|
|
|
1732
1766
|
return d;
|
|
1733
1767
|
}
|
|
1734
1768
|
/**
|
|
1735
|
-
*
|
|
1769
|
+
* Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
|
|
1736
1770
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1737
1771
|
*/
|
|
1738
1772
|
export function PositionEntryPrice(asset) {
|
|
@@ -1759,7 +1793,7 @@ export function PositionMaxDrawup(asset) {
|
|
|
1759
1793
|
return d;
|
|
1760
1794
|
}
|
|
1761
1795
|
/**
|
|
1762
|
-
*
|
|
1796
|
+
* 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
1797
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1764
1798
|
*/
|
|
1765
1799
|
export function PositionMinutesSinceHigh(asset) {
|
|
@@ -1768,7 +1802,7 @@ export function PositionMinutesSinceHigh(asset) {
|
|
|
1768
1802
|
return d;
|
|
1769
1803
|
}
|
|
1770
1804
|
/**
|
|
1771
|
-
*
|
|
1805
|
+
* Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
|
|
1772
1806
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1773
1807
|
*/
|
|
1774
1808
|
export function PositionPeakPrice(asset) {
|