@tradejs/core 2.0.18 → 2.0.19
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/dist/backtest.js +2 -3
- package/dist/backtest.mjs +1 -1
- package/dist/{chunk-NN7Z3GIK.mjs → chunk-Q3OFPRVV.mjs} +115 -125
- package/dist/{chunk-BOETNABM.mjs → chunk-S4KHOAXM.mjs} +1 -2
- package/dist/chunk-U3GDILUZ.mjs +13 -0
- package/dist/grid.d.mts +3 -2
- package/dist/grid.d.ts +3 -2
- package/dist/grid.js +13 -11
- package/dist/grid.mjs +6 -6
- package/dist/{indicators-C4AaiFrs.d.ts → indicatorControllerContracts-DdSuUzb2.d.mts} +26 -92
- package/dist/{indicators-C4AaiFrs.d.mts → indicatorControllerContracts-DdSuUzb2.d.ts} +26 -92
- package/dist/indicators.d.mts +70 -3
- package/dist/indicators.d.ts +70 -3
- package/dist/indicators.js +114 -125
- package/dist/indicators.mjs +2 -2
- package/dist/strategies.d.mts +6 -3
- package/dist/strategies.d.ts +6 -3
- package/dist/strategies.js +133 -138
- package/dist/strategies.mjs +9 -6
- package/dist/time.js +2 -3
- package/dist/time.mjs +1 -1
- package/dist/uuid-DMoErO_1.d.mts +3 -0
- package/dist/uuid-DMoErO_1.d.ts +3 -0
- package/package.json +2 -2
- package/dist/chunk-AJK4NS7Y.mjs +0 -10
package/dist/indicators.js
CHANGED
|
@@ -6975,7 +6975,7 @@ var calculateRecentRangeExpansionSeries = (candles, lookback) => calculateRecent
|
|
|
6975
6975
|
(index) => calculateRangeExpansionAt(candles, index)
|
|
6976
6976
|
);
|
|
6977
6977
|
|
|
6978
|
-
// src/utils/
|
|
6978
|
+
// src/utils/indicatorBaseContextRelative.ts
|
|
6979
6979
|
var SESSION_WINDOWS = [
|
|
6980
6980
|
{ name: "asia", startMinuteUtc: 0, endMinuteUtc: 8 * 60 },
|
|
6981
6981
|
{ name: "europe", startMinuteUtc: 7 * 60, endMinuteUtc: 16 * 60 },
|
|
@@ -6984,28 +6984,24 @@ var SESSION_WINDOWS = [
|
|
|
6984
6984
|
var FUNDING_WINDOW_STEP_MINUTES = 8 * 60;
|
|
6985
6985
|
var FUNDING_WINDOW_NEARBY_MINUTES = 60;
|
|
6986
6986
|
var SESSION_WINDOW_EDGE_MINUTES = 60;
|
|
6987
|
-
var BASE_INTERVAL_MS = 15 * 6e4;
|
|
6988
6987
|
var PSYCHOLOGICAL_LEVEL_WINDOWS = {
|
|
6989
|
-
m15:
|
|
6988
|
+
m15: 15 * 6e4,
|
|
6990
6989
|
h1: 60 * 6e4,
|
|
6991
6990
|
h4: 4 * 60 * 6e4
|
|
6992
6991
|
};
|
|
6993
|
-
var isInsideSession = (minuteUtc, startMinuteUtc, endMinuteUtc) => startMinuteUtc <= endMinuteUtc ? minuteUtc >= startMinuteUtc && minuteUtc < endMinuteUtc : minuteUtc >= startMinuteUtc || minuteUtc < endMinuteUtc;
|
|
6994
6992
|
var buildSessionContext = (timestamp) => {
|
|
6995
6993
|
const date = new Date(timestamp);
|
|
6996
|
-
const
|
|
6997
|
-
const utcMinute = date.getUTCMinutes();
|
|
6998
|
-
const minuteUtc = utcHour * 60 + utcMinute;
|
|
6994
|
+
const minuteUtc = date.getUTCHours() * 60 + date.getUTCMinutes();
|
|
6999
6995
|
const dayOfWeekUtc = date.getUTCDay() || 7;
|
|
7000
6996
|
const activeSessions = SESSION_WINDOWS.filter(
|
|
7001
|
-
(
|
|
7002
|
-
).map((
|
|
6997
|
+
({ startMinuteUtc, endMinuteUtc }) => startMinuteUtc <= endMinuteUtc ? minuteUtc >= startMinuteUtc && minuteUtc < endMinuteUtc : minuteUtc >= startMinuteUtc || minuteUtc < endMinuteUtc
|
|
6998
|
+
).map(({ name }) => name);
|
|
7003
6999
|
const sessionPhase = activeSessions.includes("us") ? "us" : activeSessions.includes("europe") ? "europe" : activeSessions.includes("asia") ? "asia" : "off_hours";
|
|
7004
7000
|
const primaryWindow = SESSION_WINDOWS.find(
|
|
7005
|
-
(
|
|
7001
|
+
({ name }) => name === sessionPhase
|
|
7006
7002
|
);
|
|
7007
|
-
const minutesFromSessionOpen = primaryWindow
|
|
7008
|
-
const minutesToSessionClose = primaryWindow
|
|
7003
|
+
const minutesFromSessionOpen = primaryWindow ? minuteUtc - primaryWindow.startMinuteUtc : null;
|
|
7004
|
+
const minutesToSessionClose = primaryWindow ? primaryWindow.endMinuteUtc - minuteUtc : null;
|
|
7009
7005
|
const sessionWindowPhase = primaryWindow == null || minutesFromSessionOpen == null ? "off_hours" : minutesFromSessionOpen < SESSION_WINDOW_EDGE_MINUTES ? "opening" : minutesToSessionClose != null && minutesToSessionClose <= SESSION_WINDOW_EDGE_MINUTES ? "closing" : "active";
|
|
7010
7006
|
const minutesToFundingWindow = (FUNDING_WINDOW_STEP_MINUTES - minuteUtc % FUNDING_WINDOW_STEP_MINUTES) % FUNDING_WINDOW_STEP_MINUTES;
|
|
7011
7007
|
return {
|
|
@@ -7021,7 +7017,7 @@ var buildSessionContext = (timestamp) => {
|
|
|
7021
7017
|
isWeekendUtc: dayOfWeekUtc >= 6
|
|
7022
7018
|
};
|
|
7023
7019
|
};
|
|
7024
|
-
var
|
|
7020
|
+
var unavailablePsychologicalLevelWindow = () => ({
|
|
7025
7021
|
crossed: null,
|
|
7026
7022
|
direction: "unknown",
|
|
7027
7023
|
level: null,
|
|
@@ -7030,7 +7026,7 @@ var buildUnavailablePsychologicalLevelWindow = () => ({
|
|
|
7030
7026
|
});
|
|
7031
7027
|
var buildPsychologicalLevelWindow = (startPrice, endPrice, stepUsd) => {
|
|
7032
7028
|
if (!Number.isFinite(startPrice) || !Number.isFinite(endPrice) || !Number.isFinite(stepUsd) || startPrice <= 0 || endPrice <= 0 || stepUsd <= 0) {
|
|
7033
|
-
return
|
|
7029
|
+
return unavailablePsychologicalLevelWindow();
|
|
7034
7030
|
}
|
|
7035
7031
|
if (endPrice === startPrice) {
|
|
7036
7032
|
return {
|
|
@@ -7054,21 +7050,17 @@ var buildPsychologicalLevelWindow = (startPrice, endPrice, stepUsd) => {
|
|
|
7054
7050
|
distanceBeyondLevelBps: null
|
|
7055
7051
|
};
|
|
7056
7052
|
}
|
|
7057
|
-
const levelsCrossed = Math.round(Math.abs(lastCrossedLevel - firstCrossedLevel) / stepUsd) + 1;
|
|
7058
|
-
const distanceBeyondLevelBps = Math.abs(endPrice - lastCrossedLevel) / lastCrossedLevel * 1e4;
|
|
7059
7053
|
return {
|
|
7060
7054
|
crossed: true,
|
|
7061
7055
|
direction: movingUp ? "up" : "down",
|
|
7062
7056
|
level: lastCrossedLevel,
|
|
7063
|
-
levelsCrossed,
|
|
7064
|
-
distanceBeyondLevelBps
|
|
7057
|
+
levelsCrossed: Math.round(Math.abs(lastCrossedLevel - firstCrossedLevel) / stepUsd) + 1,
|
|
7058
|
+
distanceBeyondLevelBps: Math.abs(endPrice - lastCrossedLevel) / lastCrossedLevel * 1e4
|
|
7065
7059
|
};
|
|
7066
7060
|
};
|
|
7067
7061
|
var buildPsychologicalLevelAssetContext = (candles, stepUsd) => {
|
|
7068
7062
|
const endCandle = candles[candles.length - 1];
|
|
7069
|
-
if (!endCandle)
|
|
7070
|
-
return null;
|
|
7071
|
-
}
|
|
7063
|
+
if (!endCandle) return null;
|
|
7072
7064
|
const candlesByTimestamp = new Map(
|
|
7073
7065
|
candles.map((item) => [item.timestamp, item])
|
|
7074
7066
|
);
|
|
@@ -7083,104 +7075,70 @@ var buildPsychologicalLevelAssetContext = (candles, stepUsd) => {
|
|
|
7083
7075
|
startCandle.close,
|
|
7084
7076
|
endCandle.close,
|
|
7085
7077
|
stepUsd
|
|
7086
|
-
) :
|
|
7078
|
+
) : unavailablePsychologicalLevelWindow()
|
|
7087
7079
|
];
|
|
7088
7080
|
})
|
|
7089
7081
|
);
|
|
7090
|
-
return {
|
|
7091
|
-
source: "aligned_15m_ohlcv",
|
|
7092
|
-
stepUsd,
|
|
7093
|
-
windows
|
|
7094
|
-
};
|
|
7082
|
+
return { source: "aligned_15m_ohlcv", stepUsd, windows };
|
|
7095
7083
|
};
|
|
7096
|
-
var
|
|
7097
|
-
var BASE_CONTEXT_CANDLE_WINDOW = 256;
|
|
7098
|
-
var PIVOT_LEFT_RIGHT = 2;
|
|
7099
|
-
var ZONE_ATR_FACTOR = 0.5;
|
|
7100
|
-
var PROFILE_BIN_COUNT = 24;
|
|
7101
|
-
var SR_ZONE_PIVOT_PERIOD = 9;
|
|
7102
|
-
var SR_ZONE_MIN_STRENGTH = 2;
|
|
7103
|
-
var SR_ZONE_MAX_PIVOTS = 15;
|
|
7104
|
-
var SR_ZONE_CHANNEL_WIDTH_PCT = 8;
|
|
7105
|
-
var SR_ZONE_MAX_LEVELS = 6;
|
|
7106
|
-
var VOLUME_STRUCTURE_CALC_BARS = 180;
|
|
7107
|
-
var VOLUME_STRUCTURE_ROW_COUNT = 20;
|
|
7108
|
-
var LIQUIDITY_ZONE_LOOKBACK = 15;
|
|
7109
|
-
var LIQUIDITY_ZONE_MAX_AGE = 120;
|
|
7110
|
-
var LIQUIDITY_TAIL_ATR_LENGTH = 14;
|
|
7111
|
-
var LIQUIDITY_TAIL_ATR_MULT = 0.8;
|
|
7112
|
-
var LIQUIDITY_TAIL_MIN_WICK_RATIO = 1.3;
|
|
7113
|
-
var LIQUIDITY_TAIL_WICK_DOMINANCE = 1.2;
|
|
7114
|
-
var LIQUIDITY_TAIL_MIN_GAP = 5;
|
|
7115
|
-
var LIQUIDITY_TAIL_MAX_AGE = 120;
|
|
7116
|
-
var TREND_FOLLOW_PIVOT_LENGTH = 10;
|
|
7117
|
-
var TREND_FOLLOW_ATR_LENGTH = 14;
|
|
7118
|
-
var TREND_FOLLOW_ATR_MULT = 4;
|
|
7119
|
-
var ADAPTIVE_CHANNEL_REGRESSION_BARS = 7;
|
|
7120
|
-
var ADAPTIVE_CHANNEL_ENVELOPE_BARS = 2;
|
|
7121
|
-
var ADAPTIVE_CHANNEL_ATR_STRETCH = 2;
|
|
7122
|
-
var ADAPTIVE_CHANNEL_VOLATILITY_LOOKBACK = 100;
|
|
7123
|
-
var ADAPTIVE_CHANNEL_CALC_LOOKBACK = 220;
|
|
7124
|
-
var STRUCTURE_ZONES_ZONE_WIDTH_ATR = 0.5;
|
|
7125
|
-
var STRUCTURE_ZONES_ACCEPT_BARS = 2;
|
|
7126
|
-
var calculateReturnPctFromCandles = (candles) => {
|
|
7084
|
+
var returnPct = (candles) => {
|
|
7127
7085
|
if (candles.length < 2) return null;
|
|
7128
|
-
const previous = candles[candles.length - 2];
|
|
7129
|
-
const current = candles[candles.length - 1];
|
|
7130
|
-
return percentChange(current.close, previous.close);
|
|
7131
|
-
};
|
|
7132
|
-
var calculateRatioReturnPct = (coinCandles, btcCandles) => {
|
|
7133
|
-
if (coinCandles.length < 2 || btcCandles.length < 2) return null;
|
|
7134
|
-
const currentCoin = coinCandles[coinCandles.length - 1];
|
|
7135
|
-
const previousCoin = coinCandles[coinCandles.length - 2];
|
|
7136
|
-
const currentBtc = btcCandles[btcCandles.length - 1];
|
|
7137
|
-
const previousBtc = btcCandles[btcCandles.length - 2];
|
|
7138
|
-
if (currentBtc.close <= 0 || previousBtc.close <= 0) return null;
|
|
7139
7086
|
return percentChange(
|
|
7140
|
-
|
|
7141
|
-
|
|
7087
|
+
candles[candles.length - 1].close,
|
|
7088
|
+
candles[candles.length - 2].close
|
|
7142
7089
|
);
|
|
7143
7090
|
};
|
|
7144
|
-
var
|
|
7145
|
-
|
|
7146
|
-
const
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7091
|
+
var ratioReturnPct = (target, reference) => {
|
|
7092
|
+
if (target.length < 2 || reference.length < 2) return null;
|
|
7093
|
+
const targetCurrent = target[target.length - 1];
|
|
7094
|
+
const targetPrevious = target[target.length - 2];
|
|
7095
|
+
const referenceCurrent = reference[reference.length - 1];
|
|
7096
|
+
const referencePrevious = reference[reference.length - 2];
|
|
7097
|
+
if (referenceCurrent.close <= 0 || referencePrevious.close <= 0) return null;
|
|
7098
|
+
return percentChange(
|
|
7099
|
+
targetCurrent.close / referenceCurrent.close,
|
|
7100
|
+
targetPrevious.close / referencePrevious.close
|
|
7101
|
+
);
|
|
7102
|
+
};
|
|
7103
|
+
var alignRecentCandles = (target, reference) => {
|
|
7104
|
+
const alignedTarget = [];
|
|
7105
|
+
const alignedReference = [];
|
|
7106
|
+
let targetIndex = Math.max(0, target.length - 80);
|
|
7107
|
+
let referenceIndex = Math.max(0, reference.length - 80);
|
|
7108
|
+
while (targetIndex < target.length && referenceIndex < reference.length) {
|
|
7109
|
+
const targetTimestamp = target[targetIndex].timestamp;
|
|
7110
|
+
const referenceTimestamp = reference[referenceIndex].timestamp;
|
|
7111
|
+
if (targetTimestamp === referenceTimestamp) {
|
|
7112
|
+
alignedTarget.push(target[targetIndex]);
|
|
7113
|
+
alignedReference.push(reference[referenceIndex]);
|
|
7114
|
+
targetIndex += 1;
|
|
7115
|
+
referenceIndex += 1;
|
|
7116
|
+
} else if (targetTimestamp < referenceTimestamp) {
|
|
7117
|
+
targetIndex += 1;
|
|
7159
7118
|
} else {
|
|
7160
|
-
|
|
7119
|
+
referenceIndex += 1;
|
|
7161
7120
|
}
|
|
7162
7121
|
}
|
|
7163
|
-
return {
|
|
7122
|
+
return { alignedTarget, alignedReference };
|
|
7164
7123
|
};
|
|
7165
|
-
var
|
|
7124
|
+
var returnSeries = (candles, limit) => {
|
|
7166
7125
|
const returns = [];
|
|
7167
|
-
|
|
7168
|
-
for (let index = startIndex; index < candles.length; index += 1) {
|
|
7126
|
+
for (let index = Math.max(1, candles.length - limit); index < candles.length; index += 1) {
|
|
7169
7127
|
const previous = candles[index - 1];
|
|
7170
7128
|
const current = candles[index];
|
|
7171
7129
|
if (previous.close <= 0) continue;
|
|
7172
|
-
const
|
|
7173
|
-
if (
|
|
7130
|
+
const value = percentChange(current.close, previous.close);
|
|
7131
|
+
if (value != null && Number.isFinite(value)) returns.push(value);
|
|
7174
7132
|
}
|
|
7175
7133
|
return returns;
|
|
7176
7134
|
};
|
|
7177
|
-
var
|
|
7135
|
+
var beta = (targetReturns, referenceReturns) => {
|
|
7178
7136
|
const length = Math.min(targetReturns.length, referenceReturns.length);
|
|
7179
7137
|
if (length < 2) return null;
|
|
7180
7138
|
const target = targetReturns.slice(-length);
|
|
7181
7139
|
const reference = referenceReturns.slice(-length);
|
|
7182
|
-
const referenceMean = reference.reduce((sum2, value) => sum2 + value, 0) /
|
|
7183
|
-
const targetMean = target.reduce((sum2, value) => sum2 + value, 0) /
|
|
7140
|
+
const referenceMean = reference.reduce((sum2, value) => sum2 + value, 0) / length;
|
|
7141
|
+
const targetMean = target.reduce((sum2, value) => sum2 + value, 0) / length;
|
|
7184
7142
|
let covariance = 0;
|
|
7185
7143
|
let referenceVariance = 0;
|
|
7186
7144
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -7197,16 +7155,6 @@ var classifyRatioTrend = (ratioReturn24h, ratioReturn4h) => {
|
|
|
7197
7155
|
if (value < -0.15) return "down";
|
|
7198
7156
|
return "flat";
|
|
7199
7157
|
};
|
|
7200
|
-
var hasDistinctReferenceCandles = (coinCandles, referenceCandles) => {
|
|
7201
|
-
const coinLast = coinCandles[coinCandles.length - 1];
|
|
7202
|
-
const referenceLast = referenceCandles[referenceCandles.length - 1];
|
|
7203
|
-
const coinPrev = coinCandles[coinCandles.length - 2];
|
|
7204
|
-
const referencePrev = referenceCandles[referenceCandles.length - 2];
|
|
7205
|
-
if (!coinLast || !referenceLast || !coinPrev || !referencePrev) {
|
|
7206
|
-
return false;
|
|
7207
|
-
}
|
|
7208
|
-
return coinLast.timestamp !== referenceLast.timestamp || coinLast.close !== referenceLast.close || coinPrev.timestamp !== referencePrev.timestamp || coinPrev.close !== referencePrev.close;
|
|
7209
|
-
};
|
|
7210
7158
|
var buildTargetVsBtcContext = ({
|
|
7211
7159
|
coin1h,
|
|
7212
7160
|
btc1h,
|
|
@@ -7217,19 +7165,21 @@ var buildTargetVsBtcContext = ({
|
|
|
7217
7165
|
coinCandles,
|
|
7218
7166
|
btcCandles
|
|
7219
7167
|
}) => {
|
|
7220
|
-
const ratioReturn1h =
|
|
7221
|
-
const ratioReturn4h =
|
|
7222
|
-
const ratioReturn24h =
|
|
7223
|
-
const coinReturn1h =
|
|
7224
|
-
const coinReturn4h =
|
|
7225
|
-
const coinReturn24h =
|
|
7226
|
-
const btcReturn1h =
|
|
7227
|
-
const btcReturn4h =
|
|
7228
|
-
const btcReturn24h =
|
|
7229
|
-
const {
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7168
|
+
const ratioReturn1h = ratioReturnPct(coin1h, btc1h);
|
|
7169
|
+
const ratioReturn4h = ratioReturnPct(coin4h, btc4h);
|
|
7170
|
+
const ratioReturn24h = ratioReturnPct(coin1d, btc1d);
|
|
7171
|
+
const coinReturn1h = returnPct(coin1h);
|
|
7172
|
+
const coinReturn4h = returnPct(coin4h);
|
|
7173
|
+
const coinReturn24h = returnPct(coin1d);
|
|
7174
|
+
const btcReturn1h = returnPct(btc1h);
|
|
7175
|
+
const btcReturn4h = returnPct(btc4h);
|
|
7176
|
+
const btcReturn24h = returnPct(btc1d);
|
|
7177
|
+
const { alignedTarget, alignedReference } = alignRecentCandles(
|
|
7178
|
+
coinCandles,
|
|
7179
|
+
btcCandles
|
|
7180
|
+
);
|
|
7181
|
+
const coinReturns20 = returnSeries(alignedTarget, 21).slice(-20);
|
|
7182
|
+
const btcReturns20 = returnSeries(alignedReference, 21).slice(-20);
|
|
7233
7183
|
return {
|
|
7234
7184
|
source: "aligned_ohlcv",
|
|
7235
7185
|
ratioReturn1h,
|
|
@@ -7238,11 +7188,21 @@ var buildTargetVsBtcContext = ({
|
|
|
7238
7188
|
alphaVsBtc1h: coinReturn1h == null || btcReturn1h == null ? null : coinReturn1h - btcReturn1h,
|
|
7239
7189
|
alphaVsBtc4h: coinReturn4h == null || btcReturn4h == null ? null : coinReturn4h - btcReturn4h,
|
|
7240
7190
|
alphaVsBtc24h: coinReturn24h == null || btcReturn24h == null ? null : coinReturn24h - btcReturn24h,
|
|
7241
|
-
betaToBtc20:
|
|
7242
|
-
correlationToBtc20,
|
|
7191
|
+
betaToBtc20: beta(coinReturns20, btcReturns20),
|
|
7192
|
+
correlationToBtc20: coinReturns20.length === btcReturns20.length && coinReturns20.length >= 2 ? calculatePearsonCorrelation(coinReturns20, btcReturns20) : null,
|
|
7243
7193
|
ratioTrend: classifyRatioTrend(ratioReturn24h, ratioReturn4h)
|
|
7244
7194
|
};
|
|
7245
7195
|
};
|
|
7196
|
+
var hasDistinctReferenceCandles = (target, reference) => {
|
|
7197
|
+
const targetLast = target[target.length - 1];
|
|
7198
|
+
const referenceLast = reference[reference.length - 1];
|
|
7199
|
+
const targetPrevious = target[target.length - 2];
|
|
7200
|
+
const referencePrevious = reference[reference.length - 2];
|
|
7201
|
+
if (!targetLast || !referenceLast || !targetPrevious || !referencePrevious) {
|
|
7202
|
+
return false;
|
|
7203
|
+
}
|
|
7204
|
+
return targetLast.timestamp !== referenceLast.timestamp || targetLast.close !== referenceLast.close || targetPrevious.timestamp !== referencePrevious.timestamp || targetPrevious.close !== referencePrevious.close;
|
|
7205
|
+
};
|
|
7246
7206
|
var buildTargetVsEthContext = ({
|
|
7247
7207
|
coin1h,
|
|
7248
7208
|
eth1h,
|
|
@@ -7253,9 +7213,7 @@ var buildTargetVsEthContext = ({
|
|
|
7253
7213
|
coinCandles,
|
|
7254
7214
|
ethCandles
|
|
7255
7215
|
}) => {
|
|
7256
|
-
if (!hasDistinctReferenceCandles(coinCandles, ethCandles))
|
|
7257
|
-
return null;
|
|
7258
|
-
}
|
|
7216
|
+
if (!hasDistinctReferenceCandles(coinCandles, ethCandles)) return null;
|
|
7259
7217
|
const context = buildTargetVsBtcContext({
|
|
7260
7218
|
coin1h,
|
|
7261
7219
|
btc1h: eth1h,
|
|
@@ -7279,6 +7237,38 @@ var buildTargetVsEthContext = ({
|
|
|
7279
7237
|
ratioTrend: context.ratioTrend
|
|
7280
7238
|
};
|
|
7281
7239
|
};
|
|
7240
|
+
|
|
7241
|
+
// src/utils/indicatorBaseContext.ts
|
|
7242
|
+
var STRUCTURE_LOOKBACK = 80;
|
|
7243
|
+
var BASE_CONTEXT_CANDLE_WINDOW = 256;
|
|
7244
|
+
var PIVOT_LEFT_RIGHT = 2;
|
|
7245
|
+
var ZONE_ATR_FACTOR = 0.5;
|
|
7246
|
+
var PROFILE_BIN_COUNT = 24;
|
|
7247
|
+
var SR_ZONE_PIVOT_PERIOD = 9;
|
|
7248
|
+
var SR_ZONE_MIN_STRENGTH = 2;
|
|
7249
|
+
var SR_ZONE_MAX_PIVOTS = 15;
|
|
7250
|
+
var SR_ZONE_CHANNEL_WIDTH_PCT = 8;
|
|
7251
|
+
var SR_ZONE_MAX_LEVELS = 6;
|
|
7252
|
+
var VOLUME_STRUCTURE_CALC_BARS = 180;
|
|
7253
|
+
var VOLUME_STRUCTURE_ROW_COUNT = 20;
|
|
7254
|
+
var LIQUIDITY_ZONE_LOOKBACK = 15;
|
|
7255
|
+
var LIQUIDITY_ZONE_MAX_AGE = 120;
|
|
7256
|
+
var LIQUIDITY_TAIL_ATR_LENGTH = 14;
|
|
7257
|
+
var LIQUIDITY_TAIL_ATR_MULT = 0.8;
|
|
7258
|
+
var LIQUIDITY_TAIL_MIN_WICK_RATIO = 1.3;
|
|
7259
|
+
var LIQUIDITY_TAIL_WICK_DOMINANCE = 1.2;
|
|
7260
|
+
var LIQUIDITY_TAIL_MIN_GAP = 5;
|
|
7261
|
+
var LIQUIDITY_TAIL_MAX_AGE = 120;
|
|
7262
|
+
var TREND_FOLLOW_PIVOT_LENGTH = 10;
|
|
7263
|
+
var TREND_FOLLOW_ATR_LENGTH = 14;
|
|
7264
|
+
var TREND_FOLLOW_ATR_MULT = 4;
|
|
7265
|
+
var ADAPTIVE_CHANNEL_REGRESSION_BARS = 7;
|
|
7266
|
+
var ADAPTIVE_CHANNEL_ENVELOPE_BARS = 2;
|
|
7267
|
+
var ADAPTIVE_CHANNEL_ATR_STRETCH = 2;
|
|
7268
|
+
var ADAPTIVE_CHANNEL_VOLATILITY_LOOKBACK = 100;
|
|
7269
|
+
var ADAPTIVE_CHANNEL_CALC_LOOKBACK = 220;
|
|
7270
|
+
var STRUCTURE_ZONES_ZONE_WIDTH_ATR = 0.5;
|
|
7271
|
+
var STRUCTURE_ZONES_ACCEPT_BARS = 2;
|
|
7282
7272
|
var BASE_CONTEXT_MA_LAYER_PERIODS = [
|
|
7283
7273
|
[5, 12],
|
|
7284
7274
|
[9, 13],
|
|
@@ -11464,7 +11454,6 @@ var getSupportResistanceLevels = (data) => {
|
|
|
11464
11454
|
|
|
11465
11455
|
// src/utils/timestamp.ts
|
|
11466
11456
|
var import_date_fns = require("date-fns");
|
|
11467
|
-
var import_date_fns2 = require("date-fns");
|
|
11468
11457
|
var RUNTIME_STORAGE_DAY_OFFSET_MS = 6 * 60 * 60 * 1e3;
|
|
11469
11458
|
var toMs = (ts) => ts < 1e12 ? ts * 1e3 : ts;
|
|
11470
11459
|
|
package/dist/indicators.mjs
CHANGED
|
@@ -39,10 +39,10 @@ import {
|
|
|
39
39
|
toArrayData,
|
|
40
40
|
toCoinalyzeTimestampMs,
|
|
41
41
|
toFiniteNumber
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-Q3OFPRVV.mjs";
|
|
43
43
|
import "./chunk-AYC2QVKI.mjs";
|
|
44
44
|
import "./chunk-M7QGVZ3J.mjs";
|
|
45
|
-
import "./chunk-
|
|
45
|
+
import "./chunk-S4KHOAXM.mjs";
|
|
46
46
|
import "./chunk-MKCQSB4H.mjs";
|
|
47
47
|
export {
|
|
48
48
|
COINALYZE_MIN_INTRADAY_RETENTION_POINTS,
|
package/dist/strategies.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, KlineChartItem, BacktestPriceMode, BaseStrategyContextSnapshot, StrategySignalPriceParams, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, IndicatorsHistorySnapshot, StrategySharedReplayStateGetter, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
|
|
2
|
-
import { I as IndicatorPeriods, a as IndicatorsControllerRuntimeState, b as IndicatorsControllerCheckpointState } from './
|
|
2
|
+
import { I as IndicatorPeriods, a as IndicatorsControllerRuntimeState, b as IndicatorsControllerCheckpointState } from './indicatorControllerContracts-DdSuUzb2.mjs';
|
|
3
|
+
import { I as IdGenerator } from './uuid-DMoErO_1.mjs';
|
|
3
4
|
|
|
4
5
|
type IndicatorPeriodsConfig = Partial<Record<'MA_FAST' | 'MA_MEDIUM' | 'MA_SLOW' | 'OBV_SMA' | 'ATR' | 'ATR_PCT_SHORT' | 'ATR_PCT_LONG' | 'BB' | 'BB_STD' | 'MACD_FAST' | 'MACD_SLOW' | 'MACD_SIGNAL' | 'LEVEL_LOOKBACK' | 'LEVEL_DELAY', number>>;
|
|
5
6
|
declare const buildDefaultIndicatorPeriods: (config: IndicatorPeriodsConfig) => Partial<IndicatorPeriods>;
|
|
@@ -87,8 +88,9 @@ interface BuildEntrySignalDecisionParams {
|
|
|
87
88
|
signalId?: BuildStrategySignalDraft['signalId'];
|
|
88
89
|
orderPlan: StrategyEntryOrderPlan;
|
|
89
90
|
runtime?: StrategyEntryRuntimeOptions;
|
|
91
|
+
generateId?: IdGenerator;
|
|
90
92
|
}
|
|
91
|
-
declare const buildEntrySignalDecision: <TFigures extends BuildStrategySignalDraft["figures"] = BuildStrategySignalDraft["figures"], TIndicators extends BuildStrategySignalDraft["indicators"] = BuildStrategySignalDraft["indicators"], TAdditional extends BuildStrategySignalDraft["additionalIndicators"] = BuildStrategySignalDraft["additionalIndicators"]>({ code, entryContext, figures, indicators, additionalIndicators, signalId, orderPlan, runtime, }: Omit<BuildEntrySignalDecisionParams, "figures" | "indicators" | "additionalIndicators"> & {
|
|
93
|
+
declare const buildEntrySignalDecision: <TFigures extends BuildStrategySignalDraft["figures"] = BuildStrategySignalDraft["figures"], TIndicators extends BuildStrategySignalDraft["indicators"] = BuildStrategySignalDraft["indicators"], TAdditional extends BuildStrategySignalDraft["additionalIndicators"] = BuildStrategySignalDraft["additionalIndicators"]>({ code, entryContext, figures, indicators, additionalIndicators, signalId, orderPlan, runtime, generateId, }: Omit<BuildEntrySignalDecisionParams, "figures" | "indicators" | "additionalIndicators"> & {
|
|
92
94
|
figures?: TFigures;
|
|
93
95
|
indicators?: TIndicators;
|
|
94
96
|
additionalIndicators?: TAdditional;
|
|
@@ -104,6 +106,7 @@ interface CreateStrategyAPIParams {
|
|
|
104
106
|
isConfigFromBacktest?: Signal['isConfigFromBacktest'];
|
|
105
107
|
sharedReplayKey?: string;
|
|
106
108
|
getSharedReplayState?: StrategySharedReplayStateGetter;
|
|
109
|
+
generateId?: IdGenerator;
|
|
107
110
|
loadDecisionBaseContext?: (params: {
|
|
108
111
|
baseContext: BaseStrategyContextSnapshot | undefined;
|
|
109
112
|
candle: KlineChartData[number];
|
|
@@ -111,7 +114,7 @@ interface CreateStrategyAPIParams {
|
|
|
111
114
|
interval: Signal['interval'];
|
|
112
115
|
}) => Promise<BaseStrategyContextSnapshot | undefined>;
|
|
113
116
|
}
|
|
114
|
-
declare const createStrategyAPI: <TIndicators = IndicatorsHistorySnapshot | Record<string, unknown>>({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, isConfigFromBacktest, sharedReplayKey, getSharedReplayState, loadDecisionBaseContext, }: CreateStrategyAPIParams) => StrategyAPI<TIndicators>;
|
|
117
|
+
declare const createStrategyAPI: <TIndicators = IndicatorsHistorySnapshot | Record<string, unknown>>({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, isConfigFromBacktest, sharedReplayKey, getSharedReplayState, generateId, loadDecisionBaseContext, }: CreateStrategyAPIParams) => StrategyAPI<TIndicators>;
|
|
115
118
|
|
|
116
119
|
declare const getSharedStrategyReplayState: <TState>(key: string | undefined, createState: () => TState) => TState;
|
|
117
120
|
declare const releaseStrategyReplayCache: (keyPrefix: string) => void;
|
package/dist/strategies.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, KlineChartItem, BacktestPriceMode, BaseStrategyContextSnapshot, StrategySignalPriceParams, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, IndicatorsHistorySnapshot, StrategySharedReplayStateGetter, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
|
|
2
|
-
import { I as IndicatorPeriods, a as IndicatorsControllerRuntimeState, b as IndicatorsControllerCheckpointState } from './
|
|
2
|
+
import { I as IndicatorPeriods, a as IndicatorsControllerRuntimeState, b as IndicatorsControllerCheckpointState } from './indicatorControllerContracts-DdSuUzb2.js';
|
|
3
|
+
import { I as IdGenerator } from './uuid-DMoErO_1.js';
|
|
3
4
|
|
|
4
5
|
type IndicatorPeriodsConfig = Partial<Record<'MA_FAST' | 'MA_MEDIUM' | 'MA_SLOW' | 'OBV_SMA' | 'ATR' | 'ATR_PCT_SHORT' | 'ATR_PCT_LONG' | 'BB' | 'BB_STD' | 'MACD_FAST' | 'MACD_SLOW' | 'MACD_SIGNAL' | 'LEVEL_LOOKBACK' | 'LEVEL_DELAY', number>>;
|
|
5
6
|
declare const buildDefaultIndicatorPeriods: (config: IndicatorPeriodsConfig) => Partial<IndicatorPeriods>;
|
|
@@ -87,8 +88,9 @@ interface BuildEntrySignalDecisionParams {
|
|
|
87
88
|
signalId?: BuildStrategySignalDraft['signalId'];
|
|
88
89
|
orderPlan: StrategyEntryOrderPlan;
|
|
89
90
|
runtime?: StrategyEntryRuntimeOptions;
|
|
91
|
+
generateId?: IdGenerator;
|
|
90
92
|
}
|
|
91
|
-
declare const buildEntrySignalDecision: <TFigures extends BuildStrategySignalDraft["figures"] = BuildStrategySignalDraft["figures"], TIndicators extends BuildStrategySignalDraft["indicators"] = BuildStrategySignalDraft["indicators"], TAdditional extends BuildStrategySignalDraft["additionalIndicators"] = BuildStrategySignalDraft["additionalIndicators"]>({ code, entryContext, figures, indicators, additionalIndicators, signalId, orderPlan, runtime, }: Omit<BuildEntrySignalDecisionParams, "figures" | "indicators" | "additionalIndicators"> & {
|
|
93
|
+
declare const buildEntrySignalDecision: <TFigures extends BuildStrategySignalDraft["figures"] = BuildStrategySignalDraft["figures"], TIndicators extends BuildStrategySignalDraft["indicators"] = BuildStrategySignalDraft["indicators"], TAdditional extends BuildStrategySignalDraft["additionalIndicators"] = BuildStrategySignalDraft["additionalIndicators"]>({ code, entryContext, figures, indicators, additionalIndicators, signalId, orderPlan, runtime, generateId, }: Omit<BuildEntrySignalDecisionParams, "figures" | "indicators" | "additionalIndicators"> & {
|
|
92
94
|
figures?: TFigures;
|
|
93
95
|
indicators?: TIndicators;
|
|
94
96
|
additionalIndicators?: TAdditional;
|
|
@@ -104,6 +106,7 @@ interface CreateStrategyAPIParams {
|
|
|
104
106
|
isConfigFromBacktest?: Signal['isConfigFromBacktest'];
|
|
105
107
|
sharedReplayKey?: string;
|
|
106
108
|
getSharedReplayState?: StrategySharedReplayStateGetter;
|
|
109
|
+
generateId?: IdGenerator;
|
|
107
110
|
loadDecisionBaseContext?: (params: {
|
|
108
111
|
baseContext: BaseStrategyContextSnapshot | undefined;
|
|
109
112
|
candle: KlineChartData[number];
|
|
@@ -111,7 +114,7 @@ interface CreateStrategyAPIParams {
|
|
|
111
114
|
interval: Signal['interval'];
|
|
112
115
|
}) => Promise<BaseStrategyContextSnapshot | undefined>;
|
|
113
116
|
}
|
|
114
|
-
declare const createStrategyAPI: <TIndicators = IndicatorsHistorySnapshot | Record<string, unknown>>({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, isConfigFromBacktest, sharedReplayKey, getSharedReplayState, loadDecisionBaseContext, }: CreateStrategyAPIParams) => StrategyAPI<TIndicators>;
|
|
117
|
+
declare const createStrategyAPI: <TIndicators = IndicatorsHistorySnapshot | Record<string, unknown>>({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, isConfigFromBacktest, sharedReplayKey, getSharedReplayState, generateId, loadDecisionBaseContext, }: CreateStrategyAPIParams) => StrategyAPI<TIndicators>;
|
|
115
118
|
|
|
116
119
|
declare const getSharedStrategyReplayState: <TState>(key: string | undefined, createState: () => TState) => TState;
|
|
117
120
|
declare const releaseStrategyReplayCache: (keyPrefix: string) => void;
|