1. //+------------------------------------------------------------------+
  2. //| AIBRAIN OTC v45.0 - HRN FIXED + PREDICTION UPGRADED + BIG FONTS |
  3. //| Fixed: Real HRN detection, 2-candle close rule, Better prediction |
  4. //+------------------------------------------------------------------+
  5. #property copyright "AIBRAIN ULTIMATE - KM RANA"
  6. #property version "45.0"
  7. #property strict
  8. #property indicator_chart_window
  9. #define Alert(x)
  10. #define PFX "AIB9_"
  11. #define VER "v45.0 FINAL"
  12. #define LB 18
  13. #define MAX_LEVELS 5
  14. #define MAX_REJ 50
  15. #define LOOKBACK 50
  16.  
  17. input string SPM_FILE = "KM RANA";
  18. input int HOLD_SEC = 60;
  19. input int POS_X = 4;
  20. input int POS_Y = 20;
  21. input int DASH_W = 660;
  22. input bool SHOW_TIMER = true;
  23. input bool SHOW_SR_LINES = true;
  24. input string ENTRY_MODE = "TIME";
  25. input int FLAG_MIN_SEC = 10;
  26. input int FLAG_MAX_SEC = 35;
  27. input int TIME_MIN_SEC = 10;
  28. input int TIME_MAX_SEC = 35;
  29. input int MIN_REMAINING_SEC = 15;
  30. input double REVERSAL_PCT = 30.0;
  31. input double WICK_PCT = 0.65;
  32. input int HRN_CONFIRM_BARS = 2;
  33. input bool HA_ALIGN_FILTER = false;
  34. input bool CONSENSUS_FILTER = false;
  35. input bool ENABLE_NOTIFY = true;
  36. input bool FAST_MODE = false;
  37. input int BROKER_SPREAD_THRESHOLD= 6;
  38. input double OTC_TRAP_WEIGHT = 15.0;
  39. input int CROWD_EXTREME_PCT = 70;
  40. input bool ENABLE_BROKER_KILLER = true;
  41. input bool ENABLE_SESSION_FILTER = true;
  42. input bool ENABLE_SPIKE_FILTER = true;
  43. input bool ENABLE_LAST_SEC_BLOCK = true;
  44. input bool ENABLE_RISK_CONTROL = true;
  45. input bool ENABLE_ENTRY_ZONE = true;
  46. input bool ML_ADAPTIVE = true;
  47. input bool VOLUME_PROFILE_TRAP = true;
  48. input bool MTF_CONFIRM = false;
  49. input bool ENABLE_TELEGRAM = false;
  50. input string TELEGRAM_TOKEN = "";
  51. input string TELEGRAM_CHAT_ID = "";
  52. input string TRADE_MODE = "NORMAL";
  53. input string STRATEGY_MODE = "TRAP_ONLY";
  54. input int STRATEGY_THRESHOLD = 75;
  55. input int MAX_LOSS_STREAK = 2;
  56. input double MIN_CONFIDENCE = 75.0;
  57. input bool ENABLE_RISK_LOCK = true;
  58. input double PATTERN_TOLERANCE_PIPS = 8.0;
  59. input int MIN_PATTERN_SEPARATION = 5;
  60. input bool SHOW_COMMON_POINTS = true;
  61. input double COMMON_POINT_TOL_PIPS = 15.0;
  62. input bool SHOW_WICK_REJECT_LINES = true;
  63. input int WICK_MIN_TOUCHES = 1;
  64. input double WICK_ZONE_PIPS = 15.0;
  65. input int WICK_EXPIRE_BARS = 60;
  66.  
  67. #define NEON_GREEN C'0,255,100'
  68. #define NEON_RED C'255,40,80'
  69. #define NEON_YELLOW C'255,220,0'
  70. #define NEON_ORANGE C'255,120,0'
  71. #define NEON_CYAN C'0,255,200'
  72. #define NEON_PURPLE C'200,0,255'
  73. #define NEON_PINK C'255,80,180'
  74. #define NEON_BLUE C'0,200,255'
  75. #define NEON_LIME C'80,255,80'
  76. #define NEON_GOLD C'255,180,0'
  77. #define DARK_BLUE_NEON C'0,100,255'
  78. #define NEON_WHITE C'220,230,255'
  79. #define CGR C'160,170,190'
  80. #define BG_DARK1 C'6,8,16'
  81. #define BG_DARK2 C'10,14,24'
  82. #define BG_DARK3 C'14,20,32'
  83. #define BG_DARK4 C'18,26,40'
  84.  
  85. struct HTFLevel{ double price; string timeframe; string type; datetime time; int strength; bool isRoundNumber; };
  86.  
  87. //+------------------------------------------------------------------+
  88. // GLOBAL VARIABLES
  89. //+------------------------------------------------------------------+
  90. string g_haM1="",g_haM5="",g_haBoth="";
  91. color g_haM1Color=clrGray,g_haM5Color=clrGray;
  92. static string st_sig="WAIT",st_cdl="WAIT";
  93. static double st_pct=50;
  94. static datetime st_t=0;
  95. static double NW[36];
  96. static double g_rsc=0,g_tfa=3;
  97. static datetime g_spm_t=0,g_last_bar=0;
  98. double ResLevels[MAX_LEVELS],SupLevels[MAX_LEVELS];
  99. int resCount=0,supCount=0;
  100. datetime lastSRBar=0;
  101. static double g_nearest_res=0,g_nearest_sup=0;
  102. static string g_brk_str="NO BRK";
  103. static color g_brk_color=CGR;
  104. struct RejLevel{double price;int touches;};
  105. static RejLevel g_rj[MAX_REJ];
  106. static int g_rj_cnt=0;
  107.  
  108. // ===== NEW HRN SYSTEM =====
  109. static double g_hrn_price=0;
  110. static bool g_hrn_is_sup=true;
  111. static int g_hrn_brk_bars=0;
  112. static datetime g_hrn_scan_bar=0;
  113. static string g_hrn_str="--";
  114. static double g_hrn_score=0;
  115. static bool g_hrn_confirmed_break=false;
  116.  
  117. static string g_otcCallPct=50,g_otcPutPct=50;
  118. static string g_pairNames[5],g_pairSigs[5];
  119. static double g_pairConfs[5];
  120. static int g_pairCount=0;
  121. static string g_copiedPair="";
  122. static string g_adv1="WAIT KAR",g_adv2="Signals mix",g_adv3="";
  123. static color g_advC=NEON_YELLOW;
  124. static double g_frozen_gProb=50,g_frozen_rProb=50;
  125. static string g_frozen_pAction="UNCERTAIN";
  126. static color g_frozen_pColor=NEON_YELLOW;
  127. static double g_calc_gProb=50,g_calc_rProb=50;
  128. static string g_calc_pAction="UNCERTAIN";
  129. static color g_calc_pColor=NEON_YELLOW;
  130. static double g_gProb=50,g_rProb=50;
  131. static string g_pAction="UNCERTAIN";
  132. static color g_pColor=NEON_YELLOW;
  133. static datetime g_last_freeze_bar=0;
  134. static double g_accuracy=65.0;
  135. static int g_acc_correct=0,g_acc_total=0;
  136. static datetime g_acc_lastBar=0;
  137. static double g_lastPredGreen=50.0;
  138. static datetime g_lastPredBar=0;
  139. static datetime g_lastLogBar=0;
  140. static string g_finalSignal="WAIT";
  141. static color g_finalColor=NEON_YELLOW;
  142. static datetime g_signalTime=0;
  143. static string g_lastNotified="";
  144. static string g_marketMode="RANGE",g_prevMode="";
  145. static int g_lossStreak=0;
  146. static bool g_tradingStopped=false;
  147. static datetime g_stopStartTime=0;
  148. static double g_brokerBias=0.0;
  149. static string g_symbolKey="";
  150. static string g_strategyType="NONE";
  151. static string g_strategySignal="WAIT";
  152. static string g_strategyReason="";
  153. static double qmrA=0,qmrB=0,qmrC=0,qmrD=0;
  154. static datetime qmrTA=0,qmrTB=0,qmrTC=0,qmrTD=0;
  155. static bool qmrActive=false;
  156. static datetime qmrExpire=0;
  157. #define MAX_COMMON_PTS 5
  158. static double g_commonPrice[MAX_COMMON_PTS];
  159. static datetime g_commonTime[MAX_COMMON_PTS];
  160. static int g_commonCount=0;
  161. static datetime g_commonExpire[MAX_COMMON_PTS];
  162. static string g_commonType[MAX_COMMON_PTS];
  163. static datetime g_lastCommonScan=0;
  164. #define MAX_WICK_LINES 5
  165. static double g_wickLinePrice[MAX_WICK_LINES];
  166. static int g_wickLineTouches[MAX_WICK_LINES];
  167. static datetime g_wickLineExpire[MAX_WICK_LINES];
  168. static int g_wickLineCount=0;
  169. static datetime g_lastWickScan=0;
  170. static bool g_isSideways=false;
  171. static string g_tfa_detail="";
  172. static HTFLevel g_htfLevels[50];
  173. static int g_htfLevelCount=0;
  174. static datetime g_lastLevelScan=0;
  175. static bool g_mtfConfirmed=true;
  176. static string g_filterStatus="ALL CLEAR";
  177.  
  178. //+------------------------------------------------------------------+
  179. // HA CANDLE CALCULATION
  180. //+------------------------------------------------------------------+
  181. void CalcHA(){
  182. if(Bars<10) return;
  183. ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true); ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true);
  184. static double haO1[500],haC1[500]; static datetime lb1=0;
  185. ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true);
  186. datetime c1=iTime(NULL,PERIOD_M1,0);
  187. if(c1!=lb1){ lb1=c1; int lim=MathMin(iBars(NULL,PERIOD_M1),500);
  188. for(int i=lim-1;i>=0;i--){ haC1[i]=(Open[i]+High[i]+Low[i]+Close[i])/4.0;
  189. if(i==lim-1) haO1[i]=(Open[i]+Close[i])/2.0; else haO1[i]=(haO1[i+1]+haC1[i+1])/2.0; }}
  190. double d1=MathAbs(haC1[1]-haO1[1]),r1=High[1]-Low[1];
  191. bool dz=(r1>0&&d1<r1*0.1),b1=(!dz&&haC1[1]>haO1[1]),be1=(!dz&&haC1[1]<haO1[1]);
  192. if(b1){g_haM1="HA BULLISH 1";g_haM1Color=clrLime;}
  193. else if(be1){g_haM1="HA BEARISH 1";g_haM1Color=clrRed;}
  194. else{g_haM1="HA DOJI 1";g_haM1Color=clrYellow;}
  195.  
  196. if(iBars(NULL,PERIOD_M5)>=10){
  197. static double haO5[200],haC5[200]; static datetime lb5=0;
  198. ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true);
  199. datetime c5=iTime(NULL,PERIOD_M5,0);
  200. if(c5!=lb5){ lb5=c5; int lim=MathMin(iBars(NULL,PERIOD_M5),200);
  201. for(int i=lim-1;i>=0;i--){ double o=iOpen(NULL,PERIOD_M5,i),h=iHigh(NULL,PERIOD_M5,i),l=iLow(NULL,PERIOD_M5,i),c=iClose(NULL,PERIOD_M5,i);
  202. haC5[i]=(o+h+l+c)/4.0; if(i==lim-1) haO5[i]=(o+c)/2.0; else haO5[i]=(haO5[i+1]+haC5[i+1])/2.0; }}
  203. double d5=MathAbs(haC5[1]-haO5[1]),r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1);
  204. bool dz5=(r5>0&&d5<r5*0.1),b5=(!dz5&&haC5[1]>haO5[1]),be5=(!dz5&&haC5[1]<haO5[1]);
  205. if(b5){g_haM5="HA BULLISH 5";g_haM5Color=clrLime;}
  206. else if(be5){g_haM5="HA BEARISH 5";g_haM5Color=clrRed;}
  207. else{g_haM5="HA DOJI 5";g_haM5Color=clrYellow;}
  208. if(b1&&b5)g_haBoth="BOTH BULL"; else if(be1&&be5)g_haBoth="BOTH BEAR"; else g_haBoth="MIXED";
  209. }else{g_haM5="5 --";g_haM5Color=clrGray;g_haBoth="HA --";}
  210. }
  211.  
  212. //+------------------------------------------------------------------+
  213. // HELPER FUNCTIONS
  214. //+------------------------------------------------------------------+
  215. bool IsLineNearby(double price,double pipTol=3.0){
  216. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip;
  217. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i);
  218. if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE){
  219. double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)<tol) return true; }}
  220. return false;
  221. }
  222.  
  223. string GetCurrentSession(color &sC){
  224. int h=TimeHour(TimeGMT());
  225. if(h>=12&&h<16){sC=NEON_GOLD;return "LON+NY";}
  226. if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";}
  227. if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";}
  228. if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";}
  229. if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";}
  230. sC=C'100,100,120'; return "SYDNEY";
  231. }
  232.  
  233. bool IsSessionActive(){int h=TimeHour(TimeGMT());return(h>=7&&h<=21);}
  234.  
  235. bool IsBigCandle(int s){if(Bars<20)return false;double a=iATR(NULL,PERIOD_M1,14,0);return(a>0&&(High[s]-Low[s])>a*1.8);}
  236.  
  237. //+------------------------------------------------------------------+
  238. // MTF CONFIRMATION
  239. //+------------------------------------------------------------------+
  240. bool CheckMTFConfirmation(){
  241. if(!MTF_CONFIRM) return true;
  242. bool m1Bull=(Close[1]>Open[1]);
  243. bool m5Bull=false,m15Bull=false;
  244. if(iBars(NULL,PERIOD_M5)>=3) m5Bull=(iClose(NULL,PERIOD_M5,1)>iOpen(NULL,PERIOD_M5,1));
  245. if(iBars(NULL,PERIOD_M15)>=3) m15Bull=(iClose(NULL,PERIOD_M15,1)>iOpen(NULL,PERIOD_M15,1));
  246. int bullCount=0,bearCount=0;
  247. if(m1Bull) bullCount++; else bearCount++;
  248. if(m5Bull) bullCount++; else bearCount++;
  249. if(m15Bull) bullCount++; else bearCount++;
  250. g_mtfConfirmed=(bullCount>=2 || bearCount>=2);
  251. return g_mtfConfirmed;
  252. }
  253.  
  254. //+------------------------------------------------------------------+
  255. // CUSTOM TANH FOR MQL4
  256. //+------------------------------------------------------------------+
  257. double Tanh(double x){
  258. double exp2x = MathExp(2.0 * x);
  259. return (exp2x - 1.0) / (exp2x + 1.0);
  260. }
  261.  
  262. //+------------------------------------------------------------------+
  263. // FRACTAL DIMENSION
  264. //+------------------------------------------------------------------+
  265. double CalcFractalDimension(int period){
  266. if(period < 2) return 1.5;
  267. double sum = 0.0;
  268. for(int i = 1; i < period; i++){
  269. double range1 = High[i] - Low[i];
  270. double range2 = High[i+1] - Low[i+1];
  271. if(range1 <= 0.0 || range2 <= 0.0) continue;
  272. sum += MathLog(range1 / range2 + 0.001) * MathLog((double)i / (double)period);
  273. }
  274. double result = 2.0 - sum / period;
  275. if(result < 1.0) result = 1.0;
  276. if(result > 2.0) result = 2.0;
  277. return result;
  278. }
  279.  
  280. //+------------------------------------------------------------------+
  281. // BROKER TRAP DETECTION
  282. //+------------------------------------------------------------------+
  283. double DetectBrokerTrap(int lookback){
  284. int bull = 0, bear = 0;
  285. for(int i = 1; i <= lookback; i++){
  286. if(Close[i] > Open[i]) bull++;
  287. else if(Close[i] < Open[i]) bear++;
  288. }
  289. double crowd = (bull > bear) ? (double)bull / lookback : (double)bear / lookback;
  290. double priceMove = MathAbs(Close[1] - Close[lookback]) / (Close[lookback] + 0.00001);
  291. if(crowd > 0.7 && priceMove < 0.002) return 0.9;
  292. if(crowd > 0.6 && priceMove > 0.001) return 0.5;
  293. return 0.3;
  294. }
  295.  
  296. //+------------------------------------------------------------------+
  297. // QUICK MEDIAN
  298. //+------------------------------------------------------------------+
  299. double QuickMedian(double &arr[], int size){
  300. double sorted[20];
  301. for(int i = 0; i < size; i++) sorted[i] = arr[i];
  302. for(int i = 0; i < size-1; i++)
  303. for(int j = i+1; j < size; j++)
  304. if(sorted[i] > sorted[j]){
  305. double tmp = sorted[i];
  306. sorted[i] = sorted[j];
  307. sorted[j] = tmp;
  308. }
  309. return (sorted[size/2] + sorted[(size-1)/2]) / 2.0;
  310. }
  311.  
  312. //+------------------------------------------------------------------+
  313. // MAIN ADVANCED TFA
  314. //+------------------------------------------------------------------+
  315. double CalcAdvancedTFA(string &detail){
  316. if(Bars < 30){
  317. detail = "Bars low";
  318. return 3.0;
  319. }
  320.  
  321. double score = 0;
  322. string p = "";
  323.  
  324. // === 1. ADX (Trend Strength) ===
  325. double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  326. double adxSc = (adx>=25)?1.0:(adx>=20)?0.6:(adx>=15)?0.3:0.1;
  327. score += adxSc;
  328. p += "ADX:" + ((adxSc>=0.6)?"+":"-") + " ";
  329.  
  330. // === 2. VOLUME ===
  331. double v1 = iVolume(NULL, PERIOD_M1, 1);
  332. double vA = 0;
  333. for(int i=2; i<=6; i++) vA += iVolume(NULL, PERIOD_M1, i);
  334. vA = (vA>0)? vA/5.0 : 1;
  335. double vr = v1 / vA;
  336. double volSc = (vr>=2.0)?1.0:(vr>=1.5)?0.7:(vr>=1.1)?0.4:0.1;
  337. score += volSc;
  338. p += "VOL:" + ((volSc>=0.5)?"+":"-") + " ";
  339.  
  340. // === 3. RSI ===
  341. double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  342. double rsiSc = 0.2;
  343. if(rsi>=60 || rsi<=40) rsiSc = 1.0;
  344. else if(rsi>=55 || rsi<=45) rsiSc = 0.6;
  345. else if(rsi>=50 || rsi<=50) rsiSc = 0.3;
  346. score += rsiSc;
  347. p += "RSI:" + ((rsiSc>=0.6)?"+":"-") + " ";
  348.  
  349. // === 4. ATR ===
  350. double atr = iATR(NULL, PERIOD_M1, 14, 1);
  351. double cs = High[1] - Low[1];
  352. double atrSc = 0.2;
  353. if(atr > 0){
  354. double r = cs / atr;
  355. if(r>=0.7 && r<=1.5) atrSc = 1.0;
  356. else if(r>=0.5 && r<=2.0) atrSc = 0.6;
  357. else atrSc = 0.3;
  358. }
  359. score += atrSc;
  360. p += "ATR:" + ((atrSc>=0.6)?"+":"-") + " ";
  361.  
  362. // === 5. CANDLE BODY ===
  363. double body = MathAbs(Close[1] - Open[1]);
  364. double range = High[1] - Low[1];
  365. double bdySc = 0.2;
  366. if(range > 0){
  367. double br = body / range;
  368. if(br>=0.6) bdySc = 1.0;
  369. else if(br>=0.4) bdySc = 0.6;
  370. else if(br>=0.2) bdySc = 0.3;
  371. }
  372. score += bdySc;
  373. p += "BODY:" + ((bdySc>=0.6)?"+":"-") + " ";
  374.  
  375. // === 6. SESSION ===
  376. double sesSc = IsSessionActive() ? 1.0 : 0.4;
  377. score += sesSc;
  378. p += "SES:" + ((sesSc>=0.7)?"+":"-");
  379.  
  380. double finalScore = MathMin(6.0, score);
  381. int rounded = (int)MathRound(finalScore);
  382. string scoreStr = IntegerToString(rounded) + "/6";
  383.  
  384. string dir = "MIX";
  385. if(g_haM1=="HA BULLISH 1" && g_haM5=="HA BULLISH 5") dir = "STRONG UP";
  386. else if(g_haM1=="HA BEARISH 1" && g_haM5=="HA BEARISH 5") dir = "STRONG DOWN";
  387. else if(g_haM1=="HA BULLISH 1" || g_haM5=="HA BULLISH 5") dir = "UP";
  388. else if(g_haM1=="HA BEARISH 1" || g_haM5=="HA BEARISH 5") dir = "DOWN";
  389.  
  390. detail = p + " | " + scoreStr + " " + dir;
  391. g_tfa_detail = detail;
  392.  
  393. return finalScore;
  394. }
  395.  
  396. //+------------------------------------------------------------------+
  397. // MICRO AI
  398. //+------------------------------------------------------------------+
  399. double CalcAdvancedMicroAI(){
  400. if(Bars<20) return 50.0; double score=50.0;
  401. for(int i=1;i<=5;i++){double r=High[i]-Low[i];if(r<=0)continue;
  402. double uw=(High[i]-MathMax(Open[i],Close[i]))/r,lw=(MathMin(Open[i],Close[i])-Low[i])/r,w=(6.0-i)/5.0;
  403. if(uw>0.60)score-=w*15; if(lw>0.60)score+=w*15;}
  404. double pos5=0; for(int i=1;i<=5;i++){double r=High[i]-Low[i];if(r<=0)continue;pos5+=(Close[i]-Low[i])/r;}
  405. score+=(pos5/5.0-0.5)*20.0;
  406. int gc=0,rc=0; for(int i=1;i<=8;i++){if(Close[i]>Open[i])gc++;else if(Close[i]<Open[i])rc++;} score+=(gc-rc)*2.5;
  407. double vl1=(double)iVolume(NULL,PERIOD_M1,1),vA=0;
  408. for(int i=2;i<=6;i++)vA+=iVolume(NULL,PERIOD_M1,i);vA/=5.0;
  409. if(vA>0){double vr=vl1/vA;if(vr>1.5&&Close[1]>Open[1])score+=8;if(vr>1.5&&Close[1]<Open[1])score-=8;}
  410. double r1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),r5=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  411. if(r1<35)score+=10;if(r1>65)score-=10;if(r1>r5&&Close[1]<Close[5])score+=6;if(r1<r5&&Close[1]>Close[5])score-=6;
  412. return MathMax(5.0,MathMin(95.0,score));
  413. }
  414.  
  415. //+------------------------------------------------------------------+
  416. // MICRO TRAP
  417. //+------------------------------------------------------------------+
  418. double VolumeTrapScore();
  419. int CalcAdvancedMicroTrap(){
  420. if(Bars<20)return 0;int score=0;double r=High[1]-Low[1];
  421. if(r>0){double uw=(High[1]-MathMax(Open[1],Close[1]))/r,lw=(MathMin(Open[1],Close[1])-Low[1])/r;
  422. if(uw>0.65)score+=30;else if(uw>0.50)score+=15;if(lw>0.65)score+=20;else if(lw>0.50)score+=10;}
  423. double v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  424. if(v2>0&&v1/v2>2.0)score+=25;else if(v2>0&&v1/v2>1.5)score+=12;
  425. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  426. if(rsi>78||rsi<22)score+=20;else if(rsi>72||rsi<28)score+=10;
  427. if((High[1]>g_nearest_res&&Close[1]<g_nearest_res)||(Low[1]<g_nearest_sup&&Close[1]>g_nearest_sup))score+=25;
  428. bool aG=(Close[1]>Open[1]&&Close[2]>Open[2]&&Close[3]>Open[3]),aR=(Close[1]<Open[1]&&Close[2]<Open[2]&&Close[3]<Open[3]);
  429. if(aG||aR)score+=15;
  430. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);if(sp>BROKER_SPREAD_THRESHOLD*1.5)score+=10;
  431. score+=(int)VolumeTrapScore();return MathMin(100,score);
  432. }
  433.  
  434. //+------------------------------------------------------------------+
  435. // FRACTAL
  436. //+------------------------------------------------------------------+
  437. double CalcAdvancedFractal(){
  438. if(Bars<15)return 0;double score=0;
  439. for(int i=2;i<=8&&i+2<Bars;i++){
  440. if(High[i]>High[i-1]&&High[i]>High[i-2]&&High[i]>High[i+1]&&High[i]>High[i+2]){double d=(High[i]-Close[0])/Point;if(d<50&&d>-10)score+=35;}
  441. if(Low[i]<Low[i-1]&&Low[i]<Low[i-2]&&Low[i]<Low[i+1]&&Low[i]<Low[i+2]){double d=(Close[0]-Low[i])/Point;if(d<50&&d>-10)score+=25;}}
  442. int dj=0;for(int i=1;i<=6;i++){double b=MathAbs(Close[i]-Open[i]),rg=High[i]-Low[i];if(rg>0&&b<rg*0.20)dj++;}
  443. if(dj>=3)score+=25;
  444. double r1=High[1]-Low[1];if(r1>0){double uw1=(High[1]-MathMax(Open[1],Close[1]))/r1,lw1=(MathMin(Open[1],Close[1])-Low[1])/r1;if(uw1>0.70||lw1>0.70)score+=20;}
  445. return MathMin(100,score);
  446. }
  447.  
  448. //+------------------------------------------------------------------+
  449. // MARKET BIAS
  450. //+------------------------------------------------------------------+
  451. string CalcAdvancedMarketBias(color &bC,double brain,double rsc){
  452. if(Bars<30){bC=NEON_YELLOW;return "CALCULATING";}
  453. double score=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  454. double pc=Close[0]-Close[10];
  455. if(pc>5*pip)score+=4;else if(pc>2*pip)score+=2;else if(pc<-5*pip)score-=4;else if(pc<-2*pip)score-=2;
  456. double hh1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],hh2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  457. double ll1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],ll2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  458. if(hh1>hh2&&ll1>ll2)score+=4;else if(hh1<hh2&&ll1<ll2)score-=4;else if(hh1>hh2)score+=2;else if(hh1<hh2)score-=2;
  459. double ema20=0,ema20p=0;for(int i=0;i<20;i++)ema20+=Close[i];ema20/=20;
  460. for(int i=1;i<=20&&i<Bars;i++)ema20p+=Close[i];ema20p/=20;
  461. if(ema20>ema20p)score+=3;else if(ema20<ema20p)score-=3;
  462. double ema50=0;for(int i=0;i<50&&i<Bars;i++)ema50+=Close[i];ema50/=MathMin(50,Bars);
  463. if(ema20>ema50)score+=3;else score-=3;
  464. int gC=0,rC=0;for(int i=1;i<=10;i++){if(Close[i]>Open[i])gC++;else if(Close[i]<Open[i])rC++;}
  465. if(gC>=7)score+=3;else if(rC>=7)score-=3;else if(gC>=5)score+=1;else if(rC>=5)score-=1;
  466. bool m1B=(g_haM1=="HA BULLISH 1"),m1Be=(g_haM1=="HA BEARISH 1"),m5B=(g_haM5=="HA BULLISH 5"),m5Be=(g_haM5=="HA BEARISH 5");
  467. if(m1B&&m5B)score+=4;else if(m1Be&&m5Be)score-=4;else if(m1B)score+=2;else if(m1Be)score-=2;
  468. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1),pDI=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_PLUSDI,1),mDI=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MINUSDI,1);
  469. if(adx>20){if(pDI>mDI+5)score+=4;else if(mDI>pDI+5)score-=4;}
  470. if(brain>3)score-=2;else if(brain<-3)score+=2;
  471. if(Close[1]>Open[1])score+=1;else if(Close[1]<Open[1])score-=1;
  472. if(rsc>2)score+=1;else if(rsc<-2)score-=1;
  473.  
  474. if(score>=12){bC=NEON_GREEN;return "STRONG BULL";}
  475. if(score>=7){bC=NEON_GREEN;return "BULLISH";}
  476. if(score>=3){bC=NEON_CYAN;return "LIGHT BULL";}
  477. if(score<=-12){bC=NEON_RED;return "STRONG BEAR";}
  478. if(score<=-7){bC=NEON_RED;return "BEARISH";}
  479. if(score<=-3){bC=NEON_ORANGE;return "LIGHT BEAR";}
  480. bC=NEON_YELLOW;return "NEUTRAL";
  481. }
  482.  
  483. //+------------------------------------------------------------------+
  484. // ████████████████████████████████████████████████████████████████████
  485. // ██ ULTIMATE NEXT CANDLE PREDICTION v2.0 - MUCH BETTER ██
  486. // ████████████████████████████████████████████████████████████████████
  487. //+------------------------------------------------------------------+
  488. void CalcAdvancedPrediction(double &gP, double &rP, string &reason, color &pC){
  489. if(Bars < 50){
  490. gP = 50; rP = 50; reason = "Bars low"; pC = NEON_YELLOW;
  491. return;
  492. }
  493.  
  494. bool jpy = (StringFind(Symbol(), "JPY") >= 0);
  495. double pip = jpy ? 0.01 : 0.0001;
  496. double green = 0, red = 0;
  497.  
  498. // ==========================================
  499. // 1. MOMENTUM + WICK TRAP (Weight 22)
  500. // ==========================================
  501. double body1 = MathAbs(Close[1] - Open[1]);
  502. double range1 = High[1] - Low[1];
  503. if(range1 > 0) {
  504. double wick_ratio = (range1 - body1) / range1;
  505. double upper_wick = High[1] - MathMax(Open[1], Close[1]);
  506. double lower_wick = MathMin(Open[1], Close[1]) - Low[1];
  507.  
  508. // Strong upper wick + green candle = BEAR TRAP
  509. if(upper_wick > range1 * 0.60 && Close[1] > Open[1]) {
  510. red += 22;
  511. }
  512. // Strong lower wick + red candle = BULL TRAP
  513. else if(lower_wick > range1 * 0.60 && Close[1] < Open[1]) {
  514. green += 22;
  515. }
  516. // Moderate wick
  517. else if(wick_ratio > 0.55) {
  518. if(upper_wick > lower_wick) red += 12;
  519. else green += 12;
  520. }
  521. }
  522.  
  523. // ==========================================
  524. // 2. RSI + CCI + STOCH TRIPLE (Weight 18)
  525. // ==========================================
  526. double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  527. double cci = iCCI(NULL, PERIOD_M1, 14, PRICE_TYPICAL, 1);
  528. double stochK = iStochastic(NULL, PERIOD_M1, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 1);
  529.  
  530. int oversold_signals = 0, overbought_signals = 0;
  531. if(rsi < 30) oversold_signals++;
  532. else if(rsi > 70) overbought_signals++;
  533. if(cci < -120) oversold_signals++;
  534. else if(cci > 120) overbought_signals++;
  535. if(stochK < 20) oversold_signals++;
  536. else if(stochK > 80) overbought_signals++;
  537.  
  538. if(oversold_signals >= 3) green += 18;
  539. else if(oversold_signals >= 2) green += 12;
  540. else if(overbought_signals >= 3) red += 18;
  541. else if(overbought_signals >= 2) red += 12;
  542.  
  543. // RSI Divergence (Extra Strong)
  544. double rsiPrev = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 5);
  545. double low1 = Low[iLowest(NULL, PERIOD_M1, MODE_LOW, 5, 1)];
  546. double low2 = Low[iLowest(NULL, PERIOD_M1, MODE_LOW, 5, 6)];
  547. double high1 = High[iHighest(NULL, PERIOD_M1, MODE_HIGH, 5, 1)];
  548. double high2 = High[iHighest(NULL, PERIOD_M1, MODE_HIGH, 5, 6)];
  549.  
  550. // Bullish Divergence: Price lower low, RSI higher low
  551. if(low1 < low2 && rsi > rsiPrev && rsi < 45) green += 15;
  552. // Bearish Divergence: Price higher high, RSI lower high
  553. if(high1 > high2 && rsi < rsiPrev && rsi > 55) red += 15;
  554.  
  555. // ==========================================
  556. // 3. VOLUME REVERSAL TRAP (Weight 20)
  557. // ==========================================
  558. double v1 = iVolume(NULL, PERIOD_M1, 1);
  559. double vAvg = 0;
  560. for(int i=2; i<=10; i++) vAvg += iVolume(NULL, PERIOD_M1, i);
  561. vAvg = (vAvg > 0) ? vAvg / 9.0 : 1.0;
  562. double vol_ratio = (vAvg > 0) ? v1 / vAvg : 1.0;
  563.  
  564. // High volume + opposite close = REVERSAL
  565. if(vol_ratio > 2.0) {
  566. if(Close[1] > Open[1]) red += 20; // Big green candle = trap up
  567. else green += 20; // Big red candle = trap down
  568. } else if(vol_ratio > 1.5) {
  569. if(Close[1] > Open[1]) red += 12;
  570. else green += 12;
  571. } else if(vol_ratio > 1.2) {
  572. // Normal volume = follow trend
  573. if(Close[1] > Open[1]) green += 5;
  574. else red += 5;
  575. }
  576.  
  577. // ==========================================
  578. // 4. HEIKEN ASHI SYNC M1 + M5 (Weight 15)
  579. // ==========================================
  580. // Calculate HA properly for M1
  581. double m1_haC1 = (Open[1]+High[1]+Low[1]+Close[1])/4.0;
  582. double m1_haC2 = (Open[2]+High[2]+Low[2]+Close[2])/4.0;
  583. double m1_haO2_apx = (Open[3]+Close[3])/2.0;
  584. double m1_haO1 = (m1_haO2_apx + m1_haC2)/2.0;
  585. bool haBull1 = (m1_haC1 > m1_haO1);
  586. double haStrength1 = MathAbs(m1_haC1 - m1_haO1) / (High[1] - Low[1] + 0.00001);
  587.  
  588. // Calculate HA for M5
  589. bool haBull5 = false;
  590. double haStrength5 = 0;
  591. if(iBars(NULL, PERIOD_M5) >= 5) {
  592. double m5_o1=iOpen(NULL,PERIOD_M5,1), m5_h1=iHigh(NULL,PERIOD_M5,1);
  593. double m5_l1=iLow(NULL,PERIOD_M5,1), m5_c1=iClose(NULL,PERIOD_M5,1);
  594. double m5_o2=iOpen(NULL,PERIOD_M5,2), m5_h2=iHigh(NULL,PERIOD_M5,2);
  595. double m5_l2=iLow(NULL,PERIOD_M5,2), m5_c2=iClose(NULL,PERIOD_M5,2);
  596. double m5_o3=iOpen(NULL,PERIOD_M5,3), m5_c3=iClose(NULL,PERIOD_M5,3);
  597. double m5_haC1 = (m5_o1+m5_h1+m5_l1+m5_c1)/4.0;
  598. double m5_haC2 = (m5_o2+m5_h2+m5_l2+m5_c2)/4.0;
  599. double m5_haO2_apx = (m5_o3+m5_c3)/2.0;
  600. double m5_haO1 = (m5_haO2_apx + m5_haC2)/2.0;
  601. haBull5 = (m5_haC1 > m5_haO1);
  602. haStrength5 = MathAbs(m5_haC1 - m5_haO1) / (m5_h1 - m5_l1 + 0.00001);
  603. }
  604.  
  605. if(haBull1 && haBull5) green += 15;
  606. else if(!haBull1 && !haBull5) red += 15;
  607. else if(haBull1 && haStrength1 > 0.5) green += 8;
  608. else if(!haBull1 && haStrength1 > 0.5) red += 8;
  609.  
  610. // ==========================================
  611. // 5. ADX + DI DIRECTION (Weight 12)
  612. // ==========================================
  613. double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  614. double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  615. double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  616.  
  617. if(adx > 25) {
  618. // Strong trend - follow DI direction
  619. double diDiff = plusDI - minusDI;
  620. if(diDiff > 8) green += 12;
  621. else if(diDiff > 4) green += 8;
  622. else if(diDiff < -8) red += 12;
  623. else if(diDiff < -4) red += 8;
  624. } else if(adx > 15) {
  625. // Weak trend
  626. if(plusDI > minusDI) green += 4;
  627. else red += 4;
  628. }
  629. // Low ADX = ranging = possible reversal
  630. else {
  631. if(Close[1] > Open[1]) red += 3;
  632. else green += 3;
  633. }
  634.  
  635. // ==========================================
  636. // 6. SUPPORT/RESISTANCE PROXIMITY (Weight 12)
  637. // ==========================================
  638. double sup = Low[iLowest(NULL, PERIOD_M1, MODE_LOW, 20, 2)];
  639. double res = High[iHighest(NULL, PERIOD_M1, MODE_HIGH, 20, 2)];
  640.  
  641. double distToRes = (res - Close[0]) / pip;
  642. double distToSup = (Close[0] - sup) / pip;
  643.  
  644. // Near resistance = expect rejection (red)
  645. if(distToRes < 8 && distToRes >= 0) red += 12;
  646. else if(distToRes < 15 && distToRes >= 0) red += 6;
  647.  
  648. // Near support = expect bounce (green)
  649. if(distToSup < 8 && distToSup >= 0) green += 12;
  650. else if(distToSup < 15 && distToSup >= 0) green += 6;
  651.  
  652. // HRN Level check
  653. if(g_hrn_price > 0) {
  654. double distToHRN = MathAbs(Close[0] - g_hrn_price) / pip;
  655. if(distToHRN < 5) {
  656. if(Close[0] > g_hrn_price) red += 8; // Above HRN = rejection expected
  657. else green += 8; // Below HRN = bounce expected
  658. }
  659. }
  660.  
  661. // ==========================================
  662. // 7. MACD CROSS + MOMENTUM (Weight 10)
  663. // ==========================================
  664. double macdMain = iMACD(NULL, PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);
  665. double macdSig = iMACD(NULL, PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1);
  666. double macdPrev = iMACD(NULL, PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 2);
  667. double macdSigPrev = iMACD(NULL, PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 2);
  668.  
  669. // Fresh crossover
  670. if(macdMain > macdSig && macdPrev <= macdSigPrev) green += 10;
  671. else if(macdMain < macdSig && macdPrev >= macdSigPrev) red += 10;
  672. // Already crossed
  673. else if(macdMain > macdSig) green += 5;
  674. else if(macdMain < macdSig) red += 5;
  675.  
  676. // ==========================================
  677. // 8. OTC CROWD TRAP (Weight 15)
  678. // ==========================================
  679. if(g_otcCallPct >= 75 && !haBull1) red += 15; // Heavy call crowd + HA red = trap
  680. else if(g_otcPutPct >= 75 && haBull1) green += 15; // Heavy put crowd + HA green = trap
  681. else if(g_otcCallPct >= 65 && !haBull1) red += 8;
  682. else if(g_otcPutPct >= 65 && haBull1) green += 8;
  683.  
  684. // ==========================================
  685. // 9. 3-CANDLE PATTERN (Weight 10)
  686. // ==========================================
  687. bool isHammer = (Low[1] == Low[iLowest(NULL, PERIOD_M1, MODE_LOW, 3, 1)] &&
  688. Close[1] > Open[1] &&
  689. (Close[1] - Low[1]) > (High[1] - Close[1]) * 2);
  690. bool isShootingStar = (High[1] == High[iHighest(NULL, PERIOD_M1, MODE_HIGH, 3, 1)] &&
  691. Close[1] < Open[1] &&
  692. (High[1] - Close[1]) > (Close[1] - Low[1]) * 2);
  693.  
  694. if(isHammer) green += 10;
  695. if(isShootingStar) red += 10;
  696.  
  697. // ==========================================
  698. // 10. STREAK REVERSAL (Weight 8)
  699. // ==========================================
  700. int streak = 0;
  701. bool streakDir = (Close[1] > Open[1]);
  702. for(int i = 1; i <= 8 && i < Bars; i++) {
  703. bool candleUp = (Close[i] > Open[i]);
  704. if(candleUp == streakDir) streak++;
  705. else break;
  706. }
  707. // Long streak = reversal likely
  708. if(streak >= 5) {
  709. if(streakDir) red += 8; // Long green streak = expect red
  710. else green += 8; // Long red streak = expect green
  711. } else if(streak >= 4) {
  712. if(streakDir) red += 5;
  713. else green += 5;
  714. }
  715.  
  716. // ==========================================
  717. // FINAL CALCULATION
  718. // ==========================================
  719. double diff = MathMax(-100.0, MathMin(100.0, green - red));
  720. gP = MathMax(8.0, MathMin(92.0, 50.0 + diff * 0.65));
  721. rP = 100.0 - gP;
  722. double dom = MathMax(gP, rP);
  723.  
  724. if(dom >= 82) {
  725. reason = (gP > rP) ? "STRONG GREEN" : "STRONG RED";
  726. pC = (gP > rP) ? NEON_GREEN : NEON_RED;
  727. } else if(dom >= 72) {
  728. reason = (gP > rP) ? "GREEN" : "RED";
  729. pC = (gP > rP) ? NEON_GREEN : NEON_RED;
  730. } else if(dom >= 60) {
  731. reason = (gP > rP) ? "WEAK GREEN" : "WEAK RED";
  732. pC = (gP > rP) ? NEON_CYAN : NEON_ORANGE;
  733. } else {
  734. reason = "WAIT";
  735. pC = NEON_YELLOW;
  736. }
  737. }
  738.  
  739. //+------------------------------------------------------------------+
  740. // STRATEGY DETECTION
  741. //+------------------------------------------------------------------+
  742. string DetectMyStrategy(){
  743. int cc=g_otcCallPct,cp=g_otcPutPct,thr=STRATEGY_THRESHOLD;
  744. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TRAP_ONLY"){
  745. if(cc>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TRAP";g_strategySignal="PUT";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA RED";return "PUT";}
  746. if(cp>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TRAP";g_strategySignal="CALL";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA GREEN";return "CALL";}}
  747. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TREND_ONLY"){
  748. if(cc>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TREND";g_strategySignal="CALL";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA GREEN";return "CALL";}
  749. if(cp>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TREND";g_strategySignal="PUT";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA RED";return "PUT";}}
  750. g_strategyType="NONE";g_strategySignal="WAIT";g_strategyReason="Wait "+IntegerToString(thr)+"% + HA";return "WAIT";
  751. }
  752.  
  753. //+------------------------------------------------------------------+
  754. // OTC CROWD
  755. //+------------------------------------------------------------------+
  756. void CalcOTCCrowd(){
  757. int cS=0,pS=0;
  758. for(int i=1;i<=15&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  759. double uw=(High[i]-MathMax(Open[i],Close[i]))/rg,lw=(MathMin(Open[i],Close[i])-Low[i])/rg;
  760. if(uw>0.70&&Close[i]<Open[i])cS+=4;if(lw>0.70&&Close[i]>Open[i])pS+=4;
  761. if(uw>0.55&&Close[i]<Open[i])cS+=2;if(lw>0.55&&Close[i]>Open[i])pS+=2;
  762. if(Close[i]>Open[i])cS+=1;else if(Close[i]<Open[i])pS+=1;}
  763. int tot=cS+pS;if(tot==0){g_otcCallPct=50;g_otcPutPct=50;}
  764. else{int rC=(int)(cS*100.0/tot),rP=100-rC;
  765. if(rC>=rP){g_otcCallPct=MathMax(50,rC);g_otcPutPct=100-g_otcCallPct;}
  766. else{g_otcPutPct=MathMax(50,rP);g_otcCallPct=100-g_otcPutPct;}}
  767. }
  768.  
  769. //+------------------------------------------------------------------+
  770. // BRAIN SCORE
  771. //+------------------------------------------------------------------+
  772. double BrainSc(int &cp){
  773. double s=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  774. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,LB,1)],res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,LB,1)];
  775. double bH=MathMax(Open[1],Close[1]),bL=MathMin(Open[1],Close[1]);
  776. if(High[1]>res&&bL<res)s-=4;if(Low[1]<sup&&bH>sup)s+=4;
  777. if(High[0]>res)s-=2;if(Low[0]<sup)s+=2;
  778. double atr=iATR(NULL,PERIOD_M1,14,1);
  779. if(atr!=0){double cn=(High[1]-Low[1])/atr,v1=(double)iVolume(NULL,PERIOD_M1,1),va=0;
  780. for(int i=2;i<=10;i++)va+=iVolume(NULL,PERIOD_M1,i);va/=9.0;
  781. double vr=va>0?v1/va:1;if(cn>1.2&&vr>1.5){if(Close[1]>Open[1])s-=3;else s+=3;}}
  782. int c=0;for(int i=1;i<=30;i++)if(Close[i]>Open[i])c++;
  783. cp=(int)(c*100.0/30.0);if(cp>=70)s-=5;if(cp<=30)s+=5;s*=1.5;
  784. int dj=0;for(int i=1;i<=8;i++){double bd=MathAbs(Close[i]-Open[i]),rg=High[i]-Low[i];if(rg<=0)continue;
  785. if(bd<rg*0.2)dj++;double uw=High[i]-MathMax(Open[i],Close[i]),lw=MathMin(Open[i],Close[i])-Low[i];
  786. if(uw>bd*3)s+=2;if(lw>bd*3)s-=2;}if(dj>=4)s*=1.5;
  787. int bu=0,be=0;for(int i=1;i<=8;i++){if(Close[i]>Open[i]){bu++;be=0;}else{be++;bu=0;}if(bu>=5)s-=3;if(be>=5)s+=3;}
  788. int h=TimeHour(TimeCurrent());double mul=1.0;
  789. if((h>=0&&h<=2)||(h>=8&&h<=11)||(h>=14&&h<=17))mul=1.20;if(h>=3&&h<=7)mul=0.90;
  790. return s*mul;
  791. }
  792.  
  793. //+------------------------------------------------------------------+
  794. // MICRO WICK
  795. //+------------------------------------------------------------------+
  796. double MicroWick(){double r=High[1]-Low[1];if(r<=0)return 0;return((High[1]-MathMax(Open[1],Close[1]))+(MathMin(Open[1],Close[1])-Low[1]))/r;}
  797.  
  798. //+------------------------------------------------------------------+
  799. // VOLUME TRAP
  800. //+------------------------------------------------------------------+
  801. double VolumeTrapScore(){
  802. if(!VOLUME_PROFILE_TRAP||Bars<50)return 0;
  803. double cur=Close[0],hi=High[iHighest(NULL,0,MODE_HIGH,50,1)],lo=Low[iLowest(NULL,0,MODE_LOW,50,1)];
  804. double rg=hi-lo;if(rg<=0)return 0;int zn=5;double zs=rg/zn;double vz[5]={0,0,0,0,0};int zc[5]={0,0,0,0,0};
  805. for(int i=1;i<=50;i++){double p=Close[i];int z=(int)((p-lo)/zs);if(z<0)z=0;if(z>=zn)z=zn-1;vz[z]+=Volume[i];zc[z]++;}
  806. for(int z=0;z<zn;z++)if(zc[z]>0)vz[z]/=zc[z];
  807. int cz=(int)((cur-lo)/zs);if(cz<0)cz=0;if(cz>=zn)cz=zn-1;
  808. double vr=(double)Volume[1]/(vz[cz]+0.001);double wr=MicroWick();
  809. if(vr>2.0&&wr>0.65)return 25;if(vr>1.8&&wr>0.55)return 15;return 0;
  810. }
  811.  
  812. //+------------------------------------------------------------------+
  813. // ULTIMATE TRAP SCORE
  814. //+------------------------------------------------------------------+
  815. double UltimateTrapScore(){double wr=MicroWick(),v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  816. double avg=v2>0?v2:1.0,vr=v1/avg,rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),sc=0.0;
  817. if(wr>0.65)sc+=40;if(vr>2.0)sc+=30;if(rsi>75||rsi<25)sc+=20;
  818. if((High[1]>g_nearest_res&&Close[1]<g_nearest_res)||(Low[1]<g_nearest_sup&&Close[1]>g_nearest_sup))sc+=25;
  819. sc+=VolumeTrapScore();return MathMin(100.0,sc);}
  820.  
  821. //+------------------------------------------------------------------+
  822. // BROKER FORCE
  823. //+------------------------------------------------------------------+
  824. bool IsBrokerForce(double dummy=0){
  825. int sd=0;for(int i=1;i<=3;i++){if(Close[i]>Open[i])sd++;else sd--;}
  826. double v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  827. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  828. return(MathAbs(sd)==3&&v1>v2*2.0&&sp>BROKER_SPREAD_THRESHOLD);
  829. }
  830.  
  831. //+------------------------------------------------------------------+
  832. // NEURAL NETWORK
  833. //+------------------------------------------------------------------+
  834. double NeuralBiasFast(){double r=NeuralBias(0)*0.3+NeuralBias(1)*0.7;if(r>96)r=96;if(r<4)r=4;return r;}
  835. double NeuralBias(int s){
  836. double f[8];f[0]=fDoji(s)/100.0;f[1]=fWick(s)/100.0;f[2]=fVol()/100.0;f[3]=fMom(s)/100.0;
  837. f[4]=fSpread()/100.0;f[5]=fMem(s)/100.0;f[6]=fTick(s)/100.0;f[7]=fFrac(s)/100.0;
  838. double h[4]={0,0,0,0};for(int i=0;i<4;i++){for(int j=0;j<8;j++)h[i]+=f[j]*NW[j*4+i];h[i]=MathMax(0,h[i]-0.08);}
  839. double o=0;for(int i=0;i<4;i++)o+=h[i]*NW[32+i];double r=50.0+o*22.0;return r>96?96:r<4?4:r;
  840. }
  841. double fDoji(int s){int n=0;for(int i=s;i<s+5&&i<Bars;i++){double b=MathAbs(Open[i]-Close[i]),r=High[i]-Low[i];if(r>0&&b<r*0.25)n++;}return n*20.0;}
  842. double fWick(int s){double r=High[s]-Low[s];if(r==0)return 0;double u=(High[s]-MathMax(Open[s],Close[s]))/r,l=(MathMin(Open[s],Close[s])-Low[s])/r;return(u>0.65||l>0.65)?95:(u>0.5||l>0.5)?70:0;}
  843. double fVol(){if(Bars<11)return 0;double a=0;for(int i=1;i<=10;i++)a+=iVolume(NULL,PERIOD_M1,i);a/=10.0;if(a==0)return 0;double r=(double)iVolume(NULL,PERIOD_M1,0)/a;return r>3?95:r>2?75:r>1.5?50:0;}
  844. double fMom(int s){if(s+3>=Bars)return 0;return((Close[s]>Open[s]&&Close[s+1]<Open[s+1])||(Close[s]<Open[s]&&Close[s+1]>Open[s+1]))?88:0;}
  845. double fSpread(){double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);return sp>8?90:sp>5?70:sp>3?40:0;}
  846. double fMem(int s){if(s+8>=Bars)return 0;int r=0;for(int i=s;i<s+8&&i+2<Bars;i+=2){bool vB=(Low[i]>Low[i+1]&&Low[i+2]>Low[i+1]&&Close[i+2]>Open[i+2]);bool aT=(High[i]<High[i+1]&&High[i+2]<High[i+1]&&Close[i+2]<Open[i+2]);if(vB||aT)r++;}return(double)r*12.5;}
  847. double fTick(int s){if(s+5>=Bars)return 0;double vN=(double)iVolume(NULL,PERIOD_M1,s),vP=(double)iVolume(NULL,PERIOD_M1,s+1);if(vP==0)return 0;double vR=vN/vP,pc=MathAbs(Close[s]-Close[s+1])/Close[s+1]*100;if(vR>2.0&&pc<0.1)return 85;if(vR>1.5&&pc<0.05)return 60;return 0;}
  848. double fFrac(int s){if(s+4>=Bars||s<2)return 0;bool b=(Low[s]<Low[s-1]&&Low[s]<Low[s-2]&&Low[s]<Low[s+1]&&Low[s]<Low[s+2]);bool t=(High[s]>High[s-1]&&High[s]>High[s-2]&&High[s]>High[s+1]&&High[s]>High[s+2]);return(b||t)?90:0;}
  849.  
  850. //+------------------------------------------------------------------+
  851. // MAIN PREDICTION
  852. //+------------------------------------------------------------------+
  853. void CalcPrediction(double brain,double nb,int cp,double mai,int mts,double rsc,bool bf,double mw){
  854. string ms=DetectMyStrategy();bool sA=(ms!="WAIT");
  855.  
  856. if(sA&&g_strategyType=="TRAP"){
  857. if(ms=="PUT"){g_gProb=12.0;g_rProb=88.0;g_pAction="PUT TRAP!";g_pColor=NEON_PURPLE;g_calc_gProb=g_gProb;g_calc_rProb=g_rProb;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;return;}
  858. if(ms=="CALL"){g_gProb=88.0;g_rProb=12.0;g_pAction="CALL TRAP!";g_pColor=NEON_PURPLE;g_calc_gProb=g_gProb;g_calc_rProb=g_rProb;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;return;}}
  859.  
  860. double tS=UltimateTrapScore();bool bF2=IsBrokerForce();
  861.  
  862. if(TRADE_MODE=="HUNT"){if(tS<85){g_gProb=50;g_rProb=50;g_pAction="HUNT: WAIT";g_pColor=NEON_YELLOW;g_calc_gProb=50;g_calc_rProb=50;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;return;}}
  863.  
  864. if(ENABLE_BROKER_KILLER&&(tS>=85||(tS>=75&&bF2))&&g_marketMode!="TREND"){g_gProb=15;g_rProb=85;g_pAction="TRAP DETECTED";g_pColor=NEON_PURPLE;g_calc_gProb=15;g_calc_rProb=85;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;return;}
  865.  
  866. double gS=0,rS=0,ab=MathMax(0.70,MathMin(1.30,g_accuracy/65.0));
  867.  
  868. if(IsSidewaysMarket()){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  869. bool nR=(g_nearest_res>0&&(g_nearest_res-Close[0])<8*pip),nS=(g_nearest_sup>0&&(Close[0]-g_nearest_sup)<8*pip);
  870. if(!nR&&!nS){g_gProb=50;g_rProb=50;g_pAction="SIDEWAYS";g_pColor=NEON_YELLOW;g_calc_gProb=50;g_calc_rProb=50;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;return;}
  871. if(nR)rS+=20;if(nS)gS+=20;}
  872.  
  873. if(sA&&g_strategyType=="TREND"){double sw=50.0;if(ms=="CALL"){gS+=sw*ab;g_pAction="TREND: CALL!";g_pColor=NEON_GREEN;}else if(ms=="PUT"){rS+=sw*ab;g_pAction="TREND: PUT!";g_pColor=NEON_RED;}}
  874.  
  875. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")gS+=60;
  876. else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")rS+=60;
  877. else if(g_haM1=="HA BULLISH 1")gS+=30;else if(g_haM1=="HA BEARISH 1")rS+=30;
  878.  
  879. if(HA_ALIGN_FILTER && g_haBoth=="MIXED"){gS*=0.5;rS*=0.5;}
  880.  
  881. gS+=(nb-50)/50.0*22*ab;rS-=(nb-50)/50.0*22*ab;
  882.  
  883. double bn=MathMax(-1.0,MathMin(1.0,brain/10.0));gS+=bn*15*ab;rS-=bn*15*ab;
  884.  
  885. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  886. if(g_nearest_res>0&&(g_nearest_res-Close[0])<10*pip)rS+=12;
  887. if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)<10*pip)gS+=12;
  888.  
  889. double rsi1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);if(rsi1>70)rS+=6;if(rsi1<30)gS+=6;
  890.  
  891. double sn=MathMax(-1.0,MathMin(1.0,rsc/3.0));gS+=sn*8*ab;rS-=sn*8*ab;
  892.  
  893. double wRS=GetWickRejectSignal();gS+=(wRS>0?wRS:0);rS+=(wRS<0?MathAbs(wRS):0);
  894.  
  895. double cPS=GetCommonPointSignal();gS+=(cPS>0?cPS:0);rS+=(cPS<0?MathAbs(cPS):0);
  896.  
  897. int rd=DetectRSIDivergence();if(rd==1)gS+=20;if(rd==-1)rS+=20;
  898.  
  899. int cp2=DetectClassicPatterns();if(cp2==1)gS+=12;if(cp2==-1)rS+=12;
  900.  
  901. int qm=DetectQMR();if(qm==1)gS+=25;if(qm==-1)rS+=25;
  902.  
  903. int sk=StreakReversalSignal();if(sk==1)gS+=18;if(sk==-1)rS+=18;
  904.  
  905. double adxV=GetADXStrength();int adxD=GetADXDirection();if(adxV>25){if(adxD==1)gS+=12;if(adxD==-1)rS+=12;}if(adxV<15){gS*=0.7;rS*=0.7;}
  906.  
  907. int vs=SmartVolumeSignal();if(vs==1)gS+=12;if(vs==-1)rS+=12;
  908.  
  909. if(!IsVolatilityGood()){gS*=0.5;rS*=0.5;}
  910.  
  911. double diff=MathMax(-100.0,MathMin(100.0,gS-rS));
  912. g_gProb=MathMax(8.0,MathMin(92.0,50.0+(diff/1.8)));g_rProb=100.0-g_gProb;
  913.  
  914. if(sA&&g_strategyType=="TREND"){
  915. if(ms=="CALL"){g_gProb=MathMax(g_gProb,85.0);g_rProb=100.0-g_gProb;}
  916. if(ms=="PUT"){g_rProb=MathMax(g_rProb,85.0);g_gProb=100.0-g_rProb;}
  917. g_gProb=MathMin(92.0,MathMax(8.0,g_gProb));g_rProb=100.0-g_gProb;}
  918.  
  919. double dom=MathMax(g_gProb,g_rProb);
  920. if(dom>=82){if(g_gProb>g_rProb){if(!sA){g_pAction="GREEN";g_pColor=NEON_GREEN;}}else{if(!sA){g_pAction="RED";g_pColor=NEON_RED;}}}
  921. else if(dom>=75){if(g_gProb>g_rProb){if(!sA){g_pAction="GREEN";g_pColor=NEON_CYAN;}}else{if(!sA){g_pAction="RED";g_pColor=NEON_ORANGE;}}}
  922. else{if(!sA){g_pAction="WAIT";g_pColor=NEON_YELLOW;}}
  923.  
  924. g_calc_gProb=g_gProb;g_calc_rProb=g_rProb;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;
  925. }
  926.  
  927. //+------------------------------------------------------------------+
  928. // COMMON POINTS & WICK REJECTIONS
  929. //+------------------------------------------------------------------+
  930. void DetectCommonPoints(){
  931. if(!SHOW_COMMON_POINTS){g_commonCount=0;return;}
  932. if(Time[0]==g_lastCommonScan)return;g_lastCommonScan=Time[0];g_commonCount=0;
  933. datetime nowBar=Time[0];int periodSec=PeriodSeconds(PERIOD_M1);
  934. double m5h=iHigh(NULL,PERIOD_M5,iHighest(NULL,PERIOD_M5,MODE_HIGH,10,1));
  935. double m5l=iLow(NULL,PERIOD_M5,iLowest(NULL,PERIOD_M5,MODE_LOW,10,1));
  936. if(m5l>0&&g_commonCount<MAX_COMMON_PTS){g_commonPrice[g_commonCount]=m5l;g_commonTime[g_commonCount]=nowBar;g_commonType[g_commonCount]="CALL";g_commonExpire[g_commonCount]=nowBar+periodSec*120;g_commonCount++;}
  937. if(g_hrn_price>0&&g_hrn_is_sup&&g_commonCount<MAX_COMMON_PTS){g_commonPrice[g_commonCount]=g_hrn_price;g_commonTime[g_commonCount]=nowBar;g_commonType[g_commonCount]="CALL";g_commonExpire[g_commonCount]=nowBar+periodSec*120;g_commonCount++;}
  938. if(m5h>0&&g_commonCount<MAX_COMMON_PTS){g_commonPrice[g_commonCount]=m5h;g_commonTime[g_commonCount]=nowBar;g_commonType[g_commonCount]="PUT";g_commonExpire[g_commonCount]=nowBar+periodSec*120;g_commonCount++;}
  939. if(g_hrn_price>0&&!g_hrn_is_sup&&g_commonCount<MAX_COMMON_PTS){g_commonPrice[g_commonCount]=g_hrn_price;g_commonTime[g_commonCount]=nowBar;g_commonType[g_commonCount]="PUT";g_commonExpire[g_commonCount]=nowBar+periodSec*120;g_commonCount++;}
  940. for(int i=g_commonCount-1;i>=0;i--)if(TimeCurrent()>g_commonExpire[i]){for(int j=i;j<g_commonCount-1;j++){g_commonPrice[j]=g_commonPrice[j+1];g_commonTime[j]=g_commonTime[j+1];g_commonType[j]=g_commonType[j+1];g_commonExpire[j]=g_commonExpire[j+1];}g_commonCount--;}
  941. }
  942.  
  943. void DrawCommonPoints(){
  944. for(int i=0;i<MAX_COMMON_PTS;i++){SafeDel(PFX+"COMMON_"+IntegerToString(i));SafeDel(PFX+"COMMON_L_"+IntegerToString(i));SafeDel(PFX+"COMMON_HL_"+IntegerToString(i));}
  945. if(!SHOW_COMMON_POINTS||g_commonCount==0)return;
  946. for(int i=0;i<g_commonCount;i++){if(TimeCurrent()>g_commonExpire[i])continue;if(IsLineNearby(g_commonPrice[i],8.0))continue;
  947. string id=PFX+"COMMON_"+IntegerToString(i),idL=PFX+"COMMON_L_"+IntegerToString(i),idH=PFX+"COMMON_HL_"+IntegerToString(i);color zc=DARK_BLUE_NEON;
  948. ObjectCreate(0,idH,OBJ_HLINE,0,0,g_commonPrice[i]);ObjectSetInteger(0,idH,OBJPROP_COLOR,zc);ObjectSetInteger(0,idH,OBJPROP_WIDTH,3);ObjectSetInteger(0,idH,OBJPROP_STYLE,STYLE_SOLID);ObjectSetInteger(0,idH,OBJPROP_BACK,false);
  949. ObjectCreate(0,id,OBJ_TEXT,0,Time[0],g_commonPrice[i]);ObjectSetText(id,"*",16,"Arial",zc);ObjectSetInteger(0,id,OBJPROP_BACK,false);
  950. string lbl=(g_commonType[i]=="CALL")?"^ CALL ZONE":"v PUT ZONE";
  951. ObjectCreate(0,idL,OBJ_TEXT,0,Time[0]+PeriodSeconds(PERIOD_M1)*3,g_commonPrice[i]);ObjectSetText(idL,lbl,10,"Arial Bold",zc);ObjectSetInteger(0,idL,OBJPROP_BACK,false);}
  952. }
  953.  
  954. void DetectWickRejections(){
  955. g_isSideways=IsSidewaysMarket();if(!SHOW_WICK_REJECT_LINES){g_wickLineCount=0;return;}
  956. if(Time[0]==g_lastWickScan)return;g_lastWickScan=Time[0];
  957. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double zone=WICK_ZONE_PIPS*pip*2;double cur=Close[0];
  958. g_wickLineCount=0;datetime now=Time[0],expT=now+PeriodSeconds(PERIOD_M1)*WICK_EXPIRE_BARS*2;
  959. for(int i=1;i<=40&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  960. double uw=High[i]-MathMax(Open[i],Close[i]),lw=MathMin(Open[i],Close[i])-Low[i];double rl=0;bool fd=false;
  961. if(uw>rg*0.30){rl=High[i];if(MathAbs(cur-rl)<zone*3)fd=true;}
  962. if(lw>rg*0.30){rl=Low[i];if(MathAbs(cur-rl)<zone*3)fd=true;}
  963. if(!fd)continue;bool ex=false;
  964. for(int j=0;j<g_wickLineCount;j++)if(MathAbs(g_wickLinePrice[j]-rl)<zone){g_wickLineTouches[j]++;ex=true;break;}
  965. if(!ex&&g_wickLineCount<MAX_WICK_LINES){g_wickLinePrice[g_wickLineCount]=rl;g_wickLineTouches[g_wickLineCount]=1;g_wickLineExpire[g_wickLineCount]=expT;g_wickLineCount++;}}
  966. for(int i=g_wickLineCount-1;i>=0;i--)if(TimeCurrent()>g_wickLineExpire[i]){for(int j=i;j<g_wickLineCount-1;j++){g_wickLinePrice[j]=g_wickLinePrice[j+1];g_wickLineTouches[j]=g_wickLineTouches[j+1];g_wickLineExpire[j]=g_wickLineExpire[j+1];}g_wickLineCount--;}
  967. }
  968.  
  969. void DrawWickRejectLines(){
  970. for(int i=0;i<MAX_WICK_LINES;i++){SafeDel(PFX+"WICK_"+IntegerToString(i));SafeDel(PFX+"WICK_L_"+IntegerToString(i));}
  971. if(!SHOW_WICK_REJECT_LINES||!g_isSideways)return;
  972. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  973. for(int i=0;i<g_wickLineCount;i++){if(TimeCurrent()>g_wickLineExpire[i])continue;if(MathAbs(cur-g_wickLinePrice[i])/pip>20.0)continue;if(IsLineNearby(g_wickLinePrice[i],5.0))continue;
  974. string id=PFX+"WICK_"+IntegerToString(i),idL=PFX+"WICK_L_"+IntegerToString(i);color lc=C'0,180,255';
  975. ObjectCreate(0,id,OBJ_HLINE,0,0,g_wickLinePrice[i]);ObjectSetInteger(0,id,OBJPROP_COLOR,lc);ObjectSetInteger(0,id,OBJPROP_WIDTH,2);ObjectSetInteger(0,id,OBJPROP_STYLE,STYLE_DOT);ObjectSetInteger(0,id,OBJPROP_BACK,false);
  976. string lbl="W"+IntegerToString(g_wickLineTouches[i])+"x";
  977. ObjectCreate(0,idL,OBJ_TEXT,0,Time[0]+PeriodSeconds(PERIOD_M1)*2,g_wickLinePrice[i]);ObjectSetText(idL,lbl,9,"Arial Bold",lc);ObjectSetInteger(0,idL,OBJPROP_BACK,false);}
  978. }
  979.  
  980. double GetWickRejectSignal(){if(!g_isSideways||g_wickLineCount==0)return 0;double sc=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  981. for(int i=0;i<g_wickLineCount;i++){double d=MathAbs(Close[0]-g_wickLinePrice[i])/pip;bool iS=(g_wickLinePrice[i]<Close[0]);
  982. if(d<5){if(iS)sc+=15*g_wickLineTouches[i];else sc-=15*g_wickLineTouches[i];}else if(d<10){if(iS)sc+=8*g_wickLineTouches[i];else sc-=8*g_wickLineTouches[i];}}return MathMax(-40,MathMin(40,sc));}
  983. double GetCommonPointSignal(){if(g_commonCount==0)return 0;double sc=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  984. for(int i=0;i<g_commonCount;i++){if(TimeCurrent()>g_commonExpire[i])continue;double d=MathAbs(Close[0]-g_commonPrice[i])/pip;if(d<8){if(g_commonType[i]=="CALL")sc+=25;else sc-=25;}}return MathMax(-30,MathMin(30,sc));}
  985.  
  986. //+------------------------------------------------------------------+
  987. // HIDDEN HTF LEVELS
  988. //+------------------------------------------------------------------+
  989. void DetectHiddenLevels(){g_htfLevelCount=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double curP=Close[0];
  990. double rU=MathCeil(curP/(10*pip))*(10*pip),rD=MathFloor(curP/(10*pip))*(10*pip);
  991. if(MathAbs(curP-rU)/pip<=15)AddLevel(rU,"ROUND","RESISTANCE",TimeCurrent(),8,true);
  992. if(MathAbs(curP-rD)/pip<=15)AddLevel(rD,"ROUND","SUPPORT",TimeCurrent(),8,true);
  993. DetectHTFLevels(PERIOD_M5,"M5",3,pip);DetectHTFLevels(PERIOD_M15,"M15",5,pip);DetectHTFLevels(PERIOD_M30,"M30",7,pip);DetectHTFLevels(PERIOD_H1,"H1",9,pip);
  994. SortLevelsByStrength();}
  995.  
  996. void DetectHTFLevels(ENUM_TIMEFRAMES tf,string tfN,int bS,double pip){int bars=MathMin(50,iBars(NULL,tf));if(bars<10)return;double curP=Close[0];
  997. for(int i=2;i<bars-2;i++){if(IsSwingHigh(tf,i,2)){double d=MathAbs(curP-iHigh(NULL,tf,i))/pip;if(d<=20)AddLevel(iHigh(NULL,tf,i),tfN,"RESISTANCE",iTime(NULL,tf,i),bS+(20-(int)d)/2,false);}
  998. if(IsSwingLow(tf,i,2)){double d=MathAbs(curP-iLow(NULL,tf,i))/pip;if(d<=20)AddLevel(iLow(NULL,tf,i),tfN,"SUPPORT",iTime(NULL,tf,i),bS+(20-(int)d)/2,false);}}}
  999.  
  1000. bool IsSwingHigh(ENUM_TIMEFRAMES tf,int p,int lb){double h=iHigh(NULL,tf,p);for(int i=1;i<=lb;i++){if(p-i<0||p+i>=iBars(NULL,tf))return false;if(iHigh(NULL,tf,p-i)>=h||iHigh(NULL,tf,p+i)>=h)return false;}return true;}
  1001. bool IsSwingLow(ENUM_TIMEFRAMES tf,int p,int lb){double l=iLow(NULL,tf,p);for(int i=1;i<=lb;i++){if(p-i<0||p+i>=iBars(NULL,tf))return false;if(iLow(NULL,tf,p-i)<=l||iLow(NULL,tf,p+i)<=l)return false;}return true;}
  1002.  
  1003. void AddLevel(double price,string tf,string type,datetime time,int strength,bool isRound){if(g_htfLevelCount>=50)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1004. for(int i=0;i<g_htfLevelCount;i++)if(MathAbs(g_htfLevels[i].price-price)/pip<5)return;
  1005. g_htfLevels[g_htfLevelCount].price=price;g_htfLevels[g_htfLevelCount].timeframe=tf;g_htfLevels[g_htfLevelCount].type=type;g_htfLevels[g_htfLevelCount].time=time;g_htfLevels[g_htfLevelCount].strength=strength;g_htfLevels[g_htfLevelCount].isRoundNumber=isRound;g_htfLevelCount++;}
  1006.  
  1007. void SortLevelsByStrength(){for(int i=0;i<g_htfLevelCount-1;i++)for(int j=0;j<g_htfLevelCount-i-1;j++)if(g_htfLevels[j].strength<g_htfLevels[j+1].strength){HTFLevel tmp=g_htfLevels[j];g_htfLevels[j]=g_htfLevels[j+1];g_htfLevels[j+1]=tmp;}}
  1008.  
  1009. void DrawHiddenLevels(){for(int i=0;i<50;i++){SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i));SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i)+"_LBL");}
  1010. int dc=MathMin(10,g_htfLevelCount);int drawn=0;
  1011. for(int i=0;i<dc&&drawn<5;i++){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;if(MathAbs(Close[0]-g_htfLevels[i].price)/pip>30)continue;if(IsLineNearby(g_htfLevels[i].price,5.0))continue;
  1012. string nm=PFX+"HTF_LEVEL_"+IntegerToString(drawn);color lc=g_htfLevels[i].isRoundNumber?NEON_PURPLE:(StringFind(g_htfLevels[i].type,"SUPPORT")>=0?NEON_GREEN:NEON_RED);
  1013. ObjectCreate(0,nm,OBJ_HLINE,0,0,g_htfLevels[i].price);ObjectSetInteger(0,nm,OBJPROP_COLOR,lc);ObjectSetInteger(0,nm,OBJPROP_WIDTH,1);ObjectSetInteger(0,nm,OBJPROP_STYLE,STYLE_DOT);ObjectSetInteger(0,nm,OBJPROP_BACK,false);
  1014. string ln=nm+"_LBL";ObjectCreate(0,ln,OBJ_TEXT,0,Time[0],g_htfLevels[i].price);ObjectSetText(ln,StringFormat("%s %s S:%d",g_htfLevels[i].timeframe,g_htfLevels[i].type,g_htfLevels[i].strength),9,"Arial",lc);drawn++;}}
  1015.  
  1016. //+------------------------------------------------------------------+
  1017. // REVERSAL DETECTION
  1018. //+------------------------------------------------------------------+
  1019. string DetectSuddenReversal(){string reason="";if(Close[1]<Open[1]&&Close[0]>Open[0]){reason="BULL REVERSAL";if(iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,0)<30)return reason;}if(Close[1]>Open[1]&&Close[0]<Open[0]){reason="BEAR REVERSAL";if(iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,0)>70)return reason;}return "";}
  1020.  
  1021. //+------------------------------------------------------------------+
  1022. // DRAWING HELPERS
  1023. //+------------------------------------------------------------------+
  1024. void SafeDel(string id){if(ObjectFind(0,id)>=0)ObjectDelete(0,id);}
  1025. void DrawHLine(string id,double price,color clr,int width,int style){if(price<=0)return;SafeDel(id);ObjectCreate(0,id,OBJ_HLINE,0,0,price);ObjectSetInteger(0,id,OBJPROP_COLOR,clr);ObjectSetInteger(0,id,OBJPROP_WIDTH,width);ObjectSetInteger(0,id,OBJPROP_STYLE,style);ObjectSetInteger(0,id,OBJPROP_BACK,false);}
  1026. void HideSPM(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)==0)continue;int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE);if(tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT)ObjectDelete(0,nm);}}
  1027. void NuclearDeleteAll(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE);if(tp==OBJ_HLINE||tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT)ObjectDelete(0,nm);}}
  1028. void DelDashboard(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)!=0)continue;if(StringFind(nm,"NEAREST_RES")>=0)continue;if(StringFind(nm,"NEAREST_SUP")>=0)continue;if(StringFind(nm,"HRN_LINE")>=0)continue;if(StringFind(nm,"HRN_LBL")>=0)continue;if(StringFind(nm,"candle_timer")>=0)continue;if(StringFind(nm,"HTF_LEVEL")>=0)continue;if(StringFind(nm,"COMMON_")>=0)continue;if(StringFind(nm,"WICK_")>=0)continue;ObjectDelete(nm);}}
  1029.  
  1030. //+------------------------------------------------------------------+
  1031. // ML WEIGHTS
  1032. //+------------------------------------------------------------------+
  1033. void LoadMLWeights(){if(!ML_ADAPTIVE)return;g_symbolKey=Symbol();string fn="ML_weights_"+g_symbolKey+".dat";int h=FileOpen(fn,FILE_READ|FILE_TXT);if(h!=INVALID_HANDLE){string d=FileReadString(h);FileClose(h);g_brokerBias=StringToDouble(d);if(g_brokerBias<-0.5)g_brokerBias=-0.5;if(g_brokerBias>0.5)g_brokerBias=0.5;}else g_brokerBias=0.0;}
  1034. void SaveMLWeights(){if(!ML_ADAPTIVE)return;string fn="ML_weights_"+g_symbolKey+".dat";int h=FileOpen(fn,FILE_WRITE|FILE_TXT);if(h!=INVALID_HANDLE){FileWriteString(h,DoubleToString(g_brokerBias,6));FileClose(h);}}
  1035. void UpdateMLWeights(bool win){if(!ML_ADAPTIVE)return;double lr=0.02;if(win)g_brokerBias+=lr*(g_frozen_gProb/100.0);else g_brokerBias-=lr*(g_frozen_rProb/100.0);if(g_brokerBias>0.5)g_brokerBias=0.5;if(g_brokerBias<-0.5)g_brokerBias=-0.5;SaveMLWeights();}
  1036.  
  1037. //+------------------------------------------------------------------+
  1038. // ACCURACY TRACKING
  1039. //+------------------------------------------------------------------+
  1040. void UpdateAccuracy(){if(Bars<5||Time[0]==g_acc_lastBar)return;g_acc_lastBar=Time[0];if(g_lastPredBar==Time[1]&&MathAbs(g_lastPredGreen-50.0)>10.0){bool aG=(Close[1]>Open[1]),pG=(g_lastPredGreen>50.0),win=(aG==pG);if(win){g_acc_correct++;g_lossStreak=0;}else g_lossStreak++;g_acc_total++;if(g_acc_total>0)g_accuracy=MathMax(40.0,MathMin(90.0,(double)g_acc_correct/g_acc_total*100.0));if(ML_ADAPTIVE&&g_lastPredGreen>50.0&&g_lastPredGreen<100.0)UpdateMLWeights(win);}g_lastPredGreen=g_frozen_gProb;g_lastPredBar=Time[0];}
  1041. double ValidateHistoricalAccuracy(){if(Bars<55)return 65.0;int cr=0,tt=0;for(int i=10;i<=50&&i+1<Bars;i++){int gc=0;for(int j=i+1;j<=i+5&&j<Bars;j++)if(Close[j]>Open[j])gc++;double pG=(gc>2)?65.0:35.0;bool aG=(Close[i]>Open[i]);if((pG>55&&aG)||(pG<45&&!aG))cr++;tt++;}return tt>0?(double)cr/tt*100.0:65.0;}
  1042. void UpdateWeights(){double lr=0.01;if(g_lastPredBar==Time[1]){bool c=((Close[1]>Open[1])==(g_lastPredGreen>50));if(c){NW[32]+=lr;NW[33]-=lr;}else{NW[32]-=lr;NW[33]+=lr;}NW[32]=MathMax(0.5,MathMin(2.0,NW[32]));NW[33]=MathMin(-0.5,MathMax(-2.0,NW[33]));}}
  1043.  
  1044. //+------------------------------------------------------------------+
  1045. // MARKET MODE & HELPERS
  1046. //+------------------------------------------------------------------+
  1047. string DetectMarketMode(double brain,double rsc,int cp,double nb){double atr=iATR(NULL,PERIOD_M1,14,1),avgR=(High[1]-Low[1]+High[2]-Low[2]+High[3]-Low[3])/3.0;bool hV=(avgR>0&&atr/avgR>1.3);if(MathAbs(brain)>=3.5&&MathAbs(rsc)>=1.5&&hV)return "TREND";if(cp>=70||cp<=30)return "REVERSAL";if(nb>=70||nb<=30)return "TREND";return "RANGE";}
  1048. bool IsSidewaysMarket(){if(Bars<30)return false;double adx=GetADXStrength();if(adx<25)return true;double h20=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,20,1)],l20=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,20,1)];double r20=h20-l20;double atr=iATR(NULL,PERIOD_M1,14,1);if(atr>0&&r20<atr*8)return true;return false;}
  1049. bool IsVolatilityGood(){if(Bars<100)return true;double dh=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,60,0)],dl=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,60,0)];double tr=dh-dl;double ac=0;for(int i=1;i<=20;i++)ac+=(High[i]-Low[i]);ac/=20.0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double mr=jpy?0.30:0.0030;if(tr<mr)return false;if(ac>0&&(High[0]-Low[0])<ac*0.3)return false;return true;}
  1050. double GetDynamicThreshold(){if(g_accuracy<55)return 90.0;if(g_accuracy<60)return 85.0;if(g_accuracy<65)return 80.0;if(g_accuracy<70)return 75.0;if(g_accuracy>80)return 70.0;if(g_accuracy>75)return 72.0;return 75.0;}
  1051.  
  1052. //+------------------------------------------------------------------+
  1053. // SIGNAL DETECTORS
  1054. //+------------------------------------------------------------------+
  1055. int DetectRSIDivergence(){if(Bars<30)return 0;double rN=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),rP=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,8);double lN=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],lPv=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];if(lN<lPv&&rN>rP&&rN<40)return 1;double hN=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],hPv=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];if(hN>hPv&&rN<rP&&rN>60)return -1;return 0;}
  1056. int StreakReversalSignal(){if(Bars<15)return 0;int g=0,r=0;for(int i=1;i<Bars;i++){if(Close[i]>Open[i]){if(r>0)break;g++;}else if(Close[i]<Open[i]){if(g>0)break;r++;}else break;}if(g>=4)return -1;if(r>=4)return 1;return 0;}
  1057. double GetADXStrength(){if(Bars<20)return 0;return iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);}
  1058. int GetADXDirection(){if(Bars<20)return 0;double p=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_PLUSDI,1),m=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MINUSDI,1);if(p>m+5)return 1;if(m>p+5)return -1;return 0;}
  1059. int SmartVolumeSignal(){if(Bars<15)return 0;double v1=(double)iVolume(NULL,PERIOD_M1,1),avg=0;for(int i=2;i<=10;i++)avg+=iVolume(NULL,PERIOD_M1,i);avg/=9.0;if(avg==0)return 0;double vr=v1/avg;if(vr<1.8)return 0;bool g=(Close[1]>Open[1]);if(vr>2.5&&g)return 1;if(vr>2.5&&!g)return -1;if(vr>3.0&&g&&High[1]-Close[1]>Close[1]-Low[1])return -1;if(vr>3.0&&!g&&Close[1]-Low[1]>High[1]-Close[1])return 1;return 0;}
  1060.  
  1061. //+------------------------------------------------------------------+
  1062. // CLASSIC PATTERNS
  1063. //+------------------------------------------------------------------+
  1064. int DetectClassicPatterns(){if(Bars<30)return 0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double tol=PATTERN_TOLERANCE_PIPS*pip;double sh[2],sl[2];int shB[2],slB[2];int shC=0,slC=0;
  1065. for(int i=2;i<25&&(shC<2||slC<2);i++){if(High[i]>High[i-1]&&High[i]>High[i-2]&&High[i]>High[i+1]&&High[i]>High[i+2]){if(shC<2){sh[shC]=High[i];shB[shC]=i;shC++;}}if(Low[i]<Low[i-1]&&Low[i]<Low[i-2]&&Low[i]<Low[i+1]&&Low[i]<Low[i+2]){if(slC<2){sl[slC]=Low[i];slB[slC]=i;slC++;}}}
  1066. if(shC>=2){int bd=MathAbs(shB[0]-shB[1]);if(bd>=MIN_PATTERN_SEPARATION&&MathAbs(sh[0]-sh[1])<=tol){int bn=MathMin(shB[0],shB[1]),bx=MathMax(shB[0],shB[1]);double vl=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,bx-bn+1,bn)];if(Close[0]<vl)return -1;else if(Close[0]<MathMin(sh[0],sh[1]))return -1;}}
  1067. if(slC>=2){int bd=MathAbs(slB[0]-slB[1]);if(bd>=MIN_PATTERN_SEPARATION&&MathAbs(sl[0]-sl[1])<=tol){int bn=MathMin(slB[0],slB[1]),bx=MathMax(slB[0],slB[1]);double ph=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,bx-bn+1,bn)];if(Close[0]>ph)return 1;else if(Close[0]>MathMax(sl[0],sl[1]))return 1;}}return 0;}
  1068.  
  1069. //+------------------------------------------------------------------+
  1070. // QMR PATTERN
  1071. //+------------------------------------------------------------------+
  1072. int DetectQMR(){if(Bars<40)return 0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double sH[10],sL[10];int sHB[10],sLB[10];int hC=0,lC=0;
  1073. for(int i=3;i<40&&hC<10;i++)if(High[i]>High[i-1]&&High[i]>High[i-2]&&High[i]>High[i+1]&&High[i]>High[i+2]){sH[hC]=High[i];sHB[hC]=i;hC++;}
  1074. for(int i=3;i<40&&lC<10;i++)if(Low[i]<Low[i-1]&&Low[i]<Low[i-2]&&Low[i]<Low[i+1]&&Low[i]<Low[i+2]){sL[lC]=Low[i];sLB[lC]=i;lC++;}
  1075. if(hC<2||lC<2)return 0;
  1076. for(int iA=0;iA<hC;iA++)for(int iC2=0;iC2<hC;iC2++){if(iA==iC2)continue;if(sHB[iA]<=sHB[iC2])continue;if(sH[iC2]>=sH[iA]-10*pip)continue;
  1077. for(int iB=0;iB<lC;iB++){if(sHB[iA]<=sLB[iB])continue;if(sLB[iB]<=sHB[iC2])continue;
  1078. for(int iD=0;iD<lC;iD++){if(iB==iD)continue;if(sHB[iC2]<=sLB[iD])continue;if(sL[iD]>=sL[iB])continue;
  1079. bool m3=false,m5=false;if(Bars>=8){double o1=Open[3],c1=Close[3],o2=Open[0],c2=Close[0];double b1=MathAbs(c1-o1);if(c2>o2&&c1<o1&&MathAbs(c2-o2)>b1*0.5)m3=true;}
  1080. if(iBars(NULL,PERIOD_M5)>=3){double o1=iOpen(NULL,PERIOD_M5,2),c1=iClose(NULL,PERIOD_M5,2),o2=iOpen(NULL,PERIOD_M5,1),c2=iClose(NULL,PERIOD_M5,1);double b1=MathAbs(c1-o1);if(c2>o2&&c1<o1&&MathAbs(c2-o2)>b1*0.5)m5=true;}
  1081. if(m3||m5)if(Close[0]>sL[iD]&&Close[0]<sH[iC2]){qmrA=sH[iA];qmrB=sL[iB];qmrC=sH[iC2];qmrD=sL[iD];qmrActive=true;qmrExpire=TimeCurrent()+900;return 1;}}}}
  1082. for(int iA=0;iA<lC;iA++)for(int iC2=0;iC2<lC;iC2++){if(iA==iC2)continue;if(sLB[iA]<=sLB[iC2])continue;if(sL[iC2]<=sL[iA]+10*pip)continue;
  1083. for(int iB=0;iB<hC;iB++){if(sLB[iA]<=sHB[iB])continue;if(sHB[iB]<=sLB[iC2])continue;
  1084. for(int iD=0;iD<hC;iD++){if(iB==iD)continue;if(sLB[iC2]<=sHB[iD])continue;if(sH[iD]>=sH[iB])continue;
  1085. bool m3=false,m5=false;if(Bars>=8){double o1=Open[3],c1=Close[3],o2=Open[0],c2=Close[0];double b1=MathAbs(c1-o1);if(c2<o2&&c1>o1&&MathAbs(c2-o2)>b1*0.5)m3=true;}
  1086. if(iBars(NULL,PERIOD_M5)>=3){double o1=iOpen(NULL,PERIOD_M5,2),c1=iClose(NULL,PERIOD_M5,2),o2=iOpen(NULL,PERIOD_M5,1),c2=iClose(NULL,PERIOD_M5,1);double b1=MathAbs(c1-o1);if(c2<o2&&c1>o1&&MathAbs(c2-o2)>b1*0.5)m5=true;}
  1087. if(m3||m5)if(Close[0]<sH[iD]&&Close[0]>sL[iC2]){qmrA=sL[iA];qmrB=sH[iB];qmrC=sL[iC2];qmrD=sH[iD];qmrActive=true;qmrExpire=TimeCurrent()+900;return -1;}}}}
  1088. return 0;}
  1089.  
  1090. //+------------------------------------------------------------------+
  1091. // ████████████████████████████████████████████████████████████████████
  1092. // ██ NEW HRN SYSTEM - REAL ROUND NUMBERS + 2-CANDLE CLOSE RULE ██
  1093. // ████████████████████████████████████████████████████████████████████
  1094. //+------------------------------------------------------------------+
  1095.  
  1096. // Helper: Add level to array
  1097. void AddRNLevel(double &arr[], int &cnt, double lv) {
  1098. if(cnt >= 100) return;
  1099. for(int i = 0; i < cnt; i++) {
  1100. if(MathAbs(arr[i] - lv) < 0.000001) return; // Duplicate
  1101. }
  1102. arr[cnt] = lv;
  1103. cnt++;
  1104. }
  1105.  
  1106. // Score a round number based on price reactions
  1107. double ScoreRoundNumber(double level, double pip) {
  1108. double score = 0;
  1109. double tol = 3 * pip; // 3 pip tolerance for "touch"
  1110.  
  1111. int touches = 0;
  1112. int rejections_up = 0; // Touched from below, closed above (support held)
  1113. int rejections_down = 0; // Touched from above, closed below (resistance held)
  1114.  
  1115. for(int i = 1; i <= LOOKBACK && i < Bars; i++) {
  1116. double h = High[i], l = Low[i], c = Close[i], o = Open[i];
  1117.  
  1118. // Check if candle touched this level
  1119. if(h >= level - tol && l <= level + tol) {
  1120. touches++;
  1121.  
  1122. // Support reaction: Price came down to level, bounced up
  1123. if(l <= level + tol && c > level + tol) {
  1124. rejections_up++;
  1125. // Extra score for strong rejection (big lower wick)
  1126. double body_low = MathMin(o, c);
  1127. double lower_wick = body_low - l;
  1128. double range = h - l;
  1129. if(range > 0 && lower_wick > range * 0.5) {
  1130. score += 5; // Strong hammer at level
  1131. }
  1132. }
  1133.  
  1134. // Resistance reaction: Price went up to level, rejected down
  1135. if(h >= level - tol && c < level - tol) {
  1136. rejections_down++;
  1137. // Extra score for strong rejection (big upper wick)
  1138. double body_high = MathMax(o, c);
  1139. double upper_wick = h - body_high;
  1140. double range = h - l;
  1141. if(range > 0 && upper_wick > range * 0.5) {
  1142. score += 5; // Strong shooting star at level
  1143. }
  1144. }
  1145. }
  1146. }
  1147.  
  1148. // Base score from touches
  1149. score += touches * 3;
  1150.  
  1151. // High score from rejections (this is the "hidden feeling")
  1152. score += rejections_up * 8;
  1153. score += rejections_down * 8;
  1154.  
  1155. // Bonus for multiple touches = stronger level
  1156. if(touches >= 4) score += 15;
  1157. else if(touches >= 3) score += 10;
  1158. else if(touches >= 2) score += 5;
  1159.  
  1160. return score;
  1161. }
  1162.  
  1163. // Find the BEST hidden round number near current price
  1164. double FindBestHiddenRoundNumber(double curPrice) {
  1165. bool jpy = (StringFind(Symbol(), "JPY") >= 0);
  1166. double pip = jpy ? 0.01 : 0.0001;
  1167. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS);
  1168. if(dg <= 0) dg = 5;
  1169.  
  1170. // Generate all possible round number levels near current price
  1171. double levels[];
  1172. int levelCount = 0;
  1173. ArrayResize(levels, 100);
  1174.  
  1175. // === 100 pip round numbers (Big levels like 0.99000, 1.00000) ===
  1176. double base100 = MathFloor(curPrice / (100 * pip)) * (100 * pip);
  1177. for(int i = -1; i <= 2; i++) {
  1178. double lv = base100 + i * 100 * pip;
  1179. AddRNLevel(levels, levelCount, lv);
  1180. }
  1181.  
  1182. // === 50 pip round numbers (Half levels like 0.99500) ===
  1183. double base50 = MathFloor(curPrice / (50 * pip)) * (50 * pip);
  1184. for(int i = -2; i <= 3; i++) {
  1185. double lv = base50 + i * 50 * pip;
  1186. AddRNLevel(levels, levelCount, lv);
  1187. }
  1188.  
  1189. // === 25 pip round numbers (Quarter levels like 0.99250) ===
  1190. double base25 = MathFloor(curPrice / (25 * pip)) * (25 * pip);
  1191. for(int i = -3; i <= 4; i++) {
  1192. double lv = base25 + i * 25 * pip;
  1193. AddRNLevel(levels, levelCount, lv);
  1194. }
  1195.  
  1196. // === 10 pip round numbers (Deci levels like 0.99100, 0.99200) ===
  1197. double base10 = MathFloor(curPrice / (10 * pip)) * (10 * pip);
  1198. for(int i = -5; i <= 6; i++) {
  1199. double lv = base10 + i * 10 * pip;
  1200. AddRNLevel(levels, levelCount, lv);
  1201. }
  1202.  
  1203. // === 5 pip round numbers (Like 0.99150) ===
  1204. double base5 = MathFloor(curPrice / (5 * pip)) * (5 * pip);
  1205. for(int i = -4; i <= 5; i++) {
  1206. double lv = base5 + i * 5 * pip;
  1207. AddRNLevel(levels, levelCount, lv);
  1208. }
  1209.  
  1210. // Score each level and find the best one
  1211. double bestLevel = 0;
  1212. double bestScore = -1;
  1213.  
  1214. for(int i = 0; i < levelCount; i++) {
  1215. double lv = levels[i];
  1216. double dist = MathAbs(curPrice - lv) / pip;
  1217.  
  1218. // Skip levels too far away (more than 60 pips)
  1219. if(dist > 60) continue;
  1220.  
  1221. // Distance penalty (closer = better)
  1222. double distPenalty = 0;
  1223. if(dist > 40) distPenalty = 20;
  1224. else if(dist > 30) distPenalty = 10;
  1225. else if(dist > 20) distPenalty = 5;
  1226.  
  1227. // Score this level
  1228. double score = ScoreRoundNumber(lv, pip) - distPenalty;
  1229.  
  1230. // Minimum score required to be considered "hidden level"
  1231. // (Must have at least some reaction)
  1232. if(score < 5) continue;
  1233.  
  1234. if(score > bestScore) {
  1235. bestScore = score;
  1236. bestLevel = lv;
  1237. }
  1238. }
  1239.  
  1240. // If no level found with reactions, find nearest clean round number
  1241. if(bestLevel == 0) {
  1242. // Priority: 100 > 50 > 25 > 10 > 5 pip levels
  1243. double nearest100 = MathRound(curPrice / (100 * pip)) * (100 * pip);
  1244. double nearest50 = MathRound(curPrice / (50 * pip)) * (50 * pip);
  1245. double nearest25 = MathRound(curPrice / (25 * pip)) * (25 * pip);
  1246. double nearest10 = MathRound(curPrice / (10 * pip)) * (10 * pip);
  1247. double nearest5 = MathRound(curPrice / (5 * pip)) * (5 * pip);
  1248.  
  1249. double d100 = MathAbs(curPrice - nearest100);
  1250. double d50 = MathAbs(curPrice - nearest50);
  1251. double d25 = MathAbs(curPrice - nearest25);
  1252. double d10 = MathAbs(curPrice - nearest10);
  1253. double d5 = MathAbs(curPrice - nearest5);
  1254.  
  1255. // Find closest significant level
  1256. if(d100 < 30 * pip) { bestLevel = nearest100; bestScore = 3; }
  1257. else if(d50 < 20 * pip) { bestLevel = nearest50; bestScore = 3; }
  1258. else if(d25 < 15 * pip) { bestLevel = nearest25; bestScore = 2; }
  1259. else if(d10 < 10 * pip) { bestLevel = nearest10; bestScore = 1; }
  1260. else { bestLevel = nearest5; bestScore = 0.5; }
  1261. }
  1262.  
  1263. g_hrn_score = bestScore;
  1264. return NormalizeDouble(bestLevel, dg);
  1265. }
  1266.  
  1267. // Scan wick rejection zones (separate from HRN now)
  1268. void ScanHRNLevels(){
  1269. g_rj_cnt=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1270. for(int i=1;i<=LOOKBACK&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;double uw=High[i]-MathMax(Open[i],Close[i]),lw=MathMin(Open[i],Close[i])-Low[i];
  1271. if(uw>rg*0.35){double lv=High[i];if(MathAbs(lv-cur)<=40*pip){bool f=false;for(int k=0;k<g_rj_cnt;k++)if(MathAbs(g_rj[k].price-lv)<8*pip){g_rj[k].touches++;f=true;break;}if(!f&&g_rj_cnt<MAX_REJ){g_rj[g_rj_cnt].price=lv;g_rj[g_rj_cnt].touches=1;g_rj_cnt++;}}}
  1272. if(lw>rg*0.35){double lv=Low[i];if(MathAbs(lv-cur)<=40*pip){bool f=false;for(int k=0;k<g_rj_cnt;k++)if(MathAbs(g_rj[k].price-lv)<8*pip){g_rj[k].touches++;f=true;break;}if(!f&&g_rj_cnt<MAX_REJ){g_rj[g_rj_cnt].price=lv;g_rj[g_rj_cnt].touches=1;g_rj_cnt++;}}}}
  1273. for(int i=0;i<g_rj_cnt-1;i++)for(int j=0;j<g_rj_cnt-i-1;j++)if(g_rj[j].touches<g_rj[j+1].touches){RejLevel tmp=g_rj[j];g_rj[j]=g_rj[j+1];g_rj[j+1]=tmp;}}
  1274.  
  1275. double FindNearestHRN(double cur){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;if(g_rj_cnt==0)return MathRound(cur/(10*pip))*(10*pip);double best=-1,lv=0;for(int i=0;i<g_rj_cnt;i++){double d=MathAbs(cur-g_rj[i].price)/pip;if(d>50)continue;double sc=(double)g_rj[i].touches/(d+1.0);if(sc>best){best=sc;lv=g_rj[i].price;}}return lv>0?lv:MathRound(cur/(10*pip))*(10*pip);}
  1276.  
  1277. // ██ MAIN HRN UPDATE - WITH 2-CANDLE CLOSE RULE ██
  1278. void UpdateHRN(){
  1279. if(Bars < LOOKBACK + 10) return;
  1280.  
  1281. bool jpy = (StringFind(Symbol(), "JPY") >= 0);
  1282. double pip = jpy ? 0.01 : 0.0001;
  1283. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS);
  1284. if(dg <= 0) dg = 5;
  1285.  
  1286. // Scan for best hidden round number every new bar
  1287. if(Time[0] != g_hrn_scan_bar) {
  1288. // Find the best HRN level
  1289. double newHrn = FindBestHiddenRoundNumber(Close[0]);
  1290.  
  1291. // Only update if we don't have one yet, or if it's significantly different
  1292. if(g_hrn_price == 0 || MathAbs(newHrn - g_hrn_price) > 2 * pip) {
  1293. g_hrn_price = newHrn;
  1294. g_hrn_is_sup = (Close[0] > g_hrn_price);
  1295. g_hrn_brk_bars = 0;
  1296. g_hrn_confirmed_break = false;
  1297. }
  1298.  
  1299. g_hrn_scan_bar = Time[0];
  1300. }
  1301.  
  1302. // ████████████████████████████████████████████████████████████████
  1303. // ██ 2-CANDLE CLOSE CONFIRMATION RULE ██
  1304. // ██ - Support shifts when 2 CLOSED candles close BELOW support ██
  1305. // ██ - Resistance shifts when 2 CLOSED candles close ABOVE res ██
  1306. // ████████████████████████████████████████████████████████████████
  1307.  
  1308. double tol = 1 * pip; // Small tolerance
  1309.  
  1310. // Check for 2-candle close confirmation
  1311. if(g_hrn_is_sup) {
  1312. // This is a SUPPORT level
  1313. // Check if 2 consecutive CLOSED candles closed BELOW support
  1314. if(Bars >= 3) {
  1315. bool candle1_below = (Close[1] < g_hrn_price - tol);
  1316. bool candle2_below = (Close[2] < g_hrn_price - tol);
  1317.  
  1318. if(candle1_below && candle2_below) {
  1319. g_hrn_confirmed_break = true;
  1320. g_hrn_brk_bars = HRN_CONFIRM_BARS; // Trigger shift
  1321. } else if(candle1_below) {
  1322. g_hrn_brk_bars = 1; // One candle confirmed
  1323. } else {
  1324. g_hrn_brk_bars = 0; // No confirmation
  1325. }
  1326. }
  1327. } else {
  1328. // This is a RESISTANCE level
  1329. // Check if 2 consecutive CLOSED candles closed ABOVE resistance
  1330. if(Bars >= 3) {
  1331. bool candle1_above = (Close[1] > g_hrn_price + tol);
  1332. bool candle2_above = (Close[2] > g_hrn_price + tol);
  1333.  
  1334. if(candle1_above && candle2_above) {
  1335. g_hrn_confirmed_break = true;
  1336. g_hrn_brk_bars = HRN_CONFIRM_BARS; // Trigger shift
  1337. } else if(candle1_above) {
  1338. g_hrn_brk_bars = 1; // One candle confirmed
  1339. } else {
  1340. g_hrn_brk_bars = 0; // No confirmation
  1341. }
  1342. }
  1343. }
  1344.  
  1345. // SHIFT the HRN level when 2-candle confirmation is complete
  1346. if(g_hrn_brk_bars >= HRN_CONFIRM_BARS) {
  1347. // Find new HRN level based on current price position
  1348. double newHrn = FindBestHiddenRoundNumber(Close[0]);
  1349.  
  1350. // Only shift if new level is different enough (at least 3 pips)
  1351. if(MathAbs(newHrn - g_hrn_price) > 3 * pip) {
  1352. g_hrn_price = newHrn;
  1353. g_hrn_is_sup = (Close[0] > g_hrn_price);
  1354. g_hrn_brk_bars = 0;
  1355. g_hrn_confirmed_break = false;
  1356.  
  1357. Print("HRN SHIFTED to: ", DoubleToString(g_hrn_price, dg),
  1358. " | Type: ", (g_hrn_is_sup ? "SUPPORT" : "RESISTANCE"),
  1359. " | Score: ", DoubleToString(g_hrn_score, 1));
  1360. } else {
  1361. // Same level, just reset counter but keep as other type
  1362. g_hrn_is_sup = (Close[0] > g_hrn_price);
  1363. g_hrn_brk_bars = 0;
  1364. g_hrn_confirmed_break = false;
  1365. }
  1366. }
  1367.  
  1368. // Update display string
  1369. g_hrn_str = DoubleToString(NormalizeDouble(g_hrn_price, dg), dg);
  1370.  
  1371. // Draw HRN line with different style based on type and confirmation
  1372. color hrnColor = g_hrn_is_sup ? NEON_GREEN : NEON_RED;
  1373. int hrnWidth = 3;
  1374.  
  1375. // If break is being confirmed, flash the line
  1376. if(g_hrn_brk_bars == 1) {
  1377. hrnColor = NEON_YELLOW; // Warning color - 1 candle confirmed
  1378. }
  1379.  
  1380. DrawHLine(PFX + "HRN_LINE", g_hrn_price, hrnColor, hrnWidth, STYLE_SOLID);
  1381.  
  1382. // Draw label
  1383. string ln = PFX + "HRN_LBL";
  1384. SafeDel(ln);
  1385. string typeStr = g_hrn_is_sup ? "SUP" : "RES";
  1386. string confStr = "";
  1387. if(g_hrn_brk_bars == 1) confStr = " [1/2]";
  1388. if(g_hrn_confirmed_break) confStr = " [SHIFTING]";
  1389.  
  1390. ObjectCreate(0, ln, OBJ_TEXT, 0, Time[0] + Period() * 60 * 2, g_hrn_price);
  1391. ObjectSetText(ln, "HRN " + typeStr + " " + g_hrn_str + confStr, 10, "Arial Bold", hrnColor);
  1392. ObjectSetInteger(0, ln, OBJPROP_BACK, false);
  1393. }
  1394.  
  1395. //+------------------------------------------------------------------+
  1396. // S/R LEVELS
  1397. //+------------------------------------------------------------------+
  1398. void AddRes(double lv){if(lv<=0)return;for(int i=0;i<resCount;i++)if(MathAbs(ResLevels[i]-lv)<10*Point)return;if(resCount>=MAX_LEVELS){for(int i=0;i<MAX_LEVELS-1;i++)ResLevels[i]=ResLevels[i+1];resCount=MAX_LEVELS-1;}ResLevels[resCount++]=lv;}
  1399. void AddSup(double lv){if(lv<=0)return;for(int i=0;i<supCount;i++)if(MathAbs(SupLevels[i]-lv)<10*Point)return;if(supCount>=MAX_LEVELS){for(int i=0;i<MAX_LEVELS-1;i++)SupLevels[i]=SupLevels[i+1];supCount=MAX_LEVELS-1;}SupLevels[supCount++]=lv;}
  1400.  
  1401. void DrawNearestSR(){for(int i=0;i<20;i++){SafeDel(PFX+"RES_"+IntegerToString(i));SafeDel(PFX+"SUP_"+IntegerToString(i));}SafeDel(PFX+"NEAREST_RES");SafeDel(PFX+"NEAREST_SUP");if(!SHOW_SR_LINES)return;
  1402. double cur=Close[0];g_nearest_res=0;g_nearest_sup=0;double mR=999999,mS=999999;
  1403. for(int i=0;i<resCount;i++)if(ResLevels[i]>cur&&(ResLevels[i]-cur)<mR){mR=ResLevels[i]-cur;g_nearest_res=ResLevels[i];}
  1404. for(int i=0;i<supCount;i++)if(SupLevels[i]<cur&&(cur-SupLevels[i])<mS){mS=cur-SupLevels[i];g_nearest_sup=SupLevels[i];}
  1405. if(g_nearest_res>0&&!IsLineNearby(g_nearest_res,5.0))DrawHLine(PFX+"NEAREST_RES",g_nearest_res,NEON_RED,2,STYLE_SOLID);
  1406. if(g_nearest_sup>0&&!IsLineNearby(g_nearest_sup,5.0))DrawHLine(PFX+"NEAREST_SUP",g_nearest_sup,NEON_GREEN,2,STYLE_SOLID);}
  1407.  
  1408. void CheckBRK(){double pC=Close[1],pO=Open[1];g_brk_str="NO BRK";g_brk_color=CGR;if(g_nearest_res>0&&pC>g_nearest_res&&pO<=g_nearest_res){g_brk_str="BRK UP!";g_brk_color=NEON_GREEN;}else if(g_nearest_sup>0&&pC<g_nearest_sup&&pO>=g_nearest_sup){g_brk_str="BRK DOWN!";g_brk_color=NEON_RED;}}
  1409.  
  1410. void UpdateSR(){if(Time[0]==lastSRBar)return;lastSRBar=Time[0];if(Bars<15)return;double nR=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,10,1)],nS=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,10,1)],cur=Close[0];if(nR>0&&cur<nR-5*Point)AddRes(nR);if(nS>0&&cur>nS+5*Point)AddSup(nS);if(resCount<1)AddRes(High[1]);if(supCount<1)AddSup(Low[1]);DrawNearestSR();CheckBRK();}
  1411.  
  1412. //+------------------------------------------------------------------+
  1413. // TIMER
  1414. //+------------------------------------------------------------------+
  1415. void UpdateTimer(){if(!SHOW_TIMER)return;string nm=PFX+"candle_timer";int ps=Period()*60;int el=(int)(TimeCurrent()-Time[0]);int rem=ps-el;if(rem<=0)rem=ps;datetime tt=Time[0]+ps+60;double tp=High[0]+(Point*15);if(ObjectFind(0,nm)<0){ObjectCreate(0,nm,OBJ_TEXT,0,tt,tp);ObjectSetInteger(0,nm,OBJPROP_BACK,false);ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false);}ObjectSetInteger(0,nm,OBJPROP_TIME,tt);ObjectSetDouble(0,nm,OBJPROP_PRICE,tp);int mm=rem/60,ss=rem%60;string t=(mm>0?IntegerToString(mm)+":":"")+(ss<10?"0":"")+IntegerToString(ss)+"s";ObjectSetText(nm,t,13,"Arial Bold",NEON_YELLOW);}
  1416.  
  1417. //+------------------------------------------------------------------+
  1418. // NEURAL WEIGHTS INIT
  1419. //+------------------------------------------------------------------+
  1420. void InitNW(){NW[0]=0.852;NW[1]=0.724;NW[2]=0.913;NW[3]=0.681;NW[4]=0.795;NW[5]=0.836;NW[6]=0.772;NW[7]=0.894;NW[8]=0.623;NW[9]=0.748;NW[10]=0.887;NW[11]=0.716;NW[12]=0.661;NW[13]=0.829;NW[14]=0.753;NW[15]=0.942;NW[16]=0.784;NW[17]=0.697;NW[18]=0.871;NW[19]=0.735;NW[20]=0.813;NW[21]=0.768;NW[22]=0.932;NW[23]=0.674;NW[24]=0.845;NW[25]=0.709;NW[26]=0.888;NW[27]=0.651;NW[28]=0.921;NW[29]=0.743;NW[30]=0.802;NW[31]=0.867;NW[32]=1.24;NW[33]=-0.93;NW[34]=1.15;NW[35]=-1.08;}
  1421.  
  1422. //+------------------------------------------------------------------+
  1423. // ████████████████████████████████████████████████████████████████████
  1424. // ██ UI DRAWING - BIGGER FONTS ██
  1425. // ████████████████████████████████████████████████████████████████████
  1426. //+------------------------------------------------------------------+
  1427. void Bx(string id,int x,int y,int w,int h,color bg,color bd){string n=PFX+id;if(ObjectFind(0,n)<0)ObjectCreate(0,n,OBJ_RECTANGLE_LABEL,0,0,0);ObjectSetInteger(0,n,OBJPROP_XDISTANCE,x);ObjectSetInteger(0,n,OBJPROP_YDISTANCE,y);ObjectSetInteger(0,n,OBJPROP_XSIZE,w);ObjectSetInteger(0,n,OBJPROP_YSIZE,h);ObjectSetInteger(0,n,OBJPROP_BGCOLOR,bg);ObjectSetInteger(0,n,OBJPROP_BORDER_TYPE,BORDER_FLAT);ObjectSetInteger(0,n,OBJPROP_COLOR,bd);ObjectSetInteger(0,n,OBJPROP_BACK,false);}
  1428. void Tx(string id,int x,int y,string txt,color tc,int fs,bool bold){string n=PFX+id;if(ObjectFind(0,n)<0)ObjectCreate(0,n,OBJ_LABEL,0,0,0);ObjectSetInteger(0,n,OBJPROP_XDISTANCE,x);ObjectSetInteger(0,n,OBJPROP_YDISTANCE,y);ObjectSetText(n,txt,fs,bold?"Arial Bold":"Arial",tc);ObjectSetInteger(0,n,OBJPROP_BACK,false);}
  1429. void NeonBar(string id,int x,int y,int w,int h,double pct,color fc){Bx(id+"_bg",x,y,w,h,BG_DARK4,BG_DARK4);int fw=(int)(pct/100.0*w);if(fw<4)fw=4;if(fw>w)fw=w;Bx(id+"_f",x,y,fw,h,fc,fc);}
  1430. void Cube(string id,int x,int y,int w,int h,color bc,color bg,string lbl,color lc,string val,color vc,int vfs){Bx(id,x,y,w,h,bg,bc);if(StringLen(lbl)>0)Tx(id+"_l",x+10,y+6,lbl,lc,11,true);if(StringLen(val)>0)Tx(id+"_v",x+10,y+38,val,vc,vfs,true);}
  1431.  
  1432. //+------------------------------------------------------------------+
  1433. // OTHER PAIRS CUBE
  1434. //+------------------------------------------------------------------+
  1435. void DrawOtherPairsCube(int x,int y,int w,int h){
  1436. Bx("c20",x,y,w,h,BG_DARK2,NEON_GOLD);
  1437. Tx("c20_l",x+10,y+6,"OTHER PAIRS",NEON_CYAN,11,true);
  1438. if(g_pairCount==0){
  1439. Tx("c20_v0",x+10,y+34,"Scanning...",CGR,11,false);
  1440. return;
  1441. }
  1442. int lY=32;
  1443. for(int i=0;i<g_pairCount && i<5;i++){
  1444. string sp=g_pairNames[i];
  1445. if(StringLen(sp)>12) sp=StringSubstr(sp,0,12);
  1446. string txt=sp+" "+g_pairSigs[i]+" "+DoubleToString(g_pairConfs[i],0)+"%";
  1447. color sc=(g_pairSigs[i]=="CALL")?NEON_GREEN:NEON_RED;
  1448. Tx("c20_p"+IntegerToString(i),x+10,y+lY,txt,sc,11,true);
  1449. lY+=19;
  1450. }
  1451. }
  1452.  
  1453. //+------------------------------------------------------------------+
  1454. // OTC QUICK CUBE
  1455. //+------------------------------------------------------------------+
  1456. void DrawOTCQuickCube(int x,int y,int w,int h){
  1457. Bx("c_quick",x,y,w,h,BG_DARK2,NEON_LIME);
  1458. Tx("c_quick_l",x+10,y+6,"OTC QUICK",NEON_CYAN,11,true);
  1459. int age=(int)(TimeCurrent()-Time[0]);
  1460. int ps=Period()*60;
  1461. int rem=ps-age;
  1462. if(rem<0) rem=0;
  1463. int mm=rem/60, ss=rem%60;
  1464. string tl=(mm>0?IntegerToString(mm)+"m ":"")+IntegerToString(ss)+"s";
  1465. Tx("c_quick_t",x+10,y+30,"Time: "+tl,NEON_GOLD,13,true);
  1466. double spread=MarketInfo(Symbol(),MODE_SPREAD);
  1467. color spC=(spread<=BROKER_SPREAD_THRESHOLD)?NEON_GREEN:NEON_ORANGE;
  1468. Tx("c_quick_s",x+10,y+54,"Spread: "+DoubleToString(spread,0),spC,12,true);
  1469. double v1=iVolume(NULL,PERIOD_M1,1), v2=iVolume(NULL,PERIOD_M1,2);
  1470. double vr=(v2>0)?v1/v2:0;
  1471. color vC=(vr>1.5)?NEON_RED:NEON_CYAN;
  1472. // ✅ BIGGER FONT SIZE for Volume
  1473. Tx("c_quick_v",x+10,y+76,"Vol: "+DoubleToString(vr,1)+"x",vC,14,true);
  1474. string es=GetEntryStatus();
  1475. color eC=GetEntryColor();
  1476. Tx("c_quick_e",x+10,y+100,es,eC,11,true);
  1477. }
  1478.  
  1479. //+------------------------------------------------------------------+
  1480. // ENTRY STATUS FUNCTIONS
  1481. //+------------------------------------------------------------------+
  1482. string GetEntryStatus(){
  1483. int age=(int)(TimeCurrent()-Time[0]);
  1484. int ps=Period()*60;
  1485. int rem=ps-age;
  1486. if(rem<0) rem=0;
  1487. string ms=DetectMyStrategy();
  1488.  
  1489. if(ms!="WAIT"){
  1490. string type=(g_strategyType=="TRAP")?"TRAP":"TREND";
  1491. if(ENTRY_MODE=="FLAG"){
  1492. if(age<FLAG_MIN_SEC) return type+" WAIT "+IntegerToString(FLAG_MIN_SEC-age)+"s";
  1493. if(rem<MIN_REMAINING_SEC) return type+" EXPIRED";
  1494. if(age>FLAG_MAX_SEC) return type+" LATE";
  1495. return type+" OPEN "+IntegerToString(rem)+"s";
  1496. }
  1497. if(age<TIME_MIN_SEC) return type+" WAIT "+IntegerToString(TIME_MIN_SEC-age)+"s";
  1498. if(age>TIME_MAX_SEC) return type+" CLOSED";
  1499. return type+" OPEN "+IntegerToString(age)+"s";
  1500. }
  1501.  
  1502. if(ENTRY_MODE=="FLAG"){
  1503. if(age<FLAG_MIN_SEC) return "WAIT "+IntegerToString(FLAG_MIN_SEC-age)+"s";
  1504. if(rem<MIN_REMAINING_SEC) return "EXPIRED";
  1505. if(age>FLAG_MAX_SEC) return "LATE";
  1506. return "OPEN "+IntegerToString(rem)+"s left";
  1507. }
  1508. if(age<TIME_MIN_SEC) return "WAIT "+IntegerToString(TIME_MIN_SEC-age)+"s";
  1509. if(age>TIME_MAX_SEC) return "CLOSED";
  1510. return "OPEN "+IntegerToString(age)+"s";
  1511. }
  1512.  
  1513. color GetEntryColor(){
  1514. string s=GetEntryStatus();
  1515. if(StringFind(s,"TRAP OPEN")>=0) return NEON_PURPLE;
  1516. if(StringFind(s,"TREND OPEN")>=0) return NEON_LIME;
  1517. if(StringFind(s,"OPEN")>=0) return NEON_GREEN;
  1518. if(StringFind(s,"WAIT")>=0) return NEON_YELLOW;
  1519. if(StringFind(s,"LATE")>=0 || StringFind(s,"EXPIRED")>=0 || StringFind(s,"CLOSED")>=0) return NEON_ORANGE;
  1520. return NEON_RED;
  1521. }
  1522.  
  1523. //+------------------------------------------------------------------+
  1524. // DIRECTION OK
  1525. //+------------------------------------------------------------------+
  1526. bool DirectionOK(){
  1527. if(!ENABLE_ENTRY_ZONE) return true;
  1528. double cur=Close[0], lo=Low[0], hi=High[0], rg=hi-lo;
  1529. if(rg==0) return true;
  1530. double pos=(cur-lo)/rg*100.0;
  1531. if(MathMax(g_calc_gProb,g_calc_rProb)>=85) return true;
  1532. string ms=DetectMyStrategy();
  1533. if(ms=="CALL") return(pos>REVERSAL_PCT);
  1534. if(ms=="PUT") return(pos<(100.0-REVERSAL_PCT));
  1535. if(StringFind(g_adv1,"CALL")>=0) return(pos>REVERSAL_PCT && (hi-cur)<rg*WICK_PCT);
  1536. if(StringFind(g_adv1,"PUT")>=0) return(pos<(100.0-REVERSAL_PCT) && (cur-lo)<rg*WICK_PCT);
  1537. return true;
  1538. }
  1539.  
  1540. //+------------------------------------------------------------------+
  1541. // ENTRY PRECISION OK
  1542. //+------------------------------------------------------------------+
  1543. bool EntryPrecisionOK(){
  1544. if(TRADE_MODE=="GOD") return true;
  1545. if(g_calc_gProb>80 && Close[0]<Open[0]) return false;
  1546. if(g_calc_rProb>80 && Close[0]>Open[0]) return false;
  1547. return true;
  1548. }
  1549.  
  1550. //+------------------------------------------------------------------+
  1551. // CONSENSUS FILTER - COMPLETE
  1552. //+------------------------------------------------------------------+
  1553. bool ConsensusOK(){
  1554. if(!CONSENSUS_FILTER) return true;
  1555. string ms=DetectMyStrategy();
  1556. if(ms=="WAIT") return true;
  1557.  
  1558. bool haAgree=false;
  1559. if(ms=="CALL" && (g_haM1=="HA BULLISH 1" || g_haBoth=="BOTH BULL")) haAgree=true;
  1560. if(ms=="PUT" && (g_haM1=="HA BEARISH 1" || g_haBoth=="BOTH BEAR")) haAgree=true;
  1561.  
  1562. return haAgree;
  1563. }
  1564.  
  1565. //+------------------------------------------------------------------+
  1566. // TELEGRAM NOTIFICATION
  1567. //+------------------------------------------------------------------+
  1568. void SendTelegramAlert(string message){
  1569. if(!ENABLE_TELEGRAM) return;
  1570. if(StringLen(TELEGRAM_TOKEN)<10 || StringLen(TELEGRAM_CHAT_ID)<5) return;
  1571.  
  1572. string params="?chat_id="+TELEGRAM_CHAT_ID+"&text="+message;
  1573.  
  1574. string headers="Content-Type: application/x-www-form-urlencoded";
  1575. string cookie="",result="";
  1576. char post[],result_data[];
  1577. int timeout=5000;
  1578.  
  1579. ArrayResize(post,StringToCharArray(params,post,0,WHOLE_ARRAY,CP_UTF8)-1);
  1580.  
  1581. int res=WebRequest("POST",url,headers,timeout,post,result_data,result);
  1582. if(res==-1){
  1583. Print("Telegram: WebRequest failed. Check URL/Internet");
  1584. }
  1585. }
  1586.  
  1587. //+------------------------------------------------------------------+
  1588. // ████████████████████████████████████████████████████████████████████
  1589. // ██ MAIN DRAW FUNCTION - BIGGER FONTS EVERYWHERE ██
  1590. // ████████████████████████████████████████████████████████████████████
  1591. //+------------------------------------------------------------------+
  1592. void Draw(){
  1593. HideSPM(); DelDashboard();
  1594. int W=DASH_W, G=8, CW=(W-2*G)/3, CH=110, cx=POS_X+G, yy=POS_Y;
  1595. int cp=0; double brain=BrainSc(cp); double nb=NeuralBiasFast(); double mw=MicroWick(); bool bf=IsBrokerForce();
  1596. g_marketMode=DetectMarketMode(brain,g_rsc,cp,nb);
  1597. if(StringLen(g_prevMode)>0 && g_prevMode!=g_marketMode){ g_signalTime=0; g_finalSignal="WAIT"; }
  1598. g_prevMode=g_marketMode;
  1599. CalcOTCCrowd(); UpdateAccuracy(); UpdateWeights();
  1600. double mai=CalcAdvancedMicroAI(); int mts=CalcAdvancedMicroTrap();
  1601. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  1602. UpdateRiskControl();
  1603. CheckMTFConfirmation();
  1604. double tfaScore=CalcAdvancedTFA(g_tfa_detail);
  1605. color ha1C=(g_haM1=="HA BULLISH 1")?NEON_GREEN:(g_haM1=="HA BEARISH 1")?NEON_RED:NEON_YELLOW;
  1606. color ha5C=(g_haM5=="HA BULLISH 5")?NEON_GREEN:(g_haM5=="HA BEARISH 5")?NEON_RED:NEON_YELLOW;
  1607. color biasClr; string biasStr=CalcAdvancedMarketBias(biasClr,brain,g_rsc);
  1608. string ms=DetectMyStrategy();
  1609. color stratC=(g_strategyType=="TRAP")?NEON_PURPLE:(g_strategyType=="TREND")?NEON_GREEN:CGR;
  1610. string stratLabel=(g_strategyType=="TRAP")?"TRAP "+ms:(g_strategyType=="TREND")?"TREND "+ms:"NO STRATEGY";
  1611. string finalSig=g_finalSignal; color sigC=NEON_YELLOW;
  1612. if(finalSig=="CALL") sigC=NEON_GREEN; else if(finalSig=="PUT") sigC=NEON_RED;
  1613. else if(finalSig=="WEAK CALL") sigC=NEON_CYAN; else if(finalSig=="WEAK PUT") sigC=NEON_ORANGE;
  1614.  
  1615. // ========== ROW 1 - PAIR, SIGNAL, PREDICTION ==========
  1616. Cube("c1",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"PAIR",NEON_CYAN,Symbol(),NEON_BLUE,15);
  1617. Cube("c2",cx+CW+G,yy,CW,CH,sigC,BG_DARK2,"SIGNAL",NEON_CYAN,finalSig,sigC,16);
  1618.  
  1619. double gP,rP; string rsn; color pClr;
  1620. CalcAdvancedPrediction(gP,rP,rsn,pClr);
  1621. g_frozen_gProb=gP; g_frozen_rProb=rP; g_frozen_pAction=rsn; g_frozen_pColor=pClr; g_last_freeze_bar=Time[0];
  1622.  
  1623. Bx("c_pred",cx+2*(CW+G),yy,CW,CH,BG_DARK2,pClr);
  1624. Tx("c_pred_l",cx+2*(CW+G)+10,yy+5,"NEXT CANDLE",NEON_CYAN,11,true);
  1625. int bW=CW-20, gBW=(int)(gP/100.0*bW), rBW=(int)(rP/100.0*bW);
  1626. if(gBW<3) gBW=3; if(rBW<3) rBW=3;
  1627. Bx("c_pred_gbg",cx+2*(CW+G)+10,yy+26,bW,8,BG_DARK4,BG_DARK4);
  1628. Bx("c_pred_gfg",cx+2*(CW+G)+10,yy+26,gBW,8,NEON_GREEN,NEON_GREEN);
  1629. Tx("c_pred_gp",cx+2*(CW+G)+10,yy+36,"G:"+DoubleToString(gP,0)+"%",NEON_GREEN,12,true);
  1630. Bx("c_pred_rbg",cx+2*(CW+G)+10,yy+54,bW,8,BG_DARK4,BG_DARK4);
  1631. Bx("c_pred_rfg",cx+2*(CW+G)+10,yy+54,rBW,8,NEON_RED,NEON_RED);
  1632. Tx("c_pred_rp",cx+2*(CW+G)+10,yy+64,"R:"+DoubleToString(rP,0)+"%",NEON_RED,12,true);
  1633. Tx("c_pred_a",cx+2*(CW+G)+10,yy+82,rsn,pClr,12,true);
  1634. NeonBar("c_pred_b",cx+2*(CW+G)+10,yy+96,bW,8,MathMax(gP,rP),pClr);
  1635. yy+=CH+G;
  1636.  
  1637. // ========== ROW 2 - BRAIN, SPM, SESSION ==========
  1638. Cube("c4",cx,yy,CW,CH,NEON_CYAN,BG_DARK3,"BRAIN",NEON_CYAN,(brain>=0?"+":"")+DoubleToString(brain,1),(brain>0)?NEON_GREEN:NEON_RED,18);
  1639. Cube("c5",cx+CW+G,yy,CW,CH,NEON_CYAN,BG_DARK3,"SPM",NEON_CYAN,(g_rsc>=0?"+":"")+DoubleToString(g_rsc,1),(g_rsc>0)?NEON_GREEN:NEON_RED,18);
  1640. color sClr=CGR; string sName=GetCurrentSession(sClr); bool isAct=IsSessionActive();
  1641. Bx("c_ses",cx+2*(CW+G),yy,CW,CH,BG_DARK2,sClr);
  1642. Tx("c_ses_l",cx+2*(CW+G)+10,yy+5,"SESSION",NEON_CYAN,11,true);
  1643. Tx("c_ses_v",cx+2*(CW+G)+10,yy+28,sName,sClr,16,true);
  1644. int gH=TimeHour(TimeGMT()), gM=TimeMinute(TimeGMT());
  1645. Tx("c_ses_t",cx+2*(CW+G)+10,yy+56,"GMT "+(gH<10?"0":"")+IntegerToString(gH)+":"+(gM<10?"0":"")+IntegerToString(gM),NEON_WHITE,13,false);
  1646. Tx("c_ses_s",cx+2*(CW+G)+10,yy+80,isAct?"ACTIVE":"LOW VOL",isAct?NEON_GREEN:NEON_ORANGE,12,true);
  1647. yy+=CH+G;
  1648.  
  1649. // ========== ROW 3 - NEURAL AI, CROWD, STRATEGY ==========
  1650. Cube("c7",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"NEURAL AI",NEON_CYAN,DoubleToString(nb,1)+"%",(nb>72)?NEON_ORANGE:(nb<35)?NEON_CYAN:NEON_GREEN,18);
  1651. NeonBar("c7b",cx+12,yy+92,CW-24,8,nb,(nb>72)?NEON_ORANGE:(nb<35)?NEON_CYAN:NEON_GREEN);
  1652. Bx("c8",cx+CW+G,yy,CW,CH,BG_DARK2,NEON_CYAN);
  1653. Tx("c8_l",cx+CW+G+10,yy+5,"CROWD",NEON_CYAN,11,true);
  1654. Tx("c8_c",cx+CW+G+10,yy+30,"CALL "+IntegerToString(g_otcCallPct)+"%",NEON_RED,15,true);
  1655. Tx("c8_p",cx+CW+G+10,yy+56,"PUT "+IntegerToString(g_otcPutPct)+"%",NEON_GREEN,15,true);
  1656. Tx("c8_b",cx+CW+G+10,yy+84,"OTC Crowd",NEON_GOLD,11,false);
  1657. Cube("c_strat",cx+2*(CW+G),yy,CW,CH,stratC,BG_DARK3,"STRATEGY",NEON_CYAN,stratLabel,stratC,13);
  1658. yy+=CH+G;
  1659.  
  1660. // ========== ROW 4 - MICRO AI, MICRO TRAP, TFA ==========
  1661. color maC; string maDir;
  1662. if(mai>72){ maC=NEON_ORANGE; maDir="TRAP RISK!"; }
  1663. else if(mai>55){ maC=NEON_YELLOW; maDir="CAUTION"; }
  1664. else if(mai>45){ maC=NEON_CYAN; maDir="NEUTRAL"; }
  1665. else{ maC=NEON_GREEN; maDir="SAFE"; }
  1666. Cube("c_mai",cx,yy,CW,CH,maC,BG_DARK2,"MICRO AI",NEON_CYAN,DoubleToString(mai,0)+"%",maC,18);
  1667. NeonBar("c_mai_b",cx+12,yy+92,CW-24,8,mai,maC);
  1668.  
  1669. color mtsC=(mts>=90)?NEON_PURPLE:(mts>=75)?NEON_RED:(mts>=50)?NEON_ORANGE:NEON_GREEN;
  1670. string mtsL=(mts>=90)?"EXTREME TRAP":(mts>=75)?"HIGH TRAP":(mts>=50)?"MEDIUM":"CLEAR";
  1671. Cube("c_mts",cx+CW+G,yy,CW,CH,mtsC,BG_DARK2,"MICRO TRAP",NEON_CYAN,"SCORE "+IntegerToString(mts),mtsC,16);
  1672. NeonBar("c_mts_b",cx+CW+G+12,yy+92,CW-24,8,MathMin(100,mts),mtsC);
  1673.  
  1674. int tfaInt=(int)tfaScore; color tfaColor; string tfaLabel;
  1675. if(tfaInt>=5){ tfaLabel="STRONG"; tfaColor=NEON_GREEN; }
  1676. else if(tfaInt>=4){ tfaLabel="GOOD"; tfaColor=NEON_LIME; }
  1677. else if(tfaInt>=3){ tfaLabel="MEDIUM"; tfaColor=NEON_YELLOW; }
  1678. else if(tfaInt>=2){ tfaLabel="WEAK"; tfaColor=NEON_ORANGE; }
  1679. else{ tfaLabel="POOR"; tfaColor=C'100,100,120'; }
  1680. color tfaBC=tfaColor; string dirTxt="";
  1681. if(g_haM1=="HA BEARISH 1"||g_haM5=="HA BEARISH 5"){ tfaBC=NEON_RED; dirTxt=" [DOWN]"; }
  1682. else if(g_haM1=="HA BULLISH 1"||g_haM5=="HA BULLISH 5"){ tfaBC=NEON_GREEN; dirTxt=" [UP]"; }
  1683. else{ dirTxt=" [MIX]"; }
  1684. Bx("c_tfa",cx+2*(CW+G),yy,CW,CH,BG_DARK3,tfaBC);
  1685. Tx("c_tfa_l",cx+2*(CW+G)+10,yy+5,"TFA SCORE",NEON_CYAN,11,true);
  1686. Tx("c_tfa_v",cx+2*(CW+G)+10,yy+28,IntegerToString(tfaInt)+"/6 "+tfaLabel+dirTxt,tfaBC,13,true);
  1687. Tx("c_tfa_d",cx+2*(CW+G)+10,yy+56,g_tfa_detail,CGR,10,false);
  1688. NeonBar("c_tfa_b",cx+2*(CW+G)+10,yy+92,CW-20,8,(double)tfaInt/6.0*100.0,tfaBC);
  1689. yy+=CH+G;
  1690.  
  1691. // ========== ROW 5 - FRACTAL, MARKET BIAS, S/R ==========
  1692. double frac=CalcAdvancedFractal();
  1693. color frC=(frac>=75)?NEON_RED:(frac>=50)?NEON_ORANGE:(frac>=25)?NEON_YELLOW:NEON_GREEN;
  1694. string frT=(frac>=75)?"TRAP ZONE!":(frac>=50)?"WARNING":(frac>=25)?"CAUTION":"CLEAR";
  1695. Cube("c_frc",cx,yy,CW,CH,frC,BG_DARK2,"FRACTAL",NEON_CYAN,frT,frC,14);
  1696. NeonBar("c_frc_b",cx+12,yy+92,CW-24,8,frac,frC);
  1697.  
  1698. Bx("c_bias",cx+CW+G,yy,CW,CH,BG_DARK2,biasClr);
  1699. Tx("c_bias_l",cx+CW+G+10,yy+5,"MARKET BIAS",NEON_CYAN,11,true);
  1700. Tx("c_bias_v",cx+CW+G+10,yy+28,biasStr,biasClr,15,true);
  1701. Tx("c_bias_m",cx+CW+G+10,yy+56,"MODE: "+g_marketMode,(g_marketMode=="TREND")?NEON_GREEN:(g_marketMode=="REVERSAL")?NEON_RED:NEON_YELLOW,12,false);
  1702. color accC=(g_accuracy>=70)?NEON_GREEN:(g_accuracy>=60)?NEON_YELLOW:NEON_RED;
  1703. Tx("c_bias_a",cx+CW+G+10,yy+80,"ACC: "+DoubleToString(g_accuracy,1)+"%",accC,13,false);
  1704. NeonBar("c_bias_b",cx+CW+G+10,yy+96,CW-20,8,g_accuracy,accC);
  1705.  
  1706. int dg_sr=(int)MarketInfo(Symbol(),MODE_DIGITS); if(dg_sr<=0) dg_sr=5;
  1707. Bx("c18",cx+2*(CW+G),yy,CW,CH,BG_DARK2,NEON_CYAN);
  1708. Tx("c18_l",cx+2*(CW+G)+10,yy+4,"S/R LEVELS",NEON_CYAN,11,true);
  1709. Tx("c18_r",cx+2*(CW+G)+10,yy+28,"R: "+(g_nearest_res>0?DoubleToString(g_nearest_res,dg_sr):"--"),NEON_RED,14,true);
  1710. Tx("c18_s",cx+2*(CW+G)+10,yy+56,"S: "+(g_nearest_sup>0?DoubleToString(g_nearest_sup,dg_sr):"--"),NEON_GREEN,14,true);
  1711. Tx("c18_b",cx+2*(CW+G)+10,yy+84,g_brk_str,g_brk_color,13,true);
  1712. yy+=CH+G;
  1713.  
  1714. // ========== ROW 6 - WICKS, HA CANDLES, REVERSAL ==========
  1715. color wickC=(mw>0.70)?NEON_RED:(mw>0.50)?NEON_ORANGE:NEON_GREEN;
  1716. Bx("c15",cx,yy,CW,CH,BG_DARK2,wickC);
  1717. Tx("c15_l",cx+10,yy+5,"WICKS",NEON_CYAN,11,true);
  1718. Tx("c15_v",cx+10,yy+30,DoubleToString(mw,2),wickC,20,true);
  1719. Tx("c15_b",cx+10,yy+62,(mw>0.70)?"KILL SHOT":(mw>0.50)?"HIGH":"LOW",wickC,13,false);
  1720. NeonBar("c15_bar",cx+10,yy+92,CW-20,8,mw*100,wickC);
  1721.  
  1722. Bx("c_ha",cx+CW+G,yy,CW,CH,BG_DARK2,ha1C);
  1723. Tx("c_ha_l",cx+CW+G+10,yy+5,"HA CANDLES",NEON_CYAN,11,true);
  1724. Tx("c_ha_m1",cx+CW+G+10,yy+30,"M1: "+g_haM1,ha1C,14,true);
  1725. Tx("c_ha_m5",cx+CW+G+10,yy+56,"M5: "+g_haM5,ha5C,14,true);
  1726. string haComb=""; color haCombC=NEON_YELLOW;
  1727. if(g_haM1=="HA BULLISH 1" && g_haM5=="HA BULLISH 5"){ haComb="BOTH BULL"; haCombC=NEON_GREEN; }
  1728. else if(g_haM1=="HA BEARISH 1" && g_haM5=="HA BEARISH 5"){ haComb="BOTH BEAR"; haCombC=NEON_RED; }
  1729. else haComb="MIXED";
  1730. Tx("c_ha_c",cx+CW+G+10,yy+84,haComb,haCombC,13,true);
  1731.  
  1732. string revReason=DetectSuddenReversal(); color revColor=NEON_YELLOW;
  1733. if(StringFind(revReason,"BULL")>=0) revColor=NEON_GREEN;
  1734. if(StringFind(revReason,"BEAR")>=0) revColor=NEON_RED;
  1735. Bx("c_reason",cx+2*(CW+G),yy,CW,CH,BG_DARK2,revColor);
  1736. Tx("c_reason_l",cx+2*(CW+G)+10,yy+5,"REVERSAL",NEON_CYAN,11,true);
  1737. if(StringLen(revReason)>0){
  1738. string sr=revReason; if(StringLen(sr)>30) sr=StringSubstr(sr,0,28)+"..";
  1739. Tx("c_reason_v",cx+2*(CW+G)+10,yy+34,sr,revColor,13,false);
  1740. } else Tx("c_reason_v",cx+2*(CW+G)+10,yy+34,"No reversal",CGR,13,false);
  1741. yy+=CH+G;
  1742.  
  1743. // ========== ROW 7 - HRN, OTHER PAIRS, OTC QUICK ==========
  1744. int bottomW = (W - 2*G - 2*G) / 3;
  1745. int bottomH = 125;
  1746. yy += 5;
  1747. int x1 = cx;
  1748. Bx("c_hrn", x1, yy, bottomW, bottomH, BG_DARK2, NEON_PINK);
  1749. Tx("c_hrn_l", x1+8, yy+6, "HRN LEVEL", NEON_PINK, 11, true);
  1750. Tx("c_hrn_v", x1+8, yy+30, g_hrn_str, NEON_PINK, 15, true);
  1751. Tx("c_hrn_t", x1+8, yy+58, (g_hrn_is_sup?"SUPPORT":"RESISTANCE"), NEON_PINK, 12, false);
  1752. // Score display
  1753. string scoreStr = "Score: "+DoubleToString(g_hrn_score,0);
  1754. color scoreC = (g_hrn_score>=30)?NEON_GREEN:(g_hrn_score>=15)?NEON_YELLOW:NEON_ORANGE;
  1755. Tx("c_hrn_sc", x1+8, yy+80, scoreStr, scoreC, 12, false);
  1756. Tx("c_hrn_b", x1+8, yy+100, "Brk "+IntegerToString(g_hrn_brk_bars)+"/"+IntegerToString(HRN_CONFIRM_BARS), NEON_PINK, 12, false);
  1757. Tx("c_hrn_s", x1+8, yy+118, g_isSideways?"SIDEWAYS":"TRENDING", g_isSideways?NEON_YELLOW:NEON_GREEN, 11, false);
  1758.  
  1759. int x2 = x1 + bottomW + G;
  1760. DrawOtherPairsCube(x2, yy, bottomW, bottomH);
  1761.  
  1762. int x3 = x2 + bottomW + G;
  1763. DrawOTCQuickCube(x3, yy, bottomW, bottomH);
  1764.  
  1765. // ========== FILTER STATUS BAR ==========
  1766. yy += bottomH + 5;
  1767. int fsW = W - 2*G;
  1768. color fsC = (g_filterStatus=="ALL CLEAR")?NEON_GREEN:
  1769. (g_filterStatus=="TRAP ACTIVE"||g_filterStatus=="TREND ACTIVE")?NEON_LIME:
  1770. (StringFind(g_filterStatus,"LOCK")>=0)?NEON_RED:NEON_ORANGE;
  1771. Bx("c_filter", cx, yy, fsW, 22, BG_DARK3, fsC);
  1772. Tx("c_filter_v", cx+10, yy+4, "FILTER: "+g_filterStatus, fsC, 12, true);
  1773.  
  1774. UpdateTimer(); HideSPM(); ChartRedraw();
  1775. }
  1776.  
  1777. //+------------------------------------------------------------------+
  1778. // RISK CONTROL
  1779. //+------------------------------------------------------------------+
  1780. void UpdateRiskControl(){
  1781. static datetime llt=0;
  1782.  
  1783. if(ENABLE_RISK_LOCK){
  1784. if(g_lossStreak>=MAX_LOSS_STREAK){
  1785. g_tradingStopped=true;
  1786. llt=TimeCurrent();
  1787. g_filterStatus="RISK LOCK "+IntegerToString(g_lossStreak)+"L";
  1788. }
  1789. if(g_tradingStopped && TimeCurrent()-llt>3600){
  1790. g_tradingStopped=false;
  1791. g_lossStreak=0;
  1792. g_filterStatus="RISK UNLOCK";
  1793. }
  1794. }
  1795. }
  1796.  
  1797. //+------------------------------------------------------------------+
  1798. // FINAL SIGNAL ENGINE - ALL FILTERS ACTIVE
  1799. //+------------------------------------------------------------------+
  1800. void FinalSignalEngine(double brain,int cp,int mts){
  1801. g_filterStatus="ALL CLEAR";
  1802.  
  1803. // RISK CONTROL CHECK
  1804. if(ENABLE_RISK_CONTROL && g_tradingStopped){
  1805. g_finalSignal="WAIT";
  1806. g_finalColor=NEON_ORANGE;
  1807. g_filterStatus="RISK LOCKED";
  1808. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1809. return;
  1810. }
  1811.  
  1812. // SESSION FILTER CHECK
  1813. if(ENABLE_SESSION_FILTER && !IsSessionActive()){
  1814. g_finalSignal="WAIT";
  1815. g_finalColor=NEON_ORANGE;
  1816. g_filterStatus="SESSION OFF";
  1817. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1818. return;
  1819. }
  1820.  
  1821. // MTF CONFIRMATION CHECK
  1822. if(MTF_CONFIRM && !g_mtfConfirmed){
  1823. g_finalSignal="WAIT";
  1824. g_finalColor=NEON_ORANGE;
  1825. g_filterStatus="MTF NO CONF";
  1826. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1827. return;
  1828. }
  1829.  
  1830. // SPIKE FILTER CHECK
  1831. if(ENABLE_SPIKE_FILTER && IsBigCandle(1)){
  1832. g_finalSignal="WAIT";
  1833. g_finalColor=NEON_ORANGE;
  1834. g_filterStatus="SPIKE BLOCK";
  1835. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1836. return;
  1837. }
  1838.  
  1839. // LAST SECOND BLOCK CHECK
  1840. if(ENABLE_LAST_SEC_BLOCK){
  1841. int age=(int)(TimeCurrent()-Time[0]);
  1842. int ps=Period()*60;
  1843. int rem=ps-age;
  1844. if(rem<0) rem=0;
  1845. if(rem < MIN_REMAINING_SEC){
  1846. g_finalSignal="WAIT";
  1847. g_finalColor=NEON_ORANGE;
  1848. g_filterStatus="LAST SEC BLOCK";
  1849. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1850. return;
  1851. }
  1852. }
  1853.  
  1854. // MIN CONFIDENCE CHECK
  1855. double conf=MathMax(g_calc_gProb,g_calc_rProb);
  1856. if(conf < MIN_CONFIDENCE){
  1857. g_finalSignal="WAIT";
  1858. g_finalColor=NEON_YELLOW;
  1859. g_filterStatus="LOW CONF "+DoubleToString(conf,0)+"%";
  1860. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1861. return;
  1862. }
  1863.  
  1864. // STRATEGY SIGNAL FIRST
  1865. string ms=DetectMyStrategy();
  1866. if(ms!="WAIT"){
  1867. // CONSENSUS FILTER CHECK
  1868. if(CONSENSUS_FILTER && !ConsensusOK()){
  1869. g_finalSignal="WAIT";
  1870. g_finalColor=NEON_ORANGE;
  1871. g_filterStatus="NO CONSENSUS";
  1872. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1873. return;
  1874. }
  1875.  
  1876. // ENTRY ZONE CHECK
  1877. if(ENABLE_ENTRY_ZONE && !DirectionOK()){
  1878. g_finalSignal="WAIT";
  1879. g_finalColor=NEON_ORANGE;
  1880. g_filterStatus="BAD ENTRY ZONE";
  1881. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1882. return;
  1883. }
  1884.  
  1885. // ENTRY PRECISION CHECK
  1886. if(!EntryPrecisionOK()){
  1887. g_finalSignal="WAIT";
  1888. g_finalColor=NEON_ORANGE;
  1889. g_filterStatus="PRECISION FAIL";
  1890. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1891. return;
  1892. }
  1893.  
  1894. g_finalSignal=ms;
  1895. g_finalColor=(ms=="CALL")?NEON_GREEN:NEON_RED;
  1896. g_filterStatus=(g_strategyType=="TRAP")?"TRAP ACTIVE":"TREND ACTIVE";
  1897. if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT"){
  1898. g_finalSignal=ms; g_signalTime=TimeCurrent();
  1899. }
  1900.  
  1901. SendSignalNotification(ms,conf);
  1902. return;
  1903. }
  1904.  
  1905. // NORMAL SIGNAL LOGIC
  1906. double th=FAST_MODE?70:68;
  1907. if(g_calc_gProb>th) g_finalSignal="CALL";
  1908. else if(g_calc_rProb>th) g_finalSignal="PUT";
  1909. else if(g_calc_gProb>60) g_finalSignal="WEAK CALL";
  1910. else if(g_calc_rProb>60) g_finalSignal="WEAK PUT";
  1911. else g_finalSignal="WAIT";
  1912.  
  1913. // ENTRY ZONE CHECK FOR NORMAL SIGNALS
  1914. if((g_finalSignal=="CALL" || g_finalSignal=="PUT") && ENABLE_ENTRY_ZONE && !DirectionOK()){
  1915. g_finalSignal="WAIT";
  1916. g_finalColor=NEON_ORANGE;
  1917. g_filterStatus="BAD ENTRY ZONE";
  1918. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1919. return;
  1920. }
  1921.  
  1922. // ENTRY PRECISION CHECK FOR NORMAL SIGNALS
  1923. if((g_finalSignal=="CALL" || g_finalSignal=="PUT") && !EntryPrecisionOK()){
  1924. g_finalSignal="WAIT";
  1925. g_finalColor=NEON_ORANGE;
  1926. g_filterStatus="PRECISION FAIL";
  1927. if(TimeCurrent()-g_signalTime>HOLD_SEC) g_signalTime=TimeCurrent();
  1928. return;
  1929. }
  1930.  
  1931. if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT")
  1932. g_signalTime=TimeCurrent();
  1933.  
  1934. if(g_finalSignal=="CALL"){
  1935. g_finalColor=NEON_GREEN;
  1936. g_filterStatus="GREEN SIGNAL";
  1937. SendSignalNotification("CALL",conf);
  1938. }
  1939. else if(g_finalSignal=="PUT"){
  1940. g_finalColor=NEON_RED;
  1941. g_filterStatus="RED SIGNAL";
  1942. SendSignalNotification("PUT",conf);
  1943. }
  1944. else if(g_finalSignal=="WEAK CALL"){
  1945. g_finalColor=NEON_CYAN;
  1946. g_filterStatus="WEAK GREEN";
  1947. }
  1948. else if(g_finalSignal=="WEAK PUT"){
  1949. g_finalColor=NEON_ORANGE;
  1950. g_filterStatus="WEAK RED";
  1951. }
  1952. else{
  1953. g_finalColor=NEON_YELLOW;
  1954. }
  1955. }
  1956.  
  1957. //+------------------------------------------------------------------+
  1958. // SEND SIGNAL NOTIFICATION
  1959. //+------------------------------------------------------------------+
  1960. void SendSignalNotification(string sig,double conf){
  1961. if(!ENABLE_NOTIFY) return;
  1962.  
  1963. string msg=Symbol()+" | "+sig+" | "+DoubleToString(conf,0)+"% | "+g_filterStatus;
  1964.  
  1965. // Prevent spam - same signal within 10 seconds
  1966. if(msg==g_lastNotified) return;
  1967. if(TimeCurrent()-StringToTime(TimeToString(TimeCurrent()))<10) return;
  1968.  
  1969. g_lastNotified=msg;
  1970.  
  1971. Alert(msg);
  1972. SendNotification(msg);
  1973.  
  1974. if(ENABLE_TELEGRAM){
  1975. string tgMsg="*AIBRAIN Signal*\n"+Symbol()+"\n"+sig+"\nConf: "+DoubleToString(conf,0)+"%\n"+g_filterStatus;
  1976. SendTelegramAlert(tgMsg);
  1977. }
  1978.  
  1979. Print(msg);
  1980. }
  1981.  
  1982. //+------------------------------------------------------------------+
  1983. // BROADCAST SIGNAL
  1984. //+------------------------------------------------------------------+
  1985. void BroadcastSignal(){
  1986. double conf=MathMax(g_frozen_gProb,g_frozen_rProb);if(conf<55)return;
  1987. string fn="OTC_Signals_Master.txt",pair=Symbol();
  1988. string sig=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";
  1989. int exp=(int)(TimeCurrent()+65);
  1990. string line=pair+"|"+sig+"|"+DoubleToString(conf,0)+"|"+IntegerToString((int)TimeCurrent())+"|"+IntegerToString(exp);
  1991. int h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);
  1992. if(h==INVALID_HANDLE){h=FileOpen(fn,FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);if(h==INVALID_HANDLE)return;FileWriteString(h,line+"\n");FileClose(h);return;}
  1993. string content="";while(!FileIsEnding(h)){string ex=FileReadString(h);if(StringLen(ex)>10&&StringFind(ex,pair+"|")!=0)content+=ex+"\n";}
  1994. content=line+"\n"+content;
  1995. string lns[];int cnt=0,pos=0;int f=StringFind(content,"\n",pos);
  1996. while(f!=-1&&cnt<100){ArrayResize(lns,cnt+1);lns[cnt]=StringSubstr(content,pos,f-pos);cnt++;pos=f+1;f=StringFind(content,"\n",pos);}
  1997. if(pos<StringLen(content)){ArrayResize(lns,cnt+1);lns[cnt]=StringSubstr(content,pos);cnt++;}
  1998. if(cnt>50){content="";for(int i=0;i<50;i++)if(StringLen(lns[i])>10)content+=lns[i]+"\n";}
  1999. FileSeek(h,0,SEEK_SET);FileWriteString(h,content);FileFlush(h);FileClose(h);
  2000. }
  2001.  
  2002. //+------------------------------------------------------------------+
  2003. // HELPER: HA DIRECTION
  2004. //+------------------------------------------------------------------+
  2005. string GetPairHADirection(string pair){
  2006. double open1 = iOpen(pair, PERIOD_M1, 1);
  2007. double high1 = iHigh(pair, PERIOD_M1, 1);
  2008. double low1 = iLow(pair, PERIOD_M1, 1);
  2009. double close1= iClose(pair, PERIOD_M1, 1);
  2010. double open2 = iOpen(pair, PERIOD_M1, 2);
  2011. double high2 = iHigh(pair, PERIOD_M1, 2);
  2012. double low2 = iLow(pair, PERIOD_M1, 2);
  2013. double close2= iClose(pair, PERIOD_M1, 2);
  2014. double open3 = iOpen(pair, PERIOD_M1, 3);
  2015. double close3= iClose(pair, PERIOD_M1, 3);
  2016. if(open1==0||high1==0||low1==0||close1==0||open2==0||close2==0||open3==0||close3==0)
  2017. return "NEUTRAL";
  2018. double haClose1 = (open1+high1+low1+close1)/4.0;
  2019. double haClose2 = (open2+high2+low2+close2)/4.0;
  2020. double haOpen2_approx = (open3+close3)/2.0;
  2021. double haOpen1 = (haOpen2_approx + haClose2)/2.0;
  2022. if(haClose1 > haOpen1) return "BULL";
  2023. else if(haClose1 < haOpen1) return "BEAR";
  2024. return "NEUTRAL";
  2025. }
  2026.  
  2027. //+------------------------------------------------------------------+
  2028. // HELPER: VOLUME RATIO
  2029. //+------------------------------------------------------------------+
  2030. double GetPairVolumeRatio(string pair){
  2031. double v1 = iVolume(pair, PERIOD_M1, 1);
  2032. double v2 = iVolume(pair, PERIOD_M1, 2);
  2033. if(v2 <= 0) return 1.0;
  2034. return v1 / v2;
  2035. }
  2036.  
  2037. //+------------------------------------------------------------------+
  2038. // SCAN SIGNALS
  2039. //+------------------------------------------------------------------+
  2040. void ScanSignals(){
  2041. g_pairCount = 0;
  2042. string fn = "OTC_Signals_Master.txt";
  2043. string cur = Symbol();
  2044. int h = FileOpen(fn, FILE_READ|FILE_TXT|FILE_SHARE_READ);
  2045. if(h == INVALID_HANDLE) return;
  2046.  
  2047. datetime now = TimeCurrent();
  2048. while(!FileIsEnding(h) && g_pairCount < 5){
  2049. string ln = FileReadString(h);
  2050. if(StringLen(ln) < 15) continue;
  2051.  
  2052. int p1 = StringFind(ln, "|");
  2053. int p2 = StringFind(ln, "|", p1+1);
  2054. int p3 = StringFind(ln, "|", p2+1);
  2055. int p4 = StringFind(ln, "|", p3+1);
  2056. if(p1 < 0 || p2 < 0 || p3 < 0 || p4 < 0) continue;
  2057.  
  2058. string pair = StringSubstr(ln, 0, p1);
  2059. if(pair == cur) continue;
  2060.  
  2061. string sig = StringSubstr(ln, p1+1, p2-p1-1);
  2062. double conf = StringToDouble(StringSubstr(ln, p2+1, p3-p2-1));
  2063. int ex = (int)StringToInteger(StringSubstr(ln, p4+1));
  2064.  
  2065. if(conf < 62) continue;
  2066. if(ex < (int)(now - 10)) continue;
  2067.  
  2068. string haDir = GetPairHADirection(pair);
  2069. bool haMatch = false;
  2070. if(sig == "CALL" && haDir == "BULL") haMatch = true;
  2071. if(sig == "PUT" && haDir == "BEAR") haMatch = true;
  2072. if(!haMatch) continue;
  2073.  
  2074. double vr = GetPairVolumeRatio(pair);
  2075. if(vr > 2.0) continue;
  2076.  
  2077. g_pairNames[g_pairCount] = pair;
  2078. g_pairSigs[g_pairCount] = sig;
  2079. g_pairConfs[g_pairCount] = conf;
  2080. g_pairCount++;
  2081. }
  2082. FileClose(h);
  2083. }
  2084.  
  2085. //+------------------------------------------------------------------+
  2086. // READ SPM
  2087. //+------------------------------------------------------------------+
  2088. void ReadSPM(){
  2089. datetime cb=Time[0];if(cb==g_last_bar&&TimeCurrent()-g_spm_t<5)return;
  2090. double v1=iCustom(NULL,PERIOD_M1,SPM_FILE,0,0),v2=iCustom(NULL,PERIOD_M1,SPM_FILE,1,0);
  2091. if(v1!=EMPTY_VALUE&&v1!=0){double sm=0.7;g_rsc=g_rsc*(1.0-sm)+v1*sm;}
  2092. if(v2!=EMPTY_VALUE&&v2!=0){double sm=0.7;g_tfa=g_tfa*(1.0-sm)+v2*sm;}
  2093. g_last_bar=cb;g_spm_t=TimeCurrent();
  2094. }
  2095.  
  2096. //+------------------------------------------------------------------+
  2097. // INIT
  2098. //+------------------------------------------------------------------+
  2099. int OnInit(){
  2100. InitNW();NuclearDeleteAll();
  2101. resCount=0;supCount=0;lastSRBar=0;g_hrn_price=0;g_hrn_brk_bars=0;g_hrn_scan_bar=0;
  2102. g_hrn_score=0;g_hrn_confirmed_break=false;
  2103. g_nearest_res=0;g_nearest_sup=0;g_rj_cnt=0;g_pairCount=0;
  2104. g_marketMode="RANGE";g_prevMode="";g_last_freeze_bar=0;
  2105. g_lastNotified="";g_copiedPair="";g_accuracy=ValidateHistoricalAccuracy();
  2106. g_acc_correct=0;g_acc_total=0;g_acc_lastBar=0;
  2107. g_lastPredGreen=50.0;g_lastPredBar=0;g_lastLogBar=0;
  2108. g_lossStreak=0;g_tradingStopped=false;g_stopStartTime=0;
  2109. g_strategyType="NONE";g_strategySignal="WAIT";g_strategyReason="";
  2110. g_frozen_gProb=50;g_frozen_rProb=50;g_calc_gProb=50;g_calc_rProb=50;
  2111. g_commonCount=0;g_wickLineCount=0;g_tfa_detail="";g_htfLevelCount=0;g_lastLevelScan=0;
  2112. g_mtfConfirmed=true;g_filterStatus="ALL CLEAR";
  2113. LoadMLWeights();EventSetTimer(1);
  2114.  
  2115. string filters="";
  2116. if(ENABLE_SESSION_FILTER) filters+="Session ";
  2117. if(ENABLE_SPIKE_FILTER) filters+="Spike ";
  2118. if(ENABLE_LAST_SEC_BLOCK) filters+="LastSec ";
  2119. if(ENABLE_RISK_CONTROL) filters+="Risk ";
  2120. if(ENABLE_ENTRY_ZONE) filters+="EntryZone ";
  2121. if(MTF_CONFIRM) filters+="MTF ";
  2122. if(CONSENSUS_FILTER) filters+="Consensus ";
  2123. if(ENABLE_NOTIFY) filters+="Notify ";
  2124.  
  2125. Print("===========================================");
  2126. Print("AIBRAIN v45.0 FINAL LOADED");
  2127. Print("HRN: Real Round Numbers + 2-Candle Close");
  2128. Print("Prediction: v2.0 Upgraded");
  2129. Print("Fonts: Bigger & Clearer");
  2130. Print("Active Filters: ",filters);
  2131. Print("Telegram: ",ENABLE_TELEGRAM?"ON":"OFF");
  2132. Print("===========================================");
  2133.  
  2134. return INIT_SUCCEEDED;
  2135. }
  2136.  
  2137. //+------------------------------------------------------------------+
  2138. // DEINIT
  2139. //+------------------------------------------------------------------+
  2140. void OnDeinit(const int r){
  2141. EventKillTimer();Comment("");
  2142. for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)==0)ObjectDelete(nm);}
  2143. }
  2144.  
  2145. //+------------------------------------------------------------------+
  2146. // ON TIMER
  2147. //+------------------------------------------------------------------+
  2148. void OnTimer(){
  2149. if(Bars<50)return;
  2150. static datetime last5min=0;
  2151. if(Time[0]/300 != last5min/300){ DetectHiddenLevels(); last5min=Time[0]; }
  2152. ReadSPM();CalcHA();UpdateHRN();UpdateSR();
  2153. DetectCommonPoints();DetectWickRejections();
  2154. DrawCommonPoints();DrawWickRejectLines();DrawHiddenLevels();DrawNearestSR();
  2155. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  2156. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();
  2157. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  2158. FinalSignalEngine(brain,cp,mts);
  2159. BroadcastSignal();ScanSignals();
  2160. Draw();
  2161. }
  2162.  
  2163. //+------------------------------------------------------------------+
  2164. // ON CALCULATE
  2165. //+------------------------------------------------------------------+
  2166. int OnCalculate(const int rates_total,const int prev_calculated,
  2167. const datetime &time[],const double &open[],
  2168. const double &high[],const double &low[],const double &close[],
  2169. const long &tick_volume[],const long &volume[],const int &spread[]){
  2170. return(rates_total);
  2171. }
  2172. //+------------------------------------------------------------------+