hedgequantx 2.9.117 → 2.9.119
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/lib/m/hqx-2b.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x2226ad=_0x5493;(function(_0x3164cd,_0x18254c){const _0x118c05=_0x5493,_0x107604=_0x3164cd();while(!![]){try{const _0x20984d=-parseInt(_0x118c05(0x181))/0x1+parseInt(_0x118c05(0x17b))/0x2*(-parseInt(_0x118c05(0x15f))/0x3)+parseInt(_0x118c05(0x15c))/0x4+-parseInt(_0x118c05(0x196))/0x5*(parseInt(_0x118c05(0x176))/0x6)+parseInt(_0x118c05(0x163))/0x7+-parseInt(_0x118c05(0x14f))/0x8*(-parseInt(_0x118c05(0x10e))/0x9)+parseInt(_0x118c05(0x191))/0xa;if(_0x20984d===_0x18254c)break;else _0x107604['push'](_0x107604['shift']());}catch(_0x251b2e){_0x107604['push'](_0x107604['shift']());}}}(_0x2bcb,0xe1d4c));const EventEmitter=require(_0x2226ad(0x18d)),{v4:uuidv4}=require('uuid'),OrderSide={'BID':0x0,'ASK':0x1},SignalStrength={'WEAK':0x1,'MODERATE':0x2,'STRONG':0x3,'VERY_STRONG':0x4},SweepType={'HIGH_SWEEP':'high','LOW_SWEEP':_0x2226ad(0x187)},ZoneType={'RESISTANCE':'resistance','SUPPORT':_0x2226ad(0xff)},DEFAULT_CONFIG={'tickSize':0.25,'tickValue':0x5,'swing':{'lookbackBars':0x3,'minStrength':0x2,'confirmationBars':0x1},'zone':{'clusterToleranceTicks':0x4,'minTouches':0x2,'maxZoneAgeBars':0xc8,'maxZoneDistanceTicks':0x28,'cooldownBars':0xa},'sweep':{'minPenetrationTicks':0.5,'maxPenetrationTicks':0x8,'maxDurationBars':0x5,'minQualityScore':0.25,'minVolumeRatio':0.5,'minBodyRatio':0.1},'execution':{'stopTicks':0xa,'targetTicks':0x28,'breakevenTicks':0x4,'trailTriggerTicks':0x8,'trailDistanceTicks':0x4,'cooldownMs':0x3a98,'minHoldTimeMs':0x2710,'slippageTicks':0x1,'commissionPerSide':0x2},'session':{'enabled':!![],'startHour':0x9,'startMinute':0x1e,'endHour':0x10,'endMinute':0x0,'timezone':_0x2226ad(0x14e)}};class SwingPoint{constructor(_0x59e60c,_0x14f1d1,_0x572f37,_0x4f9712,_0x4a3ee6=0x1){const _0x4b09b9=_0x2226ad;this['type']=_0x59e60c,this[_0x4b09b9(0x16e)]=_0x14f1d1,this[_0x4b09b9(0x122)]=_0x572f37,this[_0x4b09b9(0x16b)]=_0x4f9712,this[_0x4b09b9(0x170)]=_0x4a3ee6;}}function _0x2bcb(){const _0x1b269f=['support','priceHigh','_mergeConfig','startTime','short','minVolumeRatio','abs','delete','x\x20|\x20Q:','getStats','stopTicks','swept','trades','minPenetrationTicks','floor','720SDhNCg','initialize','generateSignal','\x20swings,\x20','t,\x20Trail=','toFixed','min','object','t\x20|\x20Q:\x20','set','zone','sweepType','_updateZones','getAnalysisState','extremePrice','minQualityScore','minBodyRatio','breakevenTicks','onTick','STRONG','barIndex','symbol','getLevel','[HQX-2B]\x20Initialized\x20for\x20','ASK','tickCount','t\x20Vol:','lastSignalTime','RESISTANCE','penetrationTicks','HQX-2B\x20Liquidity\x20Sweep\x20(Optimized)','swing','[2B]\x20SWEEP\x20','sort','2B\x20','\x20historical\x20signals\x20detected\x20(ignored)','stats','get','getTimezoneOffset','\x20|\x20','\x20|\x20Total:\x20','createdAt','[2B]\x20NEW\x20SWING\x20','size','_scoreSweep','execution','filter','t\x20|\x20Vol:','SUPPORT','[HQX-2B]\x20SIGNAL:\x20','emit','distance','activeSweeps','\x20|\x20Pen:','containsPrice',',\x20value=','map','high','signals','isValid','toUpperCase','x\x20|\x20Conf:','cooldownBars','tickSize','America/New_York','67288VIMerE','maxZoneAgeBars','[2B]\x20Calling\x20_generateSignal\x20for\x20','[2B]\x20_generateSignal\x20returned\x20null\x20(likely\x20cooldown)','barHistory','has','exports','find','currentBar','long','strategy','config','lookbackBars','3646276MEfkjV','VERY_STRONG','/5\x20bars','3uEvZLE','getBarHistory','sweep','trailDistanceTicks','6764716YVLaMt','isArray','recordTradeResult','reset','\x20@\x20','info','targetTicks','volumeRatio','timestamp','now','recentTrades','price','liquidityZones','strength','\x20sweep...','close','maxPenetrationTicks','swingPoints','max','6DowIar','buy','isDST','maxDurationBars','LOW_SWEEP','860972HjFEBe','processBar','debug','shift','split','HIGH_SWEEP','818206Hyckgg','push','priceLow','_detectSwings','tickValue','getHealthStatus','low','qualityScore','_generateSignal','s\x20<\x20','type','exitBarIndex','events','\x20bars,\x20','[HQX-2B]\x20Trade\x20result:\x20','lastUsedBarIndex','14618930kBITOV','getUTCMinutes','minStrength','processTick','_getVolumeRatio','9195170ZSyzHn','log','length','MODERATE','onTrade','durationBars','touches','sweptAt'];_0x2bcb=function(){return _0x1b269f;};return _0x2bcb();}class LiquidityZone{constructor(_0x1e8846,_0x1a07ee,_0x2b6c4d,_0x13e46b,_0xcac9ce){const _0x2da023=_0x2226ad;this['id']=uuidv4(),this[_0x2da023(0x18b)]=_0x1e8846,this[_0x2da023(0x100)]=_0x1a07ee,this['priceLow']=_0x2b6c4d,this[_0x2da023(0x137)]=_0x13e46b,this[_0x2da023(0x122)]=_0xcac9ce,this[_0x2da023(0xfd)]=0x1,this['swept']=![],this[_0x2da023(0xfe)]=null,this['lastUsedBarIndex']=-0x3e7,this[_0x2da023(0x188)]=0.5;}['containsPrice'](_0x164bbe,_0xe31ab9,_0x4241e5){const _0x2107f6=_0x2226ad,_0x137c53=_0xe31ab9*_0x4241e5;return _0x164bbe>=this[_0x2107f6(0x183)]-_0x137c53&&_0x164bbe<=this[_0x2107f6(0x100)]+_0x137c53;}['getLevel'](){const _0x508fcf=_0x2226ad;return(this[_0x508fcf(0x100)]+this[_0x508fcf(0x183)])/0x2;}}class SweepEvent{constructor(_0x227a5a,_0x2b13cc,_0x5b9902,_0x526305,_0x232bdc){const _0x538ed1=_0x2226ad;this['sweepType']=_0x227a5a,this[_0x538ed1(0x118)]=_0x2b13cc,this['entryBarIndex']=_0x5b9902,this['extremeBarIndex']=_0x526305,this[_0x538ed1(0x11c)]=_0x232bdc,this['exitBarIndex']=null,this['isValid']=![],this['qualityScore']=0x0,this['penetrationTicks']=0x0,this[_0x538ed1(0xfc)]=0x0,this['volumeRatio']=0x1;}}class HQX2BLiquiditySweep extends EventEmitter{constructor(_0x4d1d40={}){const _0x2fdd2d=_0x2226ad;super(),this['config']=this[_0x2fdd2d(0x101)](DEFAULT_CONFIG,_0x4d1d40),this[_0x2fdd2d(0x14d)]=this['config']['tickSize'],this[_0x2fdd2d(0x185)]=this['config'][_0x2fdd2d(0x185)],this[_0x2fdd2d(0x153)]=new Map(),this['swingPoints']=new Map(),this['liquidityZones']=new Map(),this[_0x2fdd2d(0x142)]=new Map(),this['currentBar']=new Map(),this['barIntervalMs']=0xea60,this[_0x2fdd2d(0x129)]=0x0,this['startTime']=Date['now'](),this[_0x2fdd2d(0x132)]={'signals':0x0,'trades':0x0,'wins':0x0,'losses':0x0,'pnl':0x0},this[_0x2fdd2d(0x16d)]=[];}[_0x2226ad(0x101)](_0x3ee334,_0x2771a2){const _0xfc6a9d=_0x2226ad,_0x17a108={..._0x3ee334};for(const _0x126432 in _0x2771a2){typeof _0x2771a2[_0x126432]===_0xfc6a9d(0x115)&&!Array[_0xfc6a9d(0x164)](_0x2771a2[_0x126432])?_0x17a108[_0x126432]={..._0x3ee334[_0x126432],..._0x2771a2[_0x126432]}:_0x17a108[_0x126432]=_0x2771a2[_0x126432];}return _0x17a108;}['isWithinSession'](_0x4c7b4c){const _0xc7454a=_0x2226ad;if(!this['config']['session']['enabled'])return!![];const _0x48b7c0=new Date(_0x4c7b4c),_0x4630dd=this['isDST'](_0x48b7c0)?-0x4:-0x5,_0x2817c8=_0x48b7c0['getUTCHours'](),_0x52a89f=_0x48b7c0[_0xc7454a(0x192)](),_0x32da9c=(_0x2817c8+_0x4630dd+0x18)%0x18,{startHour:_0xa1a975,startMinute:_0x5cfaa5,endHour:_0x15fbf2,endMinute:_0x483615}=this[_0xc7454a(0x15a)]['session'],_0x1f73ad=_0x32da9c*0x3c+_0x52a89f,_0x546645=_0xa1a975*0x3c+_0x5cfaa5,_0x4fa06d=_0x15fbf2*0x3c+_0x483615;return _0x1f73ad>=_0x546645&&_0x1f73ad<_0x4fa06d;}[_0x2226ad(0x178)](_0x56bf15){const _0x1b882d=_0x2226ad,_0x29b21e=new Date(_0x56bf15['getFullYear'](),0x0,0x1),_0x5a7436=new Date(_0x56bf15['getFullYear'](),0x6,0x1),_0x3a68ee=Math[_0x1b882d(0x175)](_0x29b21e[_0x1b882d(0x134)](),_0x5a7436['getTimezoneOffset']());return _0x56bf15['getTimezoneOffset']()<_0x3a68ee;}['initialize'](_0x36523e,_0x2a6f4e=0.25,_0x3a5f8c=0x5){const _0x5e65bc=_0x2226ad;this[_0x5e65bc(0x14d)]=_0x2a6f4e,this[_0x5e65bc(0x185)]=_0x3a5f8c,this[_0x5e65bc(0x15a)][_0x5e65bc(0x14d)]=_0x2a6f4e,this[_0x5e65bc(0x15a)]['tickValue']=_0x3a5f8c,this['barHistory'][_0x5e65bc(0x117)](_0x36523e,[]),this['swingPoints'][_0x5e65bc(0x117)](_0x36523e,[]),this['liquidityZones'][_0x5e65bc(0x117)](_0x36523e,[]),this['activeSweeps'][_0x5e65bc(0x117)](_0x36523e,[]),this['currentBar'][_0x5e65bc(0x106)](_0x36523e),this['emit']('log',{'type':'info','message':_0x5e65bc(0x125)+_0x36523e+':\x20tick='+_0x2a6f4e+_0x5e65bc(0x145)+_0x3a5f8c+',\x20TF=1min'}),this['emit']('log',{'type':_0x5e65bc(0x168),'message':'[HQX-2B]\x20Params:\x20Stop='+this['config'][_0x5e65bc(0x13b)][_0x5e65bc(0x109)]+'t,\x20Target='+this[_0x5e65bc(0x15a)]['execution'][_0x5e65bc(0x169)]+'t,\x20BE='+this['config'][_0x5e65bc(0x13b)]['breakevenTicks']+_0x5e65bc(0x112)+this[_0x5e65bc(0x15a)][_0x5e65bc(0x13b)]['trailTriggerTicks']+'/'+this[_0x5e65bc(0x15a)]['execution']['trailDistanceTicks']});}['processTick'](_0x8ef9cf){const _0x2f53b8=_0x2226ad,{contractId:_0x39a3f6,price:_0x2a601e,volume:_0x1fb204,timestamp:_0x1c3298}=_0x8ef9cf,_0x48519a=_0x1c3298||Date['now'](),_0x37452d=_0x1fb204||0x1;if(!this['isWithinSession'](_0x48519a))return null;let _0x15df30=this[_0x2f53b8(0x157)][_0x2f53b8(0x133)](_0x39a3f6);const _0x1cc1f4=Math[_0x2f53b8(0x10d)](_0x48519a/this['barIntervalMs'])*this['barIntervalMs'];if(!_0x15df30||_0x15df30[_0x2f53b8(0x102)]!==_0x1cc1f4){if(_0x15df30){const _0x4aed75={'timestamp':_0x15df30['startTime'],'open':_0x15df30['open'],'high':_0x15df30[_0x2f53b8(0x147)],'low':_0x15df30[_0x2f53b8(0x187)],'close':_0x15df30[_0x2f53b8(0x172)],'volume':_0x15df30['volume']},_0x117a19=this[_0x2f53b8(0x17c)](_0x39a3f6,_0x4aed75);return this[_0x2f53b8(0x157)]['set'](_0x39a3f6,{'startTime':_0x1cc1f4,'open':_0x2a601e,'high':_0x2a601e,'low':_0x2a601e,'close':_0x2a601e,'volume':_0x37452d}),_0x117a19;}else return this[_0x2f53b8(0x157)][_0x2f53b8(0x117)](_0x39a3f6,{'startTime':_0x1cc1f4,'open':_0x2a601e,'high':_0x2a601e,'low':_0x2a601e,'close':_0x2a601e,'volume':_0x37452d}),null;}else return _0x15df30[_0x2f53b8(0x147)]=Math[_0x2f53b8(0x175)](_0x15df30[_0x2f53b8(0x147)],_0x2a601e),_0x15df30[_0x2f53b8(0x187)]=Math[_0x2f53b8(0x114)](_0x15df30[_0x2f53b8(0x187)],_0x2a601e),_0x15df30[_0x2f53b8(0x172)]=_0x2a601e,_0x15df30['volume']+=_0x37452d,null;}[_0x2226ad(0x120)](_0xae5a58){const _0x2386f8=_0x2226ad;return this[_0x2386f8(0x194)](_0xae5a58);}[_0x2226ad(0xfb)](_0x462cd5){const _0x2d6908=_0x2226ad;return this['processTick']({'contractId':_0x462cd5['contractId']||_0x462cd5[_0x2d6908(0x123)],'price':_0x462cd5['price'],'volume':_0x462cd5[_0x2d6908(0x139)]||_0x462cd5['volume']||0x1,'timestamp':_0x462cd5[_0x2d6908(0x16b)]||Date[_0x2d6908(0x16c)]()});}['processBar'](_0x43ecf5,_0x446316){const _0x37e259=_0x2226ad;let _0x49c5b7=this[_0x37e259(0x153)][_0x37e259(0x133)](_0x43ecf5);!_0x49c5b7&&(this[_0x37e259(0x10f)](_0x43ecf5),_0x49c5b7=this[_0x37e259(0x153)]['get'](_0x43ecf5));_0x49c5b7[_0x37e259(0x182)](_0x446316);if(_0x49c5b7['length']>0x1f4)_0x49c5b7['shift']();const _0x16390a=_0x49c5b7['length']-0x1;if(_0x49c5b7['length']<this['config'][_0x37e259(0x12d)][_0x37e259(0x15b)]*0x3)return null;const _0x5049b0=this[_0x37e259(0x174)]['get'](_0x43ecf5)['length'];this[_0x37e259(0x184)](_0x43ecf5,_0x49c5b7,_0x16390a);const _0x46ef47=this['swingPoints']['get'](_0x43ecf5);if(_0x46ef47[_0x37e259(0xf9)]>_0x5049b0){const _0xef9edb=_0x46ef47[_0x46ef47['length']-0x1];this[_0x37e259(0x140)]('log',{'type':_0x37e259(0x17d),'message':_0x37e259(0x138)+_0xef9edb['type'][_0x37e259(0x14a)]()+_0x37e259(0x167)+_0xef9edb[_0x37e259(0x16e)][_0x37e259(0x113)](0x2)+_0x37e259(0x136)+_0x46ef47['length']});}const _0x434899=this['_detectSweep'](_0x43ecf5,_0x49c5b7,_0x16390a);_0x434899&&this['emit'](_0x37e259(0xf8),{'type':'debug','message':_0x37e259(0x12e)+_0x434899[_0x37e259(0x119)]+'\x20|\x20Valid:\x20'+_0x434899[_0x37e259(0x149)]+'\x20|\x20Pen:\x20'+_0x434899['penetrationTicks'][_0x37e259(0x113)](0x1)+_0x37e259(0x116)+(_0x434899['qualityScore']*0x64)[_0x37e259(0x113)](0x0)+'%'});const _0x587482=this['liquidityZones']['get'](_0x43ecf5)['length'];this[_0x37e259(0x11a)](_0x43ecf5,_0x16390a);const _0x4c9978=this['liquidityZones'][_0x37e259(0x133)](_0x43ecf5);if(_0x4c9978[_0x37e259(0xf9)]>_0x587482){const _0x173527=_0x4c9978[_0x4c9978['length']-0x1];this['emit']('log',{'type':_0x37e259(0x17d),'message':'[2B]\x20NEW\x20ZONE\x20'+_0x173527[_0x37e259(0x18b)]['toUpperCase']()+'\x20@\x20'+_0x173527['getLevel']()['toFixed'](0x2)+'\x20|\x20Total:\x20'+_0x4c9978['length']});}if(_0x434899&&_0x434899['isValid']){this['emit']('log',{'type':_0x37e259(0x17d),'message':_0x37e259(0x151)+_0x434899[_0x37e259(0x119)]+_0x37e259(0x171)});const _0x375001=this[_0x37e259(0x189)](_0x43ecf5,_0x446316,_0x16390a,_0x434899);return!_0x375001&&this[_0x37e259(0x140)](_0x37e259(0xf8),{'type':'debug','message':_0x37e259(0x152)}),_0x375001;}return null;}[_0x2226ad(0x184)](_0x470039,_0x198d24,_0x4edf0d){const _0x5c535f=_0x2226ad,_0x537de4=this[_0x5c535f(0x15a)]['swing'][_0x5c535f(0x15b)],_0x57642e=this['config']['swing'][_0x5c535f(0x193)];if(_0x4edf0d<_0x537de4*0x2)return;const _0x552a37=this['swingPoints'][_0x5c535f(0x133)](_0x470039),_0x435671=_0x4edf0d-_0x537de4,_0xc44619=_0x198d24[_0x435671];let _0x5e927d=!![],_0x2c0330=0x0;for(let _0x519573=_0x435671-_0x537de4;_0x519573<=_0x435671+_0x537de4;_0x519573++){if(_0x519573===_0x435671||_0x519573<0x0||_0x519573>=_0x198d24[_0x5c535f(0xf9)])continue;if(_0x198d24[_0x519573][_0x5c535f(0x147)]>=_0xc44619[_0x5c535f(0x147)]){_0x5e927d=![];break;}_0x2c0330++;}if(_0x5e927d&&_0x2c0330>=_0x57642e){const _0x4813aa=_0x552a37[_0x5c535f(0x156)](_0x3d30d4=>_0x3d30d4['barIndex']===_0x435671&&_0x3d30d4[_0x5c535f(0x18b)]===_0x5c535f(0x147));!_0x4813aa&&_0x552a37['push'](new SwingPoint('high',_0xc44619['high'],_0x435671,_0xc44619[_0x5c535f(0x16b)],_0x2c0330));}let _0x3a5286=!![],_0x579aae=0x0;for(let _0x59d8b7=_0x435671-_0x537de4;_0x59d8b7<=_0x435671+_0x537de4;_0x59d8b7++){if(_0x59d8b7===_0x435671||_0x59d8b7<0x0||_0x59d8b7>=_0x198d24['length'])continue;if(_0x198d24[_0x59d8b7][_0x5c535f(0x187)]<=_0xc44619[_0x5c535f(0x187)]){_0x3a5286=![];break;}_0x579aae++;}if(_0x3a5286&&_0x579aae>=_0x57642e){const _0x43a754=_0x552a37[_0x5c535f(0x156)](_0x41d8d5=>_0x41d8d5['barIndex']===_0x435671&&_0x41d8d5['type']===_0x5c535f(0x187));!_0x43a754&&_0x552a37[_0x5c535f(0x182)](new SwingPoint(_0x5c535f(0x187),_0xc44619[_0x5c535f(0x187)],_0x435671,_0xc44619['timestamp'],_0x579aae));}const _0x1dd3a2=this[_0x5c535f(0x15a)]['zone'][_0x5c535f(0x150)];while(_0x552a37[_0x5c535f(0xf9)]>0x0&&_0x552a37[0x0]['barIndex']<_0x4edf0d-_0x1dd3a2){_0x552a37[_0x5c535f(0x17e)]();}}['_updateZones'](_0x587c46,_0x3af955){const _0x4cb03b=_0x2226ad,_0x188b3b=this[_0x4cb03b(0x174)]['get'](_0x587c46),_0x51f799=this['liquidityZones']['get'](_0x587c46),_0x2cd457=this['config'][_0x4cb03b(0x118)]['clusterToleranceTicks']*this['tickSize'],_0x415796=this['config']['zone']['maxZoneAgeBars'];for(let _0x9d4634=_0x51f799['length']-0x1;_0x9d4634>=0x0;_0x9d4634--){_0x3af955-_0x51f799[_0x9d4634][_0x4cb03b(0x122)]>_0x415796&&_0x51f799['splice'](_0x9d4634,0x1);}for(const _0x31d426 of _0x188b3b){let _0x1e7d5f=null;for(const _0x4441cd of _0x51f799){if(_0x4441cd[_0x4cb03b(0x144)](_0x31d426['price'],this[_0x4cb03b(0x15a)]['zone']['clusterToleranceTicks'],this[_0x4cb03b(0x14d)])){_0x1e7d5f=_0x4441cd;break;}}if(_0x1e7d5f){_0x1e7d5f['touches']++;if(_0x31d426['price']>_0x1e7d5f['priceHigh'])_0x1e7d5f['priceHigh']=_0x31d426['price'];if(_0x31d426[_0x4cb03b(0x16e)]<_0x1e7d5f['priceLow'])_0x1e7d5f[_0x4cb03b(0x183)]=_0x31d426['price'];_0x1e7d5f[_0x4cb03b(0x188)]=Math[_0x4cb03b(0x114)](0x1,0.3+_0x1e7d5f[_0x4cb03b(0xfd)]*0.15);}else{const _0x11076e=_0x31d426['type']==='high'?ZoneType['RESISTANCE']:ZoneType['SUPPORT'],_0x3e48e3=new LiquidityZone(_0x11076e,_0x31d426['price']+_0x2cd457/0x2,_0x31d426['price']-_0x2cd457/0x2,_0x31d426[_0x4cb03b(0x16b)],_0x31d426['barIndex']);_0x3e48e3['qualityScore']=0.3+_0x31d426['strength']*0.1,_0x51f799['push'](_0x3e48e3);}}}['_detectSweep'](_0x548dba,_0x3a2b26,_0x466e97){const _0x59da80=_0x2226ad,_0x15efaa=this[_0x59da80(0x16f)]['get'](_0x548dba),_0x14a821=_0x3a2b26[_0x466e97],_0x1e40d0=_0x14a821['close'],_0x4e5b89=this[_0x59da80(0x15a)][_0x59da80(0x161)],_0x3461a8=this['config'][_0x59da80(0x118)];for(const _0x5a96e0 of _0x15efaa){if(_0x5a96e0[_0x59da80(0x190)]>=0x0&&_0x466e97-_0x5a96e0['lastUsedBarIndex']<_0x3461a8[_0x59da80(0x14c)])continue;const _0x45f697=_0x5a96e0[_0x59da80(0x124)](),_0x8e582a=Math['abs'](_0x1e40d0-_0x45f697)/this['tickSize'];if(_0x8e582a>_0x3461a8['maxZoneDistanceTicks'])continue;const _0x1249bc=Math['max'](0x0,_0x466e97-_0x4e5b89[_0x59da80(0x179)]*0x2);for(let _0x299086=_0x1249bc;_0x299086<_0x466e97;_0x299086++){const _0x3c948b=_0x3a2b26[_0x299086];if(_0x5a96e0['type']===ZoneType['RESISTANCE']){const _0x4eb723=(_0x3c948b['high']-_0x5a96e0['priceHigh'])/this['tickSize'];if(_0x4eb723>=_0x4e5b89[_0x59da80(0x10c)]&&_0x4eb723<=_0x4e5b89[_0x59da80(0x173)]){const _0x5c4896=Math['min'](_0x5a96e0[_0x59da80(0x100)],_0x5a96e0['priceHigh']+_0x4eb723*this['tickSize']);if(_0x1e40d0<_0x5c4896+this['tickSize']*0x2){const _0x48e778=_0x3c948b['high']-_0x3c948b[_0x59da80(0x187)],_0x527c4d=Math['abs'](_0x3c948b[_0x59da80(0x172)]-_0x3c948b['open']),_0x2475c1=_0x48e778>0x0?_0x527c4d/_0x48e778:0x0;if(_0x2475c1>=_0x4e5b89[_0x59da80(0x11e)]){const _0x691589=this[_0x59da80(0x195)](_0x3a2b26,_0x299086,0x14);if(_0x691589>=_0x4e5b89[_0x59da80(0x104)]){const _0xdbd3e5=new SweepEvent(SweepType['HIGH_SWEEP'],_0x5a96e0,_0x299086,_0x299086,_0x3c948b['high']);_0xdbd3e5['exitBarIndex']=_0x466e97,_0xdbd3e5[_0x59da80(0x12b)]=_0x4eb723,_0xdbd3e5['durationBars']=_0x466e97-_0x299086,_0xdbd3e5[_0x59da80(0x16a)]=_0x691589,_0xdbd3e5[_0x59da80(0x188)]=this[_0x59da80(0x13a)](_0xdbd3e5,_0x2475c1),_0xdbd3e5[_0x59da80(0x149)]=_0xdbd3e5[_0x59da80(0x188)]>=_0x4e5b89[_0x59da80(0x11d)];if(_0xdbd3e5['isValid'])return _0xdbd3e5;}}}}}if(_0x5a96e0[_0x59da80(0x18b)]===ZoneType[_0x59da80(0x13e)]){const _0x26b60a=(_0x5a96e0[_0x59da80(0x183)]-_0x3c948b['low'])/this[_0x59da80(0x14d)];if(_0x26b60a>=_0x4e5b89['minPenetrationTicks']&&_0x26b60a<=_0x4e5b89['maxPenetrationTicks']){const _0x2fd14e=Math[_0x59da80(0x175)](_0x5a96e0[_0x59da80(0x183)],_0x5a96e0[_0x59da80(0x183)]-_0x26b60a*this[_0x59da80(0x14d)]);if(_0x1e40d0>_0x2fd14e-this[_0x59da80(0x14d)]*0x2){const _0x12237c=_0x3c948b[_0x59da80(0x147)]-_0x3c948b['low'],_0x494225=Math['abs'](_0x3c948b[_0x59da80(0x172)]-_0x3c948b['open']),_0x2abe21=_0x12237c>0x0?_0x494225/_0x12237c:0x0;if(_0x2abe21>=_0x4e5b89[_0x59da80(0x11e)]){const _0x2270e1=this['_getVolumeRatio'](_0x3a2b26,_0x299086,0x14);if(_0x2270e1>=_0x4e5b89[_0x59da80(0x104)]){const _0x2bf6e5=new SweepEvent(SweepType[_0x59da80(0x17a)],_0x5a96e0,_0x299086,_0x299086,_0x3c948b[_0x59da80(0x187)]);_0x2bf6e5[_0x59da80(0x18c)]=_0x466e97,_0x2bf6e5[_0x59da80(0x12b)]=_0x26b60a,_0x2bf6e5[_0x59da80(0xfc)]=_0x466e97-_0x299086,_0x2bf6e5[_0x59da80(0x16a)]=_0x2270e1,_0x2bf6e5['qualityScore']=this['_scoreSweep'](_0x2bf6e5,_0x2abe21),_0x2bf6e5[_0x59da80(0x149)]=_0x2bf6e5['qualityScore']>=_0x4e5b89['minQualityScore'];if(_0x2bf6e5[_0x59da80(0x149)])return _0x2bf6e5;}}}}}}}return null;}['_getVolumeRatio'](_0x431ebe,_0x405f79,_0x3318a4){const _0x9ca874=_0x2226ad,_0x3cb0df=Math['max'](0x0,_0x405f79-_0x3318a4),_0x599986=_0x431ebe['slice'](_0x3cb0df,_0x405f79);if(_0x599986[_0x9ca874(0xf9)]===0x0)return 0x1;const _0x31eb5a=_0x599986[_0x9ca874(0x146)](_0x32968a=>_0x32968a['volume'])['sort']((_0x26951c,_0x4bee72)=>_0x26951c-_0x4bee72),_0x46f83d=Math['floor'](_0x31eb5a[_0x9ca874(0xf9)]/0x2),_0x37f5c5=_0x31eb5a[_0x46f83d]||0x1;return _0x431ebe[_0x405f79]['volume']/_0x37f5c5;}['_scoreSweep'](_0x578282,_0x32af82){const _0x6e9f36=_0x2226ad;let _0x2a826e=0x0;const _0x11af70=0x4,_0x53c8a9=Math['abs'](_0x578282['penetrationTicks']-_0x11af70);return _0x2a826e+=Math[_0x6e9f36(0x175)](0x0,0.3-_0x53c8a9*0.03),_0x2a826e+=Math[_0x6e9f36(0x175)](0x0,0.25-_0x578282[_0x6e9f36(0xfc)]*0.05),_0x2a826e+=Math[_0x6e9f36(0x114)](0.25,_0x578282[_0x6e9f36(0x16a)]*0.1),_0x2a826e+=Math[_0x6e9f36(0x114)](0.2,_0x32af82*0.4),Math[_0x6e9f36(0x114)](0x1,_0x2a826e);}['_generateSignal'](_0x423f9e,_0x360210,_0x3b3dca,_0x327d13){const _0x4984de=_0x2226ad,_0x2963fa=Date[_0x4984de(0x16c)]()-this['lastSignalTime'];if(_0x2963fa<this[_0x4984de(0x15a)]['execution']['cooldownMs'])return this[_0x4984de(0x140)](_0x4984de(0xf8),{'type':'debug','message':'[2B]\x20Signal\x20blocked\x20by\x20cooldown\x20('+(_0x2963fa/0x3e8)[_0x4984de(0x113)](0x1)+_0x4984de(0x18a)+this[_0x4984de(0x15a)][_0x4984de(0x13b)]['cooldownMs']/0x3e8+'s)'}),null;const _0x47f30d=this['config']['execution'],_0x1fa02f=_0x360210['close'],_0x33dbd6=_0x327d13[_0x4984de(0x119)]===SweepType[_0x4984de(0x180)]?_0x4984de(0x103):'long';let _0x2fb87d,_0x2201bc,_0x5487cc,_0x205818;_0x33dbd6===_0x4984de(0x158)?(_0x2fb87d=_0x1fa02f-_0x47f30d['stopTicks']*this['tickSize'],_0x2201bc=_0x1fa02f+_0x47f30d['targetTicks']*this['tickSize'],_0x5487cc=_0x1fa02f+_0x47f30d[_0x4984de(0x11f)]*this['tickSize'],_0x205818=_0x1fa02f+_0x47f30d['trailTriggerTicks']*this['tickSize']):(_0x2fb87d=_0x1fa02f+_0x47f30d[_0x4984de(0x109)]*this['tickSize'],_0x2201bc=_0x1fa02f-_0x47f30d[_0x4984de(0x169)]*this['tickSize'],_0x5487cc=_0x1fa02f-_0x47f30d['breakevenTicks']*this[_0x4984de(0x14d)],_0x205818=_0x1fa02f-_0x47f30d['trailTriggerTicks']*this[_0x4984de(0x14d)]);const _0x260923=_0x47f30d['targetTicks']/_0x47f30d[_0x4984de(0x109)],_0x1ba117=Math['min'](0x1,_0x327d13['qualityScore']*0.5+_0x327d13[_0x4984de(0x118)]['qualityScore']*0.3+(_0x327d13['volumeRatio']>1.5?0.2:_0x327d13['volumeRatio']*0.1));let _0x4d1151=SignalStrength[_0x4984de(0xfa)];if(_0x1ba117>=0.8)_0x4d1151=SignalStrength[_0x4984de(0x15d)];else{if(_0x1ba117>=0.65)_0x4d1151=SignalStrength[_0x4984de(0x121)];else{if(_0x1ba117<0.5)_0x4d1151=SignalStrength['WEAK'];}}const _0x46fd47=0.5+(_0x1ba117-0.5)*0.4,_0x24c1ff=_0x46fd47*Math[_0x4984de(0x105)](_0x2201bc-_0x1fa02f)-(0x1-_0x46fd47)*Math[_0x4984de(0x105)](_0x1fa02f-_0x2fb87d);_0x327d13['zone']['lastUsedBarIndex']=_0x3b3dca,_0x327d13['zone'][_0x4984de(0x10a)]=!![],_0x327d13[_0x4984de(0x118)]['sweptAt']=new Date(_0x360210['timestamp']),this['lastSignalTime']=Date['now'](),this[_0x4984de(0x132)][_0x4984de(0x148)]++;const _0xedee86={'id':uuidv4(),'timestamp':Date[_0x4984de(0x16c)](),'symbol':_0x423f9e[_0x4984de(0x17f)]('.')[0x0]||_0x423f9e,'contractId':_0x423f9e,'side':_0x33dbd6===_0x4984de(0x158)?OrderSide['BID']:OrderSide[_0x4984de(0x126)],'direction':_0x33dbd6,'strategy':'HQX_2B_LIQUIDITY_SWEEP','strength':_0x4d1151,'edge':_0x24c1ff,'confidence':_0x1ba117,'entry':_0x1fa02f,'entryPrice':_0x1fa02f,'stopLoss':_0x2fb87d,'takeProfit':_0x2201bc,'riskReward':_0x260923,'stopTicks':_0x47f30d['stopTicks'],'targetTicks':_0x47f30d[_0x4984de(0x169)],'breakevenTicks':_0x47f30d[_0x4984de(0x11f)],'trailTriggerTicks':_0x47f30d['trailTriggerTicks'],'trailDistanceTicks':_0x47f30d[_0x4984de(0x162)],'beLevel':_0x5487cc,'trailTrigger':_0x205818,'sweepType':_0x327d13[_0x4984de(0x119)],'penetrationTicks':_0x327d13[_0x4984de(0x12b)],'sweepDurationBars':_0x327d13[_0x4984de(0xfc)],'sweepQuality':_0x327d13['qualityScore'],'volumeRatio':_0x327d13[_0x4984de(0x16a)],'zoneType':_0x327d13[_0x4984de(0x118)]['type'],'zoneLevel':_0x327d13['zone'][_0x4984de(0x124)](),'zoneTouches':_0x327d13[_0x4984de(0x118)][_0x4984de(0xfd)],'zoneQuality':_0x327d13[_0x4984de(0x118)]['qualityScore'],'expires':Date['now']()+0xea60};return this[_0x4984de(0x140)]('signal',{'side':_0x33dbd6==='long'?_0x4984de(0x177):'sell','action':'open','reason':_0x4984de(0x130)+_0x327d13[_0x4984de(0x119)]+_0x4984de(0x143)+_0x327d13['penetrationTicks'][_0x4984de(0x113)](0x1)+_0x4984de(0x13d)+_0x327d13[_0x4984de(0x16a)]['toFixed'](0x1)+_0x4984de(0x107)+(_0x327d13['qualityScore']*0x64)[_0x4984de(0x113)](0x0)+'%',..._0xedee86}),this['emit'](_0x4984de(0xf8),{'type':_0x4984de(0x168),'message':_0x4984de(0x13f)+_0x33dbd6['toUpperCase']()+_0x4984de(0x167)+_0x1fa02f['toFixed'](0x2)+_0x4984de(0x135)+_0x327d13['sweepType']+'\x20|\x20Pen:'+_0x327d13['penetrationTicks']['toFixed'](0x1)+_0x4984de(0x128)+_0x327d13['volumeRatio']['toFixed'](0x1)+_0x4984de(0x14b)+(_0x1ba117*0x64)['toFixed'](0x0)+'%'}),_0xedee86;}[_0x2226ad(0x11b)](_0x16b3bc,_0x1b05d4){const _0x4840c5=_0x2226ad,_0x221f90=this['barHistory']['get'](_0x16b3bc)||[],_0x5b7bcf=this[_0x4840c5(0x16f)][_0x4840c5(0x133)](_0x16b3bc)||[],_0x12d727=this[_0x4840c5(0x174)]['get'](_0x16b3bc)||[];if(_0x221f90[_0x4840c5(0xf9)]<0x5)return{'ready':![],'message':'Collecting\x20data...\x20'+_0x221f90[_0x4840c5(0xf9)]+_0x4840c5(0x15e)};const _0x4fcd54=_0x5b7bcf[_0x4840c5(0x146)](_0xc6234e=>({'zone':_0xc6234e,'distance':Math['abs'](_0x1b05d4-_0xc6234e['getLevel']())}))['sort']((_0x44bea7,_0x301fd2)=>_0x44bea7['distance']-_0x301fd2[_0x4840c5(0x141)]),_0x143ff4=_0x4fcd54[_0x4840c5(0x156)](_0x52997b=>_0x52997b['zone']['type']===ZoneType['RESISTANCE']),_0x1362e5=_0x4fcd54['find'](_0x12595c=>_0x12595c['zone'][_0x4840c5(0x18b)]===ZoneType['SUPPORT']);return{'ready':!![],'barsProcessed':_0x221f90['length'],'swingsDetected':_0x12d727['length'],'activeZones':_0x5b7bcf['length'],'nearestResistance':_0x143ff4?_0x143ff4[_0x4840c5(0x118)]['getLevel']():null,'nearestSupport':_0x1362e5?_0x1362e5['zone']['getLevel']():null,'stopTicks':this['config']['execution']['stopTicks'],'targetTicks':this[_0x4840c5(0x15a)]['execution']['targetTicks'],'strategy':_0x4840c5(0x12c)};}[_0x2226ad(0x165)](_0x54f7b1){const _0x234394=_0x2226ad;this['recentTrades'][_0x234394(0x182)]({'netPnl':_0x54f7b1,'timestamp':Date['now']()});if(this['recentTrades']['length']>0x64)this[_0x234394(0x16d)]['shift']();_0x54f7b1>0x0?this['stats']['wins']++:this[_0x234394(0x132)]['losses']++,this['stats'][_0x234394(0x10b)]++,this[_0x234394(0x132)]['pnl']+=_0x54f7b1,this['emit']('log',{'type':'debug','message':_0x234394(0x18f)+(_0x54f7b1>0x0?'WIN':'LOSS')+'\x20$'+_0x54f7b1['toFixed'](0x2)});}[_0x2226ad(0x160)](_0x52610f){return this['barHistory']['get'](_0x52610f)||[];}['getStats'](){const _0x1f6177=_0x2226ad;return this[_0x1f6177(0x132)];}['getHealthStatus'](_0x190bc5){const _0x392143=_0x2226ad,_0x478ebe=this['barHistory']['get'](_0x190bc5)||[],_0x1ab606=this['liquidityZones']['get'](_0x190bc5)||[],_0x2da6d1=this['swingPoints'][_0x392143(0x133)](_0x190bc5)||[],_0x50b1f2=this[_0x392143(0x157)]['get'](_0x190bc5),_0x5c298c=_0x478ebe[_0x478ebe[_0x392143(0xf9)]-0x1],_0x455ed5=_0x5c298c?Date['now']()-_0x5c298c['timestamp']:null,_0x53c17b=_0x1ab606[_0x392143(0x13c)](_0x58e577=>_0x58e577['type']===ZoneType[_0x392143(0x12a)])['length'],_0x55e799=_0x1ab606[_0x392143(0x13c)](_0x3dd413=>_0x3dd413[_0x392143(0x18b)]===ZoneType['SUPPORT'])['length'];return{'healthy':_0x478ebe[_0x392143(0xf9)]>=0x5,'barsTotal':_0x478ebe[_0x392143(0xf9)],'barsLast5Min':_0x478ebe[_0x392143(0x13c)](_0x12f638=>Date['now']()-_0x12f638[_0x392143(0x16b)]<0x5*0x3c*0x3e8)[_0x392143(0xf9)],'swingsTotal':_0x2da6d1[_0x392143(0xf9)],'zonesResistance':_0x53c17b,'zonesSupport':_0x55e799,'zonesTotal':_0x1ab606[_0x392143(0xf9)],'currentBarTicks':_0x50b1f2?_0x50b1f2[_0x392143(0x127)]:0x0,'isAggregating':_0x50b1f2&&_0x50b1f2[_0x392143(0x127)]>0x0,'timeSinceLastBarMs':_0x455ed5,'lastSignalTime':this[_0x392143(0x129)],'signalCooldownMs':this['config']['execution']['cooldownMs'],'uptime':Date['now']()-(this[_0x392143(0x102)]||Date['now']())};}[_0x2226ad(0x166)](_0x4684ab){const _0x4e8600=_0x2226ad;this[_0x4e8600(0x153)]['set'](_0x4684ab,[]),this[_0x4e8600(0x174)][_0x4e8600(0x117)](_0x4684ab,[]),this['liquidityZones'][_0x4e8600(0x117)](_0x4684ab,[]),this[_0x4e8600(0x142)][_0x4e8600(0x117)](_0x4684ab,[]),this['currentBar']['delete'](_0x4684ab),this[_0x4e8600(0x140)](_0x4e8600(0xf8),{'type':'info','message':'[HQX-2B]\x20Reset\x20state\x20for\x20'+_0x4684ab});}['preloadBars'](_0x278de4,_0x656511){const _0x3bb1b1=_0x2226ad;if(!_0x656511||_0x656511[_0x3bb1b1(0xf9)]===0x0){this[_0x3bb1b1(0x140)](_0x3bb1b1(0xf8),{'type':_0x3bb1b1(0x17d),'message':'[HQX-2B]\x20No\x20historical\x20bars\x20to\x20preload'});return;}!this['barHistory'][_0x3bb1b1(0x154)](_0x278de4)&&this[_0x3bb1b1(0x10f)](_0x278de4);const _0x15c1bb=[..._0x656511][_0x3bb1b1(0x12f)]((_0x2109a6,_0x48fb03)=>_0x2109a6['timestamp']-_0x48fb03['timestamp']);this['emit'](_0x3bb1b1(0xf8),{'type':'info','message':'[HQX-2B]\x20Preloading\x20'+_0x15c1bb[_0x3bb1b1(0xf9)]+'\x20historical\x20bars...'});let _0x5e2914=0x0;for(const _0x33bb10 of _0x15c1bb){const _0x2ad532=this[_0x3bb1b1(0x17c)](_0x278de4,_0x33bb10);if(_0x2ad532)_0x5e2914++;}const _0x5836e7=this['barHistory']['get'](_0x278de4)||[],_0x1abdc9=this['swingPoints'][_0x3bb1b1(0x133)](_0x278de4)||[],_0x1b0e44=this['liquidityZones'][_0x3bb1b1(0x133)](_0x278de4)||[];this[_0x3bb1b1(0x140)]('log',{'type':_0x3bb1b1(0x168),'message':'[HQX-2B]\x20Preload\x20complete:\x20'+_0x5836e7['length']+_0x3bb1b1(0x18e)+_0x1abdc9['length']+_0x3bb1b1(0x111)+_0x1b0e44[_0x3bb1b1(0xf9)]+'\x20zones'}),_0x5e2914>0x0&&this['emit'](_0x3bb1b1(0xf8),{'type':'debug','message':'[HQX-2B]\x20'+_0x5e2914+_0x3bb1b1(0x131)}),this['lastSignalTime']=0x0;}}class HQX2BStrategy extends EventEmitter{constructor(_0x5b5547={}){const _0x518db6=_0x2226ad;super(),this[_0x518db6(0x15a)]=_0x5b5547,this['strategy']=new HQX2BLiquiditySweep(_0x5b5547),this[_0x518db6(0x159)]['on']('signal',_0x583c7d=>this[_0x518db6(0x140)]('signal',_0x583c7d)),this[_0x518db6(0x159)]['on'](_0x518db6(0xf8),_0x23a729=>this[_0x518db6(0x140)]('log',_0x23a729));}[_0x2226ad(0x194)](_0x37449d){const _0x7d3be3=_0x2226ad;return this[_0x7d3be3(0x159)][_0x7d3be3(0x194)](_0x37449d);}['onTick'](_0x4667e4){const _0x9301b2=_0x2226ad;return this['strategy'][_0x9301b2(0x120)](_0x4667e4);}[_0x2226ad(0xfb)](_0x1a0ebd){const _0x554887=_0x2226ad;return this['strategy'][_0x554887(0xfb)](_0x1a0ebd);}[_0x2226ad(0x17c)](_0x17fd64,_0x460e81){const _0x5c6b7e=_0x2226ad;return this['strategy'][_0x5c6b7e(0x17c)](_0x17fd64,_0x460e81);}['initialize'](_0x590436,_0x5b3ab4,_0x1f2e7e){return this['strategy']['initialize'](_0x590436,_0x5b3ab4,_0x1f2e7e);}[_0x2226ad(0x11b)](_0x42547f,_0x15573a){const _0x418516=_0x2226ad;return this['strategy'][_0x418516(0x11b)](_0x42547f,_0x15573a);}['recordTradeResult'](_0x328a2e){const _0x2bb581=_0x2226ad;return this['strategy'][_0x2bb581(0x165)](_0x328a2e);}['reset'](_0x3d8d34){const _0x481932=_0x2226ad;return this['strategy'][_0x481932(0x166)](_0x3d8d34);}[_0x2226ad(0x108)](){return this['strategy']['getStats']();}[_0x2226ad(0x160)](_0x237b0f){const _0x42ac43=_0x2226ad;return this['strategy'][_0x42ac43(0x160)](_0x237b0f);}['preloadBars'](_0x47d9ef,_0x1682d0){const _0x46e215=_0x2226ad;return this[_0x46e215(0x159)]['preloadBars'](_0x47d9ef,_0x1682d0);}[_0x2226ad(0x186)](_0x34dd8b){const _0xb4bf3=_0x2226ad;return this[_0xb4bf3(0x159)][_0xb4bf3(0x186)](_0x34dd8b);}[_0x2226ad(0x110)](_0x2c0cc1){return null;}}function _0x5493(_0x3f882a,_0x11948f){_0x3f882a=_0x3f882a-0xf8;const _0x2bcb4c=_0x2bcb();let _0x549337=_0x2bcb4c[_0x3f882a];return _0x549337;}module[_0x2226ad(0x155)]={'HQX2BLiquiditySweep':HQX2BLiquiditySweep,'HQX2BStrategy':HQX2BStrategy,'M2':HQX2BStrategy,'S2':HQX2BLiquiditySweep,'OrderSide':OrderSide,'SignalStrength':SignalStrength,'SweepType':SweepType,'ZoneType':ZoneType,'DEFAULT_CONFIG':DEFAULT_CONFIG};
|
|
1
|
+
const _0x3c2c79=_0x3286;(function(_0x29ac90,_0x4d799b){const _0x37e0b4=_0x3286,_0x2b55b4=_0x29ac90();while(!![]){try{const _0xc35e54=-parseInt(_0x37e0b4(0x170))/0x1+parseInt(_0x37e0b4(0x137))/0x2*(-parseInt(_0x37e0b4(0x12a))/0x3)+parseInt(_0x37e0b4(0x1a6))/0x4+-parseInt(_0x37e0b4(0x166))/0x5*(-parseInt(_0x37e0b4(0x16b))/0x6)+-parseInt(_0x37e0b4(0x14f))/0x7*(-parseInt(_0x37e0b4(0x163))/0x8)+-parseInt(_0x37e0b4(0x1a7))/0x9+parseInt(_0x37e0b4(0x1a5))/0xa*(-parseInt(_0x37e0b4(0x174))/0xb);if(_0xc35e54===_0x4d799b)break;else _0x2b55b4['push'](_0x2b55b4['shift']());}catch(_0x5e77b5){_0x2b55b4['push'](_0x2b55b4['shift']());}}}(_0x2306,0x6eb2b));const EventEmitter=require(_0x3c2c79(0x14b)),{v4:uuidv4}=require(_0x3c2c79(0x11d)),OrderSide={'BID':0x0,'ASK':0x1},SignalStrength={'WEAK':0x1,'MODERATE':0x2,'STRONG':0x3,'VERY_STRONG':0x4},SweepType={'HIGH_SWEEP':_0x3c2c79(0x176),'LOW_SWEEP':'low'},ZoneType={'RESISTANCE':_0x3c2c79(0x118),'SUPPORT':'support'},DEFAULT_CONFIG={'tickSize':0.25,'tickValue':0x5,'swing':{'lookbackBars':0x3,'minStrength':0x2,'confirmationBars':0x1},'zone':{'clusterToleranceTicks':0x4,'minTouches':0x2,'maxZoneAgeBars':0xc8,'maxZoneDistanceTicks':0x28,'cooldownBars':0xa},'sweep':{'minPenetrationTicks':0.5,'maxPenetrationTicks':0x8,'maxDurationBars':0x5,'minQualityScore':0.25,'minVolumeRatio':0.5,'minBodyRatio':0.1},'execution':{'stopTicks':0xa,'targetTicks':0x28,'breakevenTicks':0x4,'trailTriggerTicks':0x8,'trailDistanceTicks':0x4,'cooldownMs':0x3a98,'minHoldTimeMs':0x2710,'slippageTicks':0x1,'commissionPerSide':0x2},'session':{'enabled':![],'startHour':0x9,'startMinute':0x1e,'endHour':0x10,'endMinute':0x0,'timezone':'America/New_York'}};class SwingPoint{constructor(_0x4c7556,_0x2b0437,_0x4a33de,_0x5510cd,_0x3ea663=0x1){const _0x531e4e=_0x3c2c79;this['type']=_0x4c7556,this[_0x531e4e(0x13e)]=_0x2b0437,this['barIndex']=_0x4a33de,this['timestamp']=_0x5510cd,this['strength']=_0x3ea663;}}function _0x2306(){const _0x1d6ecf=['tickSize','getStats','stopTicks','swingPoints','getAnalysisState','session','min','s\x20<\x20','_detectSwings','timestamp','sweepType','getBarHistory','info','delete','processTick','strategy','getHealthStatus','penetrationTicks','map','execution','minVolumeRatio','sort','low','toFixed','stats','volumeRatio','barIndex','SUPPORT','length','x\x20|\x20Q:','now','cooldownBars','[HQX-2B]\x20Preload\x20complete:\x20','reset','\x20|\x20Total:\x20','clusterToleranceTicks','set','[2B]\x20SWEEP\x20','isValid','emit','breakevenTicks','priceHigh','20LUhKRy','2891544dWvjDd','516339jAtdHk','long','wins','qualityScore','size','close','log','has','split','targetTicks','maxPenetrationTicks','barHistory','resistance','WIN','_detectSweep','priceLow','filter','uuid','floor','HIGH_SWEEP','push','signal','_getVolumeRatio','open','/5\x20bars','isWithinSession','max','\x20|\x20','config','[2B]\x20Calling\x20_generateSignal\x20for\x20','2026110EvaPsr','maxZoneAgeBars','splice','maxDurationBars','RESISTANCE','startTime','\x20|\x20Pen:','exitBarIndex','preloadBars','processBar','tickCount','shift','containsPrice','2CMiweW','\x20historical\x20signals\x20detected\x20(ignored)','getLevel','trailTriggerTicks','liquidityZones','durationBars','BID','price','currentBar','extremeBarIndex','\x20historical\x20bars...','isDST','onTrade','onTick','type','WEAK','t,\x20BE=','swing','minQualityScore','generateSignal','events','_generateSignal','get','find','21RsODKP','lastSignalTime','buy','distance','barIntervalMs','STRONG','touches','HQX-2B\x20Liquidity\x20Sweep\x20(Optimized)','_mergeConfig','activeSweeps','cooldownMs','toUpperCase','recentTrades','HQX_2B_LIQUIDITY_SWEEP','exports','createdAt','tickValue','sweptAt','trailDistanceTicks','LOSS','2374576aztBTa','_updateZones','volume','550asBGBf','abs','MODERATE','short',',\x20value=','46668ElOrNT','Collecting\x20data...\x20','minPenetrationTicks','initialize','zone','542336KtDGBb','swept','\x20@\x20','recordTradeResult','4072398pKWXOf','lastUsedBarIndex','high','debug','[2B]\x20_generateSignal\x20returned\x20null\x20(likely\x20cooldown)','getFullYear','[2B]\x20NEW\x20ZONE\x20'];_0x2306=function(){return _0x1d6ecf;};return _0x2306();}class LiquidityZone{constructor(_0x47dd02,_0x91f01b,_0x2fc927,_0x60a931,_0x970786){const _0x5b63e4=_0x3c2c79;this['id']=uuidv4(),this['type']=_0x47dd02,this['priceHigh']=_0x91f01b,this['priceLow']=_0x2fc927,this[_0x5b63e4(0x15e)]=_0x60a931,this[_0x5b63e4(0x195)]=_0x970786,this['touches']=0x1,this['swept']=![],this['sweptAt']=null,this['lastUsedBarIndex']=-0x3e7,this['qualityScore']=0.5;}[_0x3c2c79(0x136)](_0x1021bb,_0x259fdd,_0x4d601d){const _0x3c5670=_0x3c2c79,_0x56b511=_0x259fdd*_0x4d601d;return _0x1021bb>=this[_0x3c5670(0x11b)]-_0x56b511&&_0x1021bb<=this[_0x3c5670(0x1a4)]+_0x56b511;}[_0x3c2c79(0x139)](){const _0x505bc5=_0x3c2c79;return(this[_0x505bc5(0x1a4)]+this[_0x505bc5(0x11b)])/0x2;}}class SweepEvent{constructor(_0x1dd70a,_0x3f2142,_0x5da72a,_0x5d7747,_0x388d23){const _0x378def=_0x3c2c79;this[_0x378def(0x185)]=_0x1dd70a,this['zone']=_0x3f2142,this['entryBarIndex']=_0x5da72a,this[_0x378def(0x140)]=_0x5d7747,this['extremePrice']=_0x388d23,this[_0x378def(0x131)]=null,this[_0x378def(0x1a1)]=![],this['qualityScore']=0x0,this[_0x378def(0x18c)]=0x0,this[_0x378def(0x13c)]=0x0,this[_0x378def(0x194)]=0x1;}}class HQX2BLiquiditySweep extends EventEmitter{constructor(_0x73ec9d={}){const _0x10b74a=_0x3c2c79;super(),this['config']=this[_0x10b74a(0x157)](DEFAULT_CONFIG,_0x73ec9d),this[_0x10b74a(0x17b)]=this[_0x10b74a(0x128)]['tickSize'],this['tickValue']=this['config'][_0x10b74a(0x15f)],this['barHistory']=new Map(),this['swingPoints']=new Map(),this['liquidityZones']=new Map(),this['activeSweeps']=new Map(),this[_0x10b74a(0x13f)]=new Map(),this[_0x10b74a(0x153)]=0xea60,this[_0x10b74a(0x150)]=0x0,this['startTime']=Date['now'](),this[_0x10b74a(0x193)]={'signals':0x0,'trades':0x0,'wins':0x0,'losses':0x0,'pnl':0x0},this[_0x10b74a(0x15b)]=[];}[_0x3c2c79(0x157)](_0x2ed7e0,_0x35aaed){const _0xffafaf={..._0x2ed7e0};for(const _0x39396d in _0x35aaed){typeof _0x35aaed[_0x39396d]==='object'&&!Array['isArray'](_0x35aaed[_0x39396d])?_0xffafaf[_0x39396d]={..._0x2ed7e0[_0x39396d],..._0x35aaed[_0x39396d]}:_0xffafaf[_0x39396d]=_0x35aaed[_0x39396d];}return _0xffafaf;}['isWithinSession'](_0x51bb43){const _0x47c243=_0x3c2c79;if(!this[_0x47c243(0x128)][_0x47c243(0x180)]['enabled'])return!![];const _0x3aaefc=new Date(_0x51bb43),_0x1bfb98=this[_0x47c243(0x142)](_0x3aaefc)?-0x4:-0x5,_0x3bc5c9=_0x3aaefc['getUTCHours'](),_0x426554=_0x3aaefc['getUTCMinutes'](),_0xd6e43d=(_0x3bc5c9+_0x1bfb98+0x18)%0x18,{startHour:_0x5ec534,startMinute:_0xcdb89c,endHour:_0x5f856b,endMinute:_0x3f11a3}=this[_0x47c243(0x128)][_0x47c243(0x180)],_0x426f54=_0xd6e43d*0x3c+_0x426554,_0x1895fd=_0x5ec534*0x3c+_0xcdb89c,_0x5d165b=_0x5f856b*0x3c+_0x3f11a3;return _0x426f54>=_0x1895fd&&_0x426f54<_0x5d165b;}['isDST'](_0x1f9d17){const _0x273de5=_0x3c2c79,_0xb94322=new Date(_0x1f9d17[_0x273de5(0x179)](),0x0,0x1),_0x227bf7=new Date(_0x1f9d17[_0x273de5(0x179)](),0x6,0x1),_0x5dc005=Math[_0x273de5(0x126)](_0xb94322['getTimezoneOffset'](),_0x227bf7['getTimezoneOffset']());return _0x1f9d17['getTimezoneOffset']()<_0x5dc005;}['initialize'](_0x188519,_0x4ddbbf=0.25,_0x5d88e0=0x5){const _0x43c69f=_0x3c2c79;this[_0x43c69f(0x17b)]=_0x4ddbbf,this['tickValue']=_0x5d88e0,this[_0x43c69f(0x128)]['tickSize']=_0x4ddbbf,this[_0x43c69f(0x128)][_0x43c69f(0x15f)]=_0x5d88e0,this[_0x43c69f(0x117)][_0x43c69f(0x19f)](_0x188519,[]),this['swingPoints']['set'](_0x188519,[]),this[_0x43c69f(0x13b)]['set'](_0x188519,[]),this['activeSweeps']['set'](_0x188519,[]),this['currentBar'][_0x43c69f(0x188)](_0x188519),this[_0x43c69f(0x1a2)]('log',{'type':_0x43c69f(0x187),'message':'[HQX-2B]\x20Initialized\x20for\x20'+_0x188519+':\x20tick='+_0x4ddbbf+_0x43c69f(0x16a)+_0x5d88e0+',\x20TF=1min'}),this['emit'](_0x43c69f(0x1ad),{'type':_0x43c69f(0x187),'message':'[HQX-2B]\x20Params:\x20Stop='+this[_0x43c69f(0x128)]['execution']['stopTicks']+'t,\x20Target='+this[_0x43c69f(0x128)]['execution'][_0x43c69f(0x115)]+_0x43c69f(0x147)+this['config']['execution']['breakevenTicks']+'t,\x20Trail='+this[_0x43c69f(0x128)][_0x43c69f(0x18e)]['trailTriggerTicks']+'/'+this['config']['execution'][_0x43c69f(0x161)]});}[_0x3c2c79(0x189)](_0x2afd93){const _0x1b6503=_0x3c2c79,{contractId:_0x3f6535,price:_0x1b0c2c,volume:_0x21311b,timestamp:_0x539db5}=_0x2afd93,_0x222ac5=_0x539db5||Date[_0x1b6503(0x199)](),_0x15d4ff=_0x21311b||0x1;if(!this[_0x1b6503(0x125)](_0x222ac5))return null;let _0x143ce8=this[_0x1b6503(0x13f)][_0x1b6503(0x14d)](_0x3f6535);const _0x57cd92=Math[_0x1b6503(0x11e)](_0x222ac5/this[_0x1b6503(0x153)])*this[_0x1b6503(0x153)];if(!_0x143ce8||_0x143ce8[_0x1b6503(0x12f)]!==_0x57cd92){if(_0x143ce8){const _0x914633={'timestamp':_0x143ce8['startTime'],'open':_0x143ce8['open'],'high':_0x143ce8['high'],'low':_0x143ce8['low'],'close':_0x143ce8[_0x1b6503(0x1ac)],'volume':_0x143ce8['volume']},_0x1a4ebb=this[_0x1b6503(0x133)](_0x3f6535,_0x914633);return this['currentBar']['set'](_0x3f6535,{'startTime':_0x57cd92,'open':_0x1b0c2c,'high':_0x1b0c2c,'low':_0x1b0c2c,'close':_0x1b0c2c,'volume':_0x15d4ff}),_0x1a4ebb;}else return this[_0x1b6503(0x13f)][_0x1b6503(0x19f)](_0x3f6535,{'startTime':_0x57cd92,'open':_0x1b0c2c,'high':_0x1b0c2c,'low':_0x1b0c2c,'close':_0x1b0c2c,'volume':_0x15d4ff}),null;}else return _0x143ce8[_0x1b6503(0x176)]=Math[_0x1b6503(0x126)](_0x143ce8[_0x1b6503(0x176)],_0x1b0c2c),_0x143ce8[_0x1b6503(0x191)]=Math[_0x1b6503(0x181)](_0x143ce8[_0x1b6503(0x191)],_0x1b0c2c),_0x143ce8[_0x1b6503(0x1ac)]=_0x1b0c2c,_0x143ce8[_0x1b6503(0x165)]+=_0x15d4ff,null;}['onTick'](_0x1c4e6b){const _0xee5035=_0x3c2c79;return this[_0xee5035(0x189)](_0x1c4e6b);}['onTrade'](_0x3cacf6){const _0x49c4c0=_0x3c2c79;return this['processTick']({'contractId':_0x3cacf6['contractId']||_0x3cacf6['symbol'],'price':_0x3cacf6[_0x49c4c0(0x13e)],'volume':_0x3cacf6[_0x49c4c0(0x1ab)]||_0x3cacf6[_0x49c4c0(0x165)]||0x1,'timestamp':_0x3cacf6[_0x49c4c0(0x184)]||Date[_0x49c4c0(0x199)]()});}[_0x3c2c79(0x133)](_0x35e484,_0x28439a){const _0x128f24=_0x3c2c79;let _0x3f7c59=this[_0x128f24(0x117)]['get'](_0x35e484);!_0x3f7c59&&(this[_0x128f24(0x16e)](_0x35e484),_0x3f7c59=this[_0x128f24(0x117)][_0x128f24(0x14d)](_0x35e484));_0x3f7c59['push'](_0x28439a);if(_0x3f7c59[_0x128f24(0x197)]>0x1f4)_0x3f7c59['shift']();const _0x328a5c=_0x3f7c59[_0x128f24(0x197)]-0x1;if(_0x3f7c59['length']<this['config'][_0x128f24(0x148)]['lookbackBars']*0x3)return null;const _0x5b9c9b=this[_0x128f24(0x17e)]['get'](_0x35e484)['length'];this['_detectSwings'](_0x35e484,_0x3f7c59,_0x328a5c);const _0x517b49=this['swingPoints'][_0x128f24(0x14d)](_0x35e484);if(_0x517b49[_0x128f24(0x197)]>_0x5b9c9b){const _0x3cbed6=_0x517b49[_0x517b49['length']-0x1];this['emit'](_0x128f24(0x1ad),{'type':_0x128f24(0x177),'message':'[2B]\x20NEW\x20SWING\x20'+_0x3cbed6['type'][_0x128f24(0x15a)]()+'\x20@\x20'+_0x3cbed6[_0x128f24(0x13e)]['toFixed'](0x2)+_0x128f24(0x19d)+_0x517b49['length']});}const _0x1f5273=this[_0x128f24(0x11a)](_0x35e484,_0x3f7c59,_0x328a5c);_0x1f5273&&this['emit'](_0x128f24(0x1ad),{'type':_0x128f24(0x177),'message':_0x128f24(0x1a0)+_0x1f5273['sweepType']+'\x20|\x20Valid:\x20'+_0x1f5273[_0x128f24(0x1a1)]+'\x20|\x20Pen:\x20'+_0x1f5273['penetrationTicks'][_0x128f24(0x192)](0x1)+'t\x20|\x20Q:\x20'+(_0x1f5273[_0x128f24(0x1aa)]*0x64)[_0x128f24(0x192)](0x0)+'%'});const _0x547e4f=this['liquidityZones']['get'](_0x35e484)[_0x128f24(0x197)];this[_0x128f24(0x164)](_0x35e484,_0x328a5c);const _0x6a3c62=this['liquidityZones'][_0x128f24(0x14d)](_0x35e484);if(_0x6a3c62[_0x128f24(0x197)]>_0x547e4f){const _0x173ed7=_0x6a3c62[_0x6a3c62[_0x128f24(0x197)]-0x1];this['emit']('log',{'type':'debug','message':_0x128f24(0x17a)+_0x173ed7['type'][_0x128f24(0x15a)]()+_0x128f24(0x172)+_0x173ed7[_0x128f24(0x139)]()['toFixed'](0x2)+'\x20|\x20Total:\x20'+_0x6a3c62['length']});}if(_0x1f5273&&_0x1f5273[_0x128f24(0x1a1)]){this[_0x128f24(0x1a2)]('log',{'type':_0x128f24(0x177),'message':_0x128f24(0x129)+_0x1f5273[_0x128f24(0x185)]+'\x20sweep...'});const _0x170907=this[_0x128f24(0x14c)](_0x35e484,_0x28439a,_0x328a5c,_0x1f5273);return!_0x170907&&this['emit'](_0x128f24(0x1ad),{'type':'debug','message':_0x128f24(0x178)}),_0x170907;}return null;}[_0x3c2c79(0x183)](_0x53b086,_0xd2b83e,_0x2e4c6e){const _0x3d9adb=_0x3c2c79,_0x1d03d9=this[_0x3d9adb(0x128)][_0x3d9adb(0x148)]['lookbackBars'],_0x5aade9=this['config'][_0x3d9adb(0x148)]['minStrength'];if(_0x2e4c6e<_0x1d03d9*0x2)return;const _0x401dcd=this['swingPoints']['get'](_0x53b086),_0x2eb524=_0x2e4c6e-_0x1d03d9,_0x3876de=_0xd2b83e[_0x2eb524];let _0x8112a=!![],_0x33497c=0x0;for(let _0x2b97ec=_0x2eb524-_0x1d03d9;_0x2b97ec<=_0x2eb524+_0x1d03d9;_0x2b97ec++){if(_0x2b97ec===_0x2eb524||_0x2b97ec<0x0||_0x2b97ec>=_0xd2b83e['length'])continue;if(_0xd2b83e[_0x2b97ec][_0x3d9adb(0x176)]>=_0x3876de[_0x3d9adb(0x176)]){_0x8112a=![];break;}_0x33497c++;}if(_0x8112a&&_0x33497c>=_0x5aade9){const _0x896569=_0x401dcd[_0x3d9adb(0x14e)](_0x246a61=>_0x246a61[_0x3d9adb(0x195)]===_0x2eb524&&_0x246a61[_0x3d9adb(0x145)]===_0x3d9adb(0x176));!_0x896569&&_0x401dcd['push'](new SwingPoint(_0x3d9adb(0x176),_0x3876de[_0x3d9adb(0x176)],_0x2eb524,_0x3876de[_0x3d9adb(0x184)],_0x33497c));}let _0x1478c8=!![],_0x24cb3d=0x0;for(let _0x1cd509=_0x2eb524-_0x1d03d9;_0x1cd509<=_0x2eb524+_0x1d03d9;_0x1cd509++){if(_0x1cd509===_0x2eb524||_0x1cd509<0x0||_0x1cd509>=_0xd2b83e[_0x3d9adb(0x197)])continue;if(_0xd2b83e[_0x1cd509]['low']<=_0x3876de['low']){_0x1478c8=![];break;}_0x24cb3d++;}if(_0x1478c8&&_0x24cb3d>=_0x5aade9){const _0x5b749b=_0x401dcd[_0x3d9adb(0x14e)](_0x5685f3=>_0x5685f3[_0x3d9adb(0x195)]===_0x2eb524&&_0x5685f3['type']==='low');!_0x5b749b&&_0x401dcd[_0x3d9adb(0x120)](new SwingPoint(_0x3d9adb(0x191),_0x3876de['low'],_0x2eb524,_0x3876de[_0x3d9adb(0x184)],_0x24cb3d));}const _0x1eb0b7=this[_0x3d9adb(0x128)]['zone'][_0x3d9adb(0x12b)];while(_0x401dcd[_0x3d9adb(0x197)]>0x0&&_0x401dcd[0x0][_0x3d9adb(0x195)]<_0x2e4c6e-_0x1eb0b7){_0x401dcd[_0x3d9adb(0x135)]();}}[_0x3c2c79(0x164)](_0x2a7d5e,_0x4d04f6){const _0x35951b=_0x3c2c79,_0x465fe9=this[_0x35951b(0x17e)]['get'](_0x2a7d5e),_0x43d9b2=this['liquidityZones'][_0x35951b(0x14d)](_0x2a7d5e),_0x16aa39=this['config']['zone'][_0x35951b(0x19e)]*this[_0x35951b(0x17b)],_0x387e8b=this[_0x35951b(0x128)][_0x35951b(0x16f)][_0x35951b(0x12b)];for(let _0x1af409=_0x43d9b2['length']-0x1;_0x1af409>=0x0;_0x1af409--){_0x4d04f6-_0x43d9b2[_0x1af409][_0x35951b(0x195)]>_0x387e8b&&_0x43d9b2[_0x35951b(0x12c)](_0x1af409,0x1);}for(const _0x2a73ac of _0x465fe9){let _0x2a8b30=null;for(const _0x5500dc of _0x43d9b2){if(_0x5500dc['containsPrice'](_0x2a73ac[_0x35951b(0x13e)],this['config'][_0x35951b(0x16f)][_0x35951b(0x19e)],this[_0x35951b(0x17b)])){_0x2a8b30=_0x5500dc;break;}}if(_0x2a8b30){_0x2a8b30['touches']++;if(_0x2a73ac[_0x35951b(0x13e)]>_0x2a8b30['priceHigh'])_0x2a8b30['priceHigh']=_0x2a73ac['price'];if(_0x2a73ac['price']<_0x2a8b30['priceLow'])_0x2a8b30[_0x35951b(0x11b)]=_0x2a73ac[_0x35951b(0x13e)];_0x2a8b30['qualityScore']=Math['min'](0x1,0.3+_0x2a8b30['touches']*0.15);}else{const _0x299f07=_0x2a73ac['type']===_0x35951b(0x176)?ZoneType['RESISTANCE']:ZoneType['SUPPORT'],_0x343645=new LiquidityZone(_0x299f07,_0x2a73ac[_0x35951b(0x13e)]+_0x16aa39/0x2,_0x2a73ac[_0x35951b(0x13e)]-_0x16aa39/0x2,_0x2a73ac['timestamp'],_0x2a73ac[_0x35951b(0x195)]);_0x343645[_0x35951b(0x1aa)]=0.3+_0x2a73ac['strength']*0.1,_0x43d9b2[_0x35951b(0x120)](_0x343645);}}}['_detectSweep'](_0x25ee86,_0x146c82,_0x5af283){const _0x10aa22=_0x3c2c79,_0x1efb0b=this[_0x10aa22(0x13b)]['get'](_0x25ee86),_0x439ded=_0x146c82[_0x5af283],_0x2753b3=_0x439ded[_0x10aa22(0x1ac)],_0x1a7494=this['config']['sweep'],_0x3b34dc=this['config'][_0x10aa22(0x16f)];for(const _0x2c9257 of _0x1efb0b){if(_0x2c9257['lastUsedBarIndex']>=0x0&&_0x5af283-_0x2c9257[_0x10aa22(0x175)]<_0x3b34dc[_0x10aa22(0x19a)])continue;const _0x448ff6=_0x2c9257[_0x10aa22(0x139)](),_0x505f83=Math['abs'](_0x2753b3-_0x448ff6)/this[_0x10aa22(0x17b)];if(_0x505f83>_0x3b34dc['maxZoneDistanceTicks'])continue;const _0x130a81=Math[_0x10aa22(0x126)](0x0,_0x5af283-_0x1a7494[_0x10aa22(0x12d)]*0x2);for(let _0x1fe75e=_0x130a81;_0x1fe75e<_0x5af283;_0x1fe75e++){const _0x21823b=_0x146c82[_0x1fe75e];if(_0x2c9257['type']===ZoneType[_0x10aa22(0x12e)]){const _0x13df06=(_0x21823b['high']-_0x2c9257['priceHigh'])/this['tickSize'];if(_0x13df06>=_0x1a7494[_0x10aa22(0x16d)]&&_0x13df06<=_0x1a7494[_0x10aa22(0x116)]){const _0x307fae=Math[_0x10aa22(0x181)](_0x2c9257['priceHigh'],_0x2c9257[_0x10aa22(0x1a4)]+_0x13df06*this['tickSize']);if(_0x2753b3<_0x307fae+this[_0x10aa22(0x17b)]*0x2){const _0x128da3=_0x21823b[_0x10aa22(0x176)]-_0x21823b['low'],_0x14d4bf=Math['abs'](_0x21823b['close']-_0x21823b['open']),_0x5eefa3=_0x128da3>0x0?_0x14d4bf/_0x128da3:0x0;if(_0x5eefa3>=_0x1a7494['minBodyRatio']){const _0x4d188b=this[_0x10aa22(0x122)](_0x146c82,_0x1fe75e,0x14);if(_0x4d188b>=_0x1a7494[_0x10aa22(0x18f)]){const _0x759152=new SweepEvent(SweepType[_0x10aa22(0x11f)],_0x2c9257,_0x1fe75e,_0x1fe75e,_0x21823b[_0x10aa22(0x176)]);_0x759152[_0x10aa22(0x131)]=_0x5af283,_0x759152['penetrationTicks']=_0x13df06,_0x759152[_0x10aa22(0x13c)]=_0x5af283-_0x1fe75e,_0x759152['volumeRatio']=_0x4d188b,_0x759152['qualityScore']=this['_scoreSweep'](_0x759152,_0x5eefa3),_0x759152['isValid']=_0x759152[_0x10aa22(0x1aa)]>=_0x1a7494[_0x10aa22(0x149)];if(_0x759152['isValid'])return _0x759152;}}}}}if(_0x2c9257['type']===ZoneType[_0x10aa22(0x196)]){const _0x45ac67=(_0x2c9257['priceLow']-_0x21823b['low'])/this[_0x10aa22(0x17b)];if(_0x45ac67>=_0x1a7494[_0x10aa22(0x16d)]&&_0x45ac67<=_0x1a7494[_0x10aa22(0x116)]){const _0x19ee56=Math['max'](_0x2c9257[_0x10aa22(0x11b)],_0x2c9257['priceLow']-_0x45ac67*this[_0x10aa22(0x17b)]);if(_0x2753b3>_0x19ee56-this[_0x10aa22(0x17b)]*0x2){const _0x281d8b=_0x21823b['high']-_0x21823b['low'],_0xc92c37=Math[_0x10aa22(0x167)](_0x21823b['close']-_0x21823b[_0x10aa22(0x123)]),_0xbc603c=_0x281d8b>0x0?_0xc92c37/_0x281d8b:0x0;if(_0xbc603c>=_0x1a7494['minBodyRatio']){const _0x367213=this['_getVolumeRatio'](_0x146c82,_0x1fe75e,0x14);if(_0x367213>=_0x1a7494['minVolumeRatio']){const _0x3a2885=new SweepEvent(SweepType['LOW_SWEEP'],_0x2c9257,_0x1fe75e,_0x1fe75e,_0x21823b[_0x10aa22(0x191)]);_0x3a2885['exitBarIndex']=_0x5af283,_0x3a2885['penetrationTicks']=_0x45ac67,_0x3a2885['durationBars']=_0x5af283-_0x1fe75e,_0x3a2885['volumeRatio']=_0x367213,_0x3a2885['qualityScore']=this['_scoreSweep'](_0x3a2885,_0xbc603c),_0x3a2885['isValid']=_0x3a2885[_0x10aa22(0x1aa)]>=_0x1a7494[_0x10aa22(0x149)];if(_0x3a2885['isValid'])return _0x3a2885;}}}}}}}return null;}[_0x3c2c79(0x122)](_0x6fb17f,_0x1ceb64,_0x4fb291){const _0x3707b1=_0x3c2c79,_0x264191=Math[_0x3707b1(0x126)](0x0,_0x1ceb64-_0x4fb291),_0x202d8f=_0x6fb17f['slice'](_0x264191,_0x1ceb64);if(_0x202d8f['length']===0x0)return 0x1;const _0x33ba18=_0x202d8f['map'](_0x35f097=>_0x35f097[_0x3707b1(0x165)])['sort']((_0x5e80e2,_0x4ba738)=>_0x5e80e2-_0x4ba738),_0x522d9a=Math[_0x3707b1(0x11e)](_0x33ba18[_0x3707b1(0x197)]/0x2),_0x214fb5=_0x33ba18[_0x522d9a]||0x1;return _0x6fb17f[_0x1ceb64]['volume']/_0x214fb5;}['_scoreSweep'](_0x4669c0,_0x439bcc){const _0x57063=_0x3c2c79;let _0x18b656=0x0;const _0x426427=0x4,_0x12f3fa=Math[_0x57063(0x167)](_0x4669c0['penetrationTicks']-_0x426427);return _0x18b656+=Math['max'](0x0,0.3-_0x12f3fa*0.03),_0x18b656+=Math[_0x57063(0x126)](0x0,0.25-_0x4669c0[_0x57063(0x13c)]*0.05),_0x18b656+=Math['min'](0.25,_0x4669c0['volumeRatio']*0.1),_0x18b656+=Math['min'](0.2,_0x439bcc*0.4),Math[_0x57063(0x181)](0x1,_0x18b656);}['_generateSignal'](_0x46a390,_0x8b7857,_0x5e7564,_0x10cf4b){const _0x12e294=_0x3c2c79,_0xb0e6cf=Date[_0x12e294(0x199)]()-this['lastSignalTime'];if(_0xb0e6cf<this[_0x12e294(0x128)]['execution'][_0x12e294(0x159)])return this['emit'](_0x12e294(0x1ad),{'type':'debug','message':'[2B]\x20Signal\x20blocked\x20by\x20cooldown\x20('+(_0xb0e6cf/0x3e8)['toFixed'](0x1)+_0x12e294(0x182)+this['config'][_0x12e294(0x18e)][_0x12e294(0x159)]/0x3e8+'s)'}),null;const _0x3a38ce=this[_0x12e294(0x128)]['execution'],_0x1487ea=_0x8b7857['close'],_0x3d7861=_0x10cf4b['sweepType']===SweepType['HIGH_SWEEP']?_0x12e294(0x169):'long';let _0x38c2c8,_0x331476,_0x159785,_0x3ae0d9;_0x3d7861==='long'?(_0x38c2c8=_0x1487ea-_0x3a38ce['stopTicks']*this[_0x12e294(0x17b)],_0x331476=_0x1487ea+_0x3a38ce[_0x12e294(0x115)]*this[_0x12e294(0x17b)],_0x159785=_0x1487ea+_0x3a38ce['breakevenTicks']*this['tickSize'],_0x3ae0d9=_0x1487ea+_0x3a38ce['trailTriggerTicks']*this['tickSize']):(_0x38c2c8=_0x1487ea+_0x3a38ce[_0x12e294(0x17d)]*this[_0x12e294(0x17b)],_0x331476=_0x1487ea-_0x3a38ce['targetTicks']*this['tickSize'],_0x159785=_0x1487ea-_0x3a38ce['breakevenTicks']*this['tickSize'],_0x3ae0d9=_0x1487ea-_0x3a38ce['trailTriggerTicks']*this['tickSize']);const _0x5ca101=_0x3a38ce['targetTicks']/_0x3a38ce[_0x12e294(0x17d)],_0x280928=Math[_0x12e294(0x181)](0x1,_0x10cf4b[_0x12e294(0x1aa)]*0.5+_0x10cf4b[_0x12e294(0x16f)][_0x12e294(0x1aa)]*0.3+(_0x10cf4b[_0x12e294(0x194)]>1.5?0.2:_0x10cf4b['volumeRatio']*0.1));let _0x511247=SignalStrength[_0x12e294(0x168)];if(_0x280928>=0.8)_0x511247=SignalStrength['VERY_STRONG'];else{if(_0x280928>=0.65)_0x511247=SignalStrength[_0x12e294(0x154)];else{if(_0x280928<0.5)_0x511247=SignalStrength[_0x12e294(0x146)];}}const _0x444401=0.5+(_0x280928-0.5)*0.4,_0x486bba=_0x444401*Math[_0x12e294(0x167)](_0x331476-_0x1487ea)-(0x1-_0x444401)*Math[_0x12e294(0x167)](_0x1487ea-_0x38c2c8);_0x10cf4b[_0x12e294(0x16f)]['lastUsedBarIndex']=_0x5e7564,_0x10cf4b[_0x12e294(0x16f)][_0x12e294(0x171)]=!![],_0x10cf4b['zone'][_0x12e294(0x160)]=new Date(_0x8b7857[_0x12e294(0x184)]),this['lastSignalTime']=Date['now'](),this[_0x12e294(0x193)]['signals']++;const _0xff5c2b={'id':uuidv4(),'timestamp':Date[_0x12e294(0x199)](),'symbol':_0x46a390[_0x12e294(0x114)]('.')[0x0]||_0x46a390,'contractId':_0x46a390,'side':_0x3d7861==='long'?OrderSide[_0x12e294(0x13d)]:OrderSide['ASK'],'direction':_0x3d7861,'strategy':_0x12e294(0x15c),'strength':_0x511247,'edge':_0x486bba,'confidence':_0x280928,'entry':_0x1487ea,'entryPrice':_0x1487ea,'stopLoss':_0x38c2c8,'takeProfit':_0x331476,'riskReward':_0x5ca101,'stopTicks':_0x3a38ce[_0x12e294(0x17d)],'targetTicks':_0x3a38ce['targetTicks'],'breakevenTicks':_0x3a38ce[_0x12e294(0x1a3)],'trailTriggerTicks':_0x3a38ce[_0x12e294(0x13a)],'trailDistanceTicks':_0x3a38ce[_0x12e294(0x161)],'beLevel':_0x159785,'trailTrigger':_0x3ae0d9,'sweepType':_0x10cf4b[_0x12e294(0x185)],'penetrationTicks':_0x10cf4b[_0x12e294(0x18c)],'sweepDurationBars':_0x10cf4b['durationBars'],'sweepQuality':_0x10cf4b['qualityScore'],'volumeRatio':_0x10cf4b[_0x12e294(0x194)],'zoneType':_0x10cf4b['zone']['type'],'zoneLevel':_0x10cf4b['zone'][_0x12e294(0x139)](),'zoneTouches':_0x10cf4b[_0x12e294(0x16f)][_0x12e294(0x155)],'zoneQuality':_0x10cf4b['zone'][_0x12e294(0x1aa)],'expires':Date['now']()+0xea60};return this['emit'](_0x12e294(0x121),{'side':_0x3d7861===_0x12e294(0x1a8)?_0x12e294(0x151):'sell','action':_0x12e294(0x123),'reason':'2B\x20'+_0x10cf4b['sweepType']+_0x12e294(0x130)+_0x10cf4b['penetrationTicks']['toFixed'](0x1)+'t\x20|\x20Vol:'+_0x10cf4b['volumeRatio']['toFixed'](0x1)+_0x12e294(0x198)+(_0x10cf4b['qualityScore']*0x64)[_0x12e294(0x192)](0x0)+'%',..._0xff5c2b}),this['emit'](_0x12e294(0x1ad),{'type':_0x12e294(0x187),'message':'[HQX-2B]\x20SIGNAL:\x20'+_0x3d7861[_0x12e294(0x15a)]()+_0x12e294(0x172)+_0x1487ea['toFixed'](0x2)+_0x12e294(0x127)+_0x10cf4b['sweepType']+_0x12e294(0x130)+_0x10cf4b['penetrationTicks'][_0x12e294(0x192)](0x1)+'t\x20Vol:'+_0x10cf4b[_0x12e294(0x194)]['toFixed'](0x1)+'x\x20|\x20Conf:'+(_0x280928*0x64)['toFixed'](0x0)+'%'}),_0xff5c2b;}[_0x3c2c79(0x17f)](_0x148f90,_0x38363f){const _0x5cdd8f=_0x3c2c79,_0x44cbcc=this[_0x5cdd8f(0x117)][_0x5cdd8f(0x14d)](_0x148f90)||[],_0x7c10e7=this[_0x5cdd8f(0x13b)]['get'](_0x148f90)||[],_0x25dd0c=this[_0x5cdd8f(0x17e)][_0x5cdd8f(0x14d)](_0x148f90)||[];if(_0x44cbcc[_0x5cdd8f(0x197)]<0x5)return{'ready':![],'message':_0x5cdd8f(0x16c)+_0x44cbcc[_0x5cdd8f(0x197)]+_0x5cdd8f(0x124)};const _0x2ff932=_0x7c10e7[_0x5cdd8f(0x18d)](_0x4d7d2a=>({'zone':_0x4d7d2a,'distance':Math['abs'](_0x38363f-_0x4d7d2a[_0x5cdd8f(0x139)]())}))[_0x5cdd8f(0x190)]((_0x19f3d4,_0x2b6c91)=>_0x19f3d4['distance']-_0x2b6c91[_0x5cdd8f(0x152)]),_0xacfc44=_0x2ff932[_0x5cdd8f(0x14e)](_0x17a28d=>_0x17a28d[_0x5cdd8f(0x16f)][_0x5cdd8f(0x145)]===ZoneType['RESISTANCE']),_0x34cc80=_0x2ff932[_0x5cdd8f(0x14e)](_0x203c43=>_0x203c43['zone'][_0x5cdd8f(0x145)]===ZoneType['SUPPORT']);return{'ready':!![],'barsProcessed':_0x44cbcc[_0x5cdd8f(0x197)],'swingsDetected':_0x25dd0c[_0x5cdd8f(0x197)],'activeZones':_0x7c10e7['length'],'nearestResistance':_0xacfc44?_0xacfc44[_0x5cdd8f(0x16f)]['getLevel']():null,'nearestSupport':_0x34cc80?_0x34cc80['zone']['getLevel']():null,'stopTicks':this[_0x5cdd8f(0x128)][_0x5cdd8f(0x18e)][_0x5cdd8f(0x17d)],'targetTicks':this[_0x5cdd8f(0x128)]['execution'][_0x5cdd8f(0x115)],'strategy':_0x5cdd8f(0x156)};}[_0x3c2c79(0x173)](_0x41d059){const _0xc6178f=_0x3c2c79;this[_0xc6178f(0x15b)][_0xc6178f(0x120)]({'netPnl':_0x41d059,'timestamp':Date['now']()});if(this['recentTrades']['length']>0x64)this['recentTrades'][_0xc6178f(0x135)]();_0x41d059>0x0?this['stats'][_0xc6178f(0x1a9)]++:this[_0xc6178f(0x193)]['losses']++,this['stats']['trades']++,this[_0xc6178f(0x193)]['pnl']+=_0x41d059,this['emit']('log',{'type':_0xc6178f(0x177),'message':'[HQX-2B]\x20Trade\x20result:\x20'+(_0x41d059>0x0?_0xc6178f(0x119):_0xc6178f(0x162))+'\x20$'+_0x41d059['toFixed'](0x2)});}['getBarHistory'](_0x24aeff){return this['barHistory']['get'](_0x24aeff)||[];}[_0x3c2c79(0x17c)](){return this['stats'];}[_0x3c2c79(0x18b)](_0x2af4f3){const _0x20a135=_0x3c2c79,_0xf3be6e=this[_0x20a135(0x117)]['get'](_0x2af4f3)||[],_0x20f361=this[_0x20a135(0x13b)][_0x20a135(0x14d)](_0x2af4f3)||[],_0x4a2ef7=this['swingPoints']['get'](_0x2af4f3)||[],_0x53eda4=this['currentBar'][_0x20a135(0x14d)](_0x2af4f3),_0x1bf284=_0xf3be6e[_0xf3be6e['length']-0x1],_0x2d0b8d=_0x1bf284?Date['now']()-_0x1bf284['timestamp']:null,_0x1c22ed=_0x20f361[_0x20a135(0x11c)](_0x138bfa=>_0x138bfa['type']===ZoneType['RESISTANCE'])['length'],_0x2a363f=_0x20f361['filter'](_0x5d761c=>_0x5d761c['type']===ZoneType['SUPPORT'])['length'];return{'healthy':_0xf3be6e[_0x20a135(0x197)]>=0x5,'barsTotal':_0xf3be6e['length'],'barsLast5Min':_0xf3be6e[_0x20a135(0x11c)](_0x5aca2d=>Date['now']()-_0x5aca2d['timestamp']<0x5*0x3c*0x3e8)['length'],'swingsTotal':_0x4a2ef7[_0x20a135(0x197)],'zonesResistance':_0x1c22ed,'zonesSupport':_0x2a363f,'zonesTotal':_0x20f361['length'],'currentBarTicks':_0x53eda4?_0x53eda4[_0x20a135(0x134)]:0x0,'isAggregating':_0x53eda4&&_0x53eda4[_0x20a135(0x134)]>0x0,'timeSinceLastBarMs':_0x2d0b8d,'lastSignalTime':this[_0x20a135(0x150)],'signalCooldownMs':this[_0x20a135(0x128)][_0x20a135(0x18e)]['cooldownMs'],'uptime':Date['now']()-(this['startTime']||Date['now']())};}['reset'](_0x204b27){const _0x2fe758=_0x3c2c79;this[_0x2fe758(0x117)][_0x2fe758(0x19f)](_0x204b27,[]),this[_0x2fe758(0x17e)]['set'](_0x204b27,[]),this[_0x2fe758(0x13b)]['set'](_0x204b27,[]),this[_0x2fe758(0x158)]['set'](_0x204b27,[]),this[_0x2fe758(0x13f)][_0x2fe758(0x188)](_0x204b27),this[_0x2fe758(0x1a2)](_0x2fe758(0x1ad),{'type':'info','message':'[HQX-2B]\x20Reset\x20state\x20for\x20'+_0x204b27});}['preloadBars'](_0x51174e,_0x50d3c4){const _0x1702ad=_0x3c2c79;if(!_0x50d3c4||_0x50d3c4['length']===0x0){this[_0x1702ad(0x1a2)](_0x1702ad(0x1ad),{'type':'debug','message':'[HQX-2B]\x20No\x20historical\x20bars\x20to\x20preload'});return;}!this[_0x1702ad(0x117)][_0x1702ad(0x1ae)](_0x51174e)&&this['initialize'](_0x51174e);const _0x26b1bc=[..._0x50d3c4]['sort']((_0x49cef0,_0x440a6f)=>_0x49cef0[_0x1702ad(0x184)]-_0x440a6f['timestamp']);this['emit']('log',{'type':'info','message':'[HQX-2B]\x20Preloading\x20'+_0x26b1bc[_0x1702ad(0x197)]+_0x1702ad(0x141)});let _0x46099c=0x0;for(const _0x6a6972 of _0x26b1bc){const _0x2d6015=this[_0x1702ad(0x133)](_0x51174e,_0x6a6972);if(_0x2d6015)_0x46099c++;}const _0x3bdbdc=this['barHistory'][_0x1702ad(0x14d)](_0x51174e)||[],_0x6235e9=this[_0x1702ad(0x17e)]['get'](_0x51174e)||[],_0x3c280b=this[_0x1702ad(0x13b)][_0x1702ad(0x14d)](_0x51174e)||[];this[_0x1702ad(0x1a2)]('log',{'type':'info','message':_0x1702ad(0x19b)+_0x3bdbdc[_0x1702ad(0x197)]+'\x20bars,\x20'+_0x6235e9[_0x1702ad(0x197)]+'\x20swings,\x20'+_0x3c280b[_0x1702ad(0x197)]+'\x20zones'}),_0x46099c>0x0&&this['emit']('log',{'type':'debug','message':'[HQX-2B]\x20'+_0x46099c+_0x1702ad(0x138)}),this[_0x1702ad(0x150)]=0x0;}}function _0x3286(_0x3044e3,_0x56310f){_0x3044e3=_0x3044e3-0x114;const _0x230694=_0x2306();let _0x32866b=_0x230694[_0x3044e3];return _0x32866b;}class HQX2BStrategy extends EventEmitter{constructor(_0x300ae8={}){const _0x5c848d=_0x3c2c79;super(),this[_0x5c848d(0x128)]=_0x300ae8,this[_0x5c848d(0x18a)]=new HQX2BLiquiditySweep(_0x300ae8),this['strategy']['on'](_0x5c848d(0x121),_0x570bcb=>this[_0x5c848d(0x1a2)]('signal',_0x570bcb)),this['strategy']['on'](_0x5c848d(0x1ad),_0x71898a=>this['emit']('log',_0x71898a));}['processTick'](_0x174544){const _0x302f2b=_0x3c2c79;return this[_0x302f2b(0x18a)][_0x302f2b(0x189)](_0x174544);}[_0x3c2c79(0x144)](_0x5c7d9c){const _0x4274bc=_0x3c2c79;return this[_0x4274bc(0x18a)]['onTick'](_0x5c7d9c);}[_0x3c2c79(0x143)](_0x163ba0){const _0x4f4246=_0x3c2c79;return this['strategy'][_0x4f4246(0x143)](_0x163ba0);}['processBar'](_0x1f5bd9,_0x2629d3){return this['strategy']['processBar'](_0x1f5bd9,_0x2629d3);}['initialize'](_0x3d64ff,_0x47305d,_0x604d79){return this['strategy']['initialize'](_0x3d64ff,_0x47305d,_0x604d79);}['getAnalysisState'](_0x5d93d8,_0x5dfcfb){const _0x2ba36d=_0x3c2c79;return this[_0x2ba36d(0x18a)]['getAnalysisState'](_0x5d93d8,_0x5dfcfb);}['recordTradeResult'](_0x3c2dc1){const _0x2cdbd6=_0x3c2c79;return this[_0x2cdbd6(0x18a)]['recordTradeResult'](_0x3c2dc1);}[_0x3c2c79(0x19c)](_0x411477){return this['strategy']['reset'](_0x411477);}['getStats'](){const _0x121bfc=_0x3c2c79;return this[_0x121bfc(0x18a)][_0x121bfc(0x17c)]();}[_0x3c2c79(0x186)](_0x3a9ae0){const _0x683ede=_0x3c2c79;return this[_0x683ede(0x18a)]['getBarHistory'](_0x3a9ae0);}[_0x3c2c79(0x132)](_0x477061,_0x5a6c68){return this['strategy']['preloadBars'](_0x477061,_0x5a6c68);}[_0x3c2c79(0x18b)](_0x450f8e){const _0x2af21b=_0x3c2c79;return this[_0x2af21b(0x18a)]['getHealthStatus'](_0x450f8e);}[_0x3c2c79(0x14a)](_0x4b30fc){return null;}}module[_0x3c2c79(0x15d)]={'HQX2BLiquiditySweep':HQX2BLiquiditySweep,'HQX2BStrategy':HQX2BStrategy,'M2':HQX2BStrategy,'S2':HQX2BLiquiditySweep,'OrderSide':OrderSide,'SignalStrength':SignalStrength,'SweepType':SweepType,'ZoneType':ZoneType,'DEFAULT_CONFIG':DEFAULT_CONFIG};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x41bd06=_0x21ae;function _0x48c5(){const _0x4e7db3=['long','_detectVolatilityRegime','vpinWindow','%,\x20OFI=','now','stats','length','strategy','priceBuffer','\x20VPIN:','ofi','WEAK','29230JdVFhQ',':\x20tick=','_calculateATR','653050yfbkEs','%,\x20cf=','emit','lossStreak','HQX_ULTRA_SCALPING_6MODELS','processBar','\x20Regime:','atrHistory','generateSignal','_computeZScore','pow','%\x20OFI:','low','set','losses','tickValue','getAnalysisState','847654bhGkfI','volatility','830992sveCRR','cooldownMs','filter','uuid','kyleLambda','normal','max','get','ofiLookback','getBarHistory','barHistory','events','min','318vNYpgx','winStreak','_computeOrderFlowImbalance','kalmanProcessNoise','tickSize','buy','kalmanMeasurementNoise','debug','_computeKyleLambda','volatilityLookback','pnl','3TtRwMa','getModelValues','slice','onTick','vpinToxicThreshold','breakevenTicks','3481356HPcOmZ','initialize','signals','profitLockPct','estimate',',\x20streak:\x20','onTrade','volume','ASK','baseStopTicks','close','toUpperCase','round','/50\x20bars','zscoreExitThreshold','sqrt','minHoldTimeMs','abs','push','recentTrades','_generateSignal','_computeVPIN','zscore','602415QhKgfm','log','lastSignalTime','shift','short','targetMultiplier','info','63nQYXIt','BID','reset','%\x20Kyle:','processTick','baseTargetTicks','1233701TQsHgu','minConfidence','sell','weights','kalmanStates','getStats','vpin','volumeBuffer','6\x20(Z-Score,\x20VPIN,\x20Kyle,\x20Kalman,\x20Vol,\x20OFI)','70xddyGO','stopMultiplier','[HQX-UltraScalping]\x206\x20Models:\x20Z-Score(30%),\x20OFI(20%),\x20VPIN(15%),\x20Kalman(15%),\x20Kyle(10%),\x20Vol(10%)','signal','price','recordTradeResult','high','toFixed','reduce','shouldExitByZScore'];_0x48c5=function(){return _0x4e7db3;};return _0x48c5();}(function(_0x480416,_0x3fd8aa){const _0x266074=_0x21ae,_0x2c9339=_0x480416();while(!![]){try{const _0xaa1fe9=parseInt(_0x266074(0x237))/0x1+parseInt(_0x266074(0x226))/0x2+parseInt(_0x266074(0x1da))/0x3*(-parseInt(_0x266074(0x1e0))/0x4)+parseInt(_0x266074(0x223))/0x5*(parseInt(_0x266074(0x246))/0x6)+parseInt(_0x266074(0x204))/0x7+-parseInt(_0x266074(0x239))/0x8*(parseInt(_0x266074(0x1fe))/0x9)+parseInt(_0x266074(0x20d))/0xa*(parseInt(_0x266074(0x1f7))/0xb);if(_0xaa1fe9===_0x3fd8aa)break;else _0x2c9339['push'](_0x2c9339['shift']());}catch(_0x447511){_0x2c9339['push'](_0x2c9339['shift']());}}}(_0x48c5,0x6cece));function _0x21ae(_0x5c39c9,_0x5cd376){_0x5c39c9=_0x5c39c9-0x1da;const _0x48c5f1=_0x48c5();let _0x21ae40=_0x48c5f1[_0x5c39c9];return _0x21ae40;}const EventEmitter=require(_0x41bd06(0x244)),{v4:uuidv4}=require(_0x41bd06(0x23c)),OrderSide={'BID':0x0,'ASK':0x1},SignalStrength={'WEAK':0x1,'MODERATE':0x2,'STRONG':0x3,'VERY_STRONG':0x4};class HQXUltraScalping extends EventEmitter{constructor(_0x6c8c3b={}){const _0x5621ad=_0x41bd06;super(),this[_0x5621ad(0x24a)]=_0x6c8c3b[_0x5621ad(0x24a)]||0.25,this[_0x5621ad(0x235)]=_0x6c8c3b['tickValue']||0x5,this['zscoreEntryThreshold']=1.5,this[_0x5621ad(0x1ee)]=0.5,this[_0x5621ad(0x219)]=0x32,this[_0x5621ad(0x1de)]=0.7,this[_0x5621ad(0x249)]=0.01,this[_0x5621ad(0x24c)]=0.1,this[_0x5621ad(0x24f)]=0x64,this[_0x5621ad(0x241)]=0x14,this['baseStopTicks']=0x8,this[_0x5621ad(0x203)]=0x10,this[_0x5621ad(0x1df)]=0x4,this['profitLockPct']=0.5,this[_0x5621ad(0x205)]=0.55,this[_0x5621ad(0x207)]={'zscore':0.3,'ofi':0.2,'vpin':0.15,'kalman':0.15,'kyleLambda':0.1,'volatility':0.1},this[_0x5621ad(0x243)]=new Map(),this[_0x5621ad(0x21f)]=new Map(),this['volumeBuffer']=new Map(),this['kalmanStates']=new Map(),this['atrHistory']=new Map(),this[_0x5621ad(0x1f3)]=[],this[_0x5621ad(0x247)]=0x0,this[_0x5621ad(0x229)]=0x0,this['lastSignalTime']=0x0,this['cooldownMs']=0x7530,this[_0x5621ad(0x1f0)]=0x2710,this[_0x5621ad(0x21c)]={'signals':0x0,'trades':0x0,'wins':0x0,'losses':0x0,'pnl':0x0};}[_0x41bd06(0x1e1)](_0x5af076,_0xe0de06=0.25,_0x5cac00=0x5){const _0x3556fe=_0x41bd06;this['tickSize']=_0xe0de06,this['tickValue']=_0x5cac00,this[_0x3556fe(0x243)]['set'](_0x5af076,[]),this['priceBuffer']['set'](_0x5af076,[]),this[_0x3556fe(0x20b)][_0x3556fe(0x233)](_0x5af076,[]),this[_0x3556fe(0x22d)]['set'](_0x5af076,[]),this['kalmanStates'][_0x3556fe(0x233)](_0x5af076,{'estimate':0x0,'errorCovariance':0x1}),this[_0x3556fe(0x228)](_0x3556fe(0x1f8),{'type':_0x3556fe(0x1fd),'message':'[HQX-UltraScalping]\x20Initialized\x20for\x20'+_0x5af076+_0x3556fe(0x224)+_0xe0de06+',\x20value='+_0x5cac00}),this[_0x3556fe(0x228)]('log',{'type':'info','message':_0x3556fe(0x20f)});}['processTick'](_0x336dd6){const {contractId:_0x4dca7a,price:_0xa81acf,volume:_0x133943,side:_0x254c22,timestamp:_0x324485}=_0x336dd6,_0x4ec5c6={'timestamp':_0x324485||Date['now'](),'open':_0xa81acf,'high':_0xa81acf,'low':_0xa81acf,'close':_0xa81acf,'volume':_0x133943||0x1};return this['processBar'](_0x4dca7a,_0x4ec5c6);}[_0x41bd06(0x1dd)](_0x5abc9a){return this['processTick'](_0x5abc9a);}[_0x41bd06(0x1e6)](_0x5cee6b){const _0x4c33e8=_0x41bd06;return this[_0x4c33e8(0x202)]({'contractId':_0x5cee6b['contractId']||_0x5cee6b['symbol'],'price':_0x5cee6b[_0x4c33e8(0x211)],'volume':_0x5cee6b['size']||_0x5cee6b[_0x4c33e8(0x1e7)]||0x1,'side':_0x5cee6b['side'],'timestamp':_0x5cee6b['timestamp']||Date['now']()});}['processBar'](_0x38be87,_0x450a59){const _0x1e07d3=_0x41bd06;let _0x36823a=this[_0x1e07d3(0x243)]['get'](_0x38be87);!_0x36823a&&(this['initialize'](_0x38be87),_0x36823a=this['barHistory'][_0x1e07d3(0x240)](_0x38be87));_0x36823a['push'](_0x450a59);if(_0x36823a[_0x1e07d3(0x21d)]>0x1f4)_0x36823a['shift']();const _0x20d723=this[_0x1e07d3(0x21f)][_0x1e07d3(0x240)](_0x38be87);_0x20d723['push'](_0x450a59[_0x1e07d3(0x1ea)]);if(_0x20d723[_0x1e07d3(0x21d)]>0xc8)_0x20d723['shift']();const _0x45e512=this[_0x1e07d3(0x20b)]['get'](_0x38be87),_0xdf1df3=_0x450a59[_0x1e07d3(0x213)]-_0x450a59['low'];let _0x26b127=_0x450a59[_0x1e07d3(0x1e7)]*0.5,_0x1aa31d=_0x450a59['volume']*0.5;if(_0xdf1df3>0x0){const _0x24e867=(_0x450a59['close']-_0x450a59[_0x1e07d3(0x232)])/_0xdf1df3;_0x26b127=_0x450a59[_0x1e07d3(0x1e7)]*_0x24e867,_0x1aa31d=_0x450a59['volume']*(0x1-_0x24e867);}_0x45e512[_0x1e07d3(0x1f2)]({'buy':_0x26b127,'sell':_0x1aa31d});if(_0x45e512['length']>0x64)_0x45e512[_0x1e07d3(0x1fa)]();if(_0x36823a[_0x1e07d3(0x21d)]<0x32)return null;const _0x1190a7=this[_0x1e07d3(0x22f)](_0x20d723),_0x145a48=this[_0x1e07d3(0x1f5)](_0x45e512),_0x51483c=this['_computeKyleLambda'](_0x36823a),_0x4b252d=this['_applyKalmanFilter'](_0x38be87,_0x450a59['close']),{regime:_0x4ad27f,params:_0x4a5cc1}=this['_detectVolatilityRegime'](_0x38be87,_0x36823a),_0x40c0e2=this['_computeOrderFlowImbalance'](_0x36823a);return this['_generateSignal'](_0x38be87,_0x450a59['close'],_0x1190a7,_0x145a48,_0x51483c,_0x4b252d,_0x4ad27f,_0x4a5cc1,_0x40c0e2,_0x36823a);}[_0x41bd06(0x22f)](_0x3fb1ea,_0x4171de=0x32){const _0x1f9557=_0x41bd06;if(_0x3fb1ea[_0x1f9557(0x21d)]<_0x4171de)return 0x0;const _0x3d41d9=_0x3fb1ea['slice'](-_0x4171de),_0x51b52d=_0x3d41d9[_0x1f9557(0x215)]((_0x178b50,_0x257fb1)=>_0x178b50+_0x257fb1,0x0)/_0x4171de,_0x43b8ff=_0x3d41d9[_0x1f9557(0x215)]((_0x32c984,_0x303dea)=>_0x32c984+Math[_0x1f9557(0x230)](_0x303dea-_0x51b52d,0x2),0x0)/_0x4171de,_0x561f07=Math[_0x1f9557(0x1ef)](_0x43b8ff);if(_0x561f07<0.0001)return 0x0;const _0x482fa2=_0x3fb1ea[_0x3fb1ea[_0x1f9557(0x21d)]-0x1];return(_0x482fa2-_0x51b52d)/_0x561f07;}['_computeVPIN'](_0x22e58d){const _0xe73c84=_0x41bd06;if(_0x22e58d['length']<this['vpinWindow'])return 0.5;const _0x1396af=_0x22e58d[_0xe73c84(0x1dc)](-this['vpinWindow']);let _0x191eb8=0x0,_0x4b3a71=0x0;for(const _0x1a2569 of _0x1396af){_0x191eb8+=_0x1a2569[_0xe73c84(0x24b)],_0x4b3a71+=_0x1a2569[_0xe73c84(0x206)];}const _0x51c14f=_0x191eb8+_0x4b3a71;if(_0x51c14f<0x1)return 0.5;return Math['abs'](_0x191eb8-_0x4b3a71)/_0x51c14f;}['_computeKyleLambda'](_0x27d0e2){const _0x562810=_0x41bd06;if(_0x27d0e2[_0x562810(0x21d)]<0x14)return 0x0;const _0x1acd0e=_0x27d0e2['slice'](-0x14),_0x50fa92=[],_0x72da0d=[];for(let _0xf46dcf=0x1;_0xf46dcf<_0x1acd0e[_0x562810(0x21d)];_0xf46dcf++){_0x50fa92['push'](_0x1acd0e[_0xf46dcf]['close']-_0x1acd0e[_0xf46dcf-0x1][_0x562810(0x1ea)]),_0x72da0d['push'](_0x1acd0e[_0xf46dcf]['volume']);}const _0x3874c0=_0x50fa92['reduce']((_0x4cd379,_0x1e05ca)=>_0x4cd379+_0x1e05ca,0x0)/_0x50fa92[_0x562810(0x21d)],_0x37b9f1=_0x72da0d[_0x562810(0x215)]((_0x323930,_0x49ac07)=>_0x323930+_0x49ac07,0x0)/_0x72da0d['length'];let _0x29a830=0x0,_0x57ed47=0x0;for(let _0x51f0f6=0x0;_0x51f0f6<_0x50fa92['length'];_0x51f0f6++){_0x29a830+=(_0x50fa92[_0x51f0f6]-_0x3874c0)*(_0x72da0d[_0x51f0f6]-_0x37b9f1),_0x57ed47+=Math[_0x562810(0x230)](_0x72da0d[_0x51f0f6]-_0x37b9f1,0x2);}_0x29a830/=_0x50fa92['length'],_0x57ed47/=_0x50fa92['length'];if(_0x57ed47<0.0001)return 0x0;return Math[_0x562810(0x1f1)](_0x29a830/_0x57ed47);}['_applyKalmanFilter'](_0x56905a,_0x20d110){const _0x4bd344=_0x41bd06;let _0x25624b=this[_0x4bd344(0x208)][_0x4bd344(0x240)](_0x56905a);if(!_0x25624b)return _0x25624b={'estimate':_0x20d110,'errorCovariance':0x1},this['kalmanStates']['set'](_0x56905a,_0x25624b),_0x20d110;const _0x4fddd0=_0x25624b[_0x4bd344(0x1e4)],_0x4b6418=_0x25624b['errorCovariance']+this['kalmanProcessNoise'],_0x2894ff=_0x4b6418/(_0x4b6418+this[_0x4bd344(0x24c)]),_0x473d4a=_0x4fddd0+_0x2894ff*(_0x20d110-_0x4fddd0),_0x903701=(0x1-_0x2894ff)*_0x4b6418;return _0x25624b['estimate']=_0x473d4a,_0x25624b['errorCovariance']=_0x903701,_0x473d4a;}[_0x41bd06(0x218)](_0x4604d4,_0x36112f){const _0x41c46a=_0x41bd06,_0x3508a8=this[_0x41c46a(0x225)](_0x36112f),_0xe9b967=_0x3508a8/this[_0x41c46a(0x24a)];let _0x19cef1=this['atrHistory']['get'](_0x4604d4);!_0x19cef1&&(_0x19cef1=[],this[_0x41c46a(0x22d)][_0x41c46a(0x233)](_0x4604d4,_0x19cef1));_0x19cef1[_0x41c46a(0x1f2)](_0x3508a8);if(_0x19cef1[_0x41c46a(0x21d)]>0x1f4)_0x19cef1['shift']();let _0x43c6fd=0.5;_0x19cef1['length']>=0x14&&(_0x43c6fd=_0x19cef1[_0x41c46a(0x23b)](_0x3d4d88=>_0x3d4d88<=_0x3508a8)[_0x41c46a(0x21d)]/_0x19cef1[_0x41c46a(0x21d)]);let _0x46352b,_0x5648c9;if(_0x43c6fd<0.25)_0x46352b='low',_0x5648c9={'stopMultiplier':0.8,'targetMultiplier':0.9,'zscoreThreshold':1.2,'confidenceBonus':0.05};else _0x43c6fd<0.75?(_0x46352b=_0x41c46a(0x23e),_0x5648c9={'stopMultiplier':0x1,'targetMultiplier':0x1,'zscoreThreshold':1.5,'confidenceBonus':0x0}):(_0x46352b=_0x41c46a(0x213),_0x5648c9={'stopMultiplier':1.3,'targetMultiplier':1.2,'zscoreThreshold':0x2,'confidenceBonus':-0.05});return{'regime':_0x46352b,'params':_0x5648c9};}[_0x41bd06(0x225)](_0x22abe9,_0x53b3bf=0xe){const _0x56cec0=_0x41bd06;if(_0x22abe9['length']<_0x53b3bf+0x1)return 2.5;const _0x50e946=[];for(let _0x3fa8a6=_0x22abe9[_0x56cec0(0x21d)]-_0x53b3bf;_0x3fa8a6<_0x22abe9['length'];_0x3fa8a6++){const _0x2bfd5e=_0x22abe9[_0x3fa8a6],_0xc65006=_0x22abe9[_0x3fa8a6-0x1][_0x56cec0(0x1ea)],_0x77959b=Math['max'](_0x2bfd5e[_0x56cec0(0x213)]-_0x2bfd5e[_0x56cec0(0x232)],Math['abs'](_0x2bfd5e[_0x56cec0(0x213)]-_0xc65006),Math[_0x56cec0(0x1f1)](_0x2bfd5e[_0x56cec0(0x232)]-_0xc65006));_0x50e946['push'](_0x77959b);}return _0x50e946['reduce']((_0x1623e9,_0x177141)=>_0x1623e9+_0x177141,0x0)/_0x50e946['length'];}['_computeOrderFlowImbalance'](_0x48f64e){const _0x2c6b1e=_0x41bd06;if(_0x48f64e['length']<this['ofiLookback'])return 0x0;const _0x4a8421=_0x48f64e['slice'](-this[_0x2c6b1e(0x241)]);let _0x12f37a=0x0,_0xf0a715=0x0;for(const _0x277a0d of _0x4a8421){const _0x5d1a0b=_0x277a0d[_0x2c6b1e(0x213)]-_0x277a0d[_0x2c6b1e(0x232)];if(_0x5d1a0b>0x0){const _0x2c7f48=(_0x277a0d[_0x2c6b1e(0x1ea)]-_0x277a0d['low'])/_0x5d1a0b;_0x12f37a+=_0x2c7f48*_0x277a0d['volume'],_0xf0a715+=(0x1-_0x2c7f48)*_0x277a0d[_0x2c6b1e(0x1e7)];}}const _0xf6c99f=_0x12f37a+_0xf0a715;if(_0xf6c99f<0x1)return 0x0;return(_0x12f37a-_0xf0a715)/_0xf6c99f;}[_0x41bd06(0x1f4)](_0xb26a83,_0x4d8e8f,_0x4d95bf,_0xbff631,_0x4907b8,_0x53b747,_0x4d6df2,_0x56f5f9,_0x3b4daa,_0x2738d0){const _0x13fc65=_0x41bd06,_0x41ed19=Math['abs'](_0x4d95bf);if(_0x41ed19<_0x56f5f9['zscoreThreshold'])return null;if(_0xbff631>this[_0x13fc65(0x1de)])return null;let _0x3dd068;if(_0x4d95bf<-_0x56f5f9['zscoreThreshold'])_0x3dd068=_0x13fc65(0x217);else{if(_0x4d95bf>_0x56f5f9['zscoreThreshold'])_0x3dd068=_0x13fc65(0x1fb);else return null;}const _0x20c480=_0x3dd068===_0x13fc65(0x217)&&_0x3b4daa>0.1||_0x3dd068===_0x13fc65(0x1fb)&&_0x3b4daa<-0.1,_0x957233=_0x4d8e8f-_0x53b747,_0x556d92=_0x3dd068==='long'&&_0x957233<0x0||_0x3dd068==='short'&&_0x957233>0x0,_0x48d3a9={'zscore':Math[_0x13fc65(0x245)](0x1,_0x41ed19/0x4),'vpin':0x1-_0xbff631,'kyleLambda':_0x4907b8>0.001?0.5:0.8,'kalman':_0x556d92?0.8:0.4,'volatility':_0x4d6df2==='normal'?0.8:_0x4d6df2==='low'?0.7:0.6,'ofi':_0x20c480?0.9:0.5,'composite':0x0};_0x48d3a9['composite']=_0x48d3a9[_0x13fc65(0x1f6)]*this[_0x13fc65(0x207)][_0x13fc65(0x1f6)]+_0x48d3a9[_0x13fc65(0x20a)]*this[_0x13fc65(0x207)][_0x13fc65(0x20a)]+_0x48d3a9['kyleLambda']*this['weights'][_0x13fc65(0x23d)]+_0x48d3a9['kalman']*this['weights']['kalman']+_0x48d3a9[_0x13fc65(0x238)]*this[_0x13fc65(0x207)][_0x13fc65(0x238)]+_0x48d3a9['ofi']*this['weights'][_0x13fc65(0x221)];const _0x331b01=Math[_0x13fc65(0x245)](0x1,_0x48d3a9['composite']+_0x56f5f9['confidenceBonus']);if(_0x331b01<this[_0x13fc65(0x205)])return null;if(Date[_0x13fc65(0x21b)]()-this[_0x13fc65(0x1f9)]<this[_0x13fc65(0x23a)])return null;const _0xe98fab=Math['round'](this[_0x13fc65(0x1e9)]*_0x56f5f9['stopMultiplier']),_0x588bf5=Math[_0x13fc65(0x1ec)](this['baseTargetTicks']*_0x56f5f9[_0x13fc65(0x1fc)]),_0x3e1806=Math[_0x13fc65(0x23f)](0x6,Math['min'](0xc,_0xe98fab)),_0x16c480=Math['max'](_0x3e1806*1.5,Math[_0x13fc65(0x245)](0x18,_0x588bf5));let _0x101298,_0x2ccb3e,_0x467185,_0x494528;_0x3dd068==='long'?(_0x101298=_0x4d8e8f-_0x3e1806*this['tickSize'],_0x2ccb3e=_0x4d8e8f+_0x16c480*this[_0x13fc65(0x24a)],_0x467185=_0x4d8e8f+this[_0x13fc65(0x1df)]*this[_0x13fc65(0x24a)],_0x494528=_0x4d8e8f+_0x16c480*this[_0x13fc65(0x1e3)]*this[_0x13fc65(0x24a)]):(_0x101298=_0x4d8e8f+_0x3e1806*this['tickSize'],_0x2ccb3e=_0x4d8e8f-_0x16c480*this['tickSize'],_0x467185=_0x4d8e8f-this['breakevenTicks']*this[_0x13fc65(0x24a)],_0x494528=_0x4d8e8f-_0x16c480*this[_0x13fc65(0x1e3)]*this['tickSize']);const _0x480741=_0x16c480/_0x3e1806,_0x10c108=Math[_0x13fc65(0x1ec)](_0x16c480*0.5),_0x15bfb4=Math['round'](_0x3e1806*0.4);let _0x459b80=SignalStrength['MODERATE'];if(_0x331b01>=0.85)_0x459b80=SignalStrength['VERY_STRONG'];else{if(_0x331b01>=0.75)_0x459b80=SignalStrength['STRONG'];else{if(_0x331b01<0.6)_0x459b80=SignalStrength[_0x13fc65(0x222)];}}const _0x339366=0.5+(_0x331b01-0.5)*0.4,_0x57a91f=_0x339366*Math['abs'](_0x2ccb3e-_0x4d8e8f)-(0x1-_0x339366)*Math['abs'](_0x4d8e8f-_0x101298);this[_0x13fc65(0x1f9)]=Date['now'](),this[_0x13fc65(0x21c)][_0x13fc65(0x1e2)]++;const _0x332b01={'id':uuidv4(),'timestamp':Date['now'](),'symbol':_0xb26a83['split']('.')[0x0]||_0xb26a83,'contractId':_0xb26a83,'side':_0x3dd068===_0x13fc65(0x217)?OrderSide[_0x13fc65(0x1ff)]:OrderSide[_0x13fc65(0x1e8)],'direction':_0x3dd068,'strategy':_0x13fc65(0x22a),'strength':_0x459b80,'edge':_0x57a91f,'confidence':_0x331b01,'entry':_0x4d8e8f,'entryPrice':_0x4d8e8f,'stopLoss':_0x101298,'takeProfit':_0x2ccb3e,'riskReward':_0x480741,'stopTicks':_0x3e1806,'targetTicks':_0x16c480,'trailTriggerTicks':_0x10c108,'trailDistanceTicks':_0x15bfb4,'beBreakeven':_0x467185,'profitLockLevel':_0x494528,'zScore':_0x4d95bf,'zScoreExit':this[_0x13fc65(0x1ee)],'vpinValue':_0xbff631,'kyleLambda':_0x4907b8,'kalmanEstimate':_0x53b747,'volatilityRegime':_0x4d6df2,'ofiValue':_0x3b4daa,'models':_0x48d3a9,'orderFlowConfirmed':_0x20c480,'kalmanConfirmed':_0x556d92,'expires':Date[_0x13fc65(0x21b)]()+0xea60};return this['emit'](_0x13fc65(0x210),{'side':_0x3dd068==='long'?'buy':_0x13fc65(0x206),'action':'open','reason':'Z='+_0x4d95bf[_0x13fc65(0x214)](0x2)+',\x20VPIN='+(_0xbff631*0x64)[_0x13fc65(0x214)](0x0)+_0x13fc65(0x21a)+(_0x3b4daa*0x64)['toFixed'](0x0)+_0x13fc65(0x227)+(_0x331b01*0x64)[_0x13fc65(0x214)](0x0)+'%',..._0x332b01}),this['emit'](_0x13fc65(0x1f8),{'type':_0x13fc65(0x1fd),'message':'[HQX]\x20SIGNAL:\x20'+_0x3dd068[_0x13fc65(0x1eb)]()+'\x20@\x20'+_0x4d8e8f['toFixed'](0x2)+'\x20|\x20Z:'+_0x4d95bf['toFixed'](0x2)+_0x13fc65(0x220)+(_0xbff631*0x64)[_0x13fc65(0x214)](0x0)+_0x13fc65(0x231)+(_0x3b4daa*0x64)[_0x13fc65(0x214)](0x0)+_0x13fc65(0x201)+_0x4907b8['toFixed'](0x5)+_0x13fc65(0x22c)+_0x4d6df2+'\x20|\x20Conf:'+(_0x331b01*0x64)['toFixed'](0x0)+'%'}),_0x332b01;}['shouldExitByZScore'](_0x2f1ca1){const _0x3ae19e=_0x41bd06,_0x4cdbc6=this[_0x3ae19e(0x21f)][_0x3ae19e(0x240)](_0x2f1ca1);if(!_0x4cdbc6||_0x4cdbc6[_0x3ae19e(0x21d)]<0x32)return![];const _0x5ca7d5=this['_computeZScore'](_0x4cdbc6);return Math[_0x3ae19e(0x1f1)](_0x5ca7d5)<this['zscoreExitThreshold'];}[_0x41bd06(0x1db)](_0x127ec6){const _0x52ea56=_0x41bd06,_0x20b498=this['priceBuffer'][_0x52ea56(0x240)](_0x127ec6),_0x2ecac2=this['volumeBuffer']['get'](_0x127ec6),_0x402fd6=this['barHistory'][_0x52ea56(0x240)](_0x127ec6);if(!_0x20b498||!_0x2ecac2||!_0x402fd6||_0x402fd6[_0x52ea56(0x21d)]<0x32)return null;const _0x437a6a=this[_0x52ea56(0x22f)](_0x20b498),_0x4d7ac3=this[_0x52ea56(0x1f5)](_0x2ecac2),_0x51c0a0=this['_computeKyleLambda'](_0x402fd6),_0x20ca1b=this['_computeOrderFlowImbalance'](_0x402fd6);return{'zscore':Math[_0x52ea56(0x245)](0x1,Math['abs'](_0x437a6a)/0x4),'vpin':0x1-_0x4d7ac3,'kyleLambda':_0x51c0a0>0.001?0.5:0.8,'kalman':0.7,'volatility':0.7,'ofi':Math['abs'](_0x20ca1b)>0.1?0.8:0.5,'composite':0.7,'raw':{'zscore':_0x437a6a,'vpin':_0x4d7ac3,'kyleLambda':_0x51c0a0,'ofi':_0x20ca1b}};}['getAnalysisState'](_0x4386de,_0xfdcc07){const _0x4abd40=_0x41bd06,_0x50cdd5=this['barHistory'][_0x4abd40(0x240)](_0x4386de)||[];if(_0x50cdd5['length']<0x32)return{'ready':![],'message':'Collecting\x20data...\x20'+_0x50cdd5[_0x4abd40(0x21d)]+_0x4abd40(0x1ed)};const _0x4f1aef=this['priceBuffer'][_0x4abd40(0x240)](_0x4386de)||[],_0x3a12a2=this[_0x4abd40(0x20b)][_0x4abd40(0x240)](_0x4386de)||[],_0x349f60=this['_computeZScore'](_0x4f1aef),_0x1e8a40=this[_0x4abd40(0x1f5)](_0x3a12a2),_0x4fd1cd=this[_0x4abd40(0x248)](_0x50cdd5),_0x49bfa3=this[_0x4abd40(0x24e)](_0x50cdd5),{regime:_0x30738f,params:_0x22b4c4}=this[_0x4abd40(0x218)](_0x4386de,_0x50cdd5);return{'ready':!![],'zScore':_0x349f60,'vpin':_0x1e8a40,'ofi':_0x4fd1cd,'kyleLambda':_0x49bfa3,'regime':_0x30738f,'stopTicks':Math[_0x4abd40(0x1ec)](this['baseStopTicks']*_0x22b4c4[_0x4abd40(0x20e)]),'targetTicks':Math['round'](this['baseTargetTicks']*_0x22b4c4['targetMultiplier']),'threshold':_0x22b4c4['zscoreThreshold'],'barsProcessed':_0x50cdd5['length'],'models':_0x4abd40(0x20c)};}[_0x41bd06(0x212)](_0x31b2d8){const _0x592335=_0x41bd06;this[_0x592335(0x1f3)]['push']({'netPnl':_0x31b2d8,'timestamp':Date[_0x592335(0x21b)]()});if(this['recentTrades'][_0x592335(0x21d)]>0x64)this['recentTrades']['shift']();_0x31b2d8>0x0?(this['winStreak']++,this['lossStreak']=0x0,this[_0x592335(0x21c)]['wins']++):(this['lossStreak']++,this['winStreak']=0x0,this['stats'][_0x592335(0x234)]++),this['stats']['trades']++,this[_0x592335(0x21c)][_0x592335(0x250)]+=_0x31b2d8,this[_0x592335(0x228)]('log',{'type':_0x592335(0x24d),'message':'[HQX]\x20Trade\x20result:\x20'+(_0x31b2d8>0x0?'WIN':'LOSS')+'\x20$'+_0x31b2d8['toFixed'](0x2)+_0x592335(0x1e5)+(_0x31b2d8>0x0?this[_0x592335(0x247)]:-this[_0x592335(0x229)])});}['getBarHistory'](_0x5a2626){return this['barHistory']['get'](_0x5a2626)||[];}['getStats'](){return this['stats'];}[_0x41bd06(0x200)](_0x17a0b2){const _0x317f70=_0x41bd06;this[_0x317f70(0x243)]['set'](_0x17a0b2,[]),this['priceBuffer'][_0x317f70(0x233)](_0x17a0b2,[]),this['volumeBuffer']['set'](_0x17a0b2,[]),this['atrHistory']['set'](_0x17a0b2,[]),this[_0x317f70(0x208)][_0x317f70(0x233)](_0x17a0b2,{'estimate':0x0,'errorCovariance':0x1}),this['emit'](_0x317f70(0x1f8),{'type':_0x317f70(0x1fd),'message':'[HQX-UltraScalping]\x20Reset\x20state\x20for\x20'+_0x17a0b2});}}class UltraScalpingStrategy extends EventEmitter{constructor(_0x6f7ee={}){const _0x2ab7b3=_0x41bd06;super(),this['config']=_0x6f7ee,this['strategy']=new HQXUltraScalping(_0x6f7ee),this['strategy']['on'](_0x2ab7b3(0x210),_0x5f3e0a=>this['emit']('signal',_0x5f3e0a)),this['strategy']['on']('log',_0x1342c7=>this[_0x2ab7b3(0x228)]('log',_0x1342c7));}[_0x41bd06(0x202)](_0x18fe95){const _0x274f6e=_0x41bd06;return this[_0x274f6e(0x21e)]['processTick'](_0x18fe95);}['onTick'](_0x16ece7){const _0x28bff4=_0x41bd06;return this[_0x28bff4(0x21e)][_0x28bff4(0x1dd)](_0x16ece7);}['onTrade'](_0x5d26a3){const _0x3af181=_0x41bd06;return this[_0x3af181(0x21e)][_0x3af181(0x1e6)](_0x5d26a3);}['processBar'](_0x16c6f3,_0x11b017){const _0x3660ce=_0x41bd06;return this[_0x3660ce(0x21e)][_0x3660ce(0x22b)](_0x16c6f3,_0x11b017);}[_0x41bd06(0x1e1)](_0x17dddd,_0x36331e,_0x3c8bd7){const _0x693100=_0x41bd06;return this['strategy'][_0x693100(0x1e1)](_0x17dddd,_0x36331e,_0x3c8bd7);}[_0x41bd06(0x236)](_0x40c2c2,_0x4e9d3f){const _0x41628c=_0x41bd06;return this['strategy'][_0x41628c(0x236)](_0x40c2c2,_0x4e9d3f);}['recordTradeResult'](_0x4886c4){const _0x37fcab=_0x41bd06;return this[_0x37fcab(0x21e)][_0x37fcab(0x212)](_0x4886c4);}['reset'](_0x33b827){const _0xfd6755=_0x41bd06;return this['strategy'][_0xfd6755(0x200)](_0x33b827);}[_0x41bd06(0x209)](){const _0x1588d7=_0x41bd06;return this['strategy'][_0x1588d7(0x209)]();}[_0x41bd06(0x242)](_0x15f622){return this['strategy']['getBarHistory'](_0x15f622);}[_0x41bd06(0x1db)](_0x32261c){const _0x192706=_0x41bd06;return this['strategy'][_0x192706(0x1db)](_0x32261c);}[_0x41bd06(0x216)](_0x4edb82){const _0x4cc465=_0x41bd06;return this[_0x4cc465(0x21e)][_0x4cc465(0x216)](_0x4edb82);}[_0x41bd06(0x22e)](_0x3ed470){return null;}}module['exports']={'HQXUltraScalping':HQXUltraScalping,'UltraScalpingStrategy':UltraScalpingStrategy,'M1':UltraScalpingStrategy,'S1':HQXUltraScalping,'OrderSide':OrderSide,'SignalStrength':SignalStrength};
|
|
1
|
+
const _0x2f642f=_0xc24e;(function(_0x534985,_0x43b609){const _0x144ed8=_0xc24e,_0x4f2c1b=_0x534985();while(!![]){try{const _0x14585b=parseInt(_0x144ed8(0x1c1))/0x1+parseInt(_0x144ed8(0x209))/0x2*(parseInt(_0x144ed8(0x1d3))/0x3)+parseInt(_0x144ed8(0x1cd))/0x4+-parseInt(_0x144ed8(0x222))/0x5*(-parseInt(_0x144ed8(0x1c5))/0x6)+parseInt(_0x144ed8(0x1f9))/0x7*(parseInt(_0x144ed8(0x1fe))/0x8)+parseInt(_0x144ed8(0x20a))/0x9+-parseInt(_0x144ed8(0x1eb))/0xa*(parseInt(_0x144ed8(0x221))/0xb);if(_0x14585b===_0x43b609)break;else _0x4f2c1b['push'](_0x4f2c1b['shift']());}catch(_0x4967e7){_0x4f2c1b['push'](_0x4f2c1b['shift']());}}}(_0x48c6,0x5f6c4));const EventEmitter=require('events'),{v4:uuidv4}=require(_0x2f642f(0x1de)),OrderSide={'BID':0x0,'ASK':0x1},SignalStrength={'WEAK':0x1,'MODERATE':0x2,'STRONG':0x3,'VERY_STRONG':0x4};function _0xc24e(_0x283884,_0x5434b3){_0x283884=_0x283884-0x1c1;const _0x48c67c=_0x48c6();let _0xc24e09=_0x48c67c[_0x283884];return _0xc24e09;}class HQXUltraScalping extends EventEmitter{constructor(_0x2414d4={}){const _0x3f1b40=_0x2f642f;super(),this['tickSize']=_0x2414d4[_0x3f1b40(0x225)]||0.25,this['tickValue']=_0x2414d4[_0x3f1b40(0x1ec)]||0x5,this[_0x3f1b40(0x1f8)]=1.5,this[_0x3f1b40(0x1f0)]=0.5,this[_0x3f1b40(0x22b)]=0x32,this['vpinToxicThreshold']=0.7,this['kalmanProcessNoise']=0.01,this[_0x3f1b40(0x1ca)]=0.1,this[_0x3f1b40(0x214)]=0x64,this['ofiLookback']=0x14,this[_0x3f1b40(0x204)]=0x8,this['baseTargetTicks']=0x10,this[_0x3f1b40(0x207)]=0x4,this[_0x3f1b40(0x21b)]=0.5,this[_0x3f1b40(0x1d7)]=0.55,this[_0x3f1b40(0x1cf)]={'zscore':0.3,'ofi':0.2,'vpin':0.15,'kalman':0.15,'kyleLambda':0.1,'volatility':0.1},this['barHistory']=new Map(),this['priceBuffer']=new Map(),this[_0x3f1b40(0x228)]=new Map(),this[_0x3f1b40(0x1f5)]=new Map(),this[_0x3f1b40(0x1da)]=new Map(),this[_0x3f1b40(0x22c)]=[],this['winStreak']=0x0,this[_0x3f1b40(0x1c7)]=0x0,this['lastSignalTime']=0x0,this[_0x3f1b40(0x1d2)]=0x7530,this['minHoldTimeMs']=0x2710,this[_0x3f1b40(0x218)]={'signals':0x0,'trades':0x0,'wins':0x0,'losses':0x0,'pnl':0x0};}['initialize'](_0x399a09,_0x345ef3=0.25,_0x2b342b=0x5){const _0x22c560=_0x2f642f;this['tickSize']=_0x345ef3,this[_0x22c560(0x1ec)]=_0x2b342b,this['barHistory'][_0x22c560(0x1e4)](_0x399a09,[]),this['priceBuffer'][_0x22c560(0x1e4)](_0x399a09,[]),this['volumeBuffer']['set'](_0x399a09,[]),this[_0x22c560(0x1da)][_0x22c560(0x1e4)](_0x399a09,[]),this['kalmanStates'][_0x22c560(0x1e4)](_0x399a09,{'estimate':0x0,'errorCovariance':0x1}),this[_0x22c560(0x1e3)](_0x22c560(0x21c),{'type':_0x22c560(0x1fb),'message':'[HQX-UltraScalping]\x20Initialized\x20for\x20'+_0x399a09+_0x22c560(0x22f)+_0x345ef3+_0x22c560(0x227)+_0x2b342b}),this['emit']('log',{'type':_0x22c560(0x1fb),'message':'[HQX-UltraScalping]\x206\x20Models:\x20Z-Score(30%),\x20OFI(20%),\x20VPIN(15%),\x20Kalman(15%),\x20Kyle(10%),\x20Vol(10%)'});}[_0x2f642f(0x1e7)](_0x75bef9){const _0x1da886=_0x2f642f,{contractId:_0x20709,price:_0x3c4554,volume:_0x59081c,side:_0x4553c2,timestamp:_0x329465}=_0x75bef9,_0x311f44={'timestamp':_0x329465||Date[_0x1da886(0x1d4)](),'open':_0x3c4554,'high':_0x3c4554,'low':_0x3c4554,'close':_0x3c4554,'volume':_0x59081c||0x1};return this[_0x1da886(0x1f7)](_0x20709,_0x311f44);}['onTick'](_0x2bb0ab){const _0x2f43a1=_0x2f642f;return this[_0x2f43a1(0x1e7)](_0x2bb0ab);}[_0x2f642f(0x1c3)](_0x409667){const _0x5b3a82=_0x2f642f;return this['processTick']({'contractId':_0x409667['contractId']||_0x409667['symbol'],'price':_0x409667['price'],'volume':_0x409667['size']||_0x409667[_0x5b3a82(0x20f)]||0x1,'side':_0x409667['side'],'timestamp':_0x409667['timestamp']||Date[_0x5b3a82(0x1d4)]()});}['processBar'](_0x26a6fa,_0x5b1f4c){const _0x4a78ef=_0x2f642f;let _0xf19f87=this[_0x4a78ef(0x1d6)]['get'](_0x26a6fa);!_0xf19f87&&(this['initialize'](_0x26a6fa),_0xf19f87=this[_0x4a78ef(0x1d6)][_0x4a78ef(0x21f)](_0x26a6fa));_0xf19f87[_0x4a78ef(0x202)](_0x5b1f4c);if(_0xf19f87['length']>0x1f4)_0xf19f87[_0x4a78ef(0x203)]();const _0x35caf7=this['priceBuffer'][_0x4a78ef(0x21f)](_0x26a6fa);_0x35caf7['push'](_0x5b1f4c[_0x4a78ef(0x1e0)]);if(_0x35caf7[_0x4a78ef(0x219)]>0xc8)_0x35caf7[_0x4a78ef(0x203)]();const _0x561b2f=this[_0x4a78ef(0x228)]['get'](_0x26a6fa),_0x572621=_0x5b1f4c[_0x4a78ef(0x210)]-_0x5b1f4c['low'];let _0x541019=_0x5b1f4c['volume']*0.5,_0x548299=_0x5b1f4c['volume']*0.5;if(_0x572621>0x0){const _0x34f7a3=(_0x5b1f4c['close']-_0x5b1f4c[_0x4a78ef(0x1cb)])/_0x572621;_0x541019=_0x5b1f4c[_0x4a78ef(0x20f)]*_0x34f7a3,_0x548299=_0x5b1f4c[_0x4a78ef(0x20f)]*(0x1-_0x34f7a3);}_0x561b2f['push']({'buy':_0x541019,'sell':_0x548299});if(_0x561b2f['length']>0x64)_0x561b2f['shift']();if(_0xf19f87[_0x4a78ef(0x219)]<0x32)return null;const _0x31da01=this['_computeZScore'](_0x35caf7),_0x56ba55=this[_0x4a78ef(0x1ce)](_0x561b2f),_0x2673a5=this['_computeKyleLambda'](_0xf19f87),_0x16f9fd=this['_applyKalmanFilter'](_0x26a6fa,_0x5b1f4c[_0x4a78ef(0x1e0)]),{regime:_0x412535,params:_0x116ada}=this['_detectVolatilityRegime'](_0x26a6fa,_0xf19f87),_0x4bf2f5=this[_0x4a78ef(0x1ee)](_0xf19f87);return this['_generateSignal'](_0x26a6fa,_0x5b1f4c[_0x4a78ef(0x1e0)],_0x31da01,_0x56ba55,_0x2673a5,_0x16f9fd,_0x412535,_0x116ada,_0x4bf2f5,_0xf19f87);}['_computeZScore'](_0x1161cd,_0x164df5=0x32){const _0x29e0cd=_0x2f642f;if(_0x1161cd[_0x29e0cd(0x219)]<_0x164df5)return 0x0;const _0xca41d6=_0x1161cd[_0x29e0cd(0x201)](-_0x164df5),_0x3d6b74=_0xca41d6[_0x29e0cd(0x21a)]((_0x438fb5,_0x5d2b28)=>_0x438fb5+_0x5d2b28,0x0)/_0x164df5,_0x3f2d03=_0xca41d6['reduce']((_0x31e357,_0xa39a04)=>_0x31e357+Math['pow'](_0xa39a04-_0x3d6b74,0x2),0x0)/_0x164df5,_0x56c7a2=Math['sqrt'](_0x3f2d03);if(_0x56c7a2<0.0001)return 0x0;const _0x101e32=_0x1161cd[_0x1161cd['length']-0x1];return(_0x101e32-_0x3d6b74)/_0x56c7a2;}[_0x2f642f(0x1ce)](_0x396c66){const _0x47d144=_0x2f642f;if(_0x396c66[_0x47d144(0x219)]<this['vpinWindow'])return 0.5;const _0x3437ba=_0x396c66['slice'](-this[_0x47d144(0x22b)]);let _0x2c7542=0x0,_0x5c01ab=0x0;for(const _0x448869 of _0x3437ba){_0x2c7542+=_0x448869['buy'],_0x5c01ab+=_0x448869[_0x47d144(0x200)];}const _0x430093=_0x2c7542+_0x5c01ab;if(_0x430093<0x1)return 0.5;return Math['abs'](_0x2c7542-_0x5c01ab)/_0x430093;}[_0x2f642f(0x20c)](_0x2ecd65){const _0x24d324=_0x2f642f;if(_0x2ecd65[_0x24d324(0x219)]<0x14)return 0x0;const _0x158b71=_0x2ecd65['slice'](-0x14),_0x25477e=[],_0xbe90ab=[];for(let _0x48142a=0x1;_0x48142a<_0x158b71['length'];_0x48142a++){_0x25477e[_0x24d324(0x202)](_0x158b71[_0x48142a][_0x24d324(0x1e0)]-_0x158b71[_0x48142a-0x1]['close']),_0xbe90ab[_0x24d324(0x202)](_0x158b71[_0x48142a]['volume']);}const _0x56e280=_0x25477e[_0x24d324(0x21a)]((_0x35b610,_0x11c18c)=>_0x35b610+_0x11c18c,0x0)/_0x25477e['length'],_0x294f35=_0xbe90ab['reduce']((_0x7fc270,_0x4ee76a)=>_0x7fc270+_0x4ee76a,0x0)/_0xbe90ab[_0x24d324(0x219)];let _0x5675fd=0x0,_0x302fd0=0x0;for(let _0x485f43=0x0;_0x485f43<_0x25477e[_0x24d324(0x219)];_0x485f43++){_0x5675fd+=(_0x25477e[_0x485f43]-_0x56e280)*(_0xbe90ab[_0x485f43]-_0x294f35),_0x302fd0+=Math['pow'](_0xbe90ab[_0x485f43]-_0x294f35,0x2);}_0x5675fd/=_0x25477e['length'],_0x302fd0/=_0x25477e[_0x24d324(0x219)];if(_0x302fd0<0.0001)return 0x0;return Math[_0x24d324(0x1e8)](_0x5675fd/_0x302fd0);}[_0x2f642f(0x1c4)](_0x30a1f0,_0x5665d3){const _0x1639e6=_0x2f642f;let _0x2ad690=this[_0x1639e6(0x1f5)]['get'](_0x30a1f0);if(!_0x2ad690)return _0x2ad690={'estimate':_0x5665d3,'errorCovariance':0x1},this[_0x1639e6(0x1f5)][_0x1639e6(0x1e4)](_0x30a1f0,_0x2ad690),_0x5665d3;const _0x1592b8=_0x2ad690[_0x1639e6(0x224)],_0x5d2221=_0x2ad690[_0x1639e6(0x1d9)]+this['kalmanProcessNoise'],_0x242476=_0x5d2221/(_0x5d2221+this['kalmanMeasurementNoise']),_0x206629=_0x1592b8+_0x242476*(_0x5665d3-_0x1592b8),_0x9d4e0d=(0x1-_0x242476)*_0x5d2221;return _0x2ad690['estimate']=_0x206629,_0x2ad690['errorCovariance']=_0x9d4e0d,_0x206629;}[_0x2f642f(0x1fc)](_0x114c0f,_0x36e0ae){const _0x42027e=_0x2f642f,_0x270f51=this['_calculateATR'](_0x36e0ae),_0x1bcad5=_0x270f51/this['tickSize'];let _0x327f56=this[_0x42027e(0x1da)][_0x42027e(0x21f)](_0x114c0f);!_0x327f56&&(_0x327f56=[],this['atrHistory']['set'](_0x114c0f,_0x327f56));_0x327f56['push'](_0x270f51);if(_0x327f56[_0x42027e(0x219)]>0x1f4)_0x327f56[_0x42027e(0x203)]();let _0x49426c=0.5;_0x327f56[_0x42027e(0x219)]>=0x14&&(_0x49426c=_0x327f56['filter'](_0x280a36=>_0x280a36<=_0x270f51)['length']/_0x327f56[_0x42027e(0x219)]);let _0x4f0473,_0x49115d;if(_0x49426c<0.25)_0x4f0473='low',_0x49115d={'stopMultiplier':0.8,'targetMultiplier':0.9,'zscoreThreshold':1.2,'confidenceBonus':0.05};else _0x49426c<0.75?(_0x4f0473=_0x42027e(0x1fd),_0x49115d={'stopMultiplier':0x1,'targetMultiplier':0x1,'zscoreThreshold':1.5,'confidenceBonus':0x0}):(_0x4f0473=_0x42027e(0x210),_0x49115d={'stopMultiplier':1.3,'targetMultiplier':1.2,'zscoreThreshold':0x2,'confidenceBonus':-0.05});return{'regime':_0x4f0473,'params':_0x49115d};}['_calculateATR'](_0x28314f,_0x3fc9b2=0xe){const _0x47e4f8=_0x2f642f;if(_0x28314f['length']<_0x3fc9b2+0x1)return 2.5;const _0x1252a8=[];for(let _0x1ec026=_0x28314f[_0x47e4f8(0x219)]-_0x3fc9b2;_0x1ec026<_0x28314f['length'];_0x1ec026++){const _0x2e3a81=_0x28314f[_0x1ec026],_0xc80a30=_0x28314f[_0x1ec026-0x1][_0x47e4f8(0x1e0)],_0x8e586d=Math['max'](_0x2e3a81['high']-_0x2e3a81['low'],Math[_0x47e4f8(0x1e8)](_0x2e3a81[_0x47e4f8(0x210)]-_0xc80a30),Math[_0x47e4f8(0x1e8)](_0x2e3a81['low']-_0xc80a30));_0x1252a8['push'](_0x8e586d);}return _0x1252a8['reduce']((_0x52e839,_0x2313d0)=>_0x52e839+_0x2313d0,0x0)/_0x1252a8['length'];}[_0x2f642f(0x1ee)](_0x52aaaa){const _0x12b781=_0x2f642f;if(_0x52aaaa['length']<this[_0x12b781(0x1fa)])return 0x0;const _0x58a42e=_0x52aaaa['slice'](-this['ofiLookback']);let _0x5e22c9=0x0,_0x3e4a54=0x0;for(const _0x3604d4 of _0x58a42e){const _0x564bb5=_0x3604d4['high']-_0x3604d4['low'];if(_0x564bb5>0x0){const _0x2252e8=(_0x3604d4[_0x12b781(0x1e0)]-_0x3604d4[_0x12b781(0x1cb)])/_0x564bb5;_0x5e22c9+=_0x2252e8*_0x3604d4['volume'],_0x3e4a54+=(0x1-_0x2252e8)*_0x3604d4['volume'];}}const _0x1a545c=_0x5e22c9+_0x3e4a54;if(_0x1a545c<0x1)return 0x0;return(_0x5e22c9-_0x3e4a54)/_0x1a545c;}[_0x2f642f(0x1e6)](_0x572768,_0x33d398,_0x5732c7,_0x285202,_0x1efeb9,_0x28e662,_0x37fb21,_0x3733a1,_0x58ba42,_0x240380){const _0x59ebe3=_0x2f642f,_0x95c4f8=Math[_0x59ebe3(0x1e8)](_0x5732c7);if(_0x95c4f8<_0x3733a1['zscoreThreshold'])return null;if(_0x285202>this['vpinToxicThreshold'])return null;let _0x270e0c;if(_0x5732c7<-_0x3733a1[_0x59ebe3(0x1d8)])_0x270e0c=_0x59ebe3(0x21d);else{if(_0x5732c7>_0x3733a1[_0x59ebe3(0x1d8)])_0x270e0c=_0x59ebe3(0x223);else return null;}const _0x1d3ef6=_0x270e0c==='long'&&_0x58ba42>0.1||_0x270e0c===_0x59ebe3(0x223)&&_0x58ba42<-0.1,_0x1fb89e=_0x33d398-_0x28e662,_0x3bf8d6=_0x270e0c===_0x59ebe3(0x21d)&&_0x1fb89e<0x0||_0x270e0c==='short'&&_0x1fb89e>0x0,_0x3c3886={'zscore':Math['min'](0x1,_0x95c4f8/0x4),'vpin':0x1-_0x285202,'kyleLambda':_0x1efeb9>0.001?0.5:0.8,'kalman':_0x3bf8d6?0.8:0.4,'volatility':_0x37fb21===_0x59ebe3(0x1fd)?0.8:_0x37fb21==='low'?0.7:0.6,'ofi':_0x1d3ef6?0.9:0.5,'composite':0x0};_0x3c3886[_0x59ebe3(0x1d0)]=_0x3c3886[_0x59ebe3(0x1cc)]*this[_0x59ebe3(0x1cf)]['zscore']+_0x3c3886['vpin']*this['weights']['vpin']+_0x3c3886[_0x59ebe3(0x20e)]*this['weights']['kyleLambda']+_0x3c3886['kalman']*this['weights']['kalman']+_0x3c3886[_0x59ebe3(0x1d1)]*this[_0x59ebe3(0x1cf)][_0x59ebe3(0x1d1)]+_0x3c3886['ofi']*this[_0x59ebe3(0x1cf)][_0x59ebe3(0x216)];const _0x3f8db7=Math['min'](0x1,_0x3c3886['composite']+_0x3733a1[_0x59ebe3(0x213)]);if(_0x3f8db7<this['minConfidence'])return null;if(Date['now']()-this['lastSignalTime']<this['cooldownMs'])return null;const _0x5bc68e=Math['round'](this['baseStopTicks']*_0x3733a1['stopMultiplier']),_0x768062=Math[_0x59ebe3(0x20b)](this[_0x59ebe3(0x22e)]*_0x3733a1['targetMultiplier']),_0x31307c=Math['max'](0x6,Math['min'](0xc,_0x5bc68e)),_0x206f74=Math['max'](_0x31307c*1.5,Math['min'](0x18,_0x768062));let _0x15c472,_0x11d4bb,_0x118339,_0x7e3ca2;_0x270e0c===_0x59ebe3(0x21d)?(_0x15c472=_0x33d398-_0x31307c*this['tickSize'],_0x11d4bb=_0x33d398+_0x206f74*this[_0x59ebe3(0x225)],_0x118339=_0x33d398+this['breakevenTicks']*this[_0x59ebe3(0x225)],_0x7e3ca2=_0x33d398+_0x206f74*this[_0x59ebe3(0x21b)]*this[_0x59ebe3(0x225)]):(_0x15c472=_0x33d398+_0x31307c*this['tickSize'],_0x11d4bb=_0x33d398-_0x206f74*this['tickSize'],_0x118339=_0x33d398-this['breakevenTicks']*this[_0x59ebe3(0x225)],_0x7e3ca2=_0x33d398-_0x206f74*this['profitLockPct']*this['tickSize']);const _0x52be1d=_0x206f74/_0x31307c,_0x72d77b=Math[_0x59ebe3(0x20b)](_0x206f74*0.5),_0x285a79=Math['round'](_0x31307c*0.4);let _0x28ac1c=SignalStrength[_0x59ebe3(0x208)];if(_0x3f8db7>=0.85)_0x28ac1c=SignalStrength['VERY_STRONG'];else{if(_0x3f8db7>=0.75)_0x28ac1c=SignalStrength['STRONG'];else{if(_0x3f8db7<0.6)_0x28ac1c=SignalStrength['WEAK'];}}const _0x2fd433=0.5+(_0x3f8db7-0.5)*0.4,_0x5483cb=_0x2fd433*Math['abs'](_0x11d4bb-_0x33d398)-(0x1-_0x2fd433)*Math[_0x59ebe3(0x1e8)](_0x33d398-_0x15c472);this[_0x59ebe3(0x1d5)]=Date[_0x59ebe3(0x1d4)](),this[_0x59ebe3(0x218)][_0x59ebe3(0x1f4)]++;const _0x4c8b68={'id':uuidv4(),'timestamp':Date[_0x59ebe3(0x1d4)](),'symbol':_0x572768['split']('.')[0x0]||_0x572768,'contractId':_0x572768,'side':_0x270e0c===_0x59ebe3(0x21d)?OrderSide[_0x59ebe3(0x1e2)]:OrderSide[_0x59ebe3(0x1c2)],'direction':_0x270e0c,'strategy':_0x59ebe3(0x1f2),'strength':_0x28ac1c,'edge':_0x5483cb,'confidence':_0x3f8db7,'entry':_0x33d398,'entryPrice':_0x33d398,'stopLoss':_0x15c472,'takeProfit':_0x11d4bb,'riskReward':_0x52be1d,'stopTicks':_0x31307c,'targetTicks':_0x206f74,'trailTriggerTicks':_0x72d77b,'trailDistanceTicks':_0x285a79,'beBreakeven':_0x118339,'profitLockLevel':_0x7e3ca2,'zScore':_0x5732c7,'zScoreExit':this['zscoreExitThreshold'],'vpinValue':_0x285202,'kyleLambda':_0x1efeb9,'kalmanEstimate':_0x28e662,'volatilityRegime':_0x37fb21,'ofiValue':_0x58ba42,'models':_0x3c3886,'orderFlowConfirmed':_0x1d3ef6,'kalmanConfirmed':_0x3bf8d6,'expires':Date['now']()+0xea60};return this[_0x59ebe3(0x1e3)](_0x59ebe3(0x229),{'side':_0x270e0c===_0x59ebe3(0x21d)?_0x59ebe3(0x217):'sell','action':_0x59ebe3(0x220),'reason':'Z='+_0x5732c7['toFixed'](0x2)+_0x59ebe3(0x1e5)+(_0x285202*0x64)['toFixed'](0x0)+'%,\x20OFI='+(_0x58ba42*0x64)[_0x59ebe3(0x1f6)](0x0)+_0x59ebe3(0x215)+(_0x3f8db7*0x64)['toFixed'](0x0)+'%',..._0x4c8b68}),this['emit']('log',{'type':_0x59ebe3(0x1fb),'message':'[HQX]\x20SIGNAL:\x20'+_0x270e0c['toUpperCase']()+'\x20@\x20'+_0x33d398[_0x59ebe3(0x1f6)](0x2)+'\x20|\x20Z:'+_0x5732c7['toFixed'](0x2)+'\x20VPIN:'+(_0x285202*0x64)[_0x59ebe3(0x1f6)](0x0)+_0x59ebe3(0x1ff)+(_0x58ba42*0x64)[_0x59ebe3(0x1f6)](0x0)+_0x59ebe3(0x21e)+_0x1efeb9['toFixed'](0x5)+'\x20Regime:'+_0x37fb21+_0x59ebe3(0x1df)+(_0x3f8db7*0x64)[_0x59ebe3(0x1f6)](0x0)+'%'}),_0x4c8b68;}['shouldExitByZScore'](_0x35553e){const _0x3100b2=_0x2f642f,_0x4d18f6=this[_0x3100b2(0x1dc)][_0x3100b2(0x21f)](_0x35553e);if(!_0x4d18f6||_0x4d18f6['length']<0x32)return![];const _0x25f249=this[_0x3100b2(0x22a)](_0x4d18f6);return Math['abs'](_0x25f249)<this[_0x3100b2(0x1f0)];}[_0x2f642f(0x226)](_0x20f79c){const _0x3967e1=_0x2f642f,_0x453533=this[_0x3967e1(0x1dc)]['get'](_0x20f79c),_0x43daf0=this['volumeBuffer']['get'](_0x20f79c),_0x1e60be=this[_0x3967e1(0x1d6)]['get'](_0x20f79c);if(!_0x453533||!_0x43daf0||!_0x1e60be||_0x1e60be['length']<0x32)return null;const _0x1a1dc9=this['_computeZScore'](_0x453533),_0x14c4da=this[_0x3967e1(0x1ce)](_0x43daf0),_0x39dceb=this[_0x3967e1(0x20c)](_0x1e60be),_0x4a2092=this['_computeOrderFlowImbalance'](_0x1e60be);return{'zscore':Math[_0x3967e1(0x1f3)](0x1,Math['abs'](_0x1a1dc9)/0x4),'vpin':0x1-_0x14c4da,'kyleLambda':_0x39dceb>0.001?0.5:0.8,'kalman':0.7,'volatility':0.7,'ofi':Math[_0x3967e1(0x1e8)](_0x4a2092)>0.1?0.8:0.5,'composite':0.7,'raw':{'zscore':_0x1a1dc9,'vpin':_0x14c4da,'kyleLambda':_0x39dceb,'ofi':_0x4a2092}};}[_0x2f642f(0x1ef)](_0x15937a,_0x56b1e5){const _0x4e2ee8=_0x2f642f,_0x139953=this['barHistory']['get'](_0x15937a)||[];if(_0x139953[_0x4e2ee8(0x219)]<0x32)return{'ready':![],'message':_0x4e2ee8(0x206)+_0x139953[_0x4e2ee8(0x219)]+'/50\x20bars'};const _0x119888=this['priceBuffer'][_0x4e2ee8(0x21f)](_0x15937a)||[],_0x57c1cf=this[_0x4e2ee8(0x228)]['get'](_0x15937a)||[],_0x19f0b4=this[_0x4e2ee8(0x22a)](_0x119888),_0x921872=this[_0x4e2ee8(0x1ce)](_0x57c1cf),_0x5def40=this['_computeOrderFlowImbalance'](_0x139953),_0xc85c2b=this[_0x4e2ee8(0x20c)](_0x139953),{regime:_0x16c6d5,params:_0x1a43c5}=this['_detectVolatilityRegime'](_0x15937a,_0x139953);return{'ready':!![],'zScore':_0x19f0b4,'vpin':_0x921872,'ofi':_0x5def40,'kyleLambda':_0xc85c2b,'regime':_0x16c6d5,'stopTicks':Math['round'](this['baseStopTicks']*_0x1a43c5['stopMultiplier']),'targetTicks':Math['round'](this['baseTargetTicks']*_0x1a43c5[_0x4e2ee8(0x205)]),'threshold':_0x1a43c5['zscoreThreshold'],'barsProcessed':_0x139953['length'],'models':'6\x20(Z-Score,\x20VPIN,\x20Kyle,\x20Kalman,\x20Vol,\x20OFI)'};}[_0x2f642f(0x1db)](_0x34f4ee){const _0x27c887=_0x2f642f;this[_0x27c887(0x22c)][_0x27c887(0x202)]({'netPnl':_0x34f4ee,'timestamp':Date[_0x27c887(0x1d4)]()});if(this['recentTrades'][_0x27c887(0x219)]>0x64)this['recentTrades'][_0x27c887(0x203)]();_0x34f4ee>0x0?(this['winStreak']++,this[_0x27c887(0x1c7)]=0x0,this['stats']['wins']++):(this[_0x27c887(0x1c7)]++,this['winStreak']=0x0,this[_0x27c887(0x218)][_0x27c887(0x22d)]++),this['stats'][_0x27c887(0x20d)]++,this['stats'][_0x27c887(0x1f1)]+=_0x34f4ee,this['emit'](_0x27c887(0x21c),{'type':'debug','message':_0x27c887(0x1c8)+(_0x34f4ee>0x0?'WIN':_0x27c887(0x1ea))+'\x20$'+_0x34f4ee[_0x27c887(0x1f6)](0x2)+_0x27c887(0x1c9)+(_0x34f4ee>0x0?this['winStreak']:-this['lossStreak'])});}['getBarHistory'](_0x93968b){const _0x132087=_0x2f642f;return this['barHistory'][_0x132087(0x21f)](_0x93968b)||[];}[_0x2f642f(0x1ed)](){return this['stats'];}[_0x2f642f(0x1dd)](_0x5bcc92){const _0x58220e=_0x2f642f;this['barHistory'][_0x58220e(0x1e4)](_0x5bcc92,[]),this['priceBuffer']['set'](_0x5bcc92,[]),this['volumeBuffer']['set'](_0x5bcc92,[]),this[_0x58220e(0x1da)][_0x58220e(0x1e4)](_0x5bcc92,[]),this['kalmanStates']['set'](_0x5bcc92,{'estimate':0x0,'errorCovariance':0x1}),this[_0x58220e(0x1e3)]('log',{'type':'info','message':'[HQX-UltraScalping]\x20Reset\x20state\x20for\x20'+_0x5bcc92});}}class UltraScalpingStrategy extends EventEmitter{constructor(_0x1c68b9={}){const _0x27786d=_0x2f642f;super(),this['config']=_0x1c68b9,this[_0x27786d(0x211)]=new HQXUltraScalping(_0x1c68b9),this['strategy']['on'](_0x27786d(0x229),_0x26640d=>this['emit'](_0x27786d(0x229),_0x26640d)),this['strategy']['on']('log',_0x24647b=>this['emit']('log',_0x24647b));}[_0x2f642f(0x1e7)](_0x43265a){const _0x1c2d27=_0x2f642f;return this[_0x1c2d27(0x211)][_0x1c2d27(0x1e7)](_0x43265a);}['onTick'](_0x3d1505){return this['strategy']['onTick'](_0x3d1505);}['onTrade'](_0x4b9f05){const _0x62a743=_0x2f642f;return this[_0x62a743(0x211)][_0x62a743(0x1c3)](_0x4b9f05);}['processBar'](_0xfb06fb,_0x5935b6){return this['strategy']['processBar'](_0xfb06fb,_0x5935b6);}['initialize'](_0x38e2e1,_0x4aea8e,_0x3d4b0f){const _0x1997da=_0x2f642f;return this['strategy'][_0x1997da(0x212)](_0x38e2e1,_0x4aea8e,_0x3d4b0f);}[_0x2f642f(0x1ef)](_0x366f26,_0x32c33d){const _0x5074bc=_0x2f642f;return this[_0x5074bc(0x211)][_0x5074bc(0x1ef)](_0x366f26,_0x32c33d);}['recordTradeResult'](_0x1c8b45){const _0x49a1ad=_0x2f642f;return this[_0x49a1ad(0x211)]['recordTradeResult'](_0x1c8b45);}[_0x2f642f(0x1dd)](_0x5b64d8){const _0x250714=_0x2f642f;return this['strategy'][_0x250714(0x1dd)](_0x5b64d8);}['getStats'](){const _0x31780e=_0x2f642f;return this[_0x31780e(0x211)][_0x31780e(0x1ed)]();}['getBarHistory'](_0x48fbb3){const _0x40b812=_0x2f642f;return this[_0x40b812(0x211)][_0x40b812(0x1c6)](_0x48fbb3);}[_0x2f642f(0x226)](_0x3120e1){const _0x1c5a1e=_0x2f642f;return this['strategy'][_0x1c5a1e(0x226)](_0x3120e1);}['shouldExitByZScore'](_0x572f72){const _0x4a0aa1=_0x2f642f;return this['strategy'][_0x4a0aa1(0x1e1)](_0x572f72);}[_0x2f642f(0x1e9)](_0x1df7f7){return null;}}module['exports']={'HQXUltraScalping':HQXUltraScalping,'UltraScalpingStrategy':UltraScalpingStrategy,'M1':UltraScalpingStrategy,'S1':HQXUltraScalping,'OrderSide':OrderSide,'SignalStrength':SignalStrength};function _0x48c6(){const _0x147040=['reset','uuid','\x20|\x20Conf:','close','shouldExitByZScore','BID','emit','set',',\x20VPIN=','_generateSignal','processTick','abs','generateSignal','LOSS','10eDFdqK','tickValue','getStats','_computeOrderFlowImbalance','getAnalysisState','zscoreExitThreshold','pnl','HQX_ULTRA_SCALPING_6MODELS','min','signals','kalmanStates','toFixed','processBar','zscoreEntryThreshold','42OUKcWP','ofiLookback','info','_detectVolatilityRegime','normal','756384ICUZpV','%\x20OFI:','sell','slice','push','shift','baseStopTicks','targetMultiplier','Collecting\x20data...\x20','breakevenTicks','MODERATE','2JHluhv','1314171KXLtHF','round','_computeKyleLambda','trades','kyleLambda','volume','high','strategy','initialize','confidenceBonus','volatilityLookback','%,\x20cf=','ofi','buy','stats','length','reduce','profitLockPct','log','long','%\x20Kyle:','get','open','14929277lhfYna','1563010cOsStZ','short','estimate','tickSize','getModelValues',',\x20value=','volumeBuffer','signal','_computeZScore','vpinWindow','recentTrades','losses','baseTargetTicks',':\x20tick=','430726yXGdiw','ASK','onTrade','_applyKalmanFilter','6icBfld','getBarHistory','lossStreak','[HQX]\x20Trade\x20result:\x20',',\x20streak:\x20','kalmanMeasurementNoise','low','zscore','749528SyvYql','_computeVPIN','weights','composite','volatility','cooldownMs','312126MTruvf','now','lastSignalTime','barHistory','minConfidence','zscoreThreshold','errorCovariance','atrHistory','recordTradeResult','priceBuffer'];_0x48c6=function(){return _0x147040;};return _0x48c6();}
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ const { loadStrategy } = require('../../lib/m');
|
|
|
7
7
|
const { MarketDataFeed } = require('../../lib/data');
|
|
8
8
|
const { SupervisionEngine } = require('../../services/ai-supervision');
|
|
9
9
|
const smartLogs = require('../../lib/smart-logs');
|
|
10
|
+
const { sessionLogger } = require('../../services/session-logger');
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Execute algo strategy with market data
|
|
@@ -76,9 +77,20 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
76
77
|
// Set strategy for context-aware smart logs
|
|
77
78
|
smartLogs.setStrategy(strategyId);
|
|
78
79
|
|
|
80
|
+
// Start session logger for persistent logs
|
|
81
|
+
const logFile = sessionLogger.start({
|
|
82
|
+
strategy: strategyId,
|
|
83
|
+
account: accountName,
|
|
84
|
+
symbol: symbolName,
|
|
85
|
+
contracts,
|
|
86
|
+
target: dailyTarget,
|
|
87
|
+
risk: maxRisk
|
|
88
|
+
});
|
|
89
|
+
|
|
79
90
|
strategy.on('log', (log) => {
|
|
80
91
|
const type = log.type === 'debug' ? 'debug' : log.type === 'info' ? 'analysis' : 'system';
|
|
81
92
|
ui.addLog(type, log.message);
|
|
93
|
+
sessionLogger.log(type.toUpperCase(), log.message);
|
|
82
94
|
});
|
|
83
95
|
|
|
84
96
|
const marketFeed = new MarketDataFeed();
|
|
@@ -101,6 +113,7 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
101
113
|
const signalLog = smartLogs.getSignalLog(dir, symbolCode, (signal.confidence || 0) * 100, strategyName);
|
|
102
114
|
ui.addLog('signal', `${signalLog.message}`);
|
|
103
115
|
ui.addLog('signal', signalLog.details);
|
|
116
|
+
sessionLogger.signal(dir, signal.entry, signal.confidence, signalLog.details);
|
|
104
117
|
|
|
105
118
|
if (!running) {
|
|
106
119
|
const riskLog = smartLogs.getRiskCheckLog(false, 'Algo stopped');
|
|
@@ -187,6 +200,7 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
187
200
|
const entryLog = smartLogs.getEntryLog(direction.toUpperCase(), symbolCode, orderSize, entry);
|
|
188
201
|
ui.addLog('fill_' + (direction === 'long' ? 'buy' : 'sell'), entryLog.message);
|
|
189
202
|
ui.addLog('trade', entryLog.details);
|
|
203
|
+
sessionLogger.trade('ENTRY', direction.toUpperCase(), entry, orderSize, orderResult.orderId);
|
|
190
204
|
|
|
191
205
|
// Bracket orders
|
|
192
206
|
if (stopLoss && takeProfit) {
|
|
@@ -202,9 +216,11 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
202
216
|
}
|
|
203
217
|
} else {
|
|
204
218
|
ui.addLog('error', `Order failed: ${orderResult.error}`);
|
|
219
|
+
sessionLogger.error('Order failed', orderResult.error);
|
|
205
220
|
}
|
|
206
221
|
} catch (e) {
|
|
207
222
|
ui.addLog('error', `Order error: ${e.message}`);
|
|
223
|
+
sessionLogger.error('Order exception', e);
|
|
208
224
|
}
|
|
209
225
|
pendingOrder = false;
|
|
210
226
|
});
|
|
@@ -264,12 +280,7 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
264
280
|
const buyPressure = totalVol > 0 ? (buyVolume / totalVol) * 100 : 50;
|
|
265
281
|
const delta = buyVolume - sellVolume;
|
|
266
282
|
|
|
267
|
-
|
|
268
|
-
let bias = 'FLAT';
|
|
269
|
-
if (buyPressure > 55) bias = 'LONG';
|
|
270
|
-
else if (buyPressure < 45) bias = 'SHORT';
|
|
271
|
-
|
|
272
|
-
// Log bias when it changes, or every 5 seconds if strong signal
|
|
283
|
+
let bias = buyPressure > 55 ? 'LONG' : buyPressure < 45 ? 'SHORT' : 'FLAT';
|
|
273
284
|
const strongSignal = Math.abs(delta) > 20 || buyPressure > 65 || buyPressure < 35;
|
|
274
285
|
if (bias !== lastBias || (strongSignal && currentSecond % 5 === 0) || (!strongSignal && currentSecond % 15 === 0)) {
|
|
275
286
|
const biasLog = smartLogs.getMarketBiasLog(bias, delta, buyPressure);
|
|
@@ -282,64 +293,36 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
282
293
|
if (currentSecond % 30 === 0) {
|
|
283
294
|
const state = strategy.getAnalysisState?.(contractId, price);
|
|
284
295
|
if (state) {
|
|
296
|
+
sessionLogger.state(state.activeZones || 0, state.swingsDetected || 0, barCount, lastBias);
|
|
285
297
|
if (!state.ready) {
|
|
286
298
|
ui.addLog('system', state.message);
|
|
287
299
|
} else {
|
|
288
300
|
const resStr = state.nearestResistance ? state.nearestResistance.toFixed(2) : '--';
|
|
289
301
|
const supStr = state.nearestSupport ? state.nearestSupport.toFixed(2) : '--';
|
|
290
302
|
|
|
291
|
-
// Combined single line for zones info
|
|
292
303
|
ui.addLog('analysis', `Zones: ${state.activeZones} | R: ${resStr} | S: ${supStr} | Swings: ${state.swingsDetected}`);
|
|
293
|
-
|
|
294
|
-
// HF-grade proximity logs with precise distance info
|
|
295
304
|
if (price && state.nearestResistance) {
|
|
296
|
-
const gapR = state.nearestResistance - price;
|
|
297
|
-
|
|
298
|
-
const dirR = gapR > 0 ? 'below' : 'above';
|
|
299
|
-
const absTicksR = Math.abs(ticksR);
|
|
300
|
-
if (absTicksR <= 50) { // Only show if within 50 ticks
|
|
301
|
-
ui.addLog('analysis', `PROX R: ${Math.abs(gapR).toFixed(2)} pts (${absTicksR} ticks ${dirR}) | Trigger: price must sweep ABOVE then reject`);
|
|
302
|
-
}
|
|
305
|
+
const gapR = state.nearestResistance - price, ticksR = Math.abs(Math.round(gapR / tickSize));
|
|
306
|
+
if (ticksR <= 50) ui.addLog('analysis', `PROX R: ${Math.abs(gapR).toFixed(2)} pts (${ticksR} ticks) | Sweep ABOVE then reject`);
|
|
303
307
|
}
|
|
304
308
|
if (price && state.nearestSupport) {
|
|
305
|
-
const gapS = price - state.nearestSupport;
|
|
306
|
-
|
|
307
|
-
const dirS = gapS > 0 ? 'above' : 'below';
|
|
308
|
-
const absTicksS = Math.abs(ticksS);
|
|
309
|
-
if (absTicksS <= 50) { // Only show if within 50 ticks
|
|
310
|
-
ui.addLog('analysis', `PROX S: ${Math.abs(gapS).toFixed(2)} pts (${absTicksS} ticks ${dirS}) | Trigger: price must sweep BELOW then reject`);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Strategy status - what we're waiting for
|
|
315
|
-
if (state.activeZones === 0) {
|
|
316
|
-
ui.addLog('risk', 'Building liquidity map - scanning swing points for zone formation...');
|
|
317
|
-
} else if (!state.nearestSupport && !state.nearestResistance) {
|
|
318
|
-
ui.addLog('risk', 'Zones detected but outside proximity range - waiting for price approach');
|
|
319
|
-
} else if (!state.nearestSupport) {
|
|
320
|
-
ui.addLog('analysis', 'Monitoring resistance for HIGH SWEEP opportunity (SHORT entry on rejection)');
|
|
321
|
-
} else if (!state.nearestResistance) {
|
|
322
|
-
ui.addLog('analysis', 'Monitoring support for LOW SWEEP opportunity (LONG entry on rejection)');
|
|
323
|
-
} else {
|
|
324
|
-
ui.addLog('ready', 'Both zones active - monitoring for liquidity sweep with rejection confirmation');
|
|
309
|
+
const gapS = price - state.nearestSupport, ticksS = Math.abs(Math.round(gapS / tickSize));
|
|
310
|
+
if (ticksS <= 50) ui.addLog('analysis', `PROX S: ${Math.abs(gapS).toFixed(2)} pts (${ticksS} ticks) | Sweep BELOW then reject`);
|
|
325
311
|
}
|
|
312
|
+
if (state.activeZones === 0) ui.addLog('risk', 'Building liquidity map...');
|
|
313
|
+
else if (!state.nearestSupport && !state.nearestResistance) ui.addLog('risk', 'Zones outside range');
|
|
314
|
+
else if (!state.nearestSupport) ui.addLog('analysis', 'Monitoring R for SHORT sweep');
|
|
315
|
+
else if (!state.nearestResistance) ui.addLog('analysis', 'Monitoring S for LONG sweep');
|
|
316
|
+
else ui.addLog('ready', 'Both zones active - awaiting sweep');
|
|
326
317
|
}
|
|
327
318
|
}
|
|
328
319
|
}
|
|
329
320
|
|
|
330
|
-
// Scanning log every 20 seconds
|
|
331
|
-
if (currentSecond % 20 === 0 && currentPosition === 0)
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// Tick flow log every 45 seconds (less frequent)
|
|
337
|
-
if (currentSecond % 45 === 0) {
|
|
338
|
-
const tickLog = smartLogs.getTickFlowLog(tickCount, ticksPerSecond);
|
|
339
|
-
ui.addLog('debug', `${tickLog.message} ${tickLog.details}`);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// AI Agents status log every 60 seconds
|
|
321
|
+
// Scanning log every 20 seconds
|
|
322
|
+
if (currentSecond % 20 === 0 && currentPosition === 0) ui.addLog('system', smartLogs.getScanningLog(true).message);
|
|
323
|
+
// Tick flow log every 45 seconds
|
|
324
|
+
if (currentSecond % 45 === 0) { const t = smartLogs.getTickFlowLog(tickCount, ticksPerSecond); ui.addLog('debug', `${t.message} ${t.details}`); }
|
|
325
|
+
// AI Agents status every 60 seconds
|
|
343
326
|
if (currentSecond % 60 === 0 && supervisionEnabled && supervisionEngine) {
|
|
344
327
|
const status = supervisionEngine.getStatus();
|
|
345
328
|
const agentNames = status.agents.map(a => a.name.split(' ')[0]).join(', ');
|
|
@@ -371,18 +354,12 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
371
354
|
timestamp: tick.timestamp || Date.now()
|
|
372
355
|
});
|
|
373
356
|
|
|
374
|
-
// Calculate latency from Rithmic ssboe/usecs
|
|
375
|
-
// Priority: ssboe/usecs (real exchange time) > inter-tick timing (fallback)
|
|
357
|
+
// Calculate latency from Rithmic ssboe/usecs or inter-tick timing
|
|
376
358
|
if (tick.ssboe && tick.usecs !== undefined) {
|
|
377
|
-
// Rithmic sends ssboe (seconds since epoch) and usecs (microseconds)
|
|
378
359
|
const tickTimeMs = (tick.ssboe * 1000) + Math.floor(tick.usecs / 1000);
|
|
379
360
|
const latency = now - tickTimeMs;
|
|
380
|
-
|
|
381
|
-
if (latency >= 0 && latency < 5000) {
|
|
382
|
-
stats.latency = latency;
|
|
383
|
-
}
|
|
361
|
+
if (latency >= 0 && latency < 5000) stats.latency = latency;
|
|
384
362
|
} else if (lastTickTime > 0) {
|
|
385
|
-
// Fallback: estimate from inter-tick timing
|
|
386
363
|
const timeSinceLastTick = now - lastTickTime;
|
|
387
364
|
if (timeSinceLastTick < 100) {
|
|
388
365
|
tickLatencies.push(timeSinceLastTick);
|
|
@@ -393,10 +370,7 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
393
370
|
lastTickTime = now;
|
|
394
371
|
});
|
|
395
372
|
|
|
396
|
-
marketFeed.on('connected', () => {
|
|
397
|
-
stats.connected = true;
|
|
398
|
-
ui.addLog('connected', 'Market data connected');
|
|
399
|
-
});
|
|
373
|
+
marketFeed.on('connected', () => { stats.connected = true; ui.addLog('connected', 'Market data connected'); });
|
|
400
374
|
marketFeed.on('subscribed', (symbol) => ui.addLog('system', `Subscribed: ${symbol}`));
|
|
401
375
|
marketFeed.on('error', (err) => ui.addLog('error', `Market: ${err.message}`));
|
|
402
376
|
marketFeed.on('disconnected', () => { stats.connected = false; ui.addLog('error', 'Market disconnected'); });
|
|
@@ -451,10 +425,14 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
451
425
|
if (stats.pnl >= dailyTarget) {
|
|
452
426
|
stopReason = 'target'; running = false;
|
|
453
427
|
ui.addLog('fill_win', `TARGET REACHED! +$${stats.pnl.toFixed(2)}`);
|
|
428
|
+
sessionLogger.log('TARGET', `Daily target reached: +$${stats.pnl.toFixed(2)}`);
|
|
454
429
|
} else if (stats.pnl <= -maxRisk) {
|
|
455
430
|
stopReason = 'risk'; running = false;
|
|
456
431
|
ui.addLog('fill_loss', `MAX RISK! -$${Math.abs(stats.pnl).toFixed(2)}`);
|
|
432
|
+
sessionLogger.log('RISK', `Max risk hit: -$${Math.abs(stats.pnl).toFixed(2)}`);
|
|
457
433
|
}
|
|
434
|
+
// Log P&L every poll
|
|
435
|
+
sessionLogger.pnl(stats.pnl, 0, currentPosition);
|
|
458
436
|
} catch (e) { /* silent */ }
|
|
459
437
|
};
|
|
460
438
|
|
|
@@ -496,7 +474,13 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
496
474
|
const durationMs = Date.now() - stats.startTime;
|
|
497
475
|
const h = Math.floor(durationMs / 3600000), m = Math.floor((durationMs % 3600000) / 60000), s = Math.floor((durationMs % 60000) / 1000);
|
|
498
476
|
stats.duration = h > 0 ? `${h}h ${m}m ${s}s` : m > 0 ? `${m}m ${s}s` : `${s}s`;
|
|
477
|
+
|
|
478
|
+
// End session logger and get log file path
|
|
479
|
+
const sessionLogPath = sessionLogger.end(stats, stopReason?.toUpperCase() || 'MANUAL');
|
|
499
480
|
renderSessionSummary(stats, stopReason);
|
|
481
|
+
if (sessionLogPath) {
|
|
482
|
+
console.log(`\n Session log: ${sessionLogPath}`);
|
|
483
|
+
}
|
|
500
484
|
|
|
501
485
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
502
486
|
await new Promise(resolve => {
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Session Logger - Persistent logs for algo trading sessions
|
|
3
|
+
* @module services/session-logger
|
|
4
|
+
*
|
|
5
|
+
* Creates a log file per session with all events:
|
|
6
|
+
* - Strategy signals, trades, P&L
|
|
7
|
+
* - Market data (ticks, bars)
|
|
8
|
+
* - Zone/Swing detection
|
|
9
|
+
* - Errors and warnings
|
|
10
|
+
*
|
|
11
|
+
* Log files: ~/.hedgequantx/sessions/YYYY-MM-DD_HH-MM-SS_<strategy>.log
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const { SECURITY } = require('../config/settings');
|
|
18
|
+
|
|
19
|
+
class SessionLogger {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.sessionDir = path.join(os.homedir(), SECURITY.SESSION_DIR, 'sessions');
|
|
22
|
+
this.logFile = null;
|
|
23
|
+
this.sessionId = null;
|
|
24
|
+
this.buffer = [];
|
|
25
|
+
this.flushInterval = null;
|
|
26
|
+
this.metadata = {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Start a new session log
|
|
31
|
+
* @param {Object} params - Session parameters
|
|
32
|
+
* @param {string} params.strategy - Strategy ID (e.g., 'hqx-2b')
|
|
33
|
+
* @param {string} params.account - Account name
|
|
34
|
+
* @param {string} params.symbol - Trading symbol
|
|
35
|
+
* @param {number} params.contracts - Number of contracts
|
|
36
|
+
* @param {number} params.target - Daily target
|
|
37
|
+
* @param {number} params.risk - Max risk
|
|
38
|
+
*/
|
|
39
|
+
start({ strategy, account, symbol, contracts, target, risk }) {
|
|
40
|
+
// Create session directory if needed
|
|
41
|
+
if (!fs.existsSync(this.sessionDir)) {
|
|
42
|
+
fs.mkdirSync(this.sessionDir, { recursive: true, mode: SECURITY.DIR_PERMISSIONS });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Generate session ID and file name
|
|
46
|
+
const now = new Date();
|
|
47
|
+
this.sessionId = now.toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
48
|
+
const fileName = `${this.sessionId}_${strategy}.log`;
|
|
49
|
+
this.logFile = path.join(this.sessionDir, fileName);
|
|
50
|
+
|
|
51
|
+
// Store metadata
|
|
52
|
+
this.metadata = {
|
|
53
|
+
strategy,
|
|
54
|
+
account,
|
|
55
|
+
symbol,
|
|
56
|
+
contracts,
|
|
57
|
+
target,
|
|
58
|
+
risk,
|
|
59
|
+
startTime: now.toISOString(),
|
|
60
|
+
startTimestamp: Date.now()
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Write header
|
|
64
|
+
const header = [
|
|
65
|
+
'================================================================================',
|
|
66
|
+
`HQX SESSION LOG - ${strategy.toUpperCase()}`,
|
|
67
|
+
'================================================================================',
|
|
68
|
+
`Session ID: ${this.sessionId}`,
|
|
69
|
+
`Started: ${now.toISOString()}`,
|
|
70
|
+
`Strategy: ${strategy}`,
|
|
71
|
+
`Account: ${account}`,
|
|
72
|
+
`Symbol: ${symbol}`,
|
|
73
|
+
`Contracts: ${contracts}`,
|
|
74
|
+
`Target: $${target}`,
|
|
75
|
+
`Risk: $${risk}`,
|
|
76
|
+
'================================================================================',
|
|
77
|
+
'',
|
|
78
|
+
].join('\n');
|
|
79
|
+
|
|
80
|
+
fs.writeFileSync(this.logFile, header, { mode: SECURITY.FILE_PERMISSIONS });
|
|
81
|
+
|
|
82
|
+
// Start flush interval (every 2 seconds)
|
|
83
|
+
this.flushInterval = setInterval(() => this._flush(), 2000);
|
|
84
|
+
|
|
85
|
+
this._write('SYSTEM', 'Session started');
|
|
86
|
+
return this.logFile;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Log an event
|
|
91
|
+
* @param {string} type - Event type (SYSTEM, SIGNAL, TRADE, MARKET, ZONE, SWING, ERROR, etc.)
|
|
92
|
+
* @param {string} message - Log message
|
|
93
|
+
* @param {Object} [data] - Optional data object
|
|
94
|
+
*/
|
|
95
|
+
log(type, message, data = null) {
|
|
96
|
+
if (!this.logFile) return;
|
|
97
|
+
|
|
98
|
+
const timestamp = new Date().toISOString().slice(11, 23); // HH:MM:SS.mmm
|
|
99
|
+
const elapsed = this._getElapsed();
|
|
100
|
+
const dataStr = data ? ` | ${JSON.stringify(data)}` : '';
|
|
101
|
+
const line = `[${timestamp}] [${elapsed}] [${type.padEnd(8)}] ${message}${dataStr}`;
|
|
102
|
+
|
|
103
|
+
this.buffer.push(line);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Log market tick
|
|
108
|
+
*/
|
|
109
|
+
tick(price, size, bid, ask) {
|
|
110
|
+
this.log('TICK', `Price: ${price} | Size: ${size} | Bid: ${bid} | Ask: ${ask}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Log bar completion
|
|
115
|
+
*/
|
|
116
|
+
bar(bar) {
|
|
117
|
+
this.log('BAR', `O:${bar.open} H:${bar.high} L:${bar.low} C:${bar.close} V:${bar.volume}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Log swing detection
|
|
122
|
+
*/
|
|
123
|
+
swing(type, price, strength) {
|
|
124
|
+
this.log('SWING', `${type} @ ${price} | Strength: ${strength}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Log zone detection
|
|
129
|
+
*/
|
|
130
|
+
zone(type, high, low, touches) {
|
|
131
|
+
this.log('ZONE', `${type} Zone @ ${high}-${low} | Touches: ${touches}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Log signal generation
|
|
136
|
+
*/
|
|
137
|
+
signal(direction, price, confidence, reason) {
|
|
138
|
+
this.log('SIGNAL', `${direction} @ ${price} | Confidence: ${(confidence * 100).toFixed(1)}% | ${reason}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Log trade execution
|
|
143
|
+
*/
|
|
144
|
+
trade(action, direction, price, qty, orderId) {
|
|
145
|
+
this.log('TRADE', `${action} ${direction} x${qty} @ ${price} | OrderID: ${orderId}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Log P&L update
|
|
150
|
+
*/
|
|
151
|
+
pnl(realized, unrealized, position) {
|
|
152
|
+
this.log('PNL', `Realized: $${realized.toFixed(2)} | Unrealized: $${unrealized.toFixed(2)} | Position: ${position}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Log strategy state
|
|
157
|
+
*/
|
|
158
|
+
state(zonesCount, swingsCount, barsCount, bias) {
|
|
159
|
+
this.log('STATE', `Zones: ${zonesCount} | Swings: ${swingsCount} | Bars: ${barsCount} | Bias: ${bias}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Log error
|
|
164
|
+
*/
|
|
165
|
+
error(message, error) {
|
|
166
|
+
this.log('ERROR', message, { error: error?.message || error });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Log warning
|
|
171
|
+
*/
|
|
172
|
+
warn(message) {
|
|
173
|
+
this.log('WARN', message);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Log debug info
|
|
178
|
+
*/
|
|
179
|
+
debug(message, data) {
|
|
180
|
+
this.log('DEBUG', message, data);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* End session and write summary
|
|
185
|
+
*/
|
|
186
|
+
end(stats, stopReason = 'MANUAL') {
|
|
187
|
+
if (!this.logFile) return null;
|
|
188
|
+
|
|
189
|
+
// Flush remaining buffer
|
|
190
|
+
this._flush();
|
|
191
|
+
|
|
192
|
+
const endTime = new Date();
|
|
193
|
+
const duration = this._formatDuration(Date.now() - this.metadata.startTimestamp);
|
|
194
|
+
|
|
195
|
+
const summary = [
|
|
196
|
+
'',
|
|
197
|
+
'================================================================================',
|
|
198
|
+
'SESSION SUMMARY',
|
|
199
|
+
'================================================================================',
|
|
200
|
+
`Ended: ${endTime.toISOString()}`,
|
|
201
|
+
`Duration: ${duration}`,
|
|
202
|
+
`Stop Reason: ${stopReason}`,
|
|
203
|
+
'--------------------------------------------------------------------------------',
|
|
204
|
+
`Trades: ${stats.trades || 0}`,
|
|
205
|
+
`Wins: ${stats.wins || 0}`,
|
|
206
|
+
`Losses: ${stats.losses || 0}`,
|
|
207
|
+
`Win Rate: ${stats.trades > 0 ? ((stats.wins / stats.trades) * 100).toFixed(1) : 0}%`,
|
|
208
|
+
`P&L: $${(stats.pnl || 0).toFixed(2)}`,
|
|
209
|
+
`Target: $${this.metadata.target}`,
|
|
210
|
+
'================================================================================',
|
|
211
|
+
'',
|
|
212
|
+
].join('\n');
|
|
213
|
+
|
|
214
|
+
fs.appendFileSync(this.logFile, summary);
|
|
215
|
+
|
|
216
|
+
// Stop flush interval
|
|
217
|
+
if (this.flushInterval) {
|
|
218
|
+
clearInterval(this.flushInterval);
|
|
219
|
+
this.flushInterval = null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const logPath = this.logFile;
|
|
223
|
+
this.logFile = null;
|
|
224
|
+
this.sessionId = null;
|
|
225
|
+
this.buffer = [];
|
|
226
|
+
this.metadata = {};
|
|
227
|
+
|
|
228
|
+
return logPath;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Get elapsed time string
|
|
233
|
+
* @private
|
|
234
|
+
*/
|
|
235
|
+
_getElapsed() {
|
|
236
|
+
if (!this.metadata.startTimestamp) return '00:00:00';
|
|
237
|
+
const elapsed = Date.now() - this.metadata.startTimestamp;
|
|
238
|
+
return this._formatDuration(elapsed);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Format duration in HH:MM:SS
|
|
243
|
+
* @private
|
|
244
|
+
*/
|
|
245
|
+
_formatDuration(ms) {
|
|
246
|
+
const seconds = Math.floor(ms / 1000);
|
|
247
|
+
const h = Math.floor(seconds / 3600);
|
|
248
|
+
const m = Math.floor((seconds % 3600) / 60);
|
|
249
|
+
const s = seconds % 60;
|
|
250
|
+
return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Write log entry immediately
|
|
255
|
+
* @private
|
|
256
|
+
*/
|
|
257
|
+
_write(type, message, data = null) {
|
|
258
|
+
this.log(type, message, data);
|
|
259
|
+
this._flush();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Flush buffer to file
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
266
|
+
_flush() {
|
|
267
|
+
if (!this.logFile || this.buffer.length === 0) return;
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
const content = this.buffer.join('\n') + '\n';
|
|
271
|
+
fs.appendFileSync(this.logFile, content);
|
|
272
|
+
this.buffer = [];
|
|
273
|
+
} catch (err) {
|
|
274
|
+
// Ignore write errors
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get path to sessions directory
|
|
280
|
+
*/
|
|
281
|
+
getSessionsDir() {
|
|
282
|
+
return this.sessionDir;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* List recent session logs
|
|
287
|
+
* @param {number} limit - Max number of sessions to return
|
|
288
|
+
*/
|
|
289
|
+
listSessions(limit = 10) {
|
|
290
|
+
if (!fs.existsSync(this.sessionDir)) return [];
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
const files = fs.readdirSync(this.sessionDir)
|
|
294
|
+
.filter(f => f.endsWith('.log'))
|
|
295
|
+
.sort()
|
|
296
|
+
.reverse()
|
|
297
|
+
.slice(0, limit);
|
|
298
|
+
|
|
299
|
+
return files.map(f => ({
|
|
300
|
+
file: f,
|
|
301
|
+
path: path.join(this.sessionDir, f),
|
|
302
|
+
date: f.slice(0, 10),
|
|
303
|
+
time: f.slice(11, 19).replace(/-/g, ':'),
|
|
304
|
+
strategy: f.slice(20, -4)
|
|
305
|
+
}));
|
|
306
|
+
} catch {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Singleton instance
|
|
313
|
+
const sessionLogger = new SessionLogger();
|
|
314
|
+
|
|
315
|
+
module.exports = { sessionLogger, SessionLogger };
|