hedgequantx 2.9.206 → 2.9.207
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/package.json +1 -1
- package/src/lib/smart-logs-engine.js +77 -53
package/package.json
CHANGED
|
@@ -38,6 +38,11 @@ class SmartLogsEngine {
|
|
|
38
38
|
this.counter = 0;
|
|
39
39
|
this.lastState = null;
|
|
40
40
|
this.lastLogTime = 0;
|
|
41
|
+
// QUANT-specific state tracking for event detection
|
|
42
|
+
this.lastZRegime = null; // 'extreme' | 'high' | 'building' | 'neutral'
|
|
43
|
+
this.lastBias = null; // 'bullish' | 'bearish' | 'neutral'
|
|
44
|
+
this.lastVpinToxic = false; // true if VPIN > 0.6
|
|
45
|
+
this.warmupLogged = false; // Track if we logged warmup milestones
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
setSymbol(s) { this.symbolCode = s; }
|
|
@@ -169,74 +174,88 @@ class SmartLogsEngine {
|
|
|
169
174
|
const events = this._detectEvents(state, this.lastState);
|
|
170
175
|
this.lastState = { ...state };
|
|
171
176
|
|
|
172
|
-
// For QUANT strategy:
|
|
173
|
-
//
|
|
177
|
+
// For QUANT strategy: EVENT-DRIVEN logs based on regime changes
|
|
178
|
+
// Only log when something SIGNIFICANT changes - no repetitive messages
|
|
174
179
|
if (this.strategyId === 'ultra-scalping') {
|
|
175
|
-
const
|
|
176
|
-
const
|
|
180
|
+
const ticks = state.tickCount || state.bars || 0;
|
|
181
|
+
const absZ = Math.abs(zScore);
|
|
182
|
+
const vpinToxic = vpin > 0.6;
|
|
177
183
|
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
ticks
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
let logType = 'analysis';
|
|
215
|
-
let message;
|
|
216
|
-
|
|
217
|
-
if (absZ >= 2.0) {
|
|
218
|
-
// Strong signal zone - use bull/bear messages
|
|
184
|
+
// Determine current regimes
|
|
185
|
+
const zRegime = absZ >= 2.0 ? 'extreme' : absZ >= 1.5 ? 'high' : absZ >= 1.0 ? 'building' : 'neutral';
|
|
186
|
+
const bias = ofi > 0.15 ? 'bullish' : ofi < -0.15 ? 'bearish' : 'neutral';
|
|
187
|
+
|
|
188
|
+
// Build data object for messages
|
|
189
|
+
const zScoreAbs = absZ.toFixed(1);
|
|
190
|
+
const vpinPct = (vpin * 100).toFixed(0);
|
|
191
|
+
const ofiPct = (ofi > 0 ? '+' : '') + (ofi * 100).toFixed(0) + '%';
|
|
192
|
+
const d = {
|
|
193
|
+
sym, price,
|
|
194
|
+
zScore: zScore.toFixed(1),
|
|
195
|
+
zScoreAbs,
|
|
196
|
+
rawZScore: zScore,
|
|
197
|
+
vpin: vpinPct,
|
|
198
|
+
ofi: ofiPct,
|
|
199
|
+
ticks
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
let event = null;
|
|
203
|
+
let logType = 'analysis';
|
|
204
|
+
let message = null;
|
|
205
|
+
|
|
206
|
+
// EVENT 1: Warmup milestone (only log once at 250 ticks)
|
|
207
|
+
if (ticks >= 250 && !this.warmupLogged) {
|
|
208
|
+
this.warmupLogged = true;
|
|
209
|
+
event = 'warmup_complete';
|
|
210
|
+
message = QUANT.init({ sym, ticks, bars: ticks, swings: 0, zones: 0 });
|
|
211
|
+
logType = 'system';
|
|
212
|
+
}
|
|
213
|
+
// EVENT 2: Z-Score regime change (neutral → building → high → extreme)
|
|
214
|
+
else if (this.lastZRegime !== null && zRegime !== this.lastZRegime) {
|
|
215
|
+
event = 'z_regime_change';
|
|
216
|
+
if (zRegime === 'extreme') {
|
|
219
217
|
logType = 'signal';
|
|
220
218
|
message = zScore < 0 ? QUANT.bull(d) : QUANT.bear(d);
|
|
221
|
-
} else if (
|
|
222
|
-
// Approaching threshold - use ready messages
|
|
219
|
+
} else if (zRegime === 'high') {
|
|
223
220
|
logType = 'signal';
|
|
224
221
|
message = QUANT.ready(d);
|
|
225
|
-
} else if (
|
|
226
|
-
// Building edge - use zones messages
|
|
222
|
+
} else if (zRegime === 'building') {
|
|
227
223
|
message = QUANT.zones(d);
|
|
228
224
|
} else {
|
|
229
|
-
// Normal market - use neutral messages
|
|
230
225
|
message = QUANT.neutral(d);
|
|
231
226
|
}
|
|
232
|
-
|
|
227
|
+
}
|
|
228
|
+
// EVENT 3: Bias flip (bullish ↔ bearish)
|
|
229
|
+
else if (this.lastBias !== null && bias !== this.lastBias && bias !== 'neutral' && this.lastBias !== 'neutral') {
|
|
230
|
+
event = 'bias_flip';
|
|
231
|
+
message = QUANT.biasFlip({ sym, from: this.lastBias, to: bias, delta: delta });
|
|
232
|
+
}
|
|
233
|
+
// EVENT 4: VPIN toxicity change
|
|
234
|
+
else if (this.lastVpinToxic !== null && vpinToxic !== this.lastVpinToxic) {
|
|
235
|
+
event = 'vpin_change';
|
|
236
|
+
if (vpinToxic) {
|
|
237
|
+
message = `[${sym}] ${price} | VPIN toxic (${vpinPct}%) - informed flow detected, caution`;
|
|
238
|
+
logType = 'risk';
|
|
239
|
+
} else {
|
|
240
|
+
message = `[${sym}] ${price} | VPIN normalized (${vpinPct}%) - flow clean`;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Update state tracking
|
|
245
|
+
this.lastZRegime = zRegime;
|
|
246
|
+
this.lastBias = bias;
|
|
247
|
+
this.lastVpinToxic = vpinToxic;
|
|
248
|
+
|
|
249
|
+
// Only return if we have an event
|
|
250
|
+
if (event && message) {
|
|
233
251
|
return {
|
|
234
252
|
type: logType,
|
|
235
253
|
message,
|
|
236
|
-
logToSession:
|
|
254
|
+
logToSession: event === 'z_regime_change' || event === 'bias_flip'
|
|
237
255
|
};
|
|
238
256
|
}
|
|
239
|
-
|
|
257
|
+
|
|
258
|
+
return null; // No event = silence
|
|
240
259
|
}
|
|
241
260
|
|
|
242
261
|
// HQX-2B strategy: event-based logging
|
|
@@ -257,6 +276,11 @@ class SmartLogsEngine {
|
|
|
257
276
|
this.lastState = null;
|
|
258
277
|
this.counter = 0;
|
|
259
278
|
this.lastLogTime = 0;
|
|
279
|
+
// Reset QUANT tracking
|
|
280
|
+
this.lastZRegime = null;
|
|
281
|
+
this.lastBias = null;
|
|
282
|
+
this.lastVpinToxic = false;
|
|
283
|
+
this.warmupLogged = false;
|
|
260
284
|
}
|
|
261
285
|
}
|
|
262
286
|
|