@tradejs/core 2.0.14 → 2.0.16
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/{chunk-HVCNGDPT.mjs → chunk-NN7Z3GIK.mjs} +437 -391
- package/dist/{indicators-Da_i06-8.d.mts → indicators-C4AaiFrs.d.mts} +1 -0
- package/dist/{indicators-Da_i06-8.d.ts → indicators-C4AaiFrs.d.ts} +1 -0
- package/dist/indicators.d.mts +1 -1
- package/dist/indicators.d.ts +1 -1
- package/dist/indicators.js +437 -391
- package/dist/indicators.mjs +1 -1
- package/dist/strategies.d.mts +1 -1
- package/dist/strategies.d.ts +1 -1
- package/dist/strategies.js +481 -504
- package/dist/strategies.mjs +47 -126
- package/package.json +2 -2
package/dist/strategies.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createIndicators,
|
|
3
3
|
getRequiredControllerSeedWindow
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NN7Z3GIK.mjs";
|
|
5
5
|
import "./chunk-AYC2QVKI.mjs";
|
|
6
6
|
import "./chunk-M7QGVZ3J.mjs";
|
|
7
7
|
import {
|
|
@@ -298,7 +298,8 @@ var createStrategyIndicatorsState = ({
|
|
|
298
298
|
ensureInitializedWithCurrentBar: ensureControllerInitialized,
|
|
299
299
|
snapshot: (options) => ensureControllerInitialized().snapshot(options),
|
|
300
300
|
latestSnapshot: () => ensureControllerInitialized().latestSnapshot(),
|
|
301
|
-
latestNumber: (key) => ensureControllerInitialized().latestNumber(key)
|
|
301
|
+
latestNumber: (key) => ensureControllerInitialized().latestNumber(key),
|
|
302
|
+
latestNumbers: (key, count) => ensureControllerInitialized().latestNumbers(key, count)
|
|
302
303
|
};
|
|
303
304
|
};
|
|
304
305
|
|
|
@@ -610,19 +611,6 @@ var toRankBucket = (value) => {
|
|
|
610
611
|
if (value <= 20) return "low";
|
|
611
612
|
return "normal";
|
|
612
613
|
};
|
|
613
|
-
var toRangePositionBucket = (value) => {
|
|
614
|
-
if (value == null) return "unknown";
|
|
615
|
-
if (value <= 0.2) return "low";
|
|
616
|
-
if (value >= 0.8) return "high";
|
|
617
|
-
return "middle";
|
|
618
|
-
};
|
|
619
|
-
var toVolumeBucket = (value) => {
|
|
620
|
-
if (value == null) return "unknown";
|
|
621
|
-
if (value < 0.8) return "thin";
|
|
622
|
-
if (value < 1.5) return "normal";
|
|
623
|
-
if (value < 3) return "elevated";
|
|
624
|
-
return "spike";
|
|
625
|
-
};
|
|
626
614
|
var toVenueSpreadSeverity = (value) => {
|
|
627
615
|
if (value == null) return "unknown";
|
|
628
616
|
const abs = Math.abs(value);
|
|
@@ -735,7 +723,6 @@ var buildBaseContextGateFeatures = ({
|
|
|
735
723
|
const atrPctZScore = asFiniteNumberOrNull(volatility?.atrPctZScore);
|
|
736
724
|
const breakoutState = localRange?.breakoutState ?? "unknown";
|
|
737
725
|
const rangePosition20 = asFiniteNumberOrNull(localRange?.rangePosition20);
|
|
738
|
-
const rangePositionBucket = toRangePositionBucket(rangePosition20);
|
|
739
726
|
const breakoutWithDirection = toDirectionalAlignment({
|
|
740
727
|
direction,
|
|
741
728
|
bullValue: "above_high_level",
|
|
@@ -854,22 +841,12 @@ var buildBaseContextGateFeatures = ({
|
|
|
854
841
|
targetVsBtc?.ratioReturn24h
|
|
855
842
|
);
|
|
856
843
|
const targetVsBtcAlpha24h = asFiniteNumberOrNull(targetVsBtc?.alphaVsBtc24h);
|
|
857
|
-
const targetVsBtcBeta20 = asFiniteNumberOrNull(targetVsBtc?.betaToBtc20);
|
|
858
|
-
const targetVsBtcCorrelation20 = asFiniteNumberOrNull(
|
|
859
|
-
targetVsBtc?.correlationToBtc20
|
|
860
|
-
);
|
|
861
|
-
const targetVsBtcRatioTrend = targetVsBtc?.ratioTrend ?? "unknown";
|
|
862
844
|
const targetVsBtcDirectionValue = targetVsBtcRatioReturn24h ?? targetVsBtcAlpha24h;
|
|
863
845
|
const targetVsBtcAligned = direction == null || targetVsBtcDirectionValue == null ? null : direction === "LONG" ? targetVsBtcDirectionValue >= 0 : targetVsBtcDirectionValue <= 0;
|
|
864
846
|
const targetVsEthRatioReturn24h = asFiniteNumberOrNull(
|
|
865
847
|
targetVsEth?.ratioReturn24h
|
|
866
848
|
);
|
|
867
849
|
const targetVsEthAlpha24h = asFiniteNumberOrNull(targetVsEth?.alphaVsEth24h);
|
|
868
|
-
const targetVsEthBeta20 = asFiniteNumberOrNull(targetVsEth?.betaToEth20);
|
|
869
|
-
const targetVsEthCorrelation20 = asFiniteNumberOrNull(
|
|
870
|
-
targetVsEth?.correlationToEth20
|
|
871
|
-
);
|
|
872
|
-
const targetVsEthRatioTrend = targetVsEth?.ratioTrend ?? "unknown";
|
|
873
850
|
const targetVsEthDirectionValue = targetVsEthRatioReturn24h ?? targetVsEthAlpha24h;
|
|
874
851
|
const targetVsEthAligned = direction == null || targetVsEthDirectionValue == null ? null : direction === "LONG" ? targetVsEthDirectionValue >= 0 : targetVsEthDirectionValue <= 0;
|
|
875
852
|
const btcAltRegimeValue = btcAltRegime?.regime ?? "unknown";
|
|
@@ -878,20 +855,15 @@ var buildBaseContextGateFeatures = ({
|
|
|
878
855
|
const btcVsAltReturn24h = asFiniteNumberOrNull(
|
|
879
856
|
btcAltRegime?.btcVsAltReturn24h
|
|
880
857
|
);
|
|
881
|
-
const btcTurnoverShare24h = asFiniteNumberOrNull(
|
|
882
|
-
btcAltRegime?.btcTurnoverShare24h
|
|
883
|
-
);
|
|
884
858
|
const venueSpreadZScore = asFiniteNumberOrNull(execution?.venueSpreadZScore);
|
|
885
859
|
const venueSpreadSeverity = toVenueSpreadSeverity(venueSpreadZScore);
|
|
886
860
|
const higherTimeframeConflict = mtfAlignmentForDirection === "unknown" ? null : mtfAlignmentForDirection === "against" || mtfAlignmentForDirection === "mixed";
|
|
887
861
|
const extremeVolatilityRisk = Math.abs(atrPctZScore ?? 0) >= 2 || atrPctRankBucket === "extreme";
|
|
888
|
-
const compressionBreakoutSupport = (volatility?.state === "compressed" || bbWidthRankBucket === "low") && breakoutState !== "inside_range" && breakoutState !== "unknown";
|
|
889
862
|
const benchmarkConflict = benchmarkAligned === false || relativeStrengthBucket.endsWith("_against");
|
|
890
863
|
const derivativesSummary = baseContext.derivatives?.summary;
|
|
891
864
|
const derivativesDirectionAligned = typeof derivativesSummary?.directionAligned === "boolean" ? derivativesSummary.directionAligned : null;
|
|
892
865
|
const derivativesRiskFlags = Array.isArray(derivativesSummary?.riskFlags) ? derivativesSummary.riskFlags : [];
|
|
893
866
|
const derivativesCrowdedForDirection = direction === "LONG" ? derivativesRiskFlags.includes("crowded_long") : direction === "SHORT" ? derivativesRiskFlags.includes("crowded_short") : false;
|
|
894
|
-
const derivativesCrowdedAny = derivativesRiskFlags.includes("crowded_long") || derivativesRiskFlags.includes("crowded_short");
|
|
895
867
|
const atr = asFiniteNumberOrNull(baseContext.raw?.volatility?.atr);
|
|
896
868
|
const currentPrice = asFiniteNumberOrNull(prices?.currentPrice);
|
|
897
869
|
const takeProfitPrice = asFiniteNumberOrNull(prices?.takeProfitPrice);
|
|
@@ -1051,142 +1023,57 @@ var buildBaseContextGateFeatures = ({
|
|
|
1051
1023
|
scores.execution,
|
|
1052
1024
|
scores.derivatives
|
|
1053
1025
|
]);
|
|
1054
|
-
const volatilityRisk = extremeVolatilityRisk ? "high" : atrPctRankBucket === "high" || bbWidthRankBucket === "high" ? "medium" : atrPctRankBucket === "unknown" && bbWidthRankBucket === "unknown" ? "unknown" : "low";
|
|
1055
1026
|
const liquidityRisk = venueSpreadSeverity === "wide" || cmcExchangeLiquidityAligned === false ? "high" : venueSpreadSeverity === "elevated" ? "medium" : venueSpreadSeverity === "unknown" && cmcExchangeLiquidityAligned == null ? "unknown" : "low";
|
|
1056
|
-
const regimeRisk = higherTimeframeConflict === true ? "high" : mtfAlignmentForDirection === "neutral" || mtfAlignmentForDirection === "unknown" ? "medium" : "low";
|
|
1057
|
-
const crowdingRisk = derivativesCrowdedForDirection ? "high" : derivativesCrowdedAny ? "medium" : derivativesSummary ? "low" : "unknown";
|
|
1058
|
-
const chaseRisk = direction === "LONG" && rangePositionBucket === "high" && breakoutWithDirection !== true || direction === "SHORT" && rangePositionBucket === "low" && breakoutWithDirection !== true ? "high" : tpDistanceAtr != null && tpDistanceAtr < 1 || rangePositionBucket === "high" || rangePositionBucket === "low" ? "medium" : rangePositionBucket === "unknown" ? "unknown" : "low";
|
|
1059
1027
|
const primaryIssue = derivativesCrowdedForDirection ? "crowded_derivatives" : higherTimeframeConflict === true ? "mtf_conflict" : venueSpreadSeverity === "wide" || cmcExchangeLiquidityAligned === false ? "bad_execution" : extremeVolatilityRisk ? "extreme_volatility" : benchmarkConflict || marketBreadthAligned === false || cmcAltLiquidityAligned === false || cmcEthBtcAligned === false || cmcFearGreedAligned === false || cmcIndexAligned === false || targetVsBtcAligned === false || targetVsEthAligned === false || btcAltRegimeAligned === false ? "market_context_against" : (scores.participation ?? 100) < 45 ? "weak_participation" : (scores.structure ?? 100) < 45 ? "weak_structure" : "none";
|
|
1060
|
-
const needsExtraConfirmation = conflicts.length > 0 || scores.totalContext != null && scores.totalContext < 60;
|
|
1061
1028
|
const approveBias = conflicts.length >= 3 || primaryIssue === "crowded_derivatives" || primaryIssue === "bad_execution" || primaryIssue === "mtf_conflict" ? "reject" : confirmations.length >= 3 && conflicts.length === 0 ? "support" : "neutral";
|
|
1062
|
-
const maxReasonableQuality = approveBias === "reject" ? 2 : conflicts.length >= 2 || needsExtraConfirmation ? 3 : approveBias === "support" ? 5 : 4;
|
|
1063
1029
|
return {
|
|
1064
|
-
direction,
|
|
1065
1030
|
setup: {
|
|
1066
|
-
riskRatio: asFiniteNumberOrNull(prices?.riskRatio),
|
|
1067
1031
|
rewardToVolatility: tpDistanceAtr,
|
|
1068
1032
|
stopDistanceAtr,
|
|
1069
1033
|
tpDistanceAtr,
|
|
1070
1034
|
entryLocation
|
|
1071
1035
|
},
|
|
1072
|
-
scores
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1036
|
+
scores: {
|
|
1037
|
+
structure: scores.structure,
|
|
1038
|
+
participation: scores.participation,
|
|
1039
|
+
execution: scores.execution,
|
|
1040
|
+
totalContext: scores.totalContext
|
|
1076
1041
|
},
|
|
1077
1042
|
conflicts: {
|
|
1078
|
-
count: conflicts.length
|
|
1079
|
-
items: conflicts
|
|
1043
|
+
count: conflicts.length
|
|
1080
1044
|
},
|
|
1081
1045
|
risk: {
|
|
1082
|
-
|
|
1083
|
-
liquidityRisk,
|
|
1084
|
-
volatilityRisk,
|
|
1085
|
-
crowdingRisk,
|
|
1086
|
-
chaseRisk
|
|
1046
|
+
liquidityRisk
|
|
1087
1047
|
},
|
|
1088
1048
|
decisionHints: {
|
|
1089
1049
|
approveBias,
|
|
1090
|
-
maxReasonableQuality,
|
|
1091
|
-
needsExtraConfirmation,
|
|
1092
1050
|
primaryIssue
|
|
1093
1051
|
},
|
|
1094
1052
|
mtf: {
|
|
1095
|
-
|
|
1096
|
-
higherTimeframeConflict,
|
|
1097
|
-
h1TrendBias: mtfSummary?.h1TrendBias ?? "unknown",
|
|
1098
|
-
h4TrendBias: mtfSummary?.h4TrendBias ?? "unknown",
|
|
1099
|
-
d1TrendBias: mtfSummary?.d1TrendBias ?? "unknown",
|
|
1100
|
-
h1RangePosition: asFiniteNumberOrNull(mtfSummary?.h1RangePosition),
|
|
1101
|
-
h4VolatilityState: mtfSummary?.h4VolatilityState ?? "unknown"
|
|
1053
|
+
higherTimeframeConflict
|
|
1102
1054
|
},
|
|
1103
1055
|
volatility: {
|
|
1104
1056
|
state: volatility?.state ?? "unknown",
|
|
1105
|
-
atrPctZScore,
|
|
1106
1057
|
atrPctRankBucket,
|
|
1107
|
-
bbWidthRankBucket
|
|
1108
|
-
extremeVolatilityRisk,
|
|
1109
|
-
compressionBreakoutSupport
|
|
1110
|
-
},
|
|
1111
|
-
structure: {
|
|
1112
|
-
breakoutState,
|
|
1113
|
-
rangePositionBucket,
|
|
1114
|
-
breakoutWithDirection,
|
|
1115
|
-
failedBreakoutForDirection,
|
|
1116
|
-
liquiditySweepForDirection,
|
|
1117
|
-
nearPointOfControl
|
|
1058
|
+
bbWidthRankBucket
|
|
1118
1059
|
},
|
|
1119
1060
|
participation: {
|
|
1120
|
-
volumeRel20,
|
|
1121
|
-
volumeBucket: toVolumeBucket(volumeRel20),
|
|
1122
|
-
deltaBias,
|
|
1123
|
-
deltaAligned,
|
|
1124
|
-
tradeFlowBuyPressurePct,
|
|
1125
|
-
tradeFlowAligned,
|
|
1126
|
-
hyperliquidWhaleBuySharePct,
|
|
1127
|
-
hyperliquidWhaleNetNotionalUsd,
|
|
1128
|
-
hyperliquidWhaleUniqueCount,
|
|
1129
|
-
hyperliquidWhaleCoveredCount,
|
|
1130
|
-
hyperliquidWhaleExpectedCount,
|
|
1131
|
-
hyperliquidWhaleCoveragePct,
|
|
1132
|
-
hyperliquidWhaleCoverageSufficient,
|
|
1133
|
-
hyperliquidWhaleNotionalUsd,
|
|
1134
|
-
hyperliquidWhaleSufficientActivity,
|
|
1135
|
-
hyperliquidWhaleFlowAligned,
|
|
1136
|
-
hyperliquidWhaleFlowStale,
|
|
1137
|
-
referenceTradeFlowBuyPressurePct,
|
|
1138
|
-
referenceTradeFlowAligned,
|
|
1139
1061
|
volumeStructureAligned
|
|
1140
1062
|
},
|
|
1141
1063
|
relative: {
|
|
1142
|
-
benchmarkTrendAlignment,
|
|
1143
|
-
benchmarkAligned,
|
|
1144
1064
|
benchmarkConflict,
|
|
1145
|
-
relativeStrength1h,
|
|
1146
|
-
relativeStrengthBucket,
|
|
1147
1065
|
marketBreadthReturn,
|
|
1148
|
-
marketBreadthAligned,
|
|
1149
1066
|
marketBreadthStale: typeof marketBreadth?.stale === "boolean" ? marketBreadth.stale : null,
|
|
1150
|
-
cmcAltLiquidityRegime,
|
|
1151
|
-
cmcAltLiquidityAligned,
|
|
1152
|
-
cmcAltLiquidityStale,
|
|
1153
|
-
cmcEthBtcReferenceRegime,
|
|
1154
|
-
cmcEthBtcAligned,
|
|
1155
|
-
cmcEthBtcStale,
|
|
1156
|
-
cmcExchangeLiquidityRegime,
|
|
1157
1067
|
cmcExchangeLiquidityAligned,
|
|
1158
1068
|
cmcExchangeLiquidityStale,
|
|
1159
1069
|
cmcExchangeLiquidityVolumeChange24hPct,
|
|
1160
1070
|
cmcFearGreedValue,
|
|
1161
1071
|
cmcFearGreedValueChange24h,
|
|
1162
|
-
cmcFearGreedRegime,
|
|
1163
|
-
cmcFearGreedAligned,
|
|
1164
1072
|
cmcFearGreedStale,
|
|
1165
|
-
cmcIndexRegime,
|
|
1166
|
-
cmcIndexAligned,
|
|
1167
|
-
cmcIndexStale,
|
|
1168
1073
|
cmc20ToCmc100RatioChange24hPct,
|
|
1169
|
-
targetVsBtcRatioReturn24h,
|
|
1170
|
-
targetVsBtcAlpha24h,
|
|
1171
|
-
targetVsBtcBeta20,
|
|
1172
|
-
targetVsBtcCorrelation20,
|
|
1173
|
-
targetVsBtcRatioTrend,
|
|
1174
|
-
targetVsBtcAligned,
|
|
1175
|
-
targetVsEthRatioReturn24h,
|
|
1176
|
-
targetVsEthAlpha24h,
|
|
1177
|
-
targetVsEthBeta20,
|
|
1178
|
-
targetVsEthCorrelation20,
|
|
1179
|
-
targetVsEthRatioTrend,
|
|
1180
|
-
targetVsEthAligned,
|
|
1181
1074
|
btcAltRegime: btcAltRegimeValue,
|
|
1182
|
-
btcAltRegimeAligned,
|
|
1183
1075
|
btcAltRegimeStale,
|
|
1184
|
-
btcVsAltReturn24h
|
|
1185
|
-
btcTurnoverShare24h
|
|
1186
|
-
},
|
|
1187
|
-
execution: {
|
|
1188
|
-
venueSpreadZScore,
|
|
1189
|
-
venueSpreadSeverity
|
|
1076
|
+
btcVsAltReturn24h
|
|
1190
1077
|
}
|
|
1191
1078
|
};
|
|
1192
1079
|
};
|
|
@@ -1194,6 +1081,40 @@ var cloneBaseContextData = (baseContext, direction, prices) => {
|
|
|
1194
1081
|
const clone = cloneSignalPayloadDataProperties(
|
|
1195
1082
|
baseContext
|
|
1196
1083
|
);
|
|
1084
|
+
clone.regime = cloneSignalPayloadDataProperties(
|
|
1085
|
+
baseContext.regime
|
|
1086
|
+
);
|
|
1087
|
+
clone.structure = cloneSignalPayloadDataProperties(
|
|
1088
|
+
baseContext.structure
|
|
1089
|
+
);
|
|
1090
|
+
const participation = baseContext.participation;
|
|
1091
|
+
if (participation) {
|
|
1092
|
+
const participationClone = cloneSignalPayloadDataProperties(
|
|
1093
|
+
participation
|
|
1094
|
+
);
|
|
1095
|
+
const priceVolumeProfile = participation.priceVolumeProfile;
|
|
1096
|
+
const volumeStructure = participation.volumeStructure;
|
|
1097
|
+
const delta = participation.delta;
|
|
1098
|
+
if (priceVolumeProfile != null) {
|
|
1099
|
+
participationClone.priceVolumeProfile = cloneSignalPayloadDataProperties(
|
|
1100
|
+
priceVolumeProfile
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
if (volumeStructure != null) {
|
|
1104
|
+
participationClone.volumeStructure = cloneSignalPayloadDataProperties(
|
|
1105
|
+
volumeStructure
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
if (delta != null) {
|
|
1109
|
+
participationClone.delta = cloneSignalPayloadDataProperties(
|
|
1110
|
+
delta
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
clone.participation = participationClone;
|
|
1114
|
+
}
|
|
1115
|
+
clone.relative = cloneSignalPayloadDataProperties(
|
|
1116
|
+
baseContext.relative
|
|
1117
|
+
);
|
|
1197
1118
|
const compactMtf = cloneCompactMtfContext(baseContext);
|
|
1198
1119
|
if (compactMtf) {
|
|
1199
1120
|
clone.mtf = compactMtf;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "MIT-licensed browser-safe API for TradeJS config, strategy authoring, figures, and shared helpers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@tradejs/types": "^2.0.
|
|
103
|
+
"@tradejs/types": "^2.0.16",
|
|
104
104
|
"date-fns": "^3.6.0",
|
|
105
105
|
"fast-technical-indicators": "^1.1.4",
|
|
106
106
|
"klinecharts": "10.0.0-alpha9",
|