1. //+------------------------------------------------------------------+
  2. //| AIBRAIN OTC v45.4 - OVERLAP + TIMER + SR + POPUP FIXED |
  3. //| Fixed: Other pairs no overlap, text size 11, timer screen pos |
  4. //| Fixed: SR lines stable (no shift), popup notification removed |
  5. //+------------------------------------------------------------------+
  6. #property copyright "AIBRAIN ULTIMATE - KM RANA"
  7. #property version "46.2"
  8. #property strict
  9. #property indicator_chart_window
  10.  
  11. #define PFX "AIB9_"
  12. #define VER "v46.2"
  13. #define LB 18
  14. #define MAX_LEVELS 5
  15. #define MAX_REJ 50
  16. #define LOOKBACK 50
  17.  
  18. input string SPM_FILE = "KM RANA";
  19. input int HOLD_SEC = 60;
  20. input int POS_X = 4;
  21. input int POS_Y = 20;
  22. input int DASH_W = 660;
  23. input bool SHOW_TIMER = true;
  24. input bool SHOW_SR_LINES = true;
  25. input string ENTRY_MODE = "TIME";
  26. input int FLAG_MIN_SEC = 10;
  27. input int FLAG_MAX_SEC = 35;
  28. input int TIME_MIN_SEC = 10;
  29. input int TIME_MAX_SEC = 35;
  30. input int MIN_REMAINING_SEC = 15;
  31. input double REVERSAL_PCT = 30.0;
  32. input double WICK_PCT = 0.65;
  33. input int HRN_CONFIRM_BARS = 2;
  34. input bool HA_ALIGN_FILTER = false;
  35. input bool CONSENSUS_FILTER = false;
  36. input bool ENABLE_NOTIFY = true;
  37. input bool FAST_MODE = false;
  38. input int BROKER_SPREAD_THRESHOLD= 6;
  39. input double OTC_TRAP_WEIGHT = 15.0;
  40. input int CROWD_EXTREME_PCT = 70;
  41. input bool ENABLE_BROKER_KILLER = true;
  42. input bool ENABLE_SESSION_FILTER = true;
  43. input bool ENABLE_SPIKE_FILTER = true;
  44. input bool ENABLE_LAST_SEC_BLOCK = true;
  45. input bool ENABLE_RISK_CONTROL = true;
  46. input bool ENABLE_ENTRY_ZONE = true;
  47. input bool ML_ADAPTIVE = true;
  48. input bool VOLUME_PROFILE_TRAP = true;
  49. input bool MTF_CONFIRM = false;
  50. input bool ENABLE_TELEGRAM = false;
  51. input string TELEGRAM_TOKEN = "";
  52. input string TELEGRAM_CHAT_ID = "";
  53. input string TRADE_MODE = "NORMAL";
  54. input string STRATEGY_MODE = "TRAP_ONLY";
  55. input int STRATEGY_THRESHOLD = 75;
  56. input int MAX_LOSS_STREAK = 2;
  57. input double MIN_CONFIDENCE = 75.0;
  58. input bool ENABLE_RISK_LOCK = true;
  59. input double PATTERN_TOLERANCE_PIPS = 8.0;
  60. input int MIN_PATTERN_SEPARATION = 5;
  61. input bool SHOW_COMMON_POINTS = true;
  62. input double COMMON_POINT_TOL_PIPS = 15.0;
  63. input bool SHOW_WICK_REJECT_LINES = true;
  64. input int WICK_MIN_TOUCHES = 1;
  65. input double WICK_ZONE_PIPS = 15.0;
  66. input int WICK_EXPIRE_BARS = 60;
  67.  
  68. // ============================================================
  69. // BB PULLBACK SETTINGS
  70. // ============================================================
  71. input bool ENABLE_BB_PULLBACK = true;
  72. input int BB_PERIOD = 20;
  73. input double BB_DEVIATION = 2.0;
  74. input int BB_SIGNAL_EXPIRE_BARS = 5;
  75.  
  76. // ============================================================
  77. // NCP PRO v7.3 SETTINGS
  78. // ============================================================
  79. input bool ENABLE_MTG = true;
  80. input int NCP_OpenNoiseSeconds = 3;
  81. input int NCP_KillZoneSeconds = 55;
  82. input double NCP_MaxSpreadPips = 4.0;
  83. input int NCP_ATRPeriod = 14;
  84. input double NCP_MinATRPips = 0.4;
  85. input int NCP_FastEMA = 3;
  86. input int NCP_MidEMA = 7;
  87. input int NCP_SlowEMA = 15;
  88. input bool NCP_UseM5Confirm = true;
  89. input bool NCP_UseVolume = true;
  90. input double NCP_RoundStepPips = 10.0;
  91. input double NCP_RoundTolPips = 4.0;
  92. input int NCP_MinProbMedium = 57;
  93. input int NCP_MinProbStrong = 63;
  94. input int NCP_MinProbExtreme = 70;
  95. input bool NCP_UseRSINorm = true;
  96. input int NCP_RSIPeriod = 10;
  97. input double NCP_RSIBase = 50.0;
  98. input double NCP_RSIM5Target = 45.0;
  99. input double NCP_RSIM15Target = 40.0;
  100. input bool ENABLE_LEARNING = true;
  101. input string MEMORY_FILE_NAME = "NCP_Brain_v7.csv";
  102. input int MIN_TRADES_TO_LEARN = 15;
  103. input double LEARNING_STEP = 0.025;
  104. input bool ENABLE_TRAP_DETECTION = true;
  105. input int TRAP_LOOKBACK = 30;
  106.  
  107. #define NEON_GREEN C'0,255,100'
  108. #define NEON_RED C'255,40,80'
  109. #define NEON_YELLOW C'255,220,0'
  110. #define NEON_ORANGE C'255,120,0'
  111. #define NEON_CYAN C'0,255,200'
  112. #define NEON_PURPLE C'200,0,255'
  113. #define NEON_PINK C'255,80,180'
  114. #define NEON_BLUE C'0,200,255'
  115. #define NEON_LIME C'80,255,80'
  116. #define NEON_GOLD C'255,180,0'
  117. #define DARK_BLUE_NEON C'0,100,255'
  118. #define NEON_WHITE C'220,230,255'
  119. #define CGR C'160,170,190'
  120. #define BB_GREY C'180,180,190'
  121. #define BG_DARK1 C'6,8,16'
  122. #define BG_DARK2 C'10,14,24'
  123. #define BG_DARK3 C'14,20,32'
  124. #define BG_DARK4 C'18,26,40'
  125.  
  126. struct HTFLevel{ double price; string timeframe; string type; datetime time; int strength; bool isRoundNumber; };
  127.  
  128. //+------------------------------------------------------------------+
  129. // GLOBAL VARIABLES
  130. //+------------------------------------------------------------------+
  131. string g_haM1="",g_haM5="",g_haBoth="";
  132. color g_haM1Color=clrGray,g_haM5Color=clrGray;
  133. static double NW[36];
  134. static double g_rsc=0,g_tfa=3;
  135. static datetime g_spm_t=0,g_last_bar=0;
  136. static double g_nearest_res=0,g_nearest_sup=0;
  137. static string g_brk_str="NO BRK";
  138. static color g_brk_color=CGR;
  139. struct RejLevel{double price;int touches;};
  140. static RejLevel g_rj[MAX_REJ];
  141. static int g_rj_cnt=0;
  142.  
  143. static double g_hrn_price=0;
  144. static bool g_hrn_is_sup=true;
  145. static int g_hrn_brk_bars=0;
  146. static datetime g_hrn_scan_bar=0;
  147. static string g_hrn_str="--";
  148. static double g_hrn_score=0;
  149. static bool g_hrn_confirmed_break=false;
  150.  
  151. static int g_otcCallPct=50,g_otcPutPct=50;
  152. static string g_pairNames[8],g_pairSigs[8];
  153. static double g_pairConfs[8];
  154. static int g_pairCount=0;
  155. static double g_frozen_gProb=50,g_frozen_rProb=50;
  156. static string g_frozen_pAction="UNCERTAIN";
  157. static color g_frozen_pColor=NEON_YELLOW;
  158. static double g_calc_gProb=50,g_calc_rProb=50;
  159. static string g_calc_pAction="UNCERTAIN";
  160. static color g_calc_pColor=NEON_YELLOW;
  161. static double g_gProb=50,g_rProb=50;
  162. static string g_pAction="UNCERTAIN";
  163. static color g_pColor=NEON_YELLOW;
  164. static datetime g_last_freeze_bar=0;
  165. static double g_accuracy=65.0;
  166. static int g_acc_correct=0,g_acc_total=0;
  167. static datetime g_acc_lastBar=0;
  168. static double g_lastPredGreen=50.0;
  169. static datetime g_lastPredBar=0;
  170. static string g_finalSignal="WAIT";
  171. static color g_finalColor=NEON_YELLOW;
  172. static datetime g_signalTime=0;
  173. static string g_lastNotified="";
  174. static string g_marketMode="RANGE",g_prevMode="";
  175. static int g_lossStreak=0;
  176. static bool g_tradingStopped=false;
  177. static string g_strategyType="NONE";
  178. static string g_strategyReason="";
  179. static double qmrA=0,qmrB=0,qmrC=0,qmrD=0;
  180. static bool qmrActive=false;
  181. static datetime qmrExpire=0;
  182. #define MAX_COMMON_PTS 5
  183. static double g_commonPrice[MAX_COMMON_PTS];
  184. static datetime g_commonTime[MAX_COMMON_PTS];
  185. static int g_commonCount=0;
  186. static datetime g_commonExpire[MAX_COMMON_PTS];
  187. static string g_commonType[MAX_COMMON_PTS];
  188. static datetime g_lastCommonScan=0;
  189. #define MAX_WICK_LINES 5
  190. static double g_wickLinePrice[MAX_WICK_LINES];
  191. static int g_wickLineTouches[MAX_WICK_LINES];
  192. static datetime g_wickLineExpire[MAX_WICK_LINES];
  193. static int g_wickLineCount=0;
  194. static datetime g_lastWickScan=0;
  195. static bool g_isSideways=false;
  196. static string g_tfa_detail="";
  197. static HTFLevel g_htfLevels[50];
  198. static int g_htfLevelCount=0;
  199. static bool g_mtfConfirmed=true;
  200. static string g_filterStatus="ALL CLEAR";
  201. static string g_adv1="WAIT KAR";
  202. static string g_symbolKey="";
  203. static double g_brokerBias=0.0;
  204.  
  205. // STABLE S/R GLOBAL VARIABLES
  206. double g_stableRes[10];
  207. double g_stableSup[10];
  208. int g_stableResCount = 0;
  209. int g_stableSupCount = 0;
  210. datetime g_lastSRScan = 0;
  211. int g_srScanInterval = 5;
  212.  
  213. // ============================================================
  214. // BB PULLBACK GLOBAL VARIABLES
  215. // ============================================================
  216. static string g_bbSignal = "--";
  217. static color g_bbColor = CGR;
  218. static double g_bbTouchPrice = 0.0;
  219. static datetime g_bbSignalTime = 0;
  220. static int g_bbSignalBars = 0;
  221. static string g_bbDetail = "";
  222.  
  223. static double g_ha30_open = 0.0;
  224. static double g_ha30_close = 0.0;
  225. static double g_ha30_high = 0.0;
  226. static double g_ha30_low = 0.0;
  227. static datetime g_ha30_bar = 0;
  228.  
  229. #define MAX_BB_LINES 8
  230. static double g_bbLinePrice[MAX_BB_LINES];
  231. static datetime g_bbLineExpire[MAX_BB_LINES];
  232. static string g_bbLineType[MAX_BB_LINES];
  233. static int g_bbLineCount=0;
  234.  
  235. // ============================================================
  236. // NCP PRO GLOBALS
  237. // ============================================================
  238. static string g_mtgState = "INIT";
  239. static string g_mtgReason = "";
  240. static string g_mtgAction = "";
  241. static color g_mtgClr = CGR;
  242. static double g_mtgHype = 50.0;
  243. static double g_mtgBetrayal = 50.0;
  244. static string g_mtgPattern = "";
  245. static int g_mtgBullCount = 0;
  246. static int g_mtgBearCount = 0;
  247. static double g_mtgRecovery = 0.0;
  248. static datetime g_mtg_lastBar = 0;
  249. static double g_trapScore = 0;
  250.  
  251. static double g_callWeight = 1.0;
  252. static double g_putWeight = 1.0;
  253. static int g_totalTrades = 0;
  254. static int g_callTrades = 0;
  255. static int g_putTrades = 0;
  256. static int g_callWins = 0;
  257. static int g_putWins = 0;
  258. static datetime g_ncpLastSignalTime = 0;
  259. static string g_ncpLastSignalType = "";
  260. static double g_ncpLastEntryPrice = 0.0;
  261. static bool g_ncpSignalProcessed = true;
  262. static double g_smoothCallScore = 50.0;
  263. static double g_smoothPutScore = 50.0;
  264.  
  265. //+------------------------------------------------------------------+
  266. // 30-SECOND HA CANDLE
  267. //+------------------------------------------------------------------+
  268. void Calc30SecHA(){
  269. if(Bars < 5) return;
  270. double cur_open = Open[0];
  271. double cur_high = High[0];
  272. double cur_low = Low[0];
  273. double cur_close = Close[0];
  274. double prev_open = Open[1];
  275. double prev_high = High[1];
  276. double prev_low = Low[1];
  277. double prev_close = Close[1];
  278. double haC_prev = (prev_open + prev_high + prev_low + prev_close) / 4.0;
  279. double haC_prev2 = (Open[2] + High[2] + Low[2] + Close[2]) / 4.0;
  280. double haO_prev2 = (Open[3] + Close[3]) / 2.0;
  281. double haO_prev = (haO_prev2 + haC_prev2) / 2.0;
  282. double haC_cur = (cur_open + cur_high + cur_low + cur_close) / 4.0;
  283. double haO_cur = (haO_prev + haC_prev) / 2.0;
  284. g_ha30_open = haO_cur;
  285. g_ha30_close = haC_cur;
  286. g_ha30_high = cur_high;
  287. g_ha30_low = cur_low;
  288. g_ha30_bar = Time[0];
  289. }
  290.  
  291. bool Is30SecHABull(){ return (g_ha30_close > g_ha30_open); }
  292. bool Is30SecHABear(){ return (g_ha30_close < g_ha30_open); }
  293.  
  294. //+------------------------------------------------------------------+
  295. // BB PULLBACK DETECTION
  296. //+------------------------------------------------------------------+
  297. void DetectBBPullback(){
  298. if(!ENABLE_BB_PULLBACK || Bars < BB_PERIOD + 5) return;
  299. Calc30SecHA();
  300. double bbUpper1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 1);
  301. double bbLower1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 1);
  302. double bbUpper0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 0);
  303. double bbLower0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 0);
  304. double bbMid0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_MAIN, 0);
  305. if(bbUpper1 <= 0 || bbLower1 <= 0) return;
  306. bool ha30Bull = Is30SecHABull();
  307. bool ha30Bear = Is30SecHABear();
  308. double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  309. double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  310. double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  311. double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  312. bool adxBull = (plusDI > minusDI);
  313. bool adxBear = (minusDI > plusDI);
  314. bool adxActive = (adx >= 15);
  315. bool adxStrong = (adx >= 20);
  316. bool rsiOverbought = (rsi >= 60);
  317. bool rsiOversold = (rsi <= 40);
  318. bool rsiExtremeOB = (rsi >= 70);
  319. bool rsiExtremeOS = (rsi <= 30);
  320. int putConfirm = 0;
  321. if(ha30Bear) putConfirm++;
  322. if(adxBear) putConfirm++;
  323. if(rsiOverbought) putConfirm++;
  324. if(rsiExtremeOB) putConfirm++;
  325. int callConfirm = 0;
  326. if(ha30Bull) callConfirm++;
  327. if(adxBull) callConfirm++;
  328. if(rsiOversold) callConfirm++;
  329. if(rsiExtremeOS) callConfirm++;
  330. string adxStr = "ADX:"+DoubleToString(adx,0)+(adxStrong?"*":"");
  331. string rsiStr = "RSI:"+DoubleToString(rsi,0);
  332. string diStr = (adxBull?"DI^":adxBear?"DIv":"DI=");
  333. if(g_bbSignal != "--" && g_bbSignalTime > 0){
  334. int barsElapsed = (int)((TimeCurrent() - g_bbSignalTime) / (Period() * 60));
  335. if(barsElapsed > BB_SIGNAL_EXPIRE_BARS){
  336. g_bbSignal = "--"; g_bbColor = NEON_YELLOW;
  337. g_bbDetail = ""; g_bbTouchPrice = 0.0;
  338. }
  339. }
  340. bool touchedUpper = (High[1] >= bbUpper1 * 0.9998);
  341. bool touchedLower = (Low[1] <= bbLower1 * 1.0002);
  342. bool wickUpper = (High[1] > bbUpper1 && Close[1] < bbUpper1);
  343. bool wickLower = (Low[1] < bbLower1 && Close[1] > bbLower1);
  344. string newSignal = "--";
  345. double touchPriceNew = 0.0;
  346. string detailNew = "";
  347. color newColor = NEON_YELLOW;
  348. if((touchedUpper || wickUpper) && putConfirm >= 2){
  349. newSignal = "PUT";
  350. touchPriceNew = bbUpper1;
  351. string conf = (putConfirm>=4)?"STRONG":(putConfirm>=3)?"GOOD":"WEAK";
  352. detailNew = "BB UP|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr;
  353. newColor = (putConfirm >= 3) ? NEON_RED : NEON_ORANGE;
  354. }
  355. else if((touchedLower || wickLower) && callConfirm >= 2){
  356. newSignal = "CALL";
  357. touchPriceNew = bbLower1;
  358. string conf = (callConfirm>=4)?"STRONG":(callConfirm>=3)?"GOOD":"WEAK";
  359. detailNew = "BB LO|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr;
  360. newColor = (callConfirm >= 3) ? NEON_GREEN : NEON_CYAN;
  361. }
  362. if(newSignal != "--"){
  363. bool isNew = (newSignal != g_bbSignal || touchPriceNew != g_bbTouchPrice);
  364. if(isNew){
  365. g_bbSignal = newSignal;
  366. g_bbTouchPrice = touchPriceNew;
  367. g_bbSignalTime = TimeCurrent();
  368. g_bbDetail = detailNew;
  369. g_bbColor = newColor;
  370. AddBBLine(touchPriceNew, newSignal);
  371. Print("BB PULLBACK: ",newSignal," | ",detailNew," Conf:",(newSignal=="PUT"?putConfirm:callConfirm),"/4");
  372. }
  373. } else if(g_bbSignal == "--"){
  374. g_bbColor = NEON_YELLOW;
  375. }
  376. DrawBBLines(bbUpper0, bbLower0, bbMid0);
  377. }
  378.  
  379. //+------------------------------------------------------------------+
  380. // BB LINES DRAW ON CHART
  381. //+------------------------------------------------------------------+
  382. void DrawBBLines(double upper, double lower, double mid){
  383. if(!ENABLE_BB_PULLBACK) return;
  384. string nmU = PFX+"BB_UPPER";
  385. SafeDel(nmU);
  386. if(upper > 0){
  387. ObjectCreate(0, nmU, OBJ_HLINE, 0, 0, upper);
  388. ObjectSetInteger(0, nmU, OBJPROP_COLOR, BB_GREY);
  389. ObjectSetInteger(0, nmU, OBJPROP_WIDTH, 1);
  390. ObjectSetInteger(0, nmU, OBJPROP_STYLE, STYLE_DASH);
  391. ObjectSetInteger(0, nmU, OBJPROP_BACK, false);
  392. }
  393. string nmL = PFX+"BB_LOWER";
  394. SafeDel(nmL);
  395. if(lower > 0){
  396. ObjectCreate(0, nmL, OBJ_HLINE, 0, 0, lower);
  397. ObjectSetInteger(0, nmL, OBJPROP_COLOR, BB_GREY);
  398. ObjectSetInteger(0, nmL, OBJPROP_WIDTH, 1);
  399. ObjectSetInteger(0, nmL, OBJPROP_STYLE, STYLE_DASH);
  400. ObjectSetInteger(0, nmL, OBJPROP_BACK, false);
  401. }
  402. string nmM = PFX+"BB_MID";
  403. SafeDel(nmM);
  404. if(mid > 0){
  405. ObjectCreate(0, nmM, OBJ_HLINE, 0, 0, mid);
  406. ObjectSetInteger(0, nmM, OBJPROP_COLOR, C'100,100,110');
  407. ObjectSetInteger(0, nmM, OBJPROP_WIDTH, 1);
  408. ObjectSetInteger(0, nmM, OBJPROP_STYLE, STYLE_DOT);
  409. ObjectSetInteger(0, nmM, OBJPROP_BACK, false);
  410. }
  411. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS);
  412. if(dg <= 0) dg = 5;
  413. string lblU = PFX+"BB_U_LBL";
  414. SafeDel(lblU);
  415. if(upper > 0 && Bars > 2){
  416. ObjectCreate(0, lblU, OBJ_TEXT, 0, Time[2], upper);
  417. ObjectSetText(lblU, "BB("+IntegerToString(BB_PERIOD)+")", 8, "Arial", BB_GREY);
  418. ObjectSetInteger(0, lblU, OBJPROP_BACK, false);
  419. }
  420. }
  421.  
  422. void AddBBLine(double price, string sigType){
  423. if(price <= 0) return;
  424. for(int i = 0; i < MAX_BB_LINES; i++){
  425. SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i));
  426. SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i));
  427. }
  428. g_bbLineCount = 0;
  429. g_bbLinePrice[0] = price;
  430. g_bbLineExpire[0] = TimeCurrent() + 60 * BB_SIGNAL_EXPIRE_BARS;
  431. g_bbLineType[0] = sigType;
  432. g_bbLineCount = 1;
  433. DrawAllBBTouchLines();
  434. }
  435.  
  436. void DrawAllBBTouchLines(){
  437. for(int i = 0; i < MAX_BB_LINES; i++){
  438. SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i));
  439. SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i));
  440. }
  441. if(g_bbLineCount > 0 && TimeCurrent() > g_bbLineExpire[0]){
  442. g_bbLineCount = 0;
  443. return;
  444. }
  445. if(g_bbLineCount <= 0) return;
  446. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS);
  447. if(dg <= 0) dg = 5;
  448. string nm = PFX+"BB_TOUCH_0";
  449. string lbl = PFX+"BB_TOUCH_LBL_0";
  450. ObjectCreate(0, nm, OBJ_HLINE, 0, 0, g_bbLinePrice[0]);
  451. ObjectSetInteger(0, nm, OBJPROP_COLOR, BB_GREY);
  452. ObjectSetInteger(0, nm, OBJPROP_WIDTH, 2);
  453. ObjectSetInteger(0, nm, OBJPROP_STYLE, STYLE_SOLID);
  454. ObjectSetInteger(0, nm, OBJPROP_BACK, false);
  455. if(Bars > 3){
  456. string txt = (g_bbLineType[0]=="CALL") ? "BB^ CALL" : "BBv PUT";
  457. color lc = (g_bbLineType[0]=="CALL") ? NEON_GREEN : NEON_RED;
  458. ObjectCreate(0, lbl, OBJ_TEXT, 0, Time[3], g_bbLinePrice[0]);
  459. ObjectSetText(lbl, txt, 8, "Arial Bold", lc);
  460. ObjectSetInteger(0, lbl, OBJPROP_BACK, false);
  461. }
  462. }
  463.  
  464. // --- LEARNING ENGINE FUNCTIONS ---
  465. void LoadBrainMemory(){
  466. if(!ENABLE_LEARNING) return;
  467. int h=FileOpen(MEMORY_FILE_NAME,FILE_READ|FILE_CSV|FILE_SHARE_READ);
  468. if(h!=INVALID_HANDLE){
  469. if(FileSize(h)>10){
  470. string line=FileReadString(h);
  471. string parts[];
  472. int cnt=StringSplit(line,',',parts);
  473. if(cnt>=7){
  474. g_totalTrades=(int)StringToInteger(parts[0]);
  475. g_callTrades =(int)StringToInteger(parts[1]);
  476. g_putTrades =(int)StringToInteger(parts[2]);
  477. g_callWins =(int)StringToInteger(parts[3]);
  478. g_putWins =(int)StringToInteger(parts[4]);
  479. g_callWeight =StringToDouble(parts[5]);
  480. g_putWeight =StringToDouble(parts[6]);
  481. if(g_callWeight<0.2||g_callWeight>1.8) g_callWeight=1.0;
  482. if(g_putWeight <0.2||g_putWeight >1.8) g_putWeight =1.0;
  483. Print("NCP Brain loaded: ",g_totalTrades," trades | CW:",DoubleToString(g_callWeight,3)," PW:",DoubleToString(g_putWeight,3));
  484. }
  485. }
  486. FileClose(h);
  487. }
  488. }
  489. void SaveBrainMemory(){
  490. if(!ENABLE_LEARNING) return;
  491. int h=FileOpen(MEMORY_FILE_NAME,FILE_WRITE|FILE_CSV|FILE_SHARE_WRITE);
  492. if(h!=INVALID_HANDLE){
  493. string line=IntegerToString(g_totalTrades)+","+IntegerToString(g_callTrades)+","+IntegerToString(g_putTrades)+","+IntegerToString(g_callWins)+","+IntegerToString(g_putWins)+","+DoubleToString(g_callWeight,6)+","+DoubleToString(g_putWeight,6);
  494. FileWrite(h,line);
  495. FileClose(h);
  496. }
  497. }
  498. void UpdateBrain(string sig,bool win){
  499. if(!ENABLE_LEARNING) return;
  500. g_totalTrades++;
  501. if(sig=="CALL"){g_callTrades++;if(win)g_callWins++;}
  502. else if(sig=="PUT"){g_putTrades++;if(win)g_putWins++;}
  503. if(g_totalTrades < MIN_TRADES_TO_LEARN){ SaveBrainMemory(); return; }
  504. double adj=LEARNING_STEP;
  505. if(sig=="CALL"){
  506. double wr=(g_callTrades>0)?(double)g_callWins/g_callTrades:0.5;
  507. double adaptive=adj*(wr-0.5)*2.0;
  508. if(win) g_callWeight=MathMin(1.8,g_callWeight+adj+adaptive);
  509. else g_callWeight=MathMax(0.3,g_callWeight-adj*1.5+adaptive);
  510. if(g_callTrades<MIN_TRADES_TO_LEARN+5) g_callWeight=MathMax(0.6,g_callWeight);
  511. } else if(sig=="PUT"){
  512. double wr=(g_putTrades>0)?(double)g_putWins/g_putTrades:0.5;
  513. double adaptive=adj*(wr-0.5)*2.0;
  514. if(win) g_putWeight=MathMin(1.8,g_putWeight+adj+adaptive);
  515. else g_putWeight=MathMax(0.3,g_putWeight-adj*1.5+adaptive);
  516. if(g_putTrades<MIN_TRADES_TO_LEARN+5) g_putWeight=MathMax(0.6,g_putWeight);
  517. }
  518. SaveBrainMemory();
  519. }
  520. void CheckPreviousResult(){
  521. if(g_ncpSignalProcessed||g_ncpLastSignalType==""||g_ncpLastSignalTime==0) return;
  522. if(Time[0]==g_ncpLastSignalTime) return;
  523. double sigOpen =iOpen(NULL,PERIOD_M1,1);
  524. double sigClose=iClose(NULL,PERIOD_M1,1);
  525. bool win=false;
  526. if(g_ncpLastSignalType=="CALL") win=(sigClose>sigOpen);
  527. else if(g_ncpLastSignalType=="PUT") win=(sigClose<sigOpen);
  528. g_ncpSignalProcessed=true;
  529. UpdateBrain(g_ncpLastSignalType,win);
  530. Print("NCP Result: ",g_ncpLastSignalType," ",win?"WIN":"LOSS"," | Trades:",g_totalTrades," | CW:",DoubleToString(g_callWeight,3)," PW:",DoubleToString(g_putWeight,3));
  531. }
  532.  
  533. // --- BROKER TRAP CALCULATOR ---
  534. double CalculateBrokerTrap(double callBias,double putBias){
  535. if(!ENABLE_TRAP_DETECTION||Bars<20) return 0;
  536. double trapScore=0;
  537. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  538. double pip=jpy?0.01:0.0001;
  539. for(int i=1;i<=15&&i<Bars-1;i++){
  540. bool bullEngulf=(Close[i]>Open[i])&&(Close[i-1]<Open[i-1])&&(Close[i]>=Open[i-1])&&(Open[i]<=Close[i-1]);
  541. bool bearEngulf=(Close[i]<Open[i])&&(Close[i-1]>Open[i-1])&&(Close[i]<=Open[i-1])&&(Open[i]>=Close[i-1]);
  542. if(i>=2){
  543. bool mornStar=(Close[i-2]<Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])<pip*3)&&(Close[i]>Open[i]);
  544. bool eveStar =(Close[i-2]>Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])<pip*3)&&(Close[i]<Open[i]);
  545. if(i>=3){
  546. if(bullEngulf&&Close[i-3]<Close[i-2]) trapScore+=3.5;
  547. if(bearEngulf&&Close[i-3]>Close[i-2]) trapScore+=3.5;
  548. if(mornStar&&Close[i-3]<Close[i-2]) trapScore+=3.0;
  549. if(eveStar&&Close[i-3]>Close[i-2]) trapScore+=3.0;
  550. }
  551. }
  552. double rng=High[i]-Low[i];
  553. if(rng<=0) continue;
  554. double uw=(High[i]-MathMax(Open[i],Close[i]))/rng;
  555. double lw=(MathMin(Open[i],Close[i])-Low[i])/rng;
  556. if(uw>0.55&&Close[i]<Open[i]) trapScore+=2.0;
  557. if(lw>0.55&&Close[i]>Open[i]) trapScore+=2.0;
  558. }
  559. double rng0=High[0]-Low[0];
  560. if(rng0>0){
  561. double uw0=(High[0]-MathMax(Open[0],Close[0]))/rng0;
  562. double lw0=(MathMin(Open[0],Close[0])-Low[0])/rng0;
  563. if(uw0>0.65&&Close[0]<Open[0]) trapScore+=4.0;
  564. if(lw0>0.65&&Close[0]>Open[0]) trapScore+=4.0;
  565. if(Close[0]>Open[0]&&Close[1]<Open[1]){
  566. if(Close[0]>Open[1]&&Open[0]<Close[1]) trapScore+=3.0;
  567. }
  568. if(Close[0]<Open[0]&&Close[1]>Open[1]){
  569. if(Close[0]<Open[1]&&Open[0]>Close[1]) trapScore+=3.0;
  570. }
  571. }
  572. double biasStr=MathMax(callBias,putBias)-50;
  573. double biasMul=1.0+biasStr/150.0;
  574. if(biasMul>1.5) biasMul=1.5;
  575. if(biasMul<0.5) biasMul=0.5;
  576. trapScore*=biasMul;
  577. return MathMin(100,trapScore);
  578. }
  579.  
  580. //+------------------------------------------------------------------+
  581. //| NCP v4.0 - OTC Broker Trap Killer (FIXED) |
  582. //+------------------------------------------------------------------+
  583. void CalculateMTG(){
  584. if(!ENABLE_MTG || Bars < 50){
  585. g_mtgState = "OFF";
  586. g_mtgReason = "";
  587. g_mtgClr = CGR;
  588. return;
  589. }
  590.  
  591. CheckPreviousResult();
  592.  
  593. bool jpy = (StringFind(Symbol(),"JPY")>=0);
  594. double pip = jpy ? 0.01 : 0.0001;
  595.  
  596. int sec = (int)(TimeCurrent() - Time[0]);
  597. if(sec < NCP_OpenNoiseSeconds){
  598. g_mtgState = "...";
  599. g_mtgReason = "Bar open";
  600. g_mtgClr = CGR;
  601. g_mtgHype = 50; g_mtgBetrayal = 50;
  602. return;
  603. }
  604. if(sec >= NCP_KillZoneSeconds){
  605. g_mtgState = "END";
  606. g_mtgReason = "Late";
  607. g_mtgClr = NEON_ORANGE;
  608. g_mtgHype = 50; g_mtgBetrayal = 50;
  609. return;
  610. }
  611.  
  612. double spPips = MarketInfo(Symbol(),MODE_SPREAD) * Point / pip;
  613. if(spPips > NCP_MaxSpreadPips){
  614. g_mtgState = "SPREAD";
  615. g_mtgReason = DoubleToString(spPips,1) + "p";
  616. g_mtgClr = NEON_ORANGE;
  617. g_mtgHype = 50; g_mtgBetrayal = 50;
  618. return;
  619. }
  620.  
  621. double atr = iATR(Symbol(),PERIOD_M1,NCP_ATRPeriod,1);
  622. if(atr <= 0) atr = Point * 10;
  623. double atrPips = atr / pip;
  624. if(atrPips < NCP_MinATRPips){
  625. g_mtgState = "FLAT";
  626. g_mtgReason = "Low ATR";
  627. g_mtgClr = CGR;
  628. g_mtgHype = 50; g_mtgBetrayal = 50;
  629. return;
  630. }
  631.  
  632. // ========== ORIGINAL SCORING CODE (cS, pS) ==========
  633. // Aapka purana scoring logic yahan aayega.
  634. // Main dummy example de raha hoon - aap ise apne original scoring se replace karna.
  635.  
  636. double cS = 50.0, pS = 50.0;
  637. // TODO: Paste your original cS/pS calculation here (EMA, RSI, volume, etc.)
  638.  
  639. // ========== NCP v4.0 SCALING ==========
  640. double adx_value = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  641. if(adx_value <= 0) adx_value = 15.0;
  642. double adx_strength = MathMax(adx_value, 15.0);
  643.  
  644. double max_conf;
  645. if(adx_strength < 20) max_conf = 45.0;
  646. else if(adx_strength < 30) max_conf = 65.0;
  647. else max_conf = 85.0;
  648.  
  649. double total = cS + pS;
  650. double call_percent, put_percent;
  651. if(total > 0.01){
  652. call_percent = (cS / total) * max_conf;
  653. put_percent = (pS / total) * max_conf;
  654. } else {
  655. call_percent = 35.0;
  656. put_percent = 35.0;
  657. }
  658.  
  659. double edge = MathAbs(call_percent - put_percent);
  660. double final_ncp;
  661. string signal_state;
  662.  
  663. if(edge >= 25.0 && adx_strength >= 22){
  664. if(call_percent > put_percent){
  665. final_ncp = call_percent;
  666. signal_state = "CALL_TRAP";
  667. } else {
  668. final_ncp = put_percent;
  669. signal_state = "PUT_TRAP";
  670. }
  671. } else if(edge >= 18.0 && adx_strength >= 20){
  672. final_ncp = MathMax(call_percent, put_percent) * 0.85;
  673. signal_state = "WEAK_TRAP";
  674. } else {
  675. final_ncp = MathMax(call_percent, put_percent) * 0.6;
  676. signal_state = "NEUTRAL";
  677. }
  678.  
  679. if(call_percent > put_percent){
  680. g_mtgState = (signal_state == "NEUTRAL") ? "NEUTRAL" : "CALL";
  681. g_mtgHype = final_ncp;
  682. g_mtgBetrayal = 100 - final_ncp;
  683. } else {
  684. g_mtgState = (signal_state == "NEUTRAL") ? "NEUTRAL" : "PUT";
  685. g_mtgBetrayal = final_ncp;
  686. g_mtgHype = 100 - final_ncp;
  687. }
  688.  
  689. g_mtgReason = "ADX:" + DoubleToString(adx_strength,0) + " Edge:" + DoubleToString(edge,0);
  690. g_mtgAction = g_mtgState + " " + DoubleToString(final_ncp,1) + "%";
  691.  
  692. if(g_mtgState == "CALL") g_mtgClr = (final_ncp>=70)?NEON_GREEN:NEON_LIME;
  693. else if(g_mtgState == "PUT") g_mtgClr = (final_ncp>=70)?NEON_RED:C'255,80,80';
  694. else g_mtgClr = NEON_YELLOW;
  695.  
  696. if(Time[0] != g_ncpLastSignalTime){
  697. g_ncpLastSignalTime = Time[0];
  698. g_ncpSignalProcessed = false;
  699. if(g_mtgState == "CALL" || g_mtgState == "PUT"){
  700. g_ncpLastSignalType = g_mtgState;
  701. }
  702. }
  703. }
  704.  
  705. //+------------------------------------------------------------------+
  706. // HA CANDLE CALCULATION (M1 + M5)
  707. //+------------------------------------------------------------------+
  708. void CalcHA(){
  709. if(Bars<10) return;
  710. ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true); ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true);
  711. static double haO1[500],haC1[500]; static datetime lb1=0;
  712. ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true);
  713. datetime c1=iTime(NULL,PERIOD_M1,0);
  714. if(c1!=lb1){ lb1=c1; int lim=MathMin(iBars(NULL,PERIOD_M1),500);
  715. for(int i=lim-1;i>=0;i--){ haC1[i]=(Open[i]+High[i]+Low[i]+Close[i])/4.0;
  716. if(i==lim-1) haO1[i]=(Open[i]+Close[i])/2.0; else haO1[i]=(haO1[i+1]+haC1[i+1])/2.0; }}
  717. double d1=MathAbs(haC1[1]-haO1[1]),r1=High[1]-Low[1];
  718. bool dz=(r1>0&&d1<r1*0.1),b1=(!dz&&haC1[1]>haO1[1]),be1=(!dz&&haC1[1]<haO1[1]);
  719. if(b1){g_haM1="HA BULLISH 1";g_haM1Color=clrLime;}
  720. else if(be1){g_haM1="HA BEARISH 1";g_haM1Color=clrRed;}
  721. else{g_haM1="HA DOJI 1";g_haM1Color=clrYellow;}
  722. if(iBars(NULL,PERIOD_M5)>=10){
  723. static double haO5[200],haC5[200]; static datetime lb5=0;
  724. ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true);
  725. datetime c5=iTime(NULL,PERIOD_M5,0);
  726. if(c5!=lb5){ lb5=c5; int lim=MathMin(iBars(NULL,PERIOD_M5),200);
  727. 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);
  728. 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; }}
  729. double d5=MathAbs(haC5[1]-haO5[1]),r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1);
  730. bool dz5=(r5>0&&d5<r5*0.1),b5=(!dz5&&haC5[1]>haO5[1]),be5=(!dz5&&haC5[1]<haO5[1]);
  731. if(b5){g_haM5="HA BULLISH 5";g_haM5Color=clrLime;}
  732. else if(be5){g_haM5="HA BEARISH 5";g_haM5Color=clrRed;}
  733. else{g_haM5="HA DOJI 5";g_haM5Color=clrYellow;}
  734. if(b1&&b5)g_haBoth="BOTH BULL"; else if(be1&&be5)g_haBoth="BOTH BEAR"; else g_haBoth="MIXED";
  735. }else{g_haM5="5 --";g_haM5Color=clrGray;g_haBoth="HA --";}
  736. }
  737.  
  738. //+------------------------------------------------------------------+
  739. // HELPER FUNCTIONS
  740. //+------------------------------------------------------------------+
  741. bool IsLineNearby(double price,double pipTol=3.0){
  742. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip;
  743. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i);
  744. if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE){
  745. double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)<tol) return true; }}
  746. return false;
  747. }
  748. string GetCurrentSession(color &sC){
  749. int h=TimeHour(TimeGMT());
  750. if(h>=12&&h<16){sC=NEON_GOLD;return "LON+NY";}
  751. if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";}
  752. if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";}
  753. if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";}
  754. if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";}
  755. sC=C'100,100,120'; return "SYDNEY";
  756. }
  757. bool IsSessionActive(){int h=TimeHour(TimeGMT());return(h>=7&&h<=21);}
  758. 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);}
  759. bool CheckMTFConfirmation(){
  760. if(!MTF_CONFIRM) return true;
  761. bool m1Bull=(Close[1]>Open[1]);
  762. bool m5Bull=false,m15Bull=false;
  763. if(iBars(NULL,PERIOD_M5)>=3) m5Bull=(iClose(NULL,PERIOD_M5,1)>iOpen(NULL,PERIOD_M5,1));
  764. if(iBars(NULL,PERIOD_M15)>=3) m15Bull=(iClose(NULL,PERIOD_M15,1)>iOpen(NULL,PERIOD_M15,1));
  765. int bullCount=0,bearCount=0;
  766. if(m1Bull) bullCount++; else bearCount++;
  767. if(m5Bull) bullCount++; else bearCount++;
  768. if(m15Bull) bullCount++; else bearCount++;
  769. g_mtfConfirmed=(bullCount>=2 || bearCount>=2);
  770. return g_mtfConfirmed;
  771. }
  772. double Tanh(double x){double e=MathExp(2.0*x);return(e-1.0)/(e+1.0);}
  773. double CalcFractalDimension(int period){
  774. if(period<2)return 1.5;double sum=0.0;
  775. for(int i=1;i<period;i++){double r1=High[i]-Low[i],r2=High[i+1]-Low[i+1];if(r1<=0.0||r2<=0.0)continue;sum+=MathLog(r1/r2+0.001)*MathLog((double)i/(double)period);}
  776. double result=2.0-sum/period;if(result<1.0)result=1.0;if(result>2.0)result=2.0;return result;
  777. }
  778. double DetectBrokerTrap(int lookback){
  779. int bull=0,bear=0;for(int i=1;i<=lookback;i++){if(Close[i]>Open[i])bull++;else if(Close[i]<Open[i])bear++;}
  780. double crowd=(bull>bear)?(double)bull/lookback:(double)bear/lookback;
  781. double priceMove=MathAbs(Close[1]-Close[lookback])/(Close[lookback]+0.00001);
  782. if(crowd>0.7&&priceMove<0.002)return 0.9;if(crowd>0.6&&priceMove>0.001)return 0.5;return 0.3;
  783. }
  784. double QuickMedian(double &arr[],int size){
  785. double sorted[20];for(int i=0;i<size;i++)sorted[i]=arr[i];
  786. for(int i=0;i<size-1;i++)for(int j=i+1;j<size;j++)if(sorted[i]>sorted[j]){double tmp=sorted[i];sorted[i]=sorted[j];sorted[j]=tmp;}
  787. return(sorted[size/2]+sorted[(size-1)/2])/2.0;
  788. }
  789. double CalcAdvancedTFA(string &detail){
  790. if(Bars<30){detail="Bars low";return 3.0;}
  791. double score=0;string p="";
  792. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);
  793. double adxSc=(adx>=25)?1.0:(adx>=20)?0.6:(adx>=15)?0.3:0.1;
  794. score+=adxSc;p+="ADX:"+((adxSc>=0.6)?"+":"-")+" ";
  795. double v1=iVolume(NULL,PERIOD_M1,1),vA=0;
  796. for(int i=2;i<=6;i++)vA+=iVolume(NULL,PERIOD_M1,i);
  797. vA=(vA>0)?vA/5.0:1;double vr=v1/vA;
  798. double volSc=(vr>=2.0)?1.0:(vr>=1.5)?0.7:(vr>=1.1)?0.4:0.1;
  799. score+=volSc;p+="VOL:"+((volSc>=0.5)?"+":"-")+" ";
  800. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  801. double rsiSc=0.2;if(rsi>=60||rsi<=40)rsiSc=1.0;else if(rsi>=55||rsi<=45)rsiSc=0.6;
  802. score+=rsiSc;p+="RSI:"+((rsiSc>=0.6)?"+":"-")+" ";
  803. double atr=iATR(NULL,PERIOD_M1,14,1),cs=High[1]-Low[1],atrSc=0.2;
  804. if(atr>0){double r=cs/atr;if(r>=0.7&&r<=1.5)atrSc=1.0;else if(r>=0.5&&r<=2.0)atrSc=0.6;else atrSc=0.3;}
  805. score+=atrSc;p+="ATR:"+((atrSc>=0.6)?"+":"-")+" ";
  806. double body=MathAbs(Close[1]-Open[1]),range=High[1]-Low[1],bdySc=0.2;
  807. if(range>0){double br=body/range;if(br>=0.6)bdySc=1.0;else if(br>=0.4)bdySc=0.6;else if(br>=0.2)bdySc=0.3;}
  808. score+=bdySc;p+="BODY:"+((bdySc>=0.6)?"+":"-")+" ";
  809. double sesSc=IsSessionActive()?1.0:0.4;
  810. score+=sesSc;p+="SES:"+((sesSc>=0.7)?"+":"-");
  811. double finalScore=MathMin(6.0,score);int rounded=(int)MathRound(finalScore);
  812. string dir="MIX";
  813. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")dir="STRONG UP";
  814. else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")dir="STRONG DOWN";
  815. else if(g_haM1=="HA BULLISH 1")dir="UP";
  816. else if(g_haM1=="HA BEARISH 1")dir="DOWN";
  817. detail=p+" | "+IntegerToString(rounded)+"/6 "+dir;
  818. g_tfa_detail=detail;return finalScore;
  819. }
  820. double CalcAdvancedMicroAI(){
  821. if(Bars<20) return 50.0;
  822. double score=50.0;
  823. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  824. double pip=jpy?0.01:0.0001;
  825.  
  826. // 1. Weighted wick analysis — recent bars zyada important
  827. for(int i=1;i<=5;i++){
  828. double r=High[i]-Low[i]; if(r<=0) continue;
  829. double uw=(High[i]-MathMax(Open[i],Close[i]))/r;
  830. double lw=(MathMin(Open[i],Close[i])-Low[i])/r;
  831. double w=(6.0-i)/5.0;
  832. // Upper wick = price rejected from above = bearish signal
  833. if(uw>0.65) score-=w*18;
  834. else if(uw>0.50) score-=w*10;
  835. // Lower wick = price rejected from below = bullish signal
  836. if(lw>0.65) score+=w*18;
  837. else if(lw>0.50) score+=w*10;
  838. }
  839.  
  840. // 2. Candle body position in range (last 5 bars)
  841. double pos5=0;
  842. for(int i=1;i<=5;i++){
  843. double r=High[i]-Low[i]; if(r<=0) continue;
  844. pos5+=(Close[i]-Low[i])/r;
  845. }
  846. score+=(pos5/5.0-0.5)*25.0;
  847.  
  848. // 3. Green/Red candle count (last 8 bars, weighted)
  849. double gc=0,rc=0;
  850. for(int i=1;i<=8;i++){
  851. double w=(9.0-i)/8.0;
  852. if(Close[i]>Open[i]) gc+=w;
  853. else if(Close[i]<Open[i]) rc+=w;
  854. }
  855. score+=(gc-rc)*4.0;
  856.  
  857. // 4. Volume confirmation
  858. double vl1=(double)iVolume(NULL,PERIOD_M1,1),vA=0;
  859. for(int i=2;i<=6;i++) vA+=iVolume(NULL,PERIOD_M1,i);
  860. vA/=5.0;
  861. if(vA>0){
  862. double vr=vl1/vA;
  863. if(vr>2.0&&Close[1]>Open[1]) score+=12;
  864. else if(vr>2.0&&Close[1]<Open[1]) score-=12;
  865. else if(vr>1.5&&Close[1]>Open[1]) score+=7;
  866. else if(vr>1.5&&Close[1]<Open[1]) score-=7;
  867. }
  868.  
  869. // 5. RSI momentum
  870. double r1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  871. double r5=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  872. if(r1<30) score+=15; // Oversold = bullish
  873. else if(r1<40) score+=7;
  874. if(r1>70) score-=15; // Overbought = bearish
  875. else if(r1>60) score-=7;
  876. // RSI divergence hint
  877. if(r1>r5&&Close[1]<Close[5]) score+=8; // Hidden bullish div
  878. if(r1<r5&&Close[1]>Close[5]) score-=8; // Hidden bearish div
  879.  
  880. // 6. Near S/R zone bonus
  881. if(g_nearest_res>0){
  882. double distR=(g_nearest_res-Close[0])/pip;
  883. if(distR<5) score-=12; // Near resistance = bearish
  884. else if(distR<10) score-=6;
  885. }
  886. if(g_nearest_sup>0){
  887. double distS=(Close[0]-g_nearest_sup)/pip;
  888. if(distS<5) score+=12; // Near support = bullish
  889. else if(distS<10) score+=6;
  890. }
  891.  
  892. // 7. Momentum: last 2 candle direction agreement
  893. if(Close[0]>Open[0]&&Close[1]>Open[1]) score+=5;
  894. if(Close[0]<Open[0]&&Close[1]<Open[1]) score-=5;
  895.  
  896. return MathMax(5.0,MathMin(95.0,score));
  897. }
  898. double VolumeTrapScore();
  899. int CalcAdvancedMicroTrap(){
  900. if(Bars<20) return 0;
  901. int score=0;
  902. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  903. double pip=jpy?0.01:0.0001;
  904.  
  905. // 1. Wick trap on current + previous candle
  906. double r1=High[1]-Low[1];
  907. if(r1>0){
  908. double uw1=(High[1]-MathMax(Open[1],Close[1]))/r1;
  909. double lw1=(MathMin(Open[1],Close[1])-Low[1])/r1;
  910. if(uw1>0.65) score+=35; // Strong upper wick = trap
  911. else if(uw1>0.50) score+=18;
  912. if(lw1>0.65) score+=25; // Strong lower wick = trap
  913. else if(lw1>0.50) score+=12;
  914. }
  915. // Current live candle wick
  916. double r0=High[0]-Low[0];
  917. if(r0>0){
  918. double uw0=(High[0]-MathMax(Open[0],Close[0]))/r0;
  919. double lw0=(MathMin(Open[0],Close[0])-Low[0])/r0;
  920. if(uw0>0.60) score+=15;
  921. if(lw0>0.60) score+=10;
  922. }
  923.  
  924. // 2. Volume spike = broker manipulation likely
  925. double v1=(double)iVolume(NULL,PERIOD_M1,1);
  926. double v2=(double)iVolume(NULL,PERIOD_M1,2);
  927. double v3=(double)iVolume(NULL,PERIOD_M1,3);
  928. double vAvg=(v2+v3)/2.0;
  929. if(vAvg>0){
  930. double vr=v1/vAvg;
  931. if(vr>3.0) score+=30;
  932. else if(vr>2.0) score+=22;
  933. else if(vr>1.5) score+=12;
  934. }
  935.  
  936. // 3. RSI extreme zones
  937. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  938. if(rsi>82||rsi<18) score+=25;
  939. else if(rsi>75||rsi<25) score+=18;
  940. else if(rsi>70||rsi<30) score+=10;
  941.  
  942. // 4. Price at S/R = high trap probability
  943. if(g_nearest_res>0 && (High[1]>g_nearest_res && Close[1]<g_nearest_res)){
  944. score+=30; // Wick above resistance = bear trap
  945. }
  946. if(g_nearest_sup>0 && (Low[1]<g_nearest_sup && Close[1]>g_nearest_sup)){
  947. score+=30; // Wick below support = bull trap
  948. }
  949.  
  950. // 5. 3 same-direction candles = exhaustion trap
  951. bool aG=(Close[1]>Open[1] && Close[2]>Open[2] && Close[3]>Open[3]);
  952. bool aR=(Close[1]<Open[1] && Close[2]<Open[2] && Close[3]<Open[3]);
  953. if(aG||aR) score+=18;
  954. // 4+ same direction = extreme exhaustion
  955. if(Bars>=5){
  956. bool aG4=(aG && Close[4]>Open[4]);
  957. bool aR4=(aR && Close[4]<Open[4]);
  958. if(aG4||aR4) score+=10;
  959. }
  960.  
  961. // 6. Spread widening = broker activity
  962. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  963. if(sp>BROKER_SPREAD_THRESHOLD*2.0) score+=15;
  964. else if(sp>BROKER_SPREAD_THRESHOLD*1.5) score+=8;
  965.  
  966. // 7. Volume profile trap bonus
  967. score+=(int)VolumeTrapScore();
  968.  
  969. // 8. Near HRN level = strong trap zone
  970. if(g_hrn_price>0){
  971. double distH=MathAbs(Close[0]-g_hrn_price)/pip;
  972. if(distH<3) score+=20;
  973. else if(distH<7) score+=10;
  974. }
  975.  
  976. return MathMin(100,score);
  977. }
  978. double CalcAdvancedFractal(){
  979. if(Bars<15)return 0;double score=0;
  980. for(int i=2;i<=8&&i+2<Bars;i++){
  981. 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;}
  982. 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;}}
  983. 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++;}
  984. if(dj>=3)score+=25;
  985. 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;}
  986. return MathMin(100,score);
  987. }
  988. string CalcAdvancedMarketBias(color &bC,double brain,double rsc){
  989. if(Bars<30){bC=NEON_YELLOW;return "CALCULATING";}
  990. double score=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  991. double pc=Close[0]-Close[10];
  992. 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;
  993. double hh1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],hh2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  994. double ll1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],ll2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  995. 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;
  996. double ema20=0,ema20p=0;for(int i=0;i<20;i++)ema20+=Close[i];ema20/=20;
  997. for(int i=1;i<=20&&i<Bars;i++)ema20p+=Close[i];ema20p/=20;
  998. if(ema20>ema20p)score+=3;else if(ema20<ema20p)score-=3;
  999. double ema50=0;for(int i=0;i<50&&i<Bars;i++)ema50+=Close[i];ema50/=MathMin(50,Bars);
  1000. if(ema20>ema50)score+=3;else score-=3;
  1001. 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++;}
  1002. if(gC>=7)score+=3;else if(rC>=7)score-=3;else if(gC>=5)score+=1;else if(rC>=5)score-=1;
  1003. 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");
  1004. if(m1B&&m5B)score+=4;else if(m1Be&&m5Be)score-=4;else if(m1B)score+=2;else if(m1Be)score-=2;
  1005. 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);
  1006. if(adx>20){if(pDI>mDI+5)score+=4;else if(mDI>pDI+5)score-=4;}
  1007. if(brain>3)score-=2;else if(brain<-3)score+=2;
  1008. if(Close[1]>Open[1])score+=1;else if(Close[1]<Open[1])score-=1;
  1009. if(rsc>2)score+=1;else if(rsc<-2)score-=1;
  1010. if(score>=12){bC=NEON_GREEN;return "STRONG BULL";}if(score>=7){bC=NEON_GREEN;return "BULLISH";}if(score>=3){bC=NEON_CYAN;return "LIGHT BULL";}
  1011. if(score<=-12){bC=NEON_RED;return "STRONG BEAR";}if(score<=-7){bC=NEON_RED;return "BEARISH";}if(score<=-3){bC=NEON_ORANGE;return "LIGHT BEAR";}
  1012. bC=NEON_YELLOW;return "NEUTRAL";
  1013. }
  1014. void CalcAdvancedPrediction(double &gP,double &rP,string &reason,color &pC){
  1015. if(Bars<50){gP=50;rP=50;reason="Bars low";pC=NEON_YELLOW;return;}
  1016. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1017. double green=0,red=0;
  1018. double body1=MathAbs(Close[1]-Open[1]),range1=High[1]-Low[1];
  1019. if(range1>0){double uw=High[1]-MathMax(Open[1],Close[1]),lw=MathMin(Open[1],Close[1])-Low[1];
  1020. if(uw>range1*0.60&&Close[1]>Open[1])red+=22;else if(lw>range1*0.60&&Close[1]<Open[1])green+=22;
  1021. else if((uw+lw)/range1>0.55){if(uw>lw)red+=12;else green+=12;}}
  1022. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),cci=iCCI(NULL,PERIOD_M1,14,PRICE_TYPICAL,1),stochK=iStochastic(NULL,PERIOD_M1,5,3,3,MODE_SMA,0,MODE_MAIN,1);
  1023. int os=0,ob=0;
  1024. if(rsi<30)os++;else if(rsi>70)ob++;if(cci<-120)os++;else if(cci>120)ob++;if(stochK<20)os++;else if(stochK>80)ob++;
  1025. if(os>=3)green+=18;else if(os>=2)green+=12;else if(ob>=3)red+=18;else if(ob>=2)red+=12;
  1026. double rsiPrev=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  1027. double low1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],low2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  1028. double high1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],high2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  1029. if(low1<low2&&rsi>rsiPrev&&rsi<45)green+=15;if(high1>high2&&rsi<rsiPrev&&rsi>55)red+=15;
  1030. double v1=iVolume(NULL,PERIOD_M1,1),vAvg=0;for(int i=2;i<=10;i++)vAvg+=iVolume(NULL,PERIOD_M1,i);vAvg=(vAvg>0)?vAvg/9.0:1.0;
  1031. double vol_ratio=(vAvg>0)?v1/vAvg:1.0;
  1032. if(vol_ratio>2.0){if(Close[1]>Open[1])red+=20;else green+=20;}else if(vol_ratio>1.5){if(Close[1]>Open[1])red+=12;else green+=12;}else if(vol_ratio>1.2){if(Close[1]>Open[1])green+=5;else red+=5;}
  1033. double m1_haC1=(Open[1]+High[1]+Low[1]+Close[1])/4.0,m1_haC2=(Open[2]+High[2]+Low[2]+Close[2])/4.0;
  1034. double m1_haO2=(Open[3]+Close[3])/2.0,m1_haO1=(m1_haO2+m1_haC2)/2.0;
  1035. bool haBull1=(m1_haC1>m1_haO1);
  1036. double haStr1=MathAbs(m1_haC1-m1_haO1)/(High[1]-Low[1]+0.00001);
  1037. bool haBull5=false;double haStr5=0;
  1038. if(iBars(NULL,PERIOD_M5)>=5){
  1039. double o1=iOpen(NULL,PERIOD_M5,1),h1=iHigh(NULL,PERIOD_M5,1),l1=iLow(NULL,PERIOD_M5,1),c1=iClose(NULL,PERIOD_M5,1);
  1040. double o2=iOpen(NULL,PERIOD_M5,2),h2=iHigh(NULL,PERIOD_M5,2),l2=iLow(NULL,PERIOD_M5,2),c2=iClose(NULL,PERIOD_M5,2);
  1041. double o3=iOpen(NULL,PERIOD_M5,3),c3=iClose(NULL,PERIOD_M5,3);
  1042. double haC1_5=(o1+h1+l1+c1)/4.0,haC2_5=(o2+h2+l2+c2)/4.0,haO2_5=(o3+c3)/2.0,haO1_5=(haO2_5+haC2_5)/2.0;
  1043. haBull5=(haC1_5>haO1_5);haStr5=MathAbs(haC1_5-haO1_5)/(h1-l1+0.00001);}
  1044. if(haBull1&&haBull5)green+=15;else if(!haBull1&&!haBull5)red+=15;
  1045. else if(haBull1&&haStr1>0.5)green+=8;else if(!haBull1&&haStr1>0.5)red+=8;
  1046. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1),plusDI=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_PLUSDI,1),minusDI=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MINUSDI,1);
  1047. double diDiff=plusDI-minusDI;
  1048. if(adx>25){if(diDiff>8)green+=12;else if(diDiff>4)green+=8;else if(diDiff<-8)red+=12;else if(diDiff<-4)red+=8;}
  1049. else if(adx>15){if(plusDI>minusDI)green+=4;else red+=4;}
  1050. else{if(Close[1]>Open[1])red+=3;else green+=3;}
  1051. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,20,2)],res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,20,2)];
  1052. double dR=(res-Close[0])/pip,dS=(Close[0]-sup)/pip;
  1053. if(dR<8&&dR>=0)red+=12;else if(dR<15&&dR>=0)red+=6;
  1054. if(dS<8&&dS>=0)green+=12;else if(dS<15&&dS>=0)green+=6;
  1055. if(g_hrn_price>0){double dH=MathAbs(Close[0]-g_hrn_price)/pip;if(dH<5){if(Close[0]>g_hrn_price)red+=8;else green+=8;}}
  1056. double macdMain=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1),macdSig=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
  1057. double macdPrev=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,2),macdSigPrev=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
  1058. if(macdMain>macdSig&&macdPrev<=macdSigPrev)green+=10;else if(macdMain<macdSig&&macdPrev>=macdSigPrev)red+=10;
  1059. else if(macdMain>macdSig)green+=5;else if(macdMain<macdSig)red+=5;
  1060. if(g_otcCallPct>=75&&!haBull1)red+=15;else if(g_otcPutPct>=75&&haBull1)green+=15;
  1061. else if(g_otcCallPct>=65&&!haBull1)red+=8;else if(g_otcPutPct>=65&&haBull1)green+=8;
  1062. if(ENABLE_BB_PULLBACK&&g_bbSignal=="CALL")green+=12;
  1063. else if(ENABLE_BB_PULLBACK&&g_bbSignal=="PUT")red+=12;
  1064. double diff=MathMax(-100.0,MathMin(100.0,green-red));
  1065. gP=MathMax(8.0,MathMin(92.0,50.0+diff*0.65));rP=100.0-gP;
  1066. double dom=MathMax(gP,rP);
  1067. if(dom>=82){reason=(gP>rP)?"STRONG GREEN":"STRONG RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  1068. else if(dom>=72){reason=(gP>rP)?"GREEN":"RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  1069. else if(dom>=60){reason=(gP>rP)?"WEAK GREEN":"WEAK RED";pC=(gP>rP)?NEON_CYAN:NEON_ORANGE;}
  1070. else{reason="WAIT";pC=NEON_YELLOW;}
  1071. }
  1072. string DetectMyStrategy(){
  1073. int cc=g_otcCallPct,cp=g_otcPutPct,thr=STRATEGY_THRESHOLD;
  1074. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TRAP_ONLY"){
  1075. if(cc>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TRAP";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA RED";return "PUT";}
  1076. if(cp>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TRAP";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA GREEN";return "CALL";}}
  1077. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TREND_ONLY"){
  1078. if(cc>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TREND";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA GREEN";return "CALL";}
  1079. if(cp>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TREND";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA RED";return "PUT";}}
  1080. g_strategyType="NONE";g_strategyReason="Wait "+IntegerToString(thr)+"% + HA";return "WAIT";
  1081. }
  1082. void CalcOTCCrowd(){
  1083. int cS=0,pS=0;int weights[15];
  1084. for(int w=0;w<15;w++)weights[w]=15-w*2;
  1085. for(int w=0;w<15;w++)if(weights[w]<1)weights[w]=1;
  1086. for(int i=1;i<=15&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  1087. double uw=(High[i]-MathMax(Open[i],Close[i]))/rg,lw=(MathMin(Open[i],Close[i])-Low[i])/rg;int wgt=weights[i-1];
  1088. if(uw>0.70&&Close[i]<Open[i])cS+=4*wgt;if(lw>0.70&&Close[i]>Open[i])pS+=4*wgt;
  1089. if(uw>0.55&&Close[i]<Open[i])cS+=2*wgt;if(lw>0.55&&Close[i]>Open[i])pS+=2*wgt;
  1090. if(Close[i]>Open[i])cS+=1*wgt;else if(Close[i]<Open[i])pS+=1*wgt;}
  1091. int tot=cS+pS;if(tot==0){g_otcCallPct=50;g_otcPutPct=50;}
  1092. else{int rC=(int)(cS*100.0/tot),rP=100-rC;
  1093. if(rC>=rP){g_otcCallPct=MathMax(50,rC);g_otcPutPct=100-g_otcCallPct;}
  1094. else{g_otcPutPct=MathMax(50,rP);g_otcCallPct=100-g_otcPutPct;}}
  1095. }
  1096.  
  1097. // ============================================================
  1098. // BRAIN AI - FIXED VERSION
  1099. // ============================================================
  1100. double BrainSc(int &cp){
  1101. double s=0;
  1102. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1103. double pip=jpy?0.01:0.0001;
  1104. if(g_nearest_res > 0){
  1105. double dR = (g_nearest_res - Close[0]) / pip;
  1106. if(dR < 5) s -= 3;
  1107. else if(dR < 15) s -= 1;
  1108. }
  1109. if(g_nearest_sup > 0){
  1110. double dS = (Close[0] - g_nearest_sup) / pip;
  1111. if(dS < 5) s += 3;
  1112. else if(dS < 15) s += 1;
  1113. }
  1114. if(g_nearest_res > 0 && High[1] > g_nearest_res){
  1115. double bodyH = MathMax(Open[1], Close[1]);
  1116. if(bodyH > g_nearest_res + 2*pip) s -= 4;
  1117. else s += 2;
  1118. }
  1119. if(g_nearest_sup > 0 && Low[1] < g_nearest_sup){
  1120. double bodyL = MathMin(Open[1], Close[1]);
  1121. if(bodyL < g_nearest_sup - 2*pip) s += 4;
  1122. else s -= 2;
  1123. }
  1124. double atr=iATR(NULL,PERIOD_M1,14,1);
  1125. if(atr > 0){
  1126. double cn=(High[1]-Low[1])/atr;
  1127. double v1=(double)iVolume(NULL,PERIOD_M1,1);
  1128. double va=0;
  1129. for(int i=2;i<=10;i++) va+=iVolume(NULL,PERIOD_M1,i);
  1130. va/=9.0;
  1131. double vr=(va>0)?v1/va:1.0;
  1132. if(cn>1.3 && vr>1.8){
  1133. if(Close[1]>Open[1]) s -= 2;
  1134. else s += 2;
  1135. }
  1136. }
  1137. int c=0;
  1138. for(int i=1;i<=30;i++) if(Close[i]>Open[i]) c++;
  1139. cp=(int)(c*100.0/30.0);
  1140. if(cp>=80) s -= 4;
  1141. else if(cp>=75) s -= 2;
  1142. else if(cp<=20) s += 4;
  1143. else if(cp<=25) s += 2;
  1144. int dj=0;
  1145. double wickBull=0, wickBear=0;
  1146. for(int i=1;i<=8;i++){
  1147. double bd=MathAbs(Close[i]-Open[i]);
  1148. double rg=High[i]-Low[i];
  1149. if(rg<=0) continue;
  1150. if(bd<rg*0.2) dj++;
  1151. double uw=High[i]-MathMax(Open[i],Close[i]);
  1152. double lw=MathMin(Open[i],Close[i])-Low[i];
  1153. double w = (9.0-i)/8.0;
  1154. if(uw>bd*2) wickBear += w;
  1155. if(lw>bd*2) wickBull += w;
  1156. }
  1157. if(wickBull > wickBear + 1.0) s += 3;
  1158. else if(wickBear > wickBull + 1.0) s -= 3;
  1159. if(dj>=4) s *= 0.8;
  1160. int bu=0, be=0;
  1161. for(int i=1;i<=8;i++){
  1162. if(Close[i]>Open[i]){bu++;be=0;}
  1163. else if(Close[i]<Open[i]){be++;bu=0;}
  1164. else {bu=0;be=0;}
  1165. if(bu>=6) s -= 3;
  1166. if(be>=6) s += 3;
  1167. }
  1168. double ema10=0;
  1169. for(int i=0;i<10&&i<Bars;i++) ema10+=Close[i];
  1170. ema10/=10.0;
  1171. double ema20=0;
  1172. for(int i=0;i<20&&i<Bars;i++) ema20+=Close[i];
  1173. ema20/=20.0;
  1174. bool strongTrendUp = (ema10 > ema20 && ema10 - ema20 > 3*pip);
  1175. bool strongTrendDn = (ema10 < ema20 && ema20 - ema10 > 3*pip);
  1176. if(strongTrendUp && s < -2) s *= 0.7;
  1177. if(strongTrendDn && s > 2) s *= 0.7;
  1178. int h=TimeHour(TimeCurrent());
  1179. double mul=1.0;
  1180. if((h>=8&&h<=11)||(h>=14&&h<=17)) mul=1.1;
  1181. if(h>=3&&h<=7) mul=0.9;
  1182. return s*mul;
  1183. }
  1184.  
  1185. // ============================================================
  1186. // S/R LEVELS - STABLE VERSION
  1187. // ============================================================
  1188. void AddStableRes(double lv){
  1189. if(lv <= 0) return;
  1190. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1191. double pip=jpy?0.01:0.0001;
  1192. double tol = 5.0 * pip;
  1193. for(int i=0; i<g_stableResCount; i++){
  1194. if(MathAbs(g_stableRes[i] - lv) < tol) return;
  1195. }
  1196. if(g_stableResCount < 10){
  1197. g_stableRes[g_stableResCount] = lv;
  1198. g_stableResCount++;
  1199. } else {
  1200. for(int i=0; i<9; i++) g_stableRes[i] = g_stableRes[i+1];
  1201. g_stableRes[9] = lv;
  1202. }
  1203. }
  1204.  
  1205. void AddStableSup(double lv){
  1206. if(lv <= 0) return;
  1207. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1208. double pip=jpy?0.01:0.0001;
  1209. double tol = 5.0 * pip;
  1210. for(int i=0; i<g_stableSupCount; i++){
  1211. if(MathAbs(g_stableSup[i] - lv) < tol) return;
  1212. }
  1213. if(g_stableSupCount < 10){
  1214. g_stableSup[g_stableSupCount] = lv;
  1215. g_stableSupCount++;
  1216. } else {
  1217. for(int i=0; i<9; i++) g_stableSup[i] = g_stableSup[i+1];
  1218. g_stableSup[9] = lv;
  1219. }
  1220. }
  1221.  
  1222. void AddRes(double lv){ AddStableRes(lv); }
  1223. void AddSup(double lv){ AddStableSup(lv); }
  1224.  
  1225. void UpdateSR(){
  1226. if(Time[0] == g_lastSRScan) return;
  1227. static int barCount = 0;
  1228. barCount++;
  1229. if(barCount < g_srScanInterval) return;
  1230. barCount = 0;
  1231. g_lastSRScan = Time[0];
  1232. if(Bars < 30) return;
  1233. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1234. double pip=jpy?0.01:0.0001;
  1235. double cur = Close[0];
  1236. for(int i=3; i<=25 && i<Bars-2; i++){
  1237. double h = High[i];
  1238. if(h > High[i-1] && h > High[i-2] && h > High[i+1] && h > High[i+2]){
  1239. if(h > cur + 3*pip){
  1240. double body = MathMax(Open[i], Close[i]);
  1241. if(body > h - 10*pip){
  1242. AddStableRes(h);
  1243. }
  1244. }
  1245. }
  1246. }
  1247. for(int i=3; i<=25 && i<Bars-2; i++){
  1248. double l = Low[i];
  1249. if(l < Low[i-1] && l < Low[i-2] && l < Low[i+1] && l < Low[i+2]){
  1250. if(l < cur - 3*pip){
  1251. double body = MathMin(Open[i], Close[i]);
  1252. if(body < l + 10*pip){
  1253. AddStableSup(l);
  1254. }
  1255. }
  1256. }
  1257. }
  1258. double rndStep = 50 * pip;
  1259. double nearRnd = MathRound(cur / rndStep) * rndStep;
  1260. for(int k=-1; k<=1; k++){
  1261. double lv = nearRnd + k * rndStep;
  1262. if(MathAbs(cur - lv) < 30*pip){
  1263. if(lv > cur) AddStableRes(lv);
  1264. else AddStableSup(lv);
  1265. }
  1266. }
  1267. DrawNearestSR();
  1268. CheckBRK();
  1269. }
  1270.  
  1271. void DrawNearestSR(){
  1272. for(int i=0; i<20; i++){
  1273. SafeDel(PFX+"RES_"+IntegerToString(i));
  1274. SafeDel(PFX+"SUP_"+IntegerToString(i));
  1275. }
  1276. SafeDel(PFX+"NEAREST_RES");
  1277. SafeDel(PFX+"NEAREST_SUP");
  1278. double cur = Close[0];
  1279. g_nearest_res = 0;
  1280. g_nearest_sup = 0;
  1281. double minResDist = 999999;
  1282. double minSupDist = 999999;
  1283. for(int i=0; i<g_stableResCount; i++){
  1284. if(g_stableRes[i] > cur){
  1285. double d = g_stableRes[i] - cur;
  1286. if(d < minResDist){
  1287. minResDist = d;
  1288. g_nearest_res = g_stableRes[i];
  1289. }
  1290. }
  1291. }
  1292. for(int i=0; i<g_stableSupCount; i++){
  1293. if(g_stableSup[i] < cur){
  1294. double d = cur - g_stableSup[i];
  1295. if(d < minSupDist){
  1296. minSupDist = d;
  1297. g_nearest_sup = g_stableSup[i];
  1298. }
  1299. }
  1300. }
  1301. }
  1302.  
  1303. 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;}}
  1304.  
  1305. 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;}
  1306. double VolumeTrapScore(){
  1307. if(!VOLUME_PROFILE_TRAP||Bars<50)return 0;
  1308. double cur=Close[0],hi=High[iHighest(NULL,0,MODE_HIGH,50,1)],lo=Low[iLowest(NULL,0,MODE_LOW,50,1)];
  1309. 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};
  1310. 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]++;}
  1311. for(int z=0;z<zn;z++)if(zc[z]>0)vz[z]/=zc[z];
  1312. int cz=(int)((cur-lo)/zs);if(cz<0)cz=0;if(cz>=zn)cz=zn-1;
  1313. double vr=(double)Volume[1]/(vz[cz]+0.001);double wr=MicroWick();
  1314. if(vr>2.0&&wr>0.65)return 25;if(vr>1.8&&wr>0.55)return 15;return 0;
  1315. }
  1316. double UltimateTrapScore(){double wr=MicroWick(),v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  1317. double avg=v2>0?v2:1.0,vr=v1/avg,rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),sc=0.0;
  1318. if(wr>0.65)sc+=40;if(vr>2.0)sc+=30;if(rsi>75||rsi<25)sc+=20;
  1319. if((High[1]>g_nearest_res&&Close[1]<g_nearest_res)||(Low[1]<g_nearest_sup&&Close[1]>g_nearest_sup))sc+=25;
  1320. sc+=VolumeTrapScore();return MathMin(100.0,sc);}
  1321. bool IsBrokerForce(double dummy=0){
  1322. int sd=0;for(int i=1;i<=3;i++){if(Close[i]>Open[i])sd++;else sd--;}
  1323. double v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  1324. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  1325. return(MathAbs(sd)==3&&v1>v2*2.0&&sp>BROKER_SPREAD_THRESHOLD);}
  1326.  
  1327. // ============================================================
  1328. // NEURAL AI v2.0 - FIXED VERSION
  1329. // ============================================================
  1330.  
  1331. double NeuralBiasFast(){
  1332. double r=NeuralBias(0)*0.3+NeuralBias(1)*0.7;
  1333. if(r>96)r=96;if(r<4)r=4;return r;
  1334. }
  1335.  
  1336. double NeuralBias(int s){
  1337. double f[8];
  1338. f[0]=fDoji(s);f[1]=fWick(s);f[2]=fVol();f[3]=fMom(s);
  1339. f[4]=fSpread();f[5]=fMem(s);f[6]=fTick(s);f[7]=fFrac(s);
  1340. for(int i=0;i<8;i++) f[i]/=100.0;
  1341. double h[4];
  1342. for(int i=0;i<4;i++){
  1343. double sum=0;
  1344. for(int j=0;j<8;j++) sum+=f[j]*NW[j*4+i];
  1345. h[i]=MathMax(0,sum-0.06);
  1346. }
  1347. double out=0;
  1348. for(int i=0;i<4;i++) out+=h[i]*NW[32+i];
  1349. double result=50.0+out*22.0;
  1350. return (result>96)?96:((result<4)?4:result);
  1351. }
  1352.  
  1353. double fDoji(int s){
  1354. if(s+8>=Bars) return 0;
  1355. double score=0;int streak=0;
  1356. for(int i=s;i<s+8&&i<Bars;i++){
  1357. double body=MathAbs(Open[i]-Close[i]);
  1358. double range=High[i]-Low[i];
  1359. if(range<=0) continue;
  1360. double ratio=body/range;
  1361. double w=(9.0-(i-s))/8.0;
  1362. if(ratio<0.15){score+=18*w;streak++;
  1363. double lw=MathMin(Open[i],Close[i])-Low[i];
  1364. if(lw>range*0.55) score+=12*w;
  1365. double uw=High[i]-MathMax(Open[i],Close[i]);
  1366. if(uw>range*0.55) score-=8*w;}
  1367. else if(ratio<0.25){score+=8*w;streak++;}
  1368. }
  1369. if(streak>=3) score+=15;else if(streak>=2) score+=8;
  1370. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1371. double pip=jpy?0.01:0.0001;
  1372. double cur=Close[0];
  1373. if(g_nearest_res>0&&(g_nearest_res-cur)<8*pip) score+=12;
  1374. if(g_nearest_sup>0&&(cur-g_nearest_sup)<8*pip) score+=12;
  1375. if(g_hrn_price>0&&MathAbs(cur-g_hrn_price)<5*pip) score+=10;
  1376. return MathMin(100,score);
  1377. }
  1378.  
  1379. double fWick(int s){
  1380. double range=High[s]-Low[s];
  1381. if(range==0) return 0;
  1382. double u=(High[s]-MathMax(Open[s],Close[s]))/range;
  1383. double l=(MathMin(Open[s],Close[s])-Low[s])/range;
  1384. double body=MathAbs(Close[s]-Open[s])/range;
  1385. bool closedRed=(Close[s]<Open[s]);
  1386. double score=0;
  1387. if(u>0.65&&!closedRed) score=95;
  1388. else if(u>0.50&&!closedRed) score=70;
  1389. else if(l>0.65&&closedRed) score=90;
  1390. else if(l>0.50&&closedRed) score=65;
  1391. else if(u>0.65||l>0.65) score=50;
  1392. else if(u>0.50||l>0.50) score=30;
  1393. if(score>=50){
  1394. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1395. double pip=jpy?0.01:0.0001;
  1396. double cur=Close[0];
  1397. if(g_nearest_res>0&&(g_nearest_res-cur)<10*pip) score+=15;
  1398. if(g_nearest_sup>0&&(cur-g_nearest_sup)<10*pip) score+=15;
  1399. }
  1400. return MathMin(100,score);
  1401. }
  1402.  
  1403. double fVol(){
  1404. if(Bars<15) return 0;
  1405. double cur=(double)iVolume(NULL,PERIOD_M1,0);
  1406. double avg=0;
  1407. for(int i=1;i<=10;i++) avg+=iVolume(NULL,PERIOD_M1,i);
  1408. avg/=10.0;
  1409. if(avg==0) return 0;
  1410. double ratio=cur/avg;
  1411. double prev=(double)iVolume(NULL,PERIOD_M1,5);
  1412. double prevAvg=0;
  1413. for(int i=6;i<=15;i++) prevAvg+=iVolume(NULL,PERIOD_M1,i);
  1414. prevAvg/=10.0;
  1415. double trend=(prevAvg>0)?prev/prevAvg:1.0;
  1416. double score=0;
  1417. if(ratio>3.0) score=95;
  1418. else if(ratio>2.5) score=85;
  1419. else if(ratio>2.0) score=75;
  1420. else if(ratio>1.5) score=50;
  1421. else if(ratio>1.2) score=30;
  1422. if(trend<0.8){
  1423. if(Close[0]>Close[5]) score+=10;
  1424. else if(Close[0]<Close[5]) score+=10;
  1425. }
  1426. if(ratio<0.7) score=MathMin(score,15);
  1427. return MathMin(100,score);
  1428. }
  1429.  
  1430. double fMom(int s){
  1431. if(s+5>=Bars) return 0;
  1432. double m1=(Close[s]-Close[s+1]);
  1433. double m2=(Close[s+1]-Close[s+2]);
  1434. double m3=(Close[s+2]-Close[s+3]);
  1435. bool shift=false;
  1436. if(m1>0 && m2<0 && m3<0) shift=true;
  1437. if(m1<0 && m2>0 && m3>0) shift=true;
  1438. double accel=MathAbs(m1)-MathAbs(m2);
  1439. double body1=MathAbs(Close[s]-Open[s]);
  1440. double body2=MathAbs(Close[s+1]-Open[s+1]);
  1441. double body3=MathAbs(Close[s+2]-Open[s+2]);
  1442. double score=0;
  1443. if(shift){score=88;if(accel>0) score+=12;}
  1444. if(body1<body2 && body2<body3 && body3>0){score=60;if(body1<body2*0.5) score=80;}
  1445. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1446. double pip=jpy?0.01:0.0001;
  1447. if(MathAbs(m2)>3*pip && MathAbs(m1)<pip) score=75;
  1448. return MathMin(100,score);
  1449. }
  1450.  
  1451. double fSpread(){
  1452. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  1453. double typical=3.0;
  1454. double ratio=sp/typical;
  1455. double score=0;
  1456. if(ratio>3.0) score=95;
  1457. else if(ratio>2.5) score=85;
  1458. else if(ratio>2.0) score=75;
  1459. else if(ratio>1.5) score=50;
  1460. else if(ratio>1.2) score=30;
  1461. double vol=(double)iVolume(NULL,PERIOD_M1,1);
  1462. double volAvg=0;
  1463. for(int i=2;i<=6;i++) volAvg+=iVolume(NULL,PERIOD_M1,i);
  1464. volAvg/=5.0;
  1465. if(volAvg>0){double volRatio=vol/volAvg;if(volRatio<0.8 && ratio>1.5) score+=15;}
  1466. int h=TimeHour(TimeGMT());
  1467. if((h>=0&&h<=3)||(h>=12&&h<=14)) score+=10;
  1468. return MathMin(100,score);
  1469. }
  1470.  
  1471. double fMem(int s){
  1472. if(s+10>=Bars) return 0;
  1473. bool bullEng=(Close[s]>Open[s])&&(Close[s+1]<Open[s+1])&&(Close[s]>=Open[s+1])&&(Open[s]<=Close[s+1]);
  1474. bool bearEng=(Close[s]<Open[s])&&(Close[s+1]>Open[s+1])&&(Close[s]<=Open[s+1])&&(Open[s]>=Close[s+1]);
  1475. double range=High[s]-Low[s];
  1476. if(range<=0) return 0;
  1477. double body=MathAbs(Close[s]-Open[s]);
  1478. double upperW=High[s]-MathMax(Open[s],Close[s]);
  1479. double lowerW=MathMin(Open[s],Close[s])-Low[s];
  1480. bool pinUp=(body<range*0.3 && lowerW>range*0.5);
  1481. bool pinDn=(body<range*0.3 && upperW>range*0.5);
  1482. bool starUp=false,starDn=false;
  1483. if(s+2<Bars){
  1484. double b2=MathAbs(Close[s+1]-Open[s+1]);
  1485. double r2=High[s+1]-Low[s+1];
  1486. if(r2>0 && b2<r2*0.25){
  1487. if(Close[s+2]<Open[s+2]&&Close[s]>Open[s]) starUp=true;
  1488. if(Close[s+2]>Open[s+2]&&Close[s]<Open[s]) starDn=true;
  1489. }
  1490. }
  1491. double score=0;
  1492. if(bullEng) score=85;
  1493. else if(bearEng) score=85;
  1494. else if(pinUp) score=80;
  1495. else if(pinDn) score=80;
  1496. else if(starUp) score=75;
  1497. else if(starDn) score=75;
  1498. if(score>=50){
  1499. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1500. double pip=jpy?0.01:0.0001;
  1501. double cur=Close[0];
  1502. if(g_nearest_res>0&&(g_nearest_res-cur)<10*pip) score+=15;
  1503. if(g_nearest_sup>0&&(cur-g_nearest_sup)<10*pip) score+=15;
  1504. }
  1505. return MathMin(100,score);
  1506. }
  1507.  
  1508. double fTick(int s){
  1509. if(s+5>=Bars) return 0;
  1510. double volN=(double)iVolume(NULL,PERIOD_M1,s);
  1511. double volP=(double)iVolume(NULL,PERIOD_M1,s+1);
  1512. if(volP==0) return 0;
  1513. double volRatio=volN/volP;
  1514. double priceMove=MathAbs(Close[s]-Close[s+1]);
  1515. double pricePct=Close[s+1]>0?priceMove/Close[s+1]*100:0;
  1516. double score=0;
  1517. if(volRatio>2.0 && pricePct<0.1) score=85;
  1518. else if(volRatio>1.5 && pricePct<0.05) score=60;
  1519. else if(volRatio>1.2 && pricePct<0.03) score=35;
  1520. if(volRatio>0.8 && volRatio<1.3 && pricePct>0.05 && pricePct<0.5) score=10;
  1521. return MathMin(100,score);
  1522. }
  1523.  
  1524. double fFrac(int s){
  1525. if(s+4>=Bars || s<2) return 0;
  1526. bool fHigh=(High[s]>High[s-1]&&High[s]>High[s-2]&&High[s]>High[s+1]&&High[s]>High[s+2]);
  1527. bool fLow=(Low[s]<Low[s-1]&&Low[s]<Low[s-2]&&Low[s]<Low[s+1]&&Low[s]<Low[s+2]);
  1528. if(!fHigh && !fLow) return 0;
  1529. double score=0;
  1530. if(fHigh){
  1531. double d1=High[s]-High[s-1],d2=High[s]-High[s-2],d3=High[s]-High[s+1],d4=High[s]-High[s+2];
  1532. double minD=MathMin(MathMin(d1,d2),MathMin(d3,d4));
  1533. score=70+minD*1000;
  1534. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1535. double pip=jpy?0.01:0.0001;
  1536. double dist=MathAbs(High[s]-Close[0])/pip;
  1537. if(dist<15) score+=20;else if(dist<30) score+=10;
  1538. if(Close[s]<High[s]) score+=15;
  1539. }
  1540. if(fLow){
  1541. double d1=Low[s-1]-Low[s],d2=Low[s-2]-Low[s],d3=Low[s+1]-Low[s],d4=Low[s+2]-Low[s];
  1542. double minD=MathMin(MathMin(d1,d2),MathMin(d3,d4));
  1543. score=70+minD*1000;
  1544. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1545. double pip=jpy?0.01:0.0001;
  1546. double dist=MathAbs(Low[s]-Close[0])/pip;
  1547. if(dist<15) score+=20;else if(dist<30) score+=10;
  1548. if(Close[s]>Low[s]) score+=15;
  1549. }
  1550. if(score>=50){
  1551. bool jpy2=(StringFind(Symbol(),"JPY")>=0);
  1552. double pip2=jpy2?0.01:0.0001;
  1553. double cur=Close[0];
  1554. if(g_nearest_res>0&&(g_nearest_res-cur)<15*pip2) score+=15;
  1555. if(g_nearest_sup>0&&(cur-g_nearest_sup)<15*pip2) score+=15;
  1556. }
  1557. return MathMin(100,score);
  1558. }
  1559.  
  1560. void InitNW(){
  1561. NW[0]=0.80;NW[1]=0.90;NW[2]=0.40;NW[3]=0.85;
  1562. NW[4]=0.70;NW[5]=0.60;NW[6]=0.30;NW[7]=0.20;
  1563. NW[8]=0.30;NW[9]=0.60;NW[10]=0.70;NW[11]=0.40;
  1564. NW[12]=0.50;NW[13]=0.65;NW[14]=0.25;NW[15]=0.35;
  1565. NW[16]=0.75;NW[17]=0.70;NW[18]=0.50;NW[19]=0.90;
  1566. NW[20]=0.30;NW[21]=0.20;NW[22]=0.60;NW[23]=0.40;
  1567. NW[24]=0.85;NW[25]=0.65;NW[26]=0.30;NW[27]=0.80;
  1568. NW[28]=0.25;NW[29]=0.30;NW[30]=0.70;NW[31]=0.35;
  1569. NW[32]=1.30;NW[33]=-0.80;NW[34]=1.10;NW[35]=-0.95;
  1570. }
  1571. void CalcPrediction(double brain,double nb,int cp,double mai,int mts,double rsc,bool bf,double mw){
  1572. string ms=DetectMyStrategy();bool sA=(ms!="WAIT");
  1573. if(sA&&g_strategyType=="TRAP"){
  1574. 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;}
  1575. 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;}}
  1576. double tS=UltimateTrapScore();bool bF2=IsBrokerForce();
  1577. 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;}}
  1578. 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;}
  1579. double gS=0,rS=0,ab=MathMax(0.70,MathMin(1.30,g_accuracy/65.0));
  1580. if(IsSidewaysMarket()){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1581. 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);
  1582. 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;}
  1583. if(nR)rS+=20;if(nS)gS+=20;}
  1584. 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;}}
  1585. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")gS+=60;
  1586. else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")rS+=60;
  1587. else if(g_haM1=="HA BULLISH 1")gS+=30;else if(g_haM1=="HA BEARISH 1")rS+=30;
  1588. if(HA_ALIGN_FILTER&&g_haBoth=="MIXED"){gS*=0.5;rS*=0.5;}
  1589. gS+=(nb-50)/50.0*22*ab;rS-=(nb-50)/50.0*22*ab;
  1590. double bn=MathMax(-1.0,MathMin(1.0,brain/10.0));gS+=bn*15*ab;rS-=bn*15*ab;
  1591. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1592. if(g_nearest_res>0&&(g_nearest_res-Close[0])<10*pip)rS+=12;
  1593. if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)<10*pip)gS+=12;
  1594. double rsi1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);if(rsi1>70)rS+=6;if(rsi1<30)gS+=6;
  1595. double sn=MathMax(-1.0,MathMin(1.0,rsc/3.0));gS+=sn*8*ab;rS-=sn*8*ab;
  1596. double wRS=GetWickRejectSignal();gS+=(wRS>0?wRS:0);rS+=(wRS<0?MathAbs(wRS):0);
  1597. double cPS=GetCommonPointSignal();gS+=(cPS>0?cPS:0);rS+=(cPS<0?MathAbs(cPS):0);
  1598. if(ENABLE_BB_PULLBACK){if(g_bbSignal=="CALL")gS+=18*ab;else if(g_bbSignal=="PUT")rS+=18*ab;}
  1599. int rd=DetectRSIDivergence();if(rd==1)gS+=20;if(rd==-1)rS+=20;
  1600. int cp2=DetectClassicPatterns();if(cp2==1)gS+=12;if(cp2==-1)rS+=12;
  1601. int qm=DetectQMR();if(qm==1)gS+=25;if(qm==-1)rS+=25;
  1602. int sk=StreakReversalSignal();if(sk==1)gS+=18;if(sk==-1)rS+=18;
  1603. 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;}
  1604. int vs=SmartVolumeSignal();if(vs==1)gS+=12;if(vs==-1)rS+=12;
  1605. if(!IsVolatilityGood()){gS*=0.5;rS*=0.5;}
  1606. double diff=MathMax(-100.0,MathMin(100.0,gS-rS));
  1607. g_gProb=MathMax(8.0,MathMin(92.0,50.0+(diff/1.8)));g_rProb=100.0-g_gProb;
  1608. if(sA&&g_strategyType=="TREND"){
  1609. if(ms=="CALL"){g_gProb=MathMax(g_gProb,85.0);g_rProb=100.0-g_gProb;}
  1610. if(ms=="PUT"){g_rProb=MathMax(g_rProb,85.0);g_gProb=100.0-g_rProb;}
  1611. g_gProb=MathMin(92.0,MathMax(8.0,g_gProb));g_rProb=100.0-g_gProb;}
  1612. double dom=MathMax(g_gProb,g_rProb);
  1613. 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;}}}
  1614. 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;}}}
  1615. else{if(!sA){g_pAction="WAIT";g_pColor=NEON_YELLOW;}}
  1616. g_calc_gProb=g_gProb;g_calc_rProb=g_rProb;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;
  1617. }
  1618. void DetectCommonPoints(){
  1619. if(!SHOW_COMMON_POINTS){g_commonCount=0;return;}
  1620. if(Time[0]==g_lastCommonScan)return;g_lastCommonScan=Time[0];g_commonCount=0;
  1621. datetime nowBar=Time[0];int periodSec=PeriodSeconds(PERIOD_M1);
  1622. double m5h=iHigh(NULL,PERIOD_M5,iHighest(NULL,PERIOD_M5,MODE_HIGH,10,1));
  1623. double m5l=iLow(NULL,PERIOD_M5,iLowest(NULL,PERIOD_M5,MODE_LOW,10,1));
  1624. 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++;}
  1625. 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++;}
  1626. 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++;}
  1627. 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++;}
  1628. 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--;}
  1629. }
  1630. void DrawCommonPoints(){
  1631. 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));}
  1632. if(!SHOW_COMMON_POINTS||g_commonCount==0)return;
  1633. for(int i=0;i<g_commonCount;i++){if(TimeCurrent()>g_commonExpire[i])continue;if(IsLineNearby(g_commonPrice[i],8.0))continue;
  1634. string id=PFX+"COMMON_"+IntegerToString(i),idL=PFX+"COMMON_L_"+IntegerToString(i),idH=PFX+"COMMON_HL_"+IntegerToString(i);color zc=DARK_BLUE_NEON;
  1635. 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);
  1636. ObjectCreate(0,id,OBJ_TEXT,0,Time[0],g_commonPrice[i]);ObjectSetText(id,"*",16,"Arial",zc);ObjectSetInteger(0,id,OBJPROP_BACK,false);
  1637. string lbl=(g_commonType[i]=="CALL")?"^ CALL ZONE":"v PUT ZONE";
  1638. 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);}
  1639. }
  1640. void DetectWickRejections(){
  1641. g_isSideways=IsSidewaysMarket();if(!SHOW_WICK_REJECT_LINES){g_wickLineCount=0;return;}
  1642. if(Time[0]==g_lastWickScan)return;g_lastWickScan=Time[0];
  1643. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double zone=WICK_ZONE_PIPS*pip*2;double cur=Close[0];
  1644. g_wickLineCount=0;datetime now=Time[0],expT=now+PeriodSeconds(PERIOD_M1)*WICK_EXPIRE_BARS*2;
  1645. for(int i=1;i<=40&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  1646. double uw=High[i]-MathMax(Open[i],Close[i]),lw=MathMin(Open[i],Close[i])-Low[i];double rl=0;bool fd=false;
  1647. if(uw>rg*0.30){rl=High[i];if(MathAbs(cur-rl)<zone*3)fd=true;}
  1648. if(lw>rg*0.30){rl=Low[i];if(MathAbs(cur-rl)<zone*3)fd=true;}
  1649. if(!fd)continue;bool ex=false;
  1650. for(int j=0;j<g_wickLineCount;j++)if(MathAbs(g_wickLinePrice[j]-rl)<zone){g_wickLineTouches[j]++;ex=true;break;}
  1651. if(!ex&&g_wickLineCount<MAX_WICK_LINES){g_wickLinePrice[g_wickLineCount]=rl;g_wickLineTouches[g_wickLineCount]=1;g_wickLineExpire[g_wickLineCount]=expT;g_wickLineCount++;}}
  1652. 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--;}
  1653. }
  1654. void DrawWickRejectLines(){
  1655. for(int i=0;i<MAX_WICK_LINES;i++){SafeDel(PFX+"WICK_"+IntegerToString(i));SafeDel(PFX+"WICK_L_"+IntegerToString(i));}
  1656. if(!SHOW_WICK_REJECT_LINES||!g_isSideways)return;
  1657. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1658. 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;
  1659. string id=PFX+"WICK_"+IntegerToString(i),idL=PFX+"WICK_L_"+IntegerToString(i);color lc=C'0,180,255';
  1660. 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);
  1661. string lbl="W"+IntegerToString(g_wickLineTouches[i])+"x";
  1662. 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);}
  1663. }
  1664. 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;
  1665. for(int i=0;i<g_wickLineCount;i++){double d=MathAbs(Close[0]-g_wickLinePrice[i])/pip;bool iS=(g_wickLinePrice[i]<Close[0]);
  1666. 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));}
  1667. double GetCommonPointSignal(){if(g_commonCount==0)return 0;double sc=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1668. 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));}
  1669. void DetectHiddenLevels(){g_htfLevelCount=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double curP=Close[0];
  1670. double rU=MathCeil(curP/(10*pip))*(10*pip),rD=MathFloor(curP/(10*pip))*(10*pip);
  1671. if(MathAbs(curP-rU)/pip<=15)AddLevel(rU,"ROUND","RESISTANCE",TimeCurrent(),8,true);
  1672. if(MathAbs(curP-rD)/pip<=15)AddLevel(rD,"ROUND","SUPPORT",TimeCurrent(),8,true);
  1673. DetectHTFLevels(PERIOD_M5,"M5",3,pip);DetectHTFLevels(PERIOD_M15,"M15",5,pip);DetectHTFLevels(PERIOD_M30,"M30",7,pip);DetectHTFLevels(PERIOD_H1,"H1",9,pip);
  1674. SortLevelsByStrength();}
  1675. void DetectHTFLevels(ENUM_TIMEFRAMES tf,string tfN,int bS,double pip){
  1676. int bars=MathMin(50,iBars(NULL,tf));if(bars<10)return;double curP=Close[0];
  1677. for(int i=2;i<bars-2;i++){
  1678. 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);}
  1679. 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);}}}
  1680. bool IsSwingHigh(ENUM_TIMEFRAMES tf,int p,int lb){
  1681. double h=iHigh(NULL,tf,p);
  1682. 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;}
  1683. return true;}
  1684. bool IsSwingLow(ENUM_TIMEFRAMES tf,int p,int lb){
  1685. double l=iLow(NULL,tf,p);
  1686. 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;}
  1687. return true;}
  1688. void AddLevel(double price,string tf,string type,datetime time,int strength,bool isRound){
  1689. if(g_htfLevelCount>=50)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1690. for(int i=0;i<g_htfLevelCount;i++)if(MathAbs(g_htfLevels[i].price-price)/pip<5)return;
  1691. 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++;}
  1692. void SortLevelsByStrength(){
  1693. 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;}}
  1694. void DrawHiddenLevels(){
  1695. for(int i=0;i<50;i++){SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i));SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i)+"_LBL");}
  1696. int dc=MathMin(10,g_htfLevelCount);int drawn=0;
  1697. 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;
  1698. 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);
  1699. 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);
  1700. 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++;}}
  1701. string DetectSuddenReversal(){
  1702. if(Bars<10) return "";
  1703. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  1704. double pip=jpy?0.01:0.0001;
  1705.  
  1706. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  1707. double atr=iATR(NULL,PERIOD_M1,14,1);
  1708. if(atr<=0) return "";
  1709.  
  1710. double rng1=High[1]-Low[1];
  1711. double body1=MathAbs(Close[1]-Open[1]);
  1712. double uw1=(rng1>0)?(High[1]-MathMax(Open[1],Close[1]))/rng1:0;
  1713. double lw1=(rng1>0)?(MathMin(Open[1],Close[1])-Low[1])/rng1:0;
  1714. bool bull1=(Close[1]>Open[1]);
  1715. bool bear1=(Close[1]<Open[1]);
  1716.  
  1717. int bullScore=0,bearScore=0;
  1718. string bullReason="",bearReason="";
  1719.  
  1720. // Pattern 1: Bullish Pin Bar
  1721. if(lw1>0.60&&body1<rng1*0.30&&rsi<48){
  1722. bullScore+=30; bullReason+="PinBar ";
  1723. }
  1724. // Pattern 2: Bearish Pin Bar
  1725. if(uw1>0.60&&body1<rng1*0.30&&rsi>52){
  1726. bearScore+=30; bearReason+="PinBar ";
  1727. }
  1728.  
  1729. // Pattern 3: Bullish Engulfing
  1730. if(bull1&&body1>MathAbs(Close[2]-Open[2])*1.1&&Close[2]<Open[2]&&body1>atr*0.35){
  1731. bullScore+=25; bullReason+="Engulf ";
  1732. }
  1733. // Pattern 4: Bearish Engulfing
  1734. if(bear1&&body1>MathAbs(Close[2]-Open[2])*1.1&&Close[2]>Open[2]&&body1>atr*0.35){
  1735. bearScore+=25; bearReason+="Engulf ";
  1736. }
  1737.  
  1738. // Pattern 5: Hammer (bullish)
  1739. if(bull1&&lw1>0.55&&uw1<0.20&&rsi<55){
  1740. bullScore+=20; bullReason+="Hammer ";
  1741. }
  1742. // Pattern 6: Shooting Star (bearish)
  1743. if(bear1&&uw1>0.55&&lw1<0.20&&rsi>45){
  1744. bearScore+=20; bearReason+="ShootStar ";
  1745. }
  1746.  
  1747. // Pattern 7: Morning Star (3-bar bullish)
  1748. if(Bars>=4){
  1749. double midBody=MathAbs(Close[2]-Open[2]);
  1750. double midRange=High[2]-Low[2];
  1751. bool smallMid=(midRange>0&&midBody<midRange*0.30);
  1752. bool mornStar=(Close[3]<Open[3])&&smallMid&&(Close[1]>Open[1])&&
  1753. (Close[1]>=(Open[3]+Close[3])/2.0);
  1754. if(mornStar&&rsi<58){bullScore+=20;bullReason+="MornStar ";}
  1755. }
  1756. // Pattern 8: Evening Star (3-bar bearish)
  1757. if(Bars>=4){
  1758. double midBody=MathAbs(Close[2]-Open[2]);
  1759. double midRange=High[2]-Low[2];
  1760. bool smallMid=(midRange>0&&midBody<midRange*0.30);
  1761. bool eveStar=(Close[3]>Open[3])&&smallMid&&(Close[1]<Open[1])&&
  1762. (Close[1]<=(Open[3]+Close[3])/2.0);
  1763. if(eveStar&&rsi>42){bearScore+=20;bearReason+="EveStar ";}
  1764. }
  1765.  
  1766. // RSI extreme confirmation bonus
  1767. if(rsi<30&&bullScore>0){bullScore+=15;bullReason+="RSI_OS ";}
  1768. if(rsi>70&&bearScore>0){bearScore+=15;bearReason+="RSI_OB ";}
  1769.  
  1770. // At Support/Resistance bonus
  1771. if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)/pip<8&&bullScore>0){
  1772. bullScore+=15;bullReason+="@SUP ";
  1773. }
  1774. if(g_nearest_res>0&&(g_nearest_res-Close[0])/pip<8&&bearScore>0){
  1775. bearScore+=15;bearReason+="@RES ";
  1776. }
  1777.  
  1778. // Near HRN level bonus
  1779. if(g_hrn_price>0){
  1780. double distH=MathAbs(Close[0]-g_hrn_price)/pip;
  1781. if(distH<5&&bullScore>0){bullScore+=10;bullReason+="@HRN ";}
  1782. if(distH<5&&bearScore>0){bearScore+=10;bearReason+="@HRN ";}
  1783. }
  1784.  
  1785. // Final decision
  1786. if(bullScore>=40&&bullScore>bearScore){
  1787. return "BULL REVERSAL";
  1788. }
  1789. else if(bearScore>=40&&bearScore>bullScore){
  1790. return "BEAR REVERSAL";
  1791. }
  1792.  
  1793. return "";
  1794. }
  1795. void SafeDel(string id){if(ObjectFind(0,id)>=0)ObjectDelete(0,id);}
  1796. 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);}
  1797. void HideSPM(){
  1798. for(int i=ObjectsTotal()-1;i>=0;i--){
  1799. string nm=ObjectName(i);
  1800. if(StringFind(nm,PFX)==0) continue;
  1801. if(StringFind(nm,PFX+"candle_timer")>=0) continue;
  1802. int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE);
  1803. if(tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT) ObjectDelete(0,nm);
  1804. }
  1805. }
  1806. void NuclearDeleteAll(){
  1807. for(int i=ObjectsTotal()-1;i>=0;i--){
  1808. string nm=ObjectName(i);
  1809. if(StringFind(nm,PFX+"candle_timer")>=0) continue;
  1810. int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE);
  1811. if(tp==OBJ_HLINE||tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT)
  1812. ObjectDelete(0,nm);
  1813. }
  1814. }
  1815. void DelDashboard(){
  1816. for(int i=ObjectsTotal()-1;i>=0;i--){
  1817. string nm=ObjectName(i);
  1818. if(StringFind(nm,PFX)!=0) continue;
  1819. if(StringFind(nm,"HRN_LINE")>=0) continue;
  1820. if(StringFind(nm,"HRN_LBL")>=0) continue;
  1821. if(StringFind(nm,"candle_timer")>=0) continue;
  1822. if(StringFind(nm,"HTF_LEVEL")>=0) continue;
  1823. if(StringFind(nm,"COMMON_")>=0) continue;
  1824. if(StringFind(nm,"WICK_")>=0) continue;
  1825. if(StringFind(nm,"BB_")>=0) continue;
  1826. ObjectDelete(nm);
  1827. }
  1828. }
  1829. void LoadMLWeights(){
  1830. if(!ML_ADAPTIVE)return;g_symbolKey=Symbol();string fn="ML_weights_"+g_symbolKey+".dat";
  1831. 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;}
  1832. void SaveMLWeights(){
  1833. if(!ML_ADAPTIVE)return;string fn="ML_weights_"+g_symbolKey+".dat";
  1834. int h=FileOpen(fn,FILE_WRITE|FILE_TXT);if(h!=INVALID_HANDLE){FileWriteString(h,DoubleToString(g_brokerBias,6));FileClose(h);}}
  1835. void UpdateMLWeights(bool win){
  1836. 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);
  1837. if(g_brokerBias>0.5)g_brokerBias=0.5;if(g_brokerBias<-0.5)g_brokerBias=-0.5;SaveMLWeights();}
  1838. void UpdateAccuracy(){if(Bars<5||Time[0]==g_acc_lastBar)return;g_acc_lastBar=Time[0];
  1839. 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);
  1840. if(win){g_acc_correct++;g_lossStreak=0;}else g_lossStreak++;g_acc_total++;
  1841. if(g_acc_total>0)g_accuracy=MathMax(40.0,MathMin(90.0,(double)g_acc_correct/g_acc_total*100.0));
  1842. if(ML_ADAPTIVE&&g_lastPredGreen>50.0&&g_lastPredGreen<100.0)UpdateMLWeights(win);}
  1843. g_lastPredGreen=g_frozen_gProb;g_lastPredBar=Time[0];}
  1844. 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;}
  1845. 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]));}}
  1846. 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";}
  1847. 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;}
  1848. 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;}
  1849. 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;}
  1850. 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;}
  1851. double GetADXStrength(){if(Bars<20)return 0;return iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);}
  1852. 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;}
  1853. 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;}
  1854. 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;
  1855. 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++;}}}
  1856. 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;}}
  1857. 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;}}return 0;}
  1858. 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;
  1859. 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++;}
  1860. 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++;}
  1861. if(hC<2||lC<2)return 0;
  1862. for(int iA=0;iA<hC;iA++)for(int iC2=0;iC2<hC;iC2++){if(iA==iC2||sHB[iA]<=sHB[iC2]||sH[iC2]>=sH[iA]-10*pip)continue;
  1863. for(int iB=0;iB<lC;iB++){if(sHB[iA]<=sLB[iB]||sLB[iB]<=sHB[iC2])continue;
  1864. for(int iD=0;iD<lC;iD++){if(iB==iD||sHB[iC2]<=sLB[iD]||sL[iD]>=sL[iB])continue;
  1865. bool m3=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;}
  1866. bool m5=false;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;}
  1867. if((m3||m5)&&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;}}}}
  1868. for(int iA=0;iA<lC;iA++)for(int iC2=0;iC2<lC;iC2++){if(iA==iC2||sLB[iA]<=sLB[iC2]||sL[iC2]<=sL[iA]+10*pip)continue;
  1869. for(int iB=0;iB<hC;iB++){if(sLB[iA]<=sHB[iB]||sHB[iB]<=sLB[iC2])continue;
  1870. for(int iD=0;iD<hC;iD++){if(iB==iD||sLB[iC2]<=sHB[iD]||sH[iD]>=sH[iB])continue;
  1871. bool m3=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;}
  1872. bool m5=false;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;}
  1873. if((m3||m5)&&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;}}}}
  1874. return 0;}
  1875. void AddRNLevel(double &arr[],int &cnt,double lv){if(cnt>=100)return;for(int i=0;i<cnt;i++)if(MathAbs(arr[i]-lv)<0.000001)return;arr[cnt]=lv;cnt++;}
  1876. double ScoreRoundNumber(double level,double pip){
  1877. double score=0,tol=3*pip;int touches=0,ru=0,rd=0;
  1878. for(int i=1;i<=LOOKBACK&&i<Bars;i++){double h=High[i],l=Low[i],c=Close[i],o=Open[i];
  1879. if(h>=level-tol&&l<=level+tol){touches++;
  1880. if(l<=level+tol&&c>level+tol){ru++;double bdy=MathMin(o,c),lw=bdy-l,rng=h-l;if(rng>0&&lw>rng*0.5)score+=5;}
  1881. if(h>=level-tol&&c<level-tol){rd++;double bdyH=MathMax(o,c),uw=h-bdyH,rng=h-l;if(rng>0&&uw>rng*0.5)score+=5;}}}
  1882. score+=touches*3;score+=ru*8+rd*8;
  1883. if(touches>=4)score+=15;else if(touches>=3)score+=10;else if(touches>=2)score+=5;
  1884. return score;}
  1885. double FindBestHiddenRoundNumber(double curPrice){
  1886. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;int dg=(int)MarketInfo(Symbol(),MODE_DIGITS);if(dg<=0)dg=5;
  1887. double levels[];int levelCount=0;ArrayResize(levels,100);
  1888. double b100=MathFloor(curPrice/(100*pip))*(100*pip);for(int i=-1;i<=2;i++)AddRNLevel(levels,levelCount,b100+i*100*pip);
  1889. double b50=MathFloor(curPrice/(50*pip))*(50*pip);for(int i=-2;i<=3;i++)AddRNLevel(levels,levelCount,b50+i*50*pip);
  1890. double b25=MathFloor(curPrice/(25*pip))*(25*pip);for(int i=-3;i<=4;i++)AddRNLevel(levels,levelCount,b25+i*25*pip);
  1891. double b10=MathFloor(curPrice/(10*pip))*(10*pip);for(int i=-5;i<=6;i++)AddRNLevel(levels,levelCount,b10+i*10*pip);
  1892. double b5=MathFloor(curPrice/(5*pip))*(5*pip);for(int i=-4;i<=5;i++)AddRNLevel(levels,levelCount,b5+i*5*pip);
  1893. double bestLevel=0,bestScore=-1;
  1894. for(int i=0;i<levelCount;i++){double lv=levels[i],dist=MathAbs(curPrice-lv)/pip;if(dist>60)continue;double dp=(dist>40)?20:(dist>30)?10:(dist>20)?5:0;double sc=ScoreRoundNumber(lv,pip)-dp;if(sc<5)continue;if(sc>bestScore){bestScore=sc;bestLevel=lv;}}
  1895. if(bestLevel==0){double n100=MathRound(curPrice/(100*pip))*(100*pip),n50=MathRound(curPrice/(50*pip))*(50*pip),n25=MathRound(curPrice/(25*pip))*(25*pip),n10=MathRound(curPrice/(10*pip))*(10*pip),n5=MathRound(curPrice/(5*pip))*(5*pip);
  1896. double d100=MathAbs(curPrice-n100),d50=MathAbs(curPrice-n50),d25=MathAbs(curPrice-n25),d10=MathAbs(curPrice-n10);
  1897. if(d100<30*pip)bestLevel=n100;else if(d50<20*pip)bestLevel=n50;else if(d25<15*pip)bestLevel=n25;else if(d10<10*pip)bestLevel=n10;else bestLevel=n5;}
  1898. g_hrn_score=bestScore;return NormalizeDouble(bestLevel,dg);}
  1899. void ScanHRNLevels(){g_rj_cnt=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1900. 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];
  1901. 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++;}}}
  1902. 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++;}}}}
  1903. 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;}}
  1904. void UpdateHRN(){
  1905. if(Bars<LOOKBACK+10)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;int dg=(int)MarketInfo(Symbol(),MODE_DIGITS);if(dg<=0)dg=5;
  1906. if(Time[0]!=g_hrn_scan_bar){double nH=FindBestHiddenRoundNumber(Close[0]);if(g_hrn_price==0||MathAbs(nH-g_hrn_price)>2*pip){g_hrn_price=nH;g_hrn_is_sup=(Close[0]>g_hrn_price);g_hrn_brk_bars=0;g_hrn_confirmed_break=false;}g_hrn_scan_bar=Time[0];}
  1907. double tol=1*pip;
  1908. if(g_hrn_is_sup){if(Bars>=3){bool c1b=(Close[1]<g_hrn_price-tol),c2b=(Close[2]<g_hrn_price-tol);if(c1b&&c2b){g_hrn_confirmed_break=true;g_hrn_brk_bars=HRN_CONFIRM_BARS;}else if(c1b)g_hrn_brk_bars=1;else g_hrn_brk_bars=0;}}
  1909. else{if(Bars>=3){bool c1a=(Close[1]>g_hrn_price+tol),c2a=(Close[2]>g_hrn_price+tol);if(c1a&&c2a){g_hrn_confirmed_break=true;g_hrn_brk_bars=HRN_CONFIRM_BARS;}else if(c1a)g_hrn_brk_bars=1;else g_hrn_brk_bars=0;}}
  1910. if(g_hrn_brk_bars>=HRN_CONFIRM_BARS){double nH=FindBestHiddenRoundNumber(Close[0]);if(MathAbs(nH-g_hrn_price)>3*pip){g_hrn_price=nH;g_hrn_is_sup=(Close[0]>g_hrn_price);g_hrn_brk_bars=0;g_hrn_confirmed_break=false;}else{g_hrn_is_sup=(Close[0]>g_hrn_price);g_hrn_brk_bars=0;g_hrn_confirmed_break=false;}}
  1911. g_hrn_str=DoubleToString(NormalizeDouble(g_hrn_price,dg),dg);
  1912. color hrnColor=g_hrn_is_sup?NEON_GREEN:NEON_RED;if(g_hrn_brk_bars==1)hrnColor=NEON_YELLOW;
  1913. DrawHLine(PFX+"HRN_LINE",g_hrn_price,hrnColor,3,STYLE_SOLID);
  1914. string ln=PFX+"HRN_LBL";SafeDel(ln);string typeStr=g_hrn_is_sup?"SUP":"RES";string confStr=(g_hrn_brk_bars==1)?" [1/2]":(g_hrn_confirmed_break?" [SHIFTING]":"");
  1915. ObjectCreate(0,ln,OBJ_TEXT,0,Time[0]+Period()*60*2,g_hrn_price);ObjectSetText(ln,"HRN "+typeStr+" "+g_hrn_str+confStr,10,"Arial Bold",hrnColor);ObjectSetInteger(0,ln,OBJPROP_BACK,false);}
  1916. void DrawOtherPairsCube(int x,int y,int w,int h){
  1917. Bx("c20",x,y,w,h,BG_DARK2,NEON_GOLD);
  1918. Tx("c20_l",x+8,y+4,"OTHER PAIRS",NEON_CYAN,10,true);
  1919. if(g_pairCount==0){Tx("c20_v0",x+8,y+30,"No signals yet",CGR,10,false);Tx("c20_v1",x+8,y+52,"(need 2+ instances)",C'100,100,100',9,false);return;}
  1920. int lY=24;
  1921. for(int i=0;i<g_pairCount&&i<5;i++){
  1922. if(lY+16 > h-4) break;
  1923. string sp=g_pairNames[i];if(StringLen(sp)>9) sp=StringSubstr(sp,0,9);
  1924. int qScore=(int)g_pairConfs[i];string qLabel;if(qScore>=80)qLabel="[S]";else if(qScore>=65)qLabel="[G]";else if(qScore>=50)qLabel="[M]";else qLabel="[W]";
  1925. bool isCallSig=(g_mtgState=="CALL"||g_mtgState=="CALL TRAP");bool isPutSig=(g_mtgState=="PUT"||g_mtgState=="PUT TRAP");
  1926. bool ncpMatch=((isCallSig&&g_pairSigs[i]=="CALL")||(isPutSig&&g_pairSigs[i]=="PUT"));
  1927. color dc;string prefix="";if(ncpMatch){dc=NEON_PURPLE;prefix="* ";}else{dc=(g_pairSigs[i]=="CALL")?NEON_GREEN:NEON_RED;}
  1928. string txt=prefix+sp+" "+g_pairSigs[i]+" "+IntegerToString(qScore)+qLabel;
  1929. Tx("c20_p"+IntegerToString(i),x+8,y+lY,txt,dc,10,true);lY+=20;}
  1930. }
  1931. void DrawOTCQuickCube(int x,int y,int w,int h){
  1932. Bx("c_quick",x,y,w,h,BG_DARK2,NEON_LIME);Tx("c_quick_l",x+8,y+2,"OTC QUICK",NEON_CYAN,10,true);
  1933. int age=(int)(TimeCurrent()-Time[0]);int ps=Period()*60;int rem=ps-age;if(rem<0)rem=0;
  1934. int mm=rem/60,ss2=rem%60;string tl=(mm>0?IntegerToString(mm)+"m ":"")+IntegerToString(ss2)+"s";
  1935. Tx("c_quick_t",x+8,y+20,"Time: "+tl,NEON_GOLD,11,true);
  1936. double spread=MarketInfo(Symbol(),MODE_SPREAD);color spC=(spread<=BROKER_SPREAD_THRESHOLD)?NEON_GREEN:NEON_ORANGE;
  1937. Tx("c_quick_s",x+8,y+38,"Spread: "+DoubleToString(spread,0),spC,10,true);
  1938. double volLast=(double)iVolume(NULL,PERIOD_M1,1);double volPrev=(double)iVolume(NULL,PERIOD_M1,2);double volRatio=(volPrev>0)?volLast/volPrev:1.0;
  1939. bool candleBull=(Close[1]>Open[1]);bool candleBear=(Close[1]<Open[1]);color vColor;string vText;
  1940. if(candleBull){if(volRatio>=2.0){vColor=NEON_GREEN;vText="UP "+DoubleToString(volRatio,1)+"x HI";}else if(volRatio>=1.3){vColor=NEON_LIME;vText="UP "+DoubleToString(volRatio,1)+"x MD";}else if(volRatio>=0.8){vColor=NEON_CYAN;vText="UP "+DoubleToString(volRatio,1)+"x LO";}else{vColor=NEON_YELLOW;vText="UP "+DoubleToString(volRatio,1)+"x WK";}}
  1941. else if(candleBear){if(volRatio>=2.0){vColor=NEON_RED;vText="DN "+DoubleToString(volRatio,1)+"x HI";}else if(volRatio>=1.3){vColor=NEON_ORANGE;vText="DN "+DoubleToString(volRatio,1)+"x MD";}else if(volRatio>=0.8){vColor=NEON_PINK;vText="DN "+DoubleToString(volRatio,1)+"x LO";}else{vColor=NEON_YELLOW;vText="DN "+DoubleToString(volRatio,1)+"x";}}
  1942. else{vColor=NEON_YELLOW;vText="DOJI "+DoubleToString(volRatio,1)+"x";}
  1943. Tx("c_quick_v",x+8,y+56,vText,vColor,11,true);
  1944. string es=GetEntryStatus();color eC=GetEntryColor();Tx("c_quick_e",x+8,y+76,es,eC,10,true);}
  1945. string GetEntryStatus(){
  1946. int age=(int)(TimeCurrent()-Time[0]);int ps=Period()*60;int rem=ps-age;if(rem<0)rem=0;string ms=DetectMyStrategy();
  1947. if(ms!="WAIT"){string type=(g_strategyType=="TRAP")?"TRAP":"TREND";
  1948. if(ENTRY_MODE=="FLAG"){if(age<FLAG_MIN_SEC)return type+" WAIT "+IntegerToString(FLAG_MIN_SEC-age)+"s";if(rem<MIN_REMAINING_SEC)return type+" EXPIRED";if(age>FLAG_MAX_SEC)return type+" LATE";return type+" OPEN "+IntegerToString(rem)+"s";}
  1949. if(age<TIME_MIN_SEC)return type+" WAIT "+IntegerToString(TIME_MIN_SEC-age)+"s";if(age>TIME_MAX_SEC)return type+" CLOSED";return type+" OPEN "+IntegerToString(age)+"s";}
  1950. if(ENTRY_MODE=="FLAG"){if(age<FLAG_MIN_SEC)return "WAIT "+IntegerToString(FLAG_MIN_SEC-age)+"s";if(rem<MIN_REMAINING_SEC)return "EXPIRED";if(age>FLAG_MAX_SEC)return "LATE";return "OPEN "+IntegerToString(rem)+"s left";}
  1951. if(age<TIME_MIN_SEC)return "WAIT "+IntegerToString(TIME_MIN_SEC-age)+"s";if(age>TIME_MAX_SEC)return "CLOSED";return "OPEN "+IntegerToString(age)+"s";}
  1952. color GetEntryColor(){string s=GetEntryStatus();if(StringFind(s,"TRAP OPEN")>=0)return NEON_PURPLE;if(StringFind(s,"TREND OPEN")>=0)return NEON_LIME;if(StringFind(s,"OPEN")>=0)return NEON_GREEN;if(StringFind(s,"WAIT")>=0)return NEON_YELLOW;if(StringFind(s,"LATE")>=0||StringFind(s,"EXPIRED")>=0||StringFind(s,"CLOSED")>=0)return NEON_ORANGE;return NEON_RED;}
  1953. bool DirectionOK(){if(!ENABLE_ENTRY_ZONE)return true;double cur=Close[0],lo=Low[0],hi=High[0],rg=hi-lo;if(rg==0)return true;double pos=(cur-lo)/rg*100.0;if(MathMax(g_calc_gProb,g_calc_rProb)>=85)return true;string ms=DetectMyStrategy();if(ms=="CALL")return(pos>REVERSAL_PCT);if(ms=="PUT")return(pos<(100.0-REVERSAL_PCT));if(StringFind(g_adv1,"CALL")>=0)return(pos>REVERSAL_PCT&&(hi-cur)<rg*WICK_PCT);if(StringFind(g_adv1,"PUT")>=0)return(pos<(100.0-REVERSAL_PCT)&&(cur-lo)<rg*WICK_PCT);return true;}
  1954. bool EntryPrecisionOK(){if(TRADE_MODE=="GOD")return true;if(g_calc_gProb>80&&Close[0]<Open[0])return false;if(g_calc_rProb>80&&Close[0]>Open[0])return false;return true;}
  1955. bool ConsensusOK(){if(!CONSENSUS_FILTER)return true;string ms=DetectMyStrategy();if(ms=="WAIT")return true;bool haAgree=false;if(ms=="CALL"&&(g_haM1=="HA BULLISH 1"||g_haBoth=="BOTH BULL"))haAgree=true;if(ms=="PUT"&&(g_haM1=="HA BEARISH 1"||g_haBoth=="BOTH BEAR"))haAgree=true;return haAgree;}
  1956. void SendTelegramAlert(string message){
  1957. if(!ENABLE_TELEGRAM)return;if(StringLen(TELEGRAM_TOKEN)<10||StringLen(TELEGRAM_CHAT_ID)<5)return;
  1958. char post[];char result_data[];string result_headers;int timeout=5000;
  1959. int res=WebRequest("GET",url,"",timeout,post,result_data,result_headers);
  1960. if(res==-1)Print("Telegram failed: ",GetLastError());}
  1961.  
  1962. //+------------------------------------------------------------------+
  1963. // MAIN DRAW FUNCTION
  1964. //+------------------------------------------------------------------+
  1965. void Draw(){
  1966. HideSPM(); DelDashboard();
  1967. int W=DASH_W,G=8,CW=(W-2*G)/3,CH=110,cx=POS_X+G,yy=POS_Y;
  1968. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  1969. g_marketMode=DetectMarketMode(brain,g_rsc,cp,nb);
  1970. if(StringLen(g_prevMode)>0&&g_prevMode!=g_marketMode){g_signalTime=0;g_finalSignal="WAIT";}
  1971. g_prevMode=g_marketMode;
  1972. CalcOTCCrowd();UpdateAccuracy();UpdateWeights();
  1973. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();
  1974. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  1975. UpdateRiskControl();CheckMTFConfirmation();
  1976. double tfaScore=CalcAdvancedTFA(g_tfa_detail);
  1977. color ha1C=(g_haM1=="HA BULLISH 1")?NEON_GREEN:(g_haM1=="HA BEARISH 1")?NEON_RED:NEON_YELLOW;
  1978. color ha5C=(g_haM5=="HA BULLISH 5")?NEON_GREEN:(g_haM5=="HA BEARISH 5")?NEON_RED:NEON_YELLOW;
  1979. color biasClr;string biasStr=CalcAdvancedMarketBias(biasClr,brain,g_rsc);
  1980. string strategyMS=g_finalSignal;
  1981. color stratC=(g_strategyType=="TRAP")?NEON_PURPLE:(g_strategyType=="TREND")?NEON_GREEN:CGR;
  1982. string stratSig="";
  1983. if(g_strategyType=="TRAP"||g_strategyType=="TREND"){
  1984. if(StringFind(g_strategyReason,"CALL")>=0)stratSig="CALL";
  1985. else if(StringFind(g_strategyReason,"PUT")>=0)stratSig="PUT";}
  1986. string stratLabel=(g_strategyType=="TRAP")?"TRAP "+stratSig:(g_strategyType=="TREND")?"TREND "+stratSig:"NO STRATEGY";
  1987. string finalSig=g_finalSignal;color sigC=NEON_YELLOW;
  1988. if(ENABLE_BB_PULLBACK&&g_bbSignal!="--"&&(finalSig=="WAIT"||finalSig=="")){finalSig="BB "+g_bbSignal;sigC=g_bbColor;}
  1989. else{if(finalSig=="CALL")sigC=NEON_GREEN;else if(finalSig=="PUT")sigC=NEON_RED;else if(finalSig=="WEAK CALL")sigC=NEON_CYAN;else if(finalSig=="WEAK PUT")sigC=NEON_ORANGE;else sigC=NEON_YELLOW;}
  1990. Cube("c1",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"PAIR",NEON_CYAN,Symbol(),NEON_BLUE,13);
  1991. Bx("c2",cx+CW+G,yy,CW,CH,BG_DARK2,sigC);Tx("c2_l",cx+CW+G+10,yy+4,"SIGNAL",NEON_CYAN,10,true);Tx("c2_v",cx+CW+G+10,yy+26,finalSig,sigC,13,true);
  1992. if(ENABLE_BB_PULLBACK){string ha30Txt=Is30SecHABull()?"HA30:BULL":Is30SecHABear()?"HA30:BEAR":"HA30:DOJI";color ha30C=Is30SecHABull()?NEON_GREEN:Is30SecHABear()?NEON_RED:NEON_YELLOW;Tx("c2_ha30",cx+CW+G+10,yy+60,ha30Txt,ha30C,9,false);if(g_bbSignal!="--")Tx("c2_bb",cx+CW+G+10,yy+78,g_bbDetail,g_bbColor,9,false);}
  1993. double gP,rP;string rsn;color pClr;CalcAdvancedPrediction(gP,rP,rsn,pClr);
  1994. g_frozen_gProb=gP;g_frozen_rProb=rP;g_frozen_pAction=rsn;g_frozen_pColor=pClr;g_last_freeze_bar=Time[0];
  1995. Bx("c_pred",cx+2*(CW+G),yy,CW,CH,BG_DARK2,pClr);Tx("c_pred_l",cx+2*(CW+G)+10,yy+4,"NEXT CANDLE",NEON_CYAN,10,true);
  1996. int bW=CW-20,gBW=(int)(gP/100.0*bW),rBW=(int)(rP/100.0*bW);if(gBW<3)gBW=3;if(rBW<3)rBW=3;
  1997. Bx("c_pred_gbg",cx+2*(CW+G)+10,yy+22,bW,7,BG_DARK4,BG_DARK4);Bx("c_pred_gfg",cx+2*(CW+G)+10,yy+22,gBW,7,NEON_GREEN,NEON_GREEN);Tx("c_pred_gp",cx+2*(CW+G)+10,yy+31,"G:"+DoubleToString(gP,0)+"%",NEON_GREEN,11,true);
  1998. Bx("c_pred_rbg",cx+2*(CW+G)+10,yy+48,bW,7,BG_DARK4,BG_DARK4);Bx("c_pred_rfg",cx+2*(CW+G)+10,yy+48,rBW,7,NEON_RED,NEON_RED);Tx("c_pred_rp",cx+2*(CW+G)+10,yy+57,"R:"+DoubleToString(rP,0)+"%",NEON_RED,11,true);
  1999. Tx("c_pred_a",cx+2*(CW+G)+10,yy+76,rsn,pClr,11,true);NeonBar("c_pred_b",cx+2*(CW+G)+10,yy+92,bW,7,MathMax(gP,rP),pClr);yy+=CH+G;
  2000. 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,16);NeonBar("c7b",cx+12,yy+92,CW-24,7,nb,(nb>72)?NEON_ORANGE:(nb<35)?NEON_CYAN:NEON_GREEN);
  2001. Bx("c8",cx+CW+G,yy,CW,CH,BG_DARK2,NEON_CYAN);Tx("c8_l",cx+CW+G+10,yy+4,"CROWD",NEON_CYAN,10,true);Tx("c8_c",cx+CW+G+10,yy+24,"CALL "+IntegerToString(g_otcCallPct)+"%",NEON_RED,14,true);Tx("c8_p",cx+CW+G+10,yy+54,"PUT "+IntegerToString(g_otcPutPct)+"%",NEON_GREEN,14,true);Tx("c8_b",cx+CW+G+10,yy+86,"OTC Crowd",NEON_GOLD,9,false);
  2002. color sClr=CGR;string sName=GetCurrentSession(sClr);bool isAct=IsSessionActive();
  2003. Bx("c_ses",cx+2*(CW+G),yy,CW,CH,BG_DARK2,sClr);Tx("c_ses_l",cx+2*(CW+G)+10,yy+4,"SESSION",NEON_CYAN,10,true);Tx("c_ses_v",cx+2*(CW+G)+10,yy+22,sName,sClr,14,true);
  2004. int gH=TimeHour(TimeGMT()),gMn=TimeMinute(TimeGMT());Tx("c_ses_t",cx+2*(CW+G)+10,yy+54,"GMT "+(gH<10?"0":"")+IntegerToString(gH)+":"+(gMn<10?"0":"")+IntegerToString(gMn),NEON_WHITE,11,false);Tx("c_ses_s",cx+2*(CW+G)+10,yy+76,isAct?"ACTIVE":"LOW VOL",isAct?NEON_GREEN:NEON_ORANGE,11,true);yy+=CH+G;
  2005. DrawOtherPairsCube(cx,yy,CW,CH);DrawOTCQuickCube(cx+CW+G,yy,CW,CH);
  2006. Bx("c_brain_r3",cx+2*(CW+G),yy,CW,CH,BG_DARK3,NEON_CYAN);Tx("c_brain_r3_l",cx+2*(CW+G)+10,yy+5,"BRAIN",NEON_CYAN,10,true);color brainClr3=(brain>0)?NEON_GREEN:NEON_RED;
  2007. Tx("c_brain_r3_v",cx+2*(CW+G)+10,yy+28,(brain>=0?"+":"")+DoubleToString(brain,1),brainClr3,22,true);Tx("c_brain_r3_s",cx+2*(CW+G)+10,yy+72,stratLabel,stratC,10,false);NeonBar("c_brain_r3_b",cx+2*(CW+G)+12,yy+92,CW-24,7,MathMin(100,MathAbs(brain)*8+50),(brain>0)?NEON_GREEN:NEON_RED);yy+=CH+G;
  2008. int CH4=120;color maC;if(mai>72)maC=NEON_ORANGE;else if(mai>55)maC=NEON_YELLOW;else if(mai>45)maC=NEON_CYAN;else maC=NEON_GREEN;
  2009. Cube("c_mai",cx,yy,CW,CH4,maC,BG_DARK2,"MICRO AI",NEON_CYAN,DoubleToString(mai,0)+"%",maC,16);NeonBar("c_mai_b",cx+12,yy+104,CW-24,7,mai,maC);
  2010. color mtsC=(mts>=90)?NEON_PURPLE:(mts>=75)?NEON_RED:(mts>=50)?NEON_ORANGE:NEON_GREEN;Cube("c_mts",cx+CW+G,yy,CW,CH4,mtsC,BG_DARK2,"MICRO TRAP",NEON_CYAN,"SCORE "+IntegerToString(mts),mtsC,14);NeonBar("c_mts_b",cx+CW+G+12,yy+104,CW-24,7,MathMin(100,mts),mtsC);
  2011. int tfaInt=(int)tfaScore;color tfaColor;string tfaLabel;if(tfaInt>=5){tfaLabel="STRONG";tfaColor=NEON_GREEN;}else if(tfaInt>=4){tfaLabel="GOOD";tfaColor=NEON_LIME;}else if(tfaInt>=3){tfaLabel="MEDIUM";tfaColor=NEON_YELLOW;}else if(tfaInt>=2){tfaLabel="WEAK";tfaColor=NEON_ORANGE;}else{tfaLabel="POOR";tfaColor=C'100,100,120';}
  2012. color tfaBC=tfaColor;string dirTxt="";if(g_haM1=="HA BEARISH 1"){tfaBC=NEON_RED;dirTxt="[DOWN]";}else if(g_haM1=="HA BULLISH 1"){tfaBC=NEON_GREEN;dirTxt="[UP]";}else dirTxt="[MIX]";
  2013. Bx("c_tfa",cx+2*(CW+G),yy,CW,CH4,BG_DARK3,tfaBC);Tx("c_tfa_l",cx+2*(CW+G)+10,yy+4,"TFA SCORE",NEON_CYAN,10,true);Tx("c_tfa_v",cx+2*(CW+G)+10,yy+22,IntegerToString(tfaInt)+"/6 "+tfaLabel,tfaBC,12,true);Tx("c_tfa_dir",cx+2*(CW+G)+10,yy+44,dirTxt,tfaBC,11,true);
  2014. string tdet=g_tfa_detail;int pp=StringFind(tdet," | ");string td1=(pp>=0)?StringSubstr(tdet,0,pp):tdet;string td2=(pp>=0)?StringSubstr(tdet,pp+3):"";if(StringLen(td1)>24)td1=StringSubstr(td1,0,23);if(StringLen(td2)>24)td2=StringSubstr(td2,0,23);
  2015. Tx("c_tfa_d1",cx+2*(CW+G)+10,yy+62,td1,CGR,8,false);if(StringLen(td2)>0)Tx("c_tfa_d2",cx+2*(CW+G)+10,yy+76,td2,CGR,8,false);
  2016. int tfaFW=(int)((double)tfaInt/6.0*(CW-20));if(tfaFW<2)tfaFW=2;if(tfaFW>CW-20)tfaFW=CW-20;Bx("c_tfa_bb",cx+2*(CW+G)+10,yy+104,CW-20,7,BG_DARK4,BG_DARK4);Bx("c_tfa_bf",cx+2*(CW+G)+10,yy+104,tfaFW,7,tfaBC,tfaBC);yy+=CH4+G;
  2017. int CH5=120;
  2018. if(ENABLE_MTG){
  2019. bool isTrap=(g_mtgState=="PUT TRAP"||g_mtgState=="CALL TRAP");color mtgC=g_mtgClr;if(mtgC==CGR||mtgC==clrGray)mtgC=C'55,65,85';color borderC=isTrap?NEON_PURPLE:mtgC;
  2020. Bx("c_mtg",cx,yy,CW,CH5,BG_DARK2,borderC);string runStr="";if(g_mtgBullCount>=2)runStr=" "+IntegerToString(g_mtgBullCount)+"G-RUN";else if(g_mtgBearCount>=2)runStr=" "+IntegerToString(g_mtgBearCount)+"R-RUN";
  2021. Tx("c_mtg_l",cx+10,yy+4,"NCP PRO"+runStr,NEON_PURPLE,9,true);int stateFS=isTrap?11:13;Tx("c_mtg_s",cx+10,yy+20,g_mtgState,mtgC,stateFS,true);
  2022. int cW=(int)(g_mtgHype/100.0*(CW-22));if(cW<2)cW=2;if(cW>CW-22)cW=CW-22;color cBarC=(g_mtgHype>=g_mtgBetrayal)?NEON_GREEN:C'35,70,35';Bx("c_mtg_cbb",cx+10,yy+42,CW-22,6,BG_DARK4,BG_DARK4);Bx("c_mtg_cbf",cx+10,yy+42,cW,6,cBarC,cBarC);Tx("c_mtg_ct",cx+10,yy+50,"CALL: "+DoubleToString(g_mtgHype,1)+"%",NEON_GREEN,10,true);
  2023. int pW=(int)(g_mtgBetrayal/100.0*(CW-22));if(pW<2)pW=2;if(pW>CW-22)pW=CW-22;color pBarC=(g_mtgBetrayal>g_mtgHype)?NEON_RED:C'70,25,25';Bx("c_mtg_pbb",cx+10,yy+66,CW-22,6,BG_DARK4,BG_DARK4);Bx("c_mtg_pbf",cx+10,yy+66,pW,6,pBarC,pBarC);Tx("c_mtg_pt",cx+10,yy+74,"PUT: "+DoubleToString(g_mtgBetrayal,1)+"%",NEON_RED,10,true);
  2024. string actD=g_mtgAction;if(StringLen(actD)>24)actD=StringSubstr(actD,0,23);color actC=isTrap?NEON_PURPLE:(g_mtgState=="CALL")?NEON_GREEN:(g_mtgState=="PUT")?NEON_RED:NEON_YELLOW;Tx("c_mtg_a",cx+10,yy+88,actD,actC,10,true);
  2025. string rsnD=(StringLen(g_mtgReason)>0)?g_mtgReason:g_mtgPattern;if(StringLen(rsnD)>24)rsnD=StringSubstr(rsnD,0,23);Tx("c_mtg_r",cx+10,yy+104,rsnD,CGR,8,false);
  2026. } else {
  2027. double frac=CalcAdvancedFractal();color frC=(frac>=75)?NEON_RED:(frac>=50)?NEON_ORANGE:(frac>=25)?NEON_YELLOW:NEON_GREEN;string frT=(frac>=75)?"TRAP ZONE!":(frac>=50)?"WARNING":(frac>=25)?"CAUTION":"CLEAR";
  2028. Cube("c_frc",cx,yy,CW,CH5,frC,BG_DARK2,"FRACTAL",NEON_CYAN,frT,frC,13);NeonBar("c_frc_b",cx+12,yy+104,CW-24,7,frac,frC);
  2029. }
  2030. Bx("c_bias",cx+CW+G,yy,CW,CH5,BG_DARK2,biasClr);Tx("c_bias_l",cx+CW+G+10,yy+4,"MARKET BIAS",NEON_CYAN,10,true);string bStr=biasStr;if(StringLen(bStr)>13)bStr=StringSubstr(bStr,0,12);Tx("c_bias_v",cx+CW+G+10,yy+22,bStr,biasClr,13,true);
  2031. Tx("c_bias_m",cx+CW+G+10,yy+52,"MODE: "+g_marketMode,(g_marketMode=="TREND")?NEON_GREEN:(g_marketMode=="REVERSAL")?NEON_RED:NEON_YELLOW,10,false);color accC=(g_accuracy>=70)?NEON_GREEN:(g_accuracy>=60)?NEON_YELLOW:NEON_RED;Tx("c_bias_a",cx+CW+G+10,yy+72,"ACC: "+DoubleToString(g_accuracy,1)+"%",accC,10,false);NeonBar("c_bias_b",cx+CW+G+10,yy+88,CW-20,7,g_accuracy,accC);
  2032. int dg_sr=(int)MarketInfo(Symbol(),MODE_DIGITS);if(dg_sr<=0)dg_sr=5;Bx("c18",cx+2*(CW+G),yy,CW,CH5,BG_DARK2,NEON_CYAN);Tx("c18_l",cx+2*(CW+G)+10,yy+4,"S/R LEVELS",NEON_CYAN,10,true);
  2033. Tx("c18_r",cx+2*(CW+G)+10,yy+24,"R: "+(g_nearest_res>0?DoubleToString(g_nearest_res,dg_sr):"--"),NEON_RED,13,true);Tx("c18_s",cx+2*(CW+G)+10,yy+54,"S: "+(g_nearest_sup>0?DoubleToString(g_nearest_sup,dg_sr):"--"),NEON_GREEN,13,true);Tx("c18_b",cx+2*(CW+G)+10,yy+86,g_brk_str,g_brk_color,11,true);yy+=CH5+G;
  2034. int CH6=120;color wickC=(mw>0.70)?NEON_RED:(mw>0.50)?NEON_ORANGE:NEON_GREEN;Bx("c15",cx,yy,CW,CH6,BG_DARK2,wickC);Tx("c15_l",cx+10,yy+4,"WICKS",NEON_CYAN,10,true);Tx("c15_v",cx+10,yy+26,DoubleToString(mw,2),wickC,18,true);Tx("c15_b",cx+10,yy+62,(mw>0.70)?"KILL SHOT":(mw>0.50)?"HIGH":"LOW",wickC,11,false);NeonBar("c15_bar",cx+10,yy+80,CW-20,7,mw*100,wickC);
  2035. Bx("c_ha",cx+CW+G,yy,CW,CH6,BG_DARK2,ha1C);Tx("c_ha_l",cx+CW+G+10,yy+4,"HA CANDLES",NEON_CYAN,10,true);string haM1txt=g_haM1,haM5txt=g_haM5;if(StringLen(haM1txt)>16)haM1txt=StringSubstr(haM1txt,3);if(StringLen(haM5txt)>16)haM5txt=StringSubstr(haM5txt,3);
  2036. Tx("c_ha_m1",cx+CW+G+10,yy+24,"M1: "+haM1txt,ha1C,11,true);Tx("c_ha_m5",cx+CW+G+10,yy+50,"M5: "+haM5txt,ha5C,11,true);
  2037. string haComb="";color haCombC=NEON_YELLOW;if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5"){haComb="BOTH BULL";haCombC=NEON_GREEN;}else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5"){haComb="BOTH BEAR";haCombC=NEON_RED;}else if(g_haBoth=="MIXED")haComb="MIXED";else haComb=g_haBoth;Tx("c_ha_c",cx+CW+G+10,yy+76,haComb,haCombC,11,true);
  2038. string revReason=DetectSuddenReversal();color revColor=NEON_YELLOW;if(StringFind(revReason,"BULL")>=0)revColor=NEON_GREEN;if(StringFind(revReason,"BEAR")>=0)revColor=NEON_RED;Bx("c_reason",cx+2*(CW+G),yy,CW,CH6,BG_DARK2,revColor);Tx("c_reason_l",cx+2*(CW+G)+10,yy+4,"REVERSAL",NEON_CYAN,10,true);Tx("c_reason_v",cx+2*(CW+G)+10,yy+36,(StringLen(revReason)>0?revReason:"No reversal"),revColor,10,false);yy+=CH6+G;
  2039. if(ENABLE_BB_PULLBACK){
  2040. int bbRowH=52;color bbRowBorder=(g_bbSignal=="CALL")?NEON_GREEN:(g_bbSignal=="PUT")?NEON_RED:BB_GREY;Bx("c_bb_row",cx,yy,W-2*G,bbRowH,BG_DARK3,bbRowBorder);
  2041. string ha30Str=Is30SecHABull()?"BULL":Is30SecHABear()?"BEAR":"DOJI";color ha30C2=Is30SecHABull()?NEON_GREEN:Is30SecHABear()?NEON_RED:NEON_YELLOW;
  2042. double adxD=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);double rsiD=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);double bbU2=iBands(NULL,PERIOD_M1,BB_PERIOD,BB_DEVIATION,0,PRICE_CLOSE,MODE_UPPER,0);double bbL2=iBands(NULL,PERIOD_M1,BB_PERIOD,BB_DEVIATION,0,PRICE_CLOSE,MODE_LOWER,0);int dg3=(int)MarketInfo(Symbol(),MODE_DIGITS);if(dg3<=0)dg3=5;
  2043. Tx("c_bb_row_l",cx+10,yy+4,"BB("+IntegerToString(BB_PERIOD)+") PULLBACK",BB_GREY,9,true);Tx("c_bb_ha2",cx+190,yy+4,"HA30:"+ha30Str,ha30C2,9,true);Tx("c_bb_adx",cx+310,yy+4,"ADX:"+DoubleToString(adxD,0),adxD>=20?NEON_LIME:CGR,9,false);Tx("c_bb_rsi",cx+390,yy+4,"RSI:"+DoubleToString(rsiD,0),(rsiD>=70||rsiD<=30)?NEON_RED:CGR,9,false);
  2044. if(bbU2>0&&bbL2>0){Tx("c_bb_u2",cx+470,yy+4,"U:"+DoubleToString(bbU2,dg3),NEON_ORANGE,8,false);Tx("c_bb_d2",cx+570,yy+4,"L:"+DoubleToString(bbL2,dg3),NEON_CYAN,8,false);}
  2045. if(g_bbSignal!="--"){string sigTxt="BB "+g_bbSignal+" | "+g_bbDetail;if(StringLen(sigTxt)>60)sigTxt=StringSubstr(sigTxt,0,58)+"..";Tx("c_bb_sig2",cx+10,yy+22,sigTxt,g_bbColor,10,true);}
  2046. else{Tx("c_bb_sig2",cx+10,yy+22,"Waiting for BB touch + 2+ confirmations...",CGR,9,false);}yy+=bbRowH+G;
  2047. }
  2048. int bottomW=(W-2*G-2*G)/3,bottomH=106;yy+=4;int x1=cx;Bx("c_hrn",x1,yy,bottomW,bottomH,BG_DARK2,NEON_PINK);Tx("c_hrn_l",x1+8,yy+4,"HRN LEVEL",NEON_PINK,10,true);Tx("c_hrn_v",x1+8,yy+22,g_hrn_str,NEON_PINK,13,true);Tx("c_hrn_t",x1+8,yy+46,g_hrn_is_sup?"SUPPORT":"RESISTANCE",NEON_PINK,10,false);color scoreC=(g_hrn_score>=30)?NEON_GREEN:(g_hrn_score>=15)?NEON_YELLOW:NEON_ORANGE;Tx("c_hrn_sc",x1+8,yy+62,"Score: "+DoubleToString(g_hrn_score,0),scoreC,10,false);Tx("c_hrn_b",x1+8,yy+78,"Brk "+IntegerToString(g_hrn_brk_bars)+"/"+IntegerToString(HRN_CONFIRM_BARS),NEON_PINK,10,false);Tx("c_hrn_s",x1+8,yy+94,g_isSideways?"SIDEWAYS":"TRENDING",g_isSideways?NEON_YELLOW:NEON_GREEN,9,false);
  2049. int x2=x1+bottomW+G;Bx("c5",x2,yy,bottomW,bottomH,BG_DARK3,NEON_CYAN);Tx("c5_l",x2+10,yy+12,"SPM",NEON_CYAN,10,true);Tx("c5_v",x2+10,yy+44,(g_rsc>=0?"+":"")+DoubleToString(g_rsc,1),(g_rsc>0)?NEON_GREEN:NEON_RED,22,true);
  2050. int x3=x2+bottomW+G;Bx("c_strat_b",x3,yy,bottomW,bottomH,BG_DARK3,stratC);Tx("c_strat_b_l",x3+10,yy+6,"STRATEGY",NEON_CYAN,10,true);Tx("c_strat_b_v",x3+10,yy+30,stratLabel,stratC,11,true);Tx("c_strat_b_r",x3+10,yy+60,g_strategyReason,CGR,8,false);yy+=bottomH+5;
  2051. int fsW=W-2*G;color fsC=(g_filterStatus=="ALL CLEAR")?NEON_GREEN:(StringFind(g_filterStatus,"ACTIVE")>=0)?NEON_LIME:(StringFind(g_filterStatus,"LOCK")>=0)?NEON_RED:NEON_ORANGE;Bx("c_filter",cx,yy,fsW,22,BG_DARK3,fsC);Tx("c_filter_v",cx+10,yy+4,"FILTER: "+g_filterStatus,fsC,11,true);HideSPM();ChartRedraw();
  2052. }
  2053. void UpdateRiskControl(){static datetime llt=0;if(ENABLE_RISK_LOCK){if(g_lossStreak>=MAX_LOSS_STREAK){g_tradingStopped=true;llt=TimeCurrent();g_filterStatus="RISK LOCK "+IntegerToString(g_lossStreak)+"L";}if(g_tradingStopped&&TimeCurrent()-llt>3600){g_tradingStopped=false;g_lossStreak=0;g_filterStatus="RISK UNLOCK";}}}
  2054. void FinalSignalEngine(double brain,int cp,int mts){
  2055. g_filterStatus="ALL CLEAR";
  2056. if(ENABLE_RISK_CONTROL&&g_tradingStopped){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="RISK LOCKED";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2057. if(ENABLE_SESSION_FILTER&&!IsSessionActive()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="SESSION OFF";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2058. if(MTF_CONFIRM&&!g_mtfConfirmed){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="MTF NO CONF";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2059. if(ENABLE_SPIKE_FILTER&&IsBigCandle(1)){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="SPIKE BLOCK";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2060. if(ENABLE_LAST_SEC_BLOCK){int age=(int)(TimeCurrent()-Time[0]);int ps=Period()*60;int rem=ps-age;if(rem<0)rem=0;if(rem<MIN_REMAINING_SEC){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="LAST SEC BLOCK";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}}
  2061. double conf=MathMax(g_calc_gProb,g_calc_rProb);if(conf<MIN_CONFIDENCE){g_finalSignal="WAIT";g_finalColor=NEON_YELLOW;g_filterStatus="LOW CONF "+DoubleToString(conf,0)+"%";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2062. bool reverseSignal=(g_accuracy<45.0&&g_acc_total>20);if(reverseSignal)g_filterStatus="REVERSE MODE";
  2063. string ms=DetectMyStrategy();
  2064. if(ms!="WAIT"){
  2065. if(CONSENSUS_FILTER&&!ConsensusOK()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="NO CONSENSUS";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2066. if(ENABLE_ENTRY_ZONE&&!DirectionOK()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="BAD ENTRY ZONE";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2067. if(!EntryPrecisionOK()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="PRECISION FAIL";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2068. if(reverseSignal){if(ms=="CALL")ms="PUT";else if(ms=="PUT")ms="CALL";}
  2069. g_finalSignal=ms;g_finalColor=(ms=="CALL")?NEON_GREEN:NEON_RED;g_filterStatus=(g_strategyType=="TRAP")?"TRAP ACTIVE":"TREND ACTIVE";
  2070. if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT"){g_finalSignal=ms;g_signalTime=TimeCurrent();}SendSignalNotification(ms,conf);return;}
  2071. double th=FAST_MODE?70:68;string rawSignal="WAIT";
  2072. if(g_calc_gProb>th)rawSignal="CALL";else if(g_calc_rProb>th)rawSignal="PUT";else if(g_calc_gProb>60)rawSignal="WEAK CALL";else if(g_calc_rProb>60)rawSignal="WEAK PUT";
  2073. if(reverseSignal){if(rawSignal=="CALL")rawSignal="PUT";else if(rawSignal=="PUT")rawSignal="CALL";else if(rawSignal=="WEAK CALL")rawSignal="WEAK PUT";else if(rawSignal=="WEAK PUT")rawSignal="WEAK CALL";}
  2074. g_finalSignal=rawSignal;
  2075. if((g_finalSignal=="CALL"||g_finalSignal=="PUT")&&ENABLE_ENTRY_ZONE&&!DirectionOK()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="BAD ENTRY ZONE";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2076. if((g_finalSignal=="CALL"||g_finalSignal=="PUT")&&!EntryPrecisionOK()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="PRECISION FAIL";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}
  2077. if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT")g_signalTime=TimeCurrent();
  2078. if(g_finalSignal=="CALL"){g_finalColor=NEON_GREEN;g_filterStatus="GREEN SIGNAL";SendSignalNotification("CALL",conf);}
  2079. else if(g_finalSignal=="PUT"){g_finalColor=NEON_RED;g_filterStatus="RED SIGNAL";SendSignalNotification("PUT",conf);}
  2080. else if(g_finalSignal=="WEAK CALL"){g_finalColor=NEON_CYAN;g_filterStatus="WEAK GREEN";}
  2081. else if(g_finalSignal=="WEAK PUT"){g_finalColor=NEON_ORANGE;g_filterStatus="WEAK RED";}
  2082. else g_finalColor=NEON_YELLOW;}
  2083. void SendSignalNotification(string sig,double conf){if(!ENABLE_NOTIFY) return;string msg=Symbol()+" | "+sig+" | "+DoubleToString(conf,0)+"% | "+g_filterStatus;if(msg==g_lastNotified) return;g_lastNotified=msg;if(ENABLE_TELEGRAM) SendTelegramAlert("AIBRAIN\n"+Symbol()+"\n"+sig+"\nConf: "+DoubleToString(conf,0)+"%\n"+g_filterStatus);Print(msg);}
  2084. void BroadcastSignal(){
  2085. double conf=MathMax(g_frozen_gProb,g_frozen_rProb);if(conf<55)return;
  2086. string fn="OTC_Signals_Master.txt",pair=Symbol();string sig=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";
  2087. int exp=(int)(TimeCurrent()+65);string line=pair+"|"+sig+"|"+DoubleToString(conf,0)+"|"+IntegerToString((int)TimeCurrent())+"|"+IntegerToString(exp);
  2088. int h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);
  2089. 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;}
  2090. string content="";while(!FileIsEnding(h)){string ex=FileReadString(h);if(StringLen(ex)>10&&StringFind(ex,pair+"|")!=0)content+=ex+"\n";}
  2091. content=line+"\n"+content;string lns[];int cnt=0,pos=0;int f=StringFind(content,"\n",pos);
  2092. 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);}
  2093. if(pos<StringLen(content)){ArrayResize(lns,cnt+1);lns[cnt]=StringSubstr(content,pos);cnt++;}
  2094. if(cnt>50){content="";for(int i=0;i<50;i++)if(StringLen(lns[i])>10)content+=lns[i]+"\n";}
  2095. FileSeek(h,0,SEEK_SET);FileWriteString(h,content);FileFlush(h);FileClose(h);}
  2096. int CalcPairQuality(string pair,string &outSig,string &outDetail){
  2097. double o1=iOpen(pair,PERIOD_M1,1),h1=iHigh(pair,PERIOD_M1,1),l1=iLow(pair,PERIOD_M1,1),c1=iClose(pair,PERIOD_M1,1);
  2098. double o2=iOpen(pair,PERIOD_M1,2),h2=iHigh(pair,PERIOD_M1,2),l2=iLow(pair,PERIOD_M1,2),c2=iClose(pair,PERIOD_M1,2);
  2099. double o3=iOpen(pair,PERIOD_M1,3),c3=iClose(pair,PERIOD_M1,3);
  2100. if(o1==0||c1==0||o2==0||c2==0||o3==0||c3==0){outSig="WAIT";return 0;}
  2101. double haC1=(o1+h1+l1+c1)/4.0,haC2=(o2+h2+l2+c2)/4.0,haO2=(o3+c3)/2.0,haO1=(haO2+haC2)/2.0;
  2102. bool haM1Bull=(haC1>haO1),haM1Bear=(haC1<haO1);double haBody=MathAbs(haC1-haO1),haRange=(h1-l1);double haStrength=(haRange>0)?haBody/haRange:0;
  2103. double m5_o1=iOpen(pair,PERIOD_M5,1),m5_h1=iHigh(pair,PERIOD_M5,1),m5_l1=iLow(pair,PERIOD_M5,1),m5_c1=iClose(pair,PERIOD_M5,1);
  2104. double m5_o2=iOpen(pair,PERIOD_M5,2),m5_h2=iHigh(pair,PERIOD_M5,2),m5_l2=iLow(pair,PERIOD_M5,2),m5_c2=iClose(pair,PERIOD_M5,2);
  2105. double m5_o3=iOpen(pair,PERIOD_M5,3),m5_c3=iClose(pair,PERIOD_M5,3);
  2106. bool haM5Bull=false,haM5Bear=false;
  2107. if(m5_o1>0&&m5_c1>0&&m5_o2>0&&m5_c2>0&&m5_o3>0&&m5_c3>0){double m5haC1=(m5_o1+m5_h1+m5_l1+m5_c1)/4.0,m5haC2=(m5_o2+m5_h2+m5_l2+m5_c2)/4.0,m5haO2=(m5_o3+m5_c3)/2.0,m5haO1=(m5haO2+m5haC2)/2.0;haM5Bull=(m5haC1>m5haO1);haM5Bear=(m5haC1<m5haO1);}
  2108. double rsi=iRSI(pair,PERIOD_M1,14,PRICE_CLOSE,1);double vol1=(double)iVolume(pair,PERIOD_M1,1),vol2=(double)iVolume(pair,PERIOD_M1,2);double volRatio=(vol2>0)?vol1/vol2:1.0;double spread=(double)MarketInfo(pair,MODE_SPREAD);
  2109. int bullStreak=0,bearStreak=0;for(int i=1;i<=4;i++){double ci=iClose(pair,PERIOD_M1,i),oi=iOpen(pair,PERIOD_M1,i);if(ci==0||oi==0)break;if(ci>oi){if(bearStreak>0)break;bullStreak++;}else if(ci<oi){if(bullStreak>0)break;bearStreak++;}else break;}
  2110. bool bullDir=false,bearDir=false;
  2111. if(haM1Bull&&haM5Bull)bullDir=true;else if(haM1Bear&&haM5Bear)bearDir=true;else if(haM1Bull&&rsi<45)bullDir=true;else if(haM1Bear&&rsi>55)bearDir=true;
  2112. else{outSig="WAIT";return 0;}
  2113. int score=0;string det="";
  2114. if(bullDir&&haM1Bull){int s=(haStrength>0.6)?25:(haStrength>0.4)?18:12;score+=s;det+="HA1+";}
  2115. if(bearDir&&haM1Bear){int s=(haStrength>0.6)?25:(haStrength>0.4)?18:12;score+=s;det+="HA1+";}
  2116. if(bullDir&&haM5Bull){score+=15;det+="HA5+";}else if(bearDir&&haM5Bear){score+=15;det+="HA5+";}else det+="HA5-";
  2117. if(bullDir){if(rsi<30){score+=20;det+="RSI_OS ";}else if(rsi<40){score+=14;det+="RSI_low ";}else if(rsi<50){score+=8;det+="RSI_mid ";}else{score+=2;det+="RSI_hi ";}}
  2118. else{if(rsi>70){score+=20;det+="RSI_OB ";}else if(rsi>60){score+=14;det+="RSI_hi ";}else if(rsi>50){score+=8;det+="RSI_mid ";}else{score+=2;det+="RSI_lo ";}}
  2119. if(volRatio>=2.0){score+=15;det+="VOL_HI ";}else if(volRatio>=1.5){score+=10;det+="VOL_MD ";}else if(volRatio>=1.1){score+=5;det+="VOL_LO ";}
  2120. int streak=(bullDir)?bullStreak:bearStreak;if(streak>=3){score+=15;det+="STK"+IntegerToString(streak);}else if(streak>=2){score+=10;det+="STK"+IntegerToString(streak);}else if(streak>=1){score+=5;det+="STK1";}
  2121. if(spread<=3)score+=10;else if(spread<=6)score+=6;else if(spread<=10)score+=3;
  2122. outSig=bullDir?"CALL":"PUT";outDetail=det;return MathMin(100,score);
  2123. }
  2124. void ScanSignals(){
  2125. g_pairCount=0;string fn="OTC_Signals_Master.txt",cur=Symbol();
  2126. int h=FileOpen(fn,FILE_READ|FILE_TXT|FILE_SHARE_READ);if(h==INVALID_HANDLE) return;
  2127. datetime now=TimeCurrent();string tmpNames[8];string tmpSigs[8];double tmpConfs[8];int tmpScores[8];string tmpDetails[8];int tmpCount=0;
  2128. while(!FileIsEnding(h)&&tmpCount<8){
  2129. string ln=FileReadString(h);if(StringLen(ln)<15) continue;
  2130. int p1=StringFind(ln,"|"),p2=StringFind(ln,"|",p1+1),p3=StringFind(ln,"|",p2+1),p4=StringFind(ln,"|",p3+1);if(p1<0||p2<0||p3<0||p4<0) continue;
  2131. string pair=StringSubstr(ln,0,p1);if(pair==cur) continue;
  2132. string sig=StringSubstr(ln,p1+1,p2-p1-1);double conf=StringToDouble(StringSubstr(ln,p2+1,p3-p2-1));int expTime=(int)StringToInteger(StringSubstr(ln,p4+1));
  2133. if(conf<60) continue;if(expTime<(int)(now-20)) continue;
  2134. string qSig="WAIT",qDetail="";int qScore=CalcPairQuality(pair,qSig,qDetail);
  2135. if(qSig!=sig) continue;if(qScore<45) continue;
  2136. tmpNames[tmpCount]=pair;tmpSigs[tmpCount]=sig;tmpConfs[tmpCount]=conf;tmpScores[tmpCount]=qScore;tmpDetails[tmpCount]=qDetail;tmpCount++;}
  2137. FileClose(h);
  2138. for(int i=0;i<tmpCount-1;i++){for(int j=0;j<tmpCount-i-1;j++){if(tmpScores[j]<tmpScores[j+1]){string ts=tmpNames[j];tmpNames[j]=tmpNames[j+1];tmpNames[j+1]=ts;ts=tmpSigs[j];tmpSigs[j]=tmpSigs[j+1];tmpSigs[j+1]=ts;ts=tmpDetails[j];tmpDetails[j]=tmpDetails[j+1];tmpDetails[j+1]=ts;double td=tmpConfs[j];tmpConfs[j]=tmpConfs[j+1];tmpConfs[j+1]=td;int ti=tmpScores[j];tmpScores[j]=tmpScores[j+1];tmpScores[j+1]=ti;}}}
  2139. g_pairCount=MathMin(5,tmpCount);for(int i=0;i<g_pairCount;i++){g_pairNames[i]=tmpNames[i];g_pairSigs[i]=tmpSigs[i];g_pairConfs[i]=tmpScores[i];}
  2140. string curPred=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";int sameDir=0;double boostTotal=0;
  2141. for(int i=0;i<g_pairCount;i++){if(g_pairSigs[i]==curPred&&tmpScores[i]>=60){sameDir++;boostTotal+=tmpScores[i];}}
  2142. if(sameDir>=2&&!g_tradingStopped){double boost=MathMin(12.0,boostTotal/50.0);if(curPred=="CALL"){g_calc_gProb+=boost;g_calc_rProb-=boost;}else{g_calc_rProb+=boost;g_calc_gProb-=boost;}g_calc_gProb=MathMax(8.0,MathMin(92.0,g_calc_gProb));g_calc_rProb=100.0-g_calc_gProb;if(StringFind(g_filterStatus,"BOOST")<0) g_filterStatus="PAIR BOOST+"+DoubleToString(boost,0)+"%";}
  2143. }
  2144. void ReadSPM(){datetime cb=Time[0];if(cb==g_last_bar&&TimeCurrent()-g_spm_t<5)return;double v1=iCustom(NULL,PERIOD_M1,SPM_FILE,0,0),v2=iCustom(NULL,PERIOD_M1,SPM_FILE,1,0);if(v1!=EMPTY_VALUE&&v1!=0){double sm=0.7;g_rsc=g_rsc*(1.0-sm)+v1*sm;}if(v2!=EMPTY_VALUE&&v2!=0){double sm=0.7;g_tfa=g_tfa*(1.0-sm)+v2*sm;}g_last_bar=cb;g_spm_t=TimeCurrent();}
  2145. void UpdateTimer(){
  2146. 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;if(rem>ps) rem=ps;
  2147. int mm=rem/60,ss=rem%60;string t=(mm>0?IntegerToString(mm)+":":"")+(ss<10?"0":"")+IntegerToString(ss)+"s";
  2148. double atrVal=iATR(NULL,PERIOD_M1,14,0);double offset=(atrVal>0)?atrVal*0.25:Point*30;datetime tPos=Time[0]+8;double pPos=High[0]+offset;
  2149. if(ObjectFind(0,nm)<0){ObjectCreate(0,nm,OBJ_TEXT,0,tPos,pPos);ObjectSetInteger(0,nm,OBJPROP_BACK,false);ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false);ObjectSetInteger(0,nm,OBJPROP_HIDDEN,false);}
  2150. ObjectSetInteger(0,nm,OBJPROP_TIME,tPos);ObjectSetDouble(0,nm,OBJPROP_PRICE,pPos);ObjectSetText(nm,t,11,"Arial Bold",NEON_YELLOW);
  2151. }
  2152.  
  2153. 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);}
  2154. 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);}
  2155. 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);}
  2156. 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);}
  2157. int OnInit(){
  2158. InitNW();NuclearDeleteAll();g_hrn_price=0;g_hrn_brk_bars=0;g_hrn_scan_bar=0;g_hrn_score=0;g_hrn_confirmed_break=false;g_nearest_res=0;g_nearest_sup=0;g_rj_cnt=0;g_pairCount=0;
  2159. g_marketMode="RANGE";g_prevMode="";g_last_freeze_bar=0;g_lastNotified="";g_accuracy=ValidateHistoricalAccuracy();g_acc_correct=0;g_acc_total=0;g_acc_lastBar=0;
  2160. g_lastPredGreen=50.0;g_lastPredBar=0;g_lossStreak=0;g_tradingStopped=false;g_strategyType="NONE";g_frozen_gProb=50;g_frozen_rProb=50;g_calc_gProb=50;g_calc_rProb=50;
  2161. g_commonCount=0;g_wickLineCount=0;g_tfa_detail="";g_htfLevelCount=0;g_mtfConfirmed=true;g_filterStatus="ALL CLEAR";g_symbolKey="";g_brokerBias=0.0;
  2162. g_bbSignal="--";g_bbColor=NEON_YELLOW;g_bbTouchPrice=0.0;g_bbSignalTime=0;g_bbSignalBars=0;g_bbDetail="";
  2163. g_mtgHype=50;g_mtgBetrayal=50;g_mtgRecovery=0;g_mtgState="INIT";g_mtgReason="";g_mtgAction="";g_mtgClr=CGR;g_mtg_lastBar=0;g_mtgPattern="";
  2164. g_mtgBullCount=0;g_mtgBearCount=0;g_trapScore=0;g_smoothCallScore=50.0;g_smoothPutScore=50.0;
  2165. g_callWeight=1.0;g_putWeight=1.0;g_totalTrades=0;g_callTrades=0;g_putTrades=0;g_callWins=0;g_putWins=0;
  2166. g_ncpLastSignalTime=0;g_ncpLastSignalType="";g_ncpLastEntryPrice=0.0;g_ncpSignalProcessed=true;
  2167. if(ENABLE_LEARNING) LoadBrainMemory();g_ha30_open=0;g_ha30_close=0;g_ha30_high=0;g_ha30_low=0;g_ha30_bar=0;g_bbLineCount=0;
  2168. g_stableResCount=0; g_stableSupCount=0; g_lastSRScan=0;
  2169. LoadMLWeights();EventSetTimer(1);
  2170. Print("===========================================");Print("AIBRAIN v46.2 - STABLE S/R + NCP v7.3");Print("===========================================");
  2171. return INIT_SUCCEEDED;}
  2172. void OnDeinit(const int r){EventKillTimer();Comment("");for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)==0)ObjectDelete(nm);}}
  2173. void OnTimer(){
  2174. if(Bars<50)return;static datetime last5min=0;if(Time[0]/300!=last5min/300){DetectHiddenLevels();last5min=Time[0];}
  2175. ReadSPM();CalcHA();UpdateHRN();UpdateSR();DetectCommonPoints();DetectWickRejections();
  2176. DrawCommonPoints();DrawWickRejectLines();DrawHiddenLevels();DrawNearestSR();
  2177. if(ENABLE_BB_PULLBACK) DetectBBPullback();if(ENABLE_MTG) CalculateMTG();
  2178. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  2179. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  2180. ScanSignals();FinalSignalEngine(brain,cp,mts);BroadcastSignal();UpdateTimer();Draw();
  2181. }
  2182. int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],const double &open[],const double &high[],const double &low[],const double &close[],const long &tick_volume[],const long &volume[],const int &spread[]){return(rates_total);}
  2183. //+------------------------------------------------------------------+