1. //+------------------------------------------------------------------+
  2. //| AIBRAIN OTC v46.3 - NCP PRO v8.0 ADVANCED INTEGRATED |
  3. //| Fixed: S/R draw, CalcHA, NCP Engine, Dashboard Layout |
  4. //| Removed: HRN/SPM/Strategy cubes, Added ShortPrice, Purple Theme |
  5. //| Updated: MTF ANALYSIS replaced with PSYCHE BREAKER v3.0 |
  6. //| ALL ERRORS FIXED - CLEAN VERSION |
  7. //+------------------------------------------------------------------+
  8. #property copyright "AIBRAIN ULTIMATE - KM RANA"
  9. #property version "46.3"
  10. #property strict
  11. #property indicator_chart_window
  12.  
  13. #define PFX "AIB9_"
  14. #define VER "v46.3"
  15. #define LB 18
  16. #define MAX_LEVELS 5
  17. #define MAX_REJ 50
  18. #define LOOKBACK 50
  19.  
  20. input string SPM_FILE = "KM RANA";
  21. input int HOLD_SEC = 60;
  22. input int POS_X = 4;
  23. input int POS_Y = 20;
  24. input int DASH_W = 660;
  25. input bool SHOW_TIMER = true;
  26. input bool SHOW_SR_LINES = true;
  27. input string ENTRY_MODE = "TIME";
  28. input int FLAG_MIN_SEC = 10;
  29. input int FLAG_MAX_SEC = 35;
  30. input int TIME_MIN_SEC = 10;
  31. input int TIME_MAX_SEC = 35;
  32. input int MIN_REMAINING_SEC = 15;
  33. input double REVERSAL_PCT = 30.0;
  34. input double WICK_PCT = 0.65;
  35. input int HRN_CONFIRM_BARS = 2;
  36. input bool HA_ALIGN_FILTER = false;
  37. input bool CONSENSUS_FILTER = false;
  38. input bool ENABLE_NOTIFY = true;
  39. input bool FAST_MODE = false;
  40. input int BROKER_SPREAD_THRESHOLD= 6;
  41. input double OTC_TRAP_WEIGHT = 15.0;
  42. input int CROWD_EXTREME_PCT = 70;
  43. input bool ENABLE_BROKER_KILLER = true;
  44. input bool ENABLE_SESSION_FILTER = true;
  45. input bool ENABLE_SPIKE_FILTER = true;
  46. input bool ENABLE_LAST_SEC_BLOCK = true;
  47. input bool ENABLE_RISK_CONTROL = true;
  48. input bool ENABLE_ENTRY_ZONE = true;
  49. input bool ML_ADAPTIVE = true;
  50. input bool VOLUME_PROFILE_TRAP = true;
  51. input bool MTF_CONFIRM = false;
  52. input bool ENABLE_TELEGRAM = false;
  53. input string TELEGRAM_TOKEN = "";
  54. input string TELEGRAM_CHAT_ID = "";
  55. input string TRADE_MODE = "NORMAL";
  56. input string STRATEGY_MODE = "TRAP_ONLY";
  57. input int STRATEGY_THRESHOLD = 75;
  58. input int MAX_LOSS_STREAK = 2;
  59. input double MIN_CONFIDENCE = 75.0;
  60. input bool ENABLE_RISK_LOCK = true;
  61. input double PATTERN_TOLERANCE_PIPS = 8.0;
  62. input int MIN_PATTERN_SEPARATION = 5;
  63. input bool SHOW_COMMON_POINTS = true;
  64. input double COMMON_POINT_TOL_PIPS = 15.0;
  65. input bool SHOW_WICK_REJECT_LINES = true;
  66. input int WICK_MIN_TOUCHES = 1;
  67. input double WICK_ZONE_PIPS = 15.0;
  68. input int WICK_EXPIRE_BARS = 60;
  69.  
  70. // ============================================================
  71. // BB PULLBACK SETTINGS
  72. // ============================================================
  73. input bool ENABLE_BB_PULLBACK = true;
  74. input int BB_PERIOD = 20;
  75. input double BB_DEVIATION = 2.0;
  76. input int BB_SIGNAL_EXPIRE_BARS = 5;
  77.  
  78. // ============================================================
  79. // NCP PRO v8.0 ADVANCED SETTINGS
  80. // ============================================================
  81. input bool ENABLE_MTG = true;
  82. input int NCP_OpenNoiseSeconds = 3;
  83. input int NCP_KillZoneSeconds = 55;
  84. input double NCP_MaxSpreadPips = 4.0;
  85. input int NCP_ATRPeriod = 14;
  86. input double NCP_MinATRPips = 0.4;
  87. input int NCP_FastEMA = 3;
  88. input int NCP_MidEMA = 7;
  89. input int NCP_SlowEMA = 15;
  90. input bool NCP_UseM5Confirm = true;
  91. input bool NCP_UseVolume = true;
  92. input double NCP_RoundStepPips = 10.0;
  93. input double NCP_RoundTolPips = 4.0;
  94. input int NCP_MinProbMedium = 57;
  95. input int NCP_MinProbStrong = 63;
  96. input int NCP_MinProbExtreme = 70;
  97. input bool NCP_UseRSINorm = true;
  98. input int NCP_RSIPeriod = 10;
  99. input double NCP_RSIBase = 50.0;
  100. input double NCP_RSIM5Target = 45.0;
  101. input double NCP_RSIM15Target = 40.0;
  102. input bool ENABLE_LEARNING = true;
  103. input string MEMORY_FILE_NAME = "NCP_Brain_v8.csv";
  104. input int MIN_TRADES_TO_LEARN = 15;
  105. input double LEARNING_STEP = 0.025;
  106. input bool ENABLE_TRAP_DETECTION = true;
  107. input int TRAP_LOOKBACK = 30;
  108.  
  109. // ===== NEW NCP v8.0 ADVANCED SETTINGS =====
  110. input string NCP8_SECTION = "=== NCP v8.0 ADVANCED ===";
  111. input bool NCP8_UseM15Trend = true;
  112. input bool NCP8_UseDynamicSR = true;
  113. input bool NCP8_UsePatterns = true;
  114. input bool NCP8_UseMultiTF = true;
  115. input bool NCP8_UseColorPattern = true;
  116. input bool NCP8_UseHRNReject = true;
  117. input bool NCP8_UseOrderBlocks = true;
  118. input bool NCP8_UseDivergence = true;
  119. input int NCP8_MinConfidence = 65;
  120. input int NCP8_StrongConfidence = 78;
  121. input int NCP8_ExtremeConfidence = 88;
  122.  
  123. // ============================================================
  124. // PSYCHE BREAKER CONSTANTS
  125. // ============================================================
  126. #define PSYCHE_DOJI_THRESHOLD 0.10
  127. #define PSYCHE_WICK_THRESHOLD 0.55
  128. #define PSYCHE_WICK_CANDLES 12
  129. #define PSYCHE_VOL_SPIKE_MULT 3.0
  130. #define PSYCHE_SR_CLOSE_PIPS 3.0
  131. #define PSYCHE_SR_NEAR_PIPS 8.0
  132. #define PSYCHE_SR_FAR_PIPS 15.0
  133. #define PSYCHE_STRONG_THRESHOLD 80
  134.  
  135. #define NEON_GREEN C'0,255,100'
  136. #define NEON_RED C'255,40,80'
  137. #define NEON_YELLOW C'255,220,0'
  138. #define NEON_ORANGE C'255,120,0'
  139. #define NEON_CYAN C'0,255,200'
  140. #define NEON_PURPLE C'200,0,255'
  141. #define NEON_PINK C'255,80,180'
  142. #define NEON_BLUE C'0,200,255'
  143. #define NEON_LIME C'80,255,80'
  144. #define NEON_GOLD C'255,180,0'
  145. #define DARK_BLUE_NEON C'0,100,255'
  146. #define NEON_WHITE C'220,230,255'
  147. #define CGR C'160,170,190'
  148. #define BB_GREY C'180,180,190'
  149. #define BG_DARK1 C'6,8,16'
  150. #define BG_DARK2 C'10,14,24'
  151. #define BG_DARK3 C'14,20,32'
  152. #define BG_DARK4 C'18,26,40'
  153.  
  154. struct HTFLevel{ double price; string timeframe; string type; datetime time; int strength; bool isRoundNumber; };
  155.  
  156. struct NCPPatternResult {
  157. string name;
  158. int type;
  159. int strength;
  160. string category;
  161. };
  162.  
  163. struct NCPSRZone {
  164. double price;
  165. string type;
  166. int touches;
  167. int strength;
  168. bool isRoundNum;
  169. bool isOrderBlock;
  170. datetime lastTouch;
  171. };
  172.  
  173. struct NCPTrendInfo {
  174. string m15Direction;
  175. int m15Strength;
  176. int m1Bias;
  177. string m5Direction;
  178. int m5Strength;
  179. bool aligned;
  180. };
  181.  
  182. struct NCPMultiTF {
  183. double rsi_m1;
  184. double rsi_m5;
  185. double rsi_m15;
  186. int cci_m1;
  187. int cci_m5;
  188. int macd_m1_dir;
  189. int macd_m5_dir;
  190. double atr_m1;
  191. double atr_m5;
  192. bool ha_m1_bull;
  193. bool ha_m1_bear;
  194. bool ha_m5_bull;
  195. bool ha_m5_bear;
  196. int bullCount;
  197. int bearCount;
  198. };
  199.  
  200. //+------------------------------------------------------------------+
  201. // GLOBAL VARIABLES
  202. //+------------------------------------------------------------------+
  203. string g_haM1="",g_haM5="",g_haBoth="";
  204. color g_haM1Color=clrGray,g_haM5Color=clrGray;
  205. static double NW[36];
  206. static double g_rsc=0,g_tfa=3;
  207. static datetime g_spm_t=0,g_last_bar=0;
  208. static double g_nearest_res=0,g_nearest_sup=0;
  209. static string g_brk_str="NO BRK";
  210. static color g_brk_color=CGR;
  211. struct RejLevel{double price;int touches;};
  212. static RejLevel g_rj[MAX_REJ];
  213. static int g_rj_cnt=0;
  214.  
  215. static double g_hrn_price=0;
  216. static bool g_hrn_is_sup=true;
  217. static int g_hrn_brk_bars=0;
  218. static datetime g_hrn_scan_bar=0;
  219. static string g_hrn_str="--";
  220. static double g_hrn_score=0;
  221. static bool g_hrn_confirmed_break=false;
  222.  
  223. static int g_otcCallPct=50,g_otcPutPct=50;
  224. static string g_pairNames[8],g_pairSigs[8];
  225. static double g_pairConfs[8];
  226. static int g_pairCount=0;
  227. static double g_frozen_gProb=50,g_frozen_rProb=50;
  228. static string g_frozen_pAction="UNCERTAIN";
  229. static color g_frozen_pColor=NEON_YELLOW;
  230. static double g_calc_gProb=50,g_calc_rProb=50;
  231. static string g_calc_pAction="UNCERTAIN";
  232. static color g_calc_pColor=NEON_YELLOW;
  233. static double g_gProb=50,g_rProb=50;
  234. static string g_pAction="UNCERTAIN";
  235. static color g_pColor=NEON_YELLOW;
  236. static datetime g_last_freeze_bar=0;
  237. static double g_accuracy=65.0;
  238. static int g_acc_correct=0,g_acc_total=0;
  239. static datetime g_acc_lastBar=0;
  240. static double g_lastPredGreen=50.0;
  241. static datetime g_lastPredBar=0;
  242. static string g_finalSignal="WAIT";
  243. static color g_finalColor=NEON_YELLOW;
  244. static datetime g_signalTime=0;
  245. static string g_lastNotified="";
  246. static string g_marketMode="RANGE",g_prevMode="";
  247. static int g_lossStreak=0;
  248. static bool g_tradingStopped=false;
  249. static string g_strategyType="NONE";
  250. static string g_strategyReason="";
  251. static double qmrA=0,qmrB=0,qmrC=0,qmrD=0;
  252. static bool qmrActive=false;
  253. static datetime qmrExpire=0;
  254. #define MAX_COMMON_PTS 5
  255. static double g_commonPrice[MAX_COMMON_PTS];
  256. static datetime g_commonTime[MAX_COMMON_PTS];
  257. static int g_commonCount=0;
  258. static datetime g_commonExpire[MAX_COMMON_PTS];
  259. static string g_commonType[MAX_COMMON_PTS];
  260. static datetime g_lastCommonScan=0;
  261. #define MAX_WICK_LINES 5
  262. static double g_wickLinePrice[MAX_WICK_LINES];
  263. static int g_wickLineTouches[MAX_WICK_LINES];
  264. static datetime g_wickLineExpire[MAX_WICK_LINES];
  265. static int g_wickLineCount=0;
  266. static datetime g_lastWickScan=0;
  267. static bool g_isSideways=false;
  268. static string g_tfa_detail="";
  269. static HTFLevel g_htfLevels[50];
  270. static int g_htfLevelCount=0;
  271. static bool g_mtfConfirmed=true;
  272. static string g_filterStatus="ALL CLEAR";
  273. static string g_adv1="WAIT KAR";
  274. static string g_symbolKey="";
  275. static double g_brokerBias=0.0;
  276.  
  277. double g_stableRes[10];
  278. double g_stableSup[10];
  279. int g_stableResCount = 0;
  280. int g_stableSupCount = 0;
  281. datetime g_lastSRScan = 0;
  282. int g_srScanInterval = 5;
  283.  
  284. static string g_bbSignal = "--";
  285. static color g_bbColor = CGR;
  286. static double g_bbTouchPrice = 0.0;
  287. static datetime g_bbSignalTime = 0;
  288. static int g_bbSignalBars = 0;
  289. static string g_bbDetail = "";
  290.  
  291. static double g_ha30_open = 0.0;
  292. static double g_ha30_close = 0.0;
  293. static double g_ha30_high = 0.0;
  294. static double g_ha30_low = 0.0;
  295. static datetime g_ha30_bar = 0;
  296.  
  297. #define MAX_BB_LINES 8
  298. static double g_bbLinePrice[MAX_BB_LINES];
  299. static datetime g_bbLineExpire[MAX_BB_LINES];
  300. static string g_bbLineType[MAX_BB_LINES];
  301. static int g_bbLineCount=0;
  302.  
  303. // NCP PRO v8.0 GLOBALS
  304. static string g_mtgState = "INIT";
  305. static string g_mtgReason = "";
  306. static string g_mtgAction = "";
  307. static color g_mtgClr = CGR;
  308. static double g_mtgHype = 50.0;
  309. static double g_mtgBetrayal = 50.0;
  310. static string g_mtgPattern = "";
  311. static int g_mtgBullCount = 0;
  312. static int g_mtgBearCount = 0;
  313. static double g_mtgRecovery = 0.0;
  314. static datetime g_mtg_lastBar = 0;
  315. static double g_trapScore = 0;
  316. static double g_ncpADX = 0.0;
  317. static double g_ncpPlusDI = 0.0;
  318. static double g_ncpMinusDI = 0.0;
  319.  
  320. static double g_callWeight = 1.0;
  321. static double g_putWeight = 1.0;
  322. static int g_totalTrades = 0;
  323. static int g_callTrades = 0;
  324. static int g_putTrades = 0;
  325. static int g_callWins = 0;
  326. static int g_putWins = 0;
  327. static datetime g_ncpLastSignalTime = 0;
  328. static string g_ncpLastSignalType = "";
  329. static double g_ncpLastEntryPrice = 0.0;
  330. static bool g_ncpSignalProcessed = true;
  331. static double g_smoothCallScore = 50.0;
  332. static double g_smoothPutScore = 50.0;
  333.  
  334. static NCPTrendInfo g_ncpTrend;
  335. static NCPMultiTF g_ncpMultiTF;
  336. static NCPSRZone g_ncpSRZones[20];
  337. static int g_ncpSRCount = 0;
  338. static string g_ncpDetailLine1 = "";
  339. static string g_ncpDetailLine2 = "";
  340. static string g_ncpDetailLine3 = "";
  341. static int g_ncpPatternBullScore = 0;
  342. static int g_ncpPatternBearScore = 0;
  343. static string g_ncpMainPattern = "";
  344.  
  345. // ============================================================
  346. // PSYCHE BREAKER v3.0 GLOBALS
  347. // ============================================================
  348. static double g_psycheScore = 0;
  349. static string g_psycheDir = "NONE";
  350. static string g_psycheWick = "--";
  351. static string g_psycheVol = "--";
  352. static string g_psycheHA = "--";
  353. static string g_psycheSR = "--";
  354. static string g_psycheSignal = "SCANNING";
  355. static color g_psycheClr = CGR;
  356. static int g_psycheUpperWick= 0;
  357. static int g_psycheLowerWick= 0;
  358.  
  359. // ============================================================
  360. // OTC BROKER KILLER v4.0 - PROFESSIONAL TRAP ENGINE
  361. // ============================================================
  362. struct VisualTrapPro {
  363. string boxStatus, gannStatus, m30Dir, m1Seq, verdict;
  364. color gannColor, verdictColor;
  365. double callBias, putBias, trapScore;
  366. bool buySignal, sellSignal;
  367. };
  368. VisualTrapPro g_visualTrapPro;
  369. static datetime g_lastTrapArrowTime = 0;
  370.  
  371. //+------------------------------------------------------------------+
  372. // SHORT PRICE FUNCTION - For chart S/R labels
  373. //+------------------------------------------------------------------+
  374. string ShortPrice(double price){
  375. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS);
  376. if(dg < 2) dg = 5;
  377. return DoubleToString(price, dg);
  378. }
  379. string SRPrice(double price){ return ShortPrice(price); }
  380.  
  381. //+------------------------------------------------------------------+
  382. // DYNAMIC ADX COLOR FUNCTION
  383. //+------------------------------------------------------------------+
  384. color GetADXColor(double adx, double plusDI, double minusDI){
  385. if(adx < 15) return CGR;
  386. if(adx < 22) return NEON_ORANGE;
  387. double diDiff = plusDI - minusDI;
  388. if(diDiff > 10) return NEON_GREEN;
  389. if(diDiff > 5) return NEON_LIME;
  390. if(diDiff < -10) return NEON_RED;
  391. if(diDiff < -5) return C'255,100,100';
  392. return NEON_YELLOW;
  393. }
  394.  
  395. //+------------------------------------------------------------------+
  396. // M30 HA CANDLE (FIXED NAME)
  397. //+------------------------------------------------------------------+
  398. void CalcM30HACandle(){
  399. if(Bars < 5) return;
  400. if(iBars(NULL, PERIOD_M30) >= 2){
  401. g_ha30_open = iOpen(NULL, PERIOD_M30, 1);
  402. g_ha30_close = iClose(NULL, PERIOD_M30, 1);
  403. g_ha30_high = iHigh(NULL, PERIOD_M30, 1);
  404. g_ha30_low = iLow(NULL, PERIOD_M30, 1);
  405. g_ha30_bar = iTime(NULL, PERIOD_M30, 1);
  406. }
  407. else {
  408. g_ha30_open = Open[0];
  409. g_ha30_close = Close[0];
  410. g_ha30_high = High[0];
  411. g_ha30_low = Low[0];
  412. g_ha30_bar = Time[0];
  413. }
  414. }
  415.  
  416. bool IsM30HABull(){ return (g_ha30_close > g_ha30_open); }
  417. bool IsM30HABear(){ return (g_ha30_close < g_ha30_open); }
  418.  
  419. //+------------------------------------------------------------------+
  420. // UPGRADED BB PULLBACK - M30 HA PHOOLBAG ENGINE (FIXED REFS)
  421. //+------------------------------------------------------------------+
  422. void DetectBBPullback(){
  423. if(!ENABLE_BB_PULLBACK || Bars < BB_PERIOD + 5) return;
  424. CalcM30HACandle();
  425. double bbUpper0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 0);
  426. double bbLower0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 0);
  427. double bbMid0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_MAIN, 0);
  428. double bbUpper1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 1);
  429. double bbLower1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 1);
  430. if(bbUpper1 <= 0 || bbLower1 <= 0) return;
  431.  
  432. bool isHaM30Bull = IsM30HABull();
  433. bool isHaM30Bear = IsM30HABear();
  434. bool topPhoolbag = (g_ha30_high >= bbUpper0 * 0.9998) && (g_ha30_close < bbUpper0) && isHaM30Bear;
  435. bool bottomPhoolbag = (g_ha30_low <= bbLower0 * 1.0002) && (g_ha30_close > bbLower0) && isHaM30Bull;
  436.  
  437. double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  438. double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  439. double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  440. double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  441. bool adxValid = (adx >= 18);
  442. bool diBull = (plusDI > minusDI);
  443. bool diBear = (minusDI > plusDI);
  444.  
  445. double ha30Range = g_ha30_high - g_ha30_low;
  446. double topWick = (ha30Range > 0) ? (g_ha30_high - MathMax(g_ha30_open, g_ha30_close)) / ha30Range : 0;
  447. double bottomWick = (ha30Range > 0) ? (MathMin(g_ha30_open, g_ha30_close) - g_ha30_low) / ha30Range : 0;
  448.  
  449. bool isStrongTopPhoolbag = topPhoolbag && (topWick > 0.50);
  450. bool isStrongBottomPhoolbag = bottomPhoolbag && (bottomWick > 0.50);
  451.  
  452. int putConfirm = 0;
  453. if(isStrongTopPhoolbag) putConfirm += 3;
  454. else if(topPhoolbag) putConfirm += 2;
  455. if(diBear) putConfirm++;
  456. if(rsi > 55) putConfirm++;
  457. if(rsi > 65) putConfirm++;
  458.  
  459. int callConfirm = 0;
  460. if(isStrongBottomPhoolbag) callConfirm += 3;
  461. else if(bottomPhoolbag) callConfirm += 2;
  462. if(diBull) callConfirm++;
  463. if(rsi < 45) callConfirm++;
  464. if(rsi < 35) callConfirm++;
  465.  
  466. if(!adxValid) { putConfirm = 0; callConfirm = 0; }
  467.  
  468. string adxStr = "ADX:"+DoubleToString(adx,0)+(adxValid?"*":"");
  469. string rsiStr = "RSI:"+DoubleToString(rsi,0);
  470. string diStr = (diBull?"DI^":diBear?"DIv":"DI=");
  471. string haStr = isHaM30Bull?"HA30:BULL":isHaM30Bear?"HA30:BEAR":"HA30:DOJI";
  472.  
  473. if(g_bbSignal != "--" && g_bbSignalTime > 0){
  474. int barsElapsed = (int)((TimeCurrent() - g_bbSignalTime) / (Period() * 60));
  475. if(barsElapsed > BB_SIGNAL_EXPIRE_BARS){
  476. g_bbSignal = "--"; g_bbColor = NEON_YELLOW;
  477. g_bbDetail = ""; g_bbTouchPrice = 0.0;
  478. }
  479. }
  480.  
  481. string newSignal = "--";
  482. double touchPriceNew = 0.0;
  483. string detailNew = "";
  484. color newColor = NEON_YELLOW;
  485.  
  486. if(putConfirm >= 2){
  487. newSignal = "PUT";
  488. touchPriceNew = bbUpper0;
  489. string conf = (putConfirm>=4)?"STRONG PB":(putConfirm>=3)?"GOOD PB":"WEAK PB";
  490. detailNew = "PB UP|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr+"|"+haStr;
  491. newColor = (putConfirm >= 3) ? NEON_RED : NEON_ORANGE;
  492. }
  493. else if(callConfirm >= 2){
  494. newSignal = "CALL";
  495. touchPriceNew = bbLower0;
  496. string conf = (callConfirm>=4)?"STRONG PB":(callConfirm>=3)?"GOOD PB":"WEAK PB";
  497. detailNew = "PB LO|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr+"|"+haStr;
  498. newColor = (callConfirm >= 3) ? NEON_GREEN : NEON_CYAN;
  499. }
  500.  
  501. if(newSignal != "--"){
  502. bool isNew = (newSignal != g_bbSignal || touchPriceNew != g_bbTouchPrice);
  503. if(isNew){
  504. g_bbSignal = newSignal;
  505. g_bbTouchPrice = touchPriceNew;
  506. g_bbSignalTime = TimeCurrent();
  507. g_bbDetail = detailNew;
  508. g_bbColor = newColor;
  509. AddBBLine(touchPriceNew, newSignal);
  510. Print("BB PHOOLBAG: ",newSignal," | ",detailNew," Conf:",(newSignal=="PUT"?putConfirm:callConfirm),"/5");
  511. }
  512. } else if(g_bbSignal == "--"){
  513. g_bbColor = NEON_YELLOW;
  514. }
  515. DrawBBLines(bbUpper0, bbLower0, bbMid0);
  516. }
  517.  
  518. void DrawBBLines(double upper, double lower, double mid){
  519. if(!ENABLE_BB_PULLBACK) return;
  520. string nmU = PFX+"BB_UPPER"; SafeDel(nmU);
  521. if(upper > 0){ ObjectCreate(0, nmU, OBJ_HLINE, 0, 0, upper); ObjectSetInteger(0, nmU, OBJPROP_COLOR, BB_GREY); ObjectSetInteger(0, nmU, OBJPROP_WIDTH, 1); ObjectSetInteger(0, nmU, OBJPROP_STYLE, STYLE_DASH); ObjectSetInteger(0, nmU, OBJPROP_BACK, false); }
  522. string nmL = PFX+"BB_LOWER"; SafeDel(nmL);
  523. if(lower > 0){ ObjectCreate(0, nmL, OBJ_HLINE, 0, 0, lower); ObjectSetInteger(0, nmL, OBJPROP_COLOR, BB_GREY); ObjectSetInteger(0, nmL, OBJPROP_WIDTH, 1); ObjectSetInteger(0, nmL, OBJPROP_STYLE, STYLE_DASH); ObjectSetInteger(0, nmL, OBJPROP_BACK, false); }
  524. string nmM = PFX+"BB_MID"; SafeDel(nmM);
  525. if(mid > 0){ ObjectCreate(0, nmM, OBJ_HLINE, 0, 0, mid); ObjectSetInteger(0, nmM, OBJPROP_COLOR, C'100,100,110'); ObjectSetInteger(0, nmM, OBJPROP_WIDTH, 1); ObjectSetInteger(0, nmM, OBJPROP_STYLE, STYLE_DOT); ObjectSetInteger(0, nmM, OBJPROP_BACK, false); }
  526. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS); if(dg <= 0) dg = 5;
  527. string lblU = PFX+"BB_U_LBL"; SafeDel(lblU);
  528. if(upper > 0 && Bars > 2){ ObjectCreate(0, lblU, OBJ_TEXT, 0, Time[2], upper); ObjectSetText(lblU, "BB("+IntegerToString(BB_PERIOD)+")", 8, "Arial", BB_GREY); ObjectSetInteger(0, lblU, OBJPROP_BACK, false); }
  529. }
  530.  
  531. void AddBBLine(double price, string sigType){
  532. if(price <= 0) return;
  533. for(int i = 0; i < MAX_BB_LINES; i++){ SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i)); SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i)); }
  534. g_bbLineCount = 0; g_bbLinePrice[0] = price; g_bbLineExpire[0] = TimeCurrent() + 60 * BB_SIGNAL_EXPIRE_BARS; g_bbLineType[0] = sigType; g_bbLineCount = 1;
  535. DrawAllBBTouchLines();
  536. }
  537.  
  538. void DrawAllBBTouchLines(){
  539. for(int i = 0; i < MAX_BB_LINES; i++){ SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i)); SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i)); }
  540. if(g_bbLineCount > 0 && TimeCurrent() > g_bbLineExpire[0]){ g_bbLineCount = 0; return; }
  541. if(g_bbLineCount <= 0) return;
  542. string nm = PFX+"BB_TOUCH_0";
  543. string lbl = PFX+"BB_TOUCH_LBL_0";
  544. color lineColor = (g_bbLineType[0]=="CALL") ? NEON_GREEN : NEON_RED;
  545. ObjectCreate(0, nm, OBJ_HLINE, 0, 0, g_bbLinePrice[0]);
  546. ObjectSetInteger(0, nm, OBJPROP_COLOR, lineColor);
  547. ObjectSetInteger(0, nm, OBJPROP_WIDTH, 2);
  548. ObjectSetInteger(0, nm, OBJPROP_STYLE, STYLE_SOLID);
  549. ObjectSetInteger(0, nm, OBJPROP_BACK, false);
  550. if(Bars > 3){
  551. string txt = (g_bbLineType[0]=="CALL") ? "PB^ CALL" : "PBv PUT";
  552. ObjectCreate(0, lbl, OBJ_TEXT, 0, Time[3], g_bbLinePrice[0]);
  553. ObjectSetText(lbl, txt, 8, "Arial Bold", lineColor);
  554. ObjectSetInteger(0, lbl, OBJPROP_BACK, false);
  555. }
  556. }
  557.  
  558. // ============================================================
  559. // BROKER TRAP CALCULATOR
  560. // ============================================================
  561. double CalculateBrokerTrap(double callBias,double putBias){
  562. if(!ENABLE_TRAP_DETECTION||Bars<20) return 0;
  563. double trapScore=0;
  564. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  565. double pip=jpy?0.01:0.0001;
  566. for(int i=1;i<=15&&i<Bars-1;i++){
  567. bool bullEngulf=(Close[i]>Open[i])&&(Close[i-1]<Open[i-1])&&(Close[i]>=Open[i-1])&&(Open[i]<=Close[i-1]);
  568. bool bearEngulf=(Close[i]<Open[i])&&(Close[i-1]>Open[i-1])&&(Close[i]<=Open[i-1])&&(Open[i]>=Close[i-1]);
  569. if(i>=2){
  570. bool mornStar=(Close[i-2]<Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])<pip*3)&&(Close[i]>Open[i]);
  571. bool eveStar =(Close[i-2]>Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])<pip*3)&&(Close[i]<Open[i]);
  572. if(i>=3){
  573. if(bullEngulf&&Close[i-3]<Close[i-2]) trapScore+=3.5;
  574. if(bearEngulf&&Close[i-3]>Close[i-2]) trapScore+=3.5;
  575. if(mornStar&&Close[i-3]<Close[i-2]) trapScore+=3.0;
  576. if(eveStar&&Close[i-3]>Close[i-2]) trapScore+=3.0;
  577. }
  578. }
  579. double rng=High[i]-Low[i];
  580. if(rng<=0) continue;
  581. double uw=(High[i]-MathMax(Open[i],Close[i]))/rng;
  582. double lw=(MathMin(Open[i],Close[i])-Low[i])/rng;
  583. if(uw>0.55&&Close[i]<Open[i]) trapScore+=2.0;
  584. if(lw>0.55&&Close[i]>Open[i]) trapScore+=2.0;
  585. }
  586. double rng0=High[0]-Low[0];
  587. if(rng0>0){
  588. double uw0=(High[0]-MathMax(Open[0],Close[0]))/rng0;
  589. double lw0=(MathMin(Open[0],Close[0])-Low[0])/rng0;
  590. if(uw0>0.65&&Close[0]<Open[0]) trapScore+=4.0;
  591. if(lw0>0.65&&Close[0]>Open[0]) trapScore+=4.0;
  592. if(Close[0]>Open[0]&&Close[1]<Open[1]){
  593. if(Close[0]>Open[1]&&Open[0]<Close[1]) trapScore+=3.0;
  594. }
  595. if(Close[0]<Open[0]&&Close[1]>Open[1]){
  596. if(Close[0]<Open[1]&&Open[0]>Close[1]) trapScore+=3.0;
  597. }
  598. }
  599. double biasStr=MathMax(callBias,putBias)-50;
  600. double biasMul=1.0+biasStr/150.0;
  601. if(biasMul>1.5) biasMul=1.5;
  602. if(biasMul<0.5) biasMul=0.5;
  603. trapScore*=biasMul;
  604. return MathMin(100,trapScore);
  605. }
  606.  
  607. // ============================================================
  608. // HA CANDLE CALCULATION (FIXED ARRAY BOUNDS)
  609. // ============================================================
  610. void CalcHA(){
  611. if(Bars<10) return;
  612. bool wasOpenSeries=ArrayGetAsSeries(Open), wasHighSeries=ArrayGetAsSeries(High),
  613. wasLowSeries=ArrayGetAsSeries(Low), wasCloseSeries=ArrayGetAsSeries(Close);
  614. ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true);
  615. ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true);
  616.  
  617. static double haO1[500], haC1[500];
  618. static datetime lb1=0;
  619. ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true);
  620. datetime c1=iTime(NULL,PERIOD_M1,0);
  621. if(c1!=lb1){
  622. lb1=c1;
  623. int lim=MathMin(iBars(NULL,PERIOD_M1), 499); // FIX: Use 499
  624. for(int i=lim; i>=0; i--){ // FIX: Start from lim
  625. haC1[i] = (Open[i]+High[i]+Low[i]+Close[i])/4.0;
  626. if(i==lim) haO1[i] = (Open[i]+Close[i])/2.0; // FIX: Use lim
  627. else haO1[i] = (haO1[i+1] + haC1[i+1])/2.0;
  628. }
  629. }
  630.  
  631. double d1=MathAbs(haC1[1]-haO1[1]), r1=High[1]-Low[1];
  632. bool dz=(r1>0 && d1<r1*0.1), b1=(!dz && haC1[1]>haO1[1]), be1=(!dz && haC1[1]<haO1[1]);
  633. if(b1){ g_haM1="HA BULLISH 1"; g_haM1Color=clrLime; }
  634. else if(be1){ g_haM1="HA BEARISH 1"; g_haM1Color=clrRed; }
  635. else{ g_haM1="HA DOJI 1"; g_haM1Color=clrYellow; }
  636.  
  637. if(iBars(NULL,PERIOD_M5)>=10){
  638. static double haO5[200], haC5[200];
  639. static datetime lb5=0;
  640. ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true);
  641. datetime c5=iTime(NULL,PERIOD_M5,0);
  642. if(c5!=lb5){
  643. lb5=c5;
  644. int lim5=MathMin(iBars(NULL,PERIOD_M5), 199); // FIX: Use 199
  645. for(int i=lim5; i>=0; i--){ // FIX: Start from lim5
  646. double o=iOpen(NULL,PERIOD_M5,i), h=iHigh(NULL,PERIOD_M5,i),
  647. l=iLow(NULL,PERIOD_M5,i), c=iClose(NULL,PERIOD_M5,i);
  648. haC5[i]=(o+h+l+c)/4.0;
  649. if(i==lim5) haO5[i]=(o+c)/2.0; // FIX: Use lim5
  650. else haO5[i]=(haO5[i+1]+haC5[i+1])/2.0;
  651. }
  652. }
  653. double d5=MathAbs(haC5[1]-haO5[1]), r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1);
  654. bool dz5=(r5>0 && d5<r5*0.1), b5=(!dz5 && haC5[1]>haO5[1]), be5=(!dz5 && haC5[1]<haO5[1]);
  655. if(b5){ g_haM5="HA BULLISH 5"; g_haM5Color=clrLime; }
  656. else if(be5){ g_haM5="HA BEARISH 5"; g_haM5Color=clrRed; }
  657. else{ g_haM5="HA DOJI 5"; g_haM5Color=clrYellow; }
  658. if(b1&&b5) g_haBoth="BOTH BULL";
  659. else if(be1&&be5) g_haBoth="BOTH BEAR";
  660. else g_haBoth="MIXED";
  661. } else {
  662. g_haM5="5 --"; g_haM5Color=clrGray; g_haBoth="HA --";
  663. }
  664.  
  665. if(!wasOpenSeries) ArraySetAsSeries(Open,false);
  666. if(!wasHighSeries) ArraySetAsSeries(High,false);
  667. if(!wasLowSeries) ArraySetAsSeries(Low,false);
  668. if(!wasCloseSeries) ArraySetAsSeries(Close,false);
  669. }
  670.  
  671. // ============================================================
  672. // HELPERS
  673. // ============================================================
  674. bool IsLineNearby(double price,double pipTol=3.0){
  675. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip;
  676. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i);
  677. if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE){
  678. double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)<tol) return true; }}
  679. return false;
  680. }
  681.  
  682. string GetCurrentSession(color &sC){
  683. int h=TimeHour(TimeGMT());
  684. if(h>=12&&h<16){sC=NEON_GOLD;return "LON+NY";}
  685. if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";}
  686. if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";}
  687. if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";}
  688. if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";}
  689. sC=C'100,100,120'; return "SYDNEY";
  690. }
  691.  
  692. bool IsSessionActive(){int h=TimeHour(TimeGMT());return(h>=7&&h<=21);}
  693. 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);}
  694.  
  695. bool CheckMTFConfirmation(){
  696. if(!MTF_CONFIRM) return true;
  697. bool m1Bull=(Close[1]>Open[1]);
  698. bool m5Bull=false,m15Bull=false;
  699. if(iBars(NULL,PERIOD_M5)>=3) m5Bull=(iClose(NULL,PERIOD_M5,1)>iOpen(NULL,PERIOD_M5,1));
  700. if(iBars(NULL,PERIOD_M15)>=3) m15Bull=(iClose(NULL,PERIOD_M15,1)>iOpen(NULL,PERIOD_M15,1));
  701. int bullCount=0,bearCount=0;
  702. if(m1Bull) bullCount++; else bearCount++;
  703. if(m5Bull) bullCount++; else bearCount++;
  704. if(m15Bull) bullCount++; else bearCount++;
  705. g_mtfConfirmed=(bullCount>=2 || bearCount>=2);
  706. return g_mtfConfirmed;
  707. }
  708.  
  709. double Tanh(double x){double e=MathExp(2.0*x);return(e-1.0)/(e+1.0);}
  710.  
  711. double CalcAdvancedMicroAI(){
  712. if(Bars<20) return 50.0;
  713. double score=50.0;
  714. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  715. double pip=jpy?0.01:0.0001;
  716. for(int i=1;i<=5;i++){
  717. double r=High[i]-Low[i]; if(r<=0) continue;
  718. double uw=(High[i]-MathMax(Open[i],Close[i]))/r;
  719. double lw=(MathMin(Open[i],Close[i])-Low[i])/r;
  720. double w=(6.0-i)/5.0;
  721. if(uw>0.65) score-=w*18; else if(uw>0.50) score-=w*10;
  722. if(lw>0.65) score+=w*18; else if(lw>0.50) score+=w*10;
  723. }
  724. double pos5=0;
  725. for(int i=1;i<=5;i++){double r=High[i]-Low[i]; if(r<=0) continue; pos5+=(Close[i]-Low[i])/r; }
  726. score+=(pos5/5.0-0.5)*25.0;
  727. double gc=0,rc=0;
  728. for(int i=1;i<=8;i++){double w=(9.0-i)/8.0; if(Close[i]>Open[i]) gc+=w; else if(Close[i]<Open[i]) rc+=w;}
  729. score+=(gc-rc)*4.0;
  730. double vl1=(double)iVolume(NULL,PERIOD_M1,1),vA=0;
  731. for(int i=2;i<=6;i++) vA+=iVolume(NULL,PERIOD_M1,i);
  732. vA/=5.0;
  733. if(vA>0){double vr=vl1/vA; if(vr>2.0&&Close[1]>Open[1]) score+=12; else if(vr>2.0&&Close[1]<Open[1]) score-=12; else if(vr>1.5&&Close[1]>Open[1]) score+=7; else if(vr>1.5&&Close[1]<Open[1]) score-=7;}
  734. double r1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  735. double r5=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  736. if(r1<30) score+=15; else if(r1<40) score+=7;
  737. if(r1>70) score-=15; else if(r1>60) score-=7;
  738. if(r1>r5&&Close[1]<Close[5]) score+=8;
  739. if(r1<r5&&Close[1]>Close[5]) score-=8;
  740. if(g_nearest_res>0){double distR=(g_nearest_res-Close[0])/pip; if(distR<5) score-=12; else if(distR<10) score-=6;}
  741. if(g_nearest_sup>0){double distS=(Close[0]-g_nearest_sup)/pip; if(distS<5) score+=12; else if(distS<10) score+=6;}
  742. if(Close[0]>Open[0]&&Close[1]>Open[1]) score+=5;
  743. if(Close[0]<Open[0]&&Close[1]<Open[1]) score-=5;
  744. return MathMax(5.0,MathMin(95.0,score));
  745. }
  746.  
  747. int CalcAdvancedMicroTrap(){
  748. if(Bars<20) return 0;
  749. int score=0;
  750. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  751. double pip=jpy?0.01:0.0001;
  752. double r1=High[1]-Low[1];
  753. if(r1>0){
  754. double uw1=(High[1]-MathMax(Open[1],Close[1]))/r1;
  755. double lw1=(MathMin(Open[1],Close[1])-Low[1])/r1;
  756. if(uw1>0.65) score+=35; else if(uw1>0.50) score+=18;
  757. if(lw1>0.65) score+=25; else if(lw1>0.50) score+=12;
  758. }
  759. double r0=High[0]-Low[0];
  760. if(r0>0){double uw0=(High[0]-MathMax(Open[0],Close[0]))/r0; double lw0=(MathMin(Open[0],Close[0])-Low[0])/r0; if(uw0>0.60) score+=15; if(lw0>0.60) score+=10;}
  761. double v1=(double)iVolume(NULL,PERIOD_M1,1); double v2=(double)iVolume(NULL,PERIOD_M1,2); double v3=(double)iVolume(NULL,PERIOD_M1,3); double vAvg=(v2+v3)/2.0;
  762. if(vAvg>0){double vr=v1/vAvg; if(vr>3.0) score+=30; else if(vr>2.0) score+=22; else if(vr>1.5) score+=12;}
  763. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  764. if(rsi>82||rsi<18) score+=25; else if(rsi>75||rsi<25) score+=18; else if(rsi>70||rsi<30) score+=10;
  765. if(g_nearest_res>0 && (High[1]>g_nearest_res && Close[1]<g_nearest_res)) score+=30;
  766. if(g_nearest_sup>0 && (Low[1]<g_nearest_sup && Close[1]>g_nearest_sup)) score+=30;
  767. bool aG=(Close[1]>Open[1] && Close[2]>Open[2] && Close[3]>Open[3]);
  768. bool aR=(Close[1]<Open[1] && Close[2]<Open[2] && Close[3]<Open[3]);
  769. if(aG||aR) score+=18;
  770. if(Bars>=5){bool aG4=(aG && Close[4]>Open[4]); bool aR4=(aR && Close[4]<Open[4]); if(aG4||aR4) score+=10;}
  771. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  772. if(sp>BROKER_SPREAD_THRESHOLD*2.0) score+=15; else if(sp>BROKER_SPREAD_THRESHOLD*1.5) score+=8;
  773. if(g_hrn_price>0){double distH=MathAbs(Close[0]-g_hrn_price)/pip; if(distH<3) score+=20; else if(distH<7) score+=10;}
  774. return MathMin(100,score);
  775. }
  776.  
  777. double CalcAdvancedTFA(string &detail){
  778. if(Bars<30){detail="Bars low";return 3.0;}
  779. double score=0;string p="";
  780. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);
  781. double adxSc=(adx>=25)?1.0:(adx>=20)?0.6:(adx>=15)?0.3:0.1;
  782. score+=adxSc;p+="ADX:"+((adxSc>=0.6)?"+":"-")+" ";
  783. double v1=iVolume(NULL,PERIOD_M1,1),vA=0;
  784. for(int i=2;i<=6;i++)vA+=iVolume(NULL,PERIOD_M1,i);
  785. vA=(vA>0)?vA/5.0:1;double vr=v1/vA;
  786. double volSc=(vr>=2.0)?1.0:(vr>=1.5)?0.7:(vr>=1.1)?0.4:0.1;
  787. score+=volSc;p+="VOL:"+((volSc>=0.5)?"+":"-")+" ";
  788. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  789. double rsiSc=0.2;if(rsi>=60||rsi<=40)rsiSc=1.0;else if(rsi>=55||rsi<=45)rsiSc=0.6;
  790. score+=rsiSc;p+="RSI:"+((rsiSc>=0.6)?"+":"-")+" ";
  791. double atr=iATR(NULL,PERIOD_M1,14,1),cs=High[1]-Low[1],atrSc=0.2;
  792. 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;}
  793. score+=atrSc;p+="ATR:"+((atrSc>=0.6)?"+":"-")+" ";
  794. double body=MathAbs(Close[1]-Open[1]),range=High[1]-Low[1],bdySc=0.2;
  795. 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;}
  796. score+=bdySc;p+="BODY:"+((bdySc>=0.6)?"+":"-")+" ";
  797. double sesSc=IsSessionActive()?1.0:0.4;
  798. score+=sesSc;p+="SES:"+((sesSc>=0.7)?"+":"-");
  799. double finalScore=MathMin(6.0,score);int rounded=(int)MathRound(finalScore);
  800. string dir="MIX";
  801. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")dir="STRONG UP";
  802. else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")dir="STRONG DOWN";
  803. else if(g_haM1=="HA BULLISH 1")dir="UP";
  804. else if(g_haM1=="HA BEARISH 1")dir="DOWN";
  805. detail=p+" | "+IntegerToString(rounded)+"/6 "+dir;
  806. g_tfa_detail=detail;return finalScore;
  807. }
  808.  
  809. string CalcAdvancedMarketBias(color &bC,double brain,double rsc){
  810. if(Bars<30){bC=NEON_YELLOW;return "CALCULATING";}
  811. double score=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  812. double pc=Close[0]-Close[10];
  813. 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;
  814. double hh1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],hh2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  815. double ll1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],ll2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  816. 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;
  817. double ema20=0,ema20p=0;for(int i=0;i<20;i++)ema20+=Close[i];ema20/=20;
  818. for(int i=1;i<=20&&i<Bars;i++)ema20p+=Close[i];ema20p/=20;
  819. if(ema20>ema20p)score+=3;else if(ema20<ema20p)score-=3;
  820. double ema50=0;for(int i=0;i<50&&i<Bars;i++)ema50+=Close[i];ema50/=MathMin(50,Bars);
  821. if(ema20>ema50)score+=3;else score-=3;
  822. 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++;}
  823. if(gC>=7)score+=3;else if(rC>=7)score-=3;else if(gC>=5)score+=1;else if(rC>=5)score-=1;
  824. 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");
  825. if(m1B&&m5B)score+=4;else if(m1Be&&m5Be)score-=4;else if(m1B)score+=2;else if(m1Be)score-=2;
  826. 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);
  827. if(adx>20){if(pDI>mDI+5)score+=4;else if(mDI>pDI+5)score-=4;}
  828. if(brain>3)score-=2;else if(brain<-3)score+=2;
  829. if(Close[1]>Open[1])score+=1;else if(Close[1]<Open[1])score-=1;
  830. if(rsc>2)score+=1;else if(rsc<-2)score-=1;
  831. 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";}
  832. 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";}
  833. bC=NEON_YELLOW;return "NEUTRAL";
  834. }
  835.  
  836. void CalcAdvancedPrediction(double &gP,double &rP,string &reason,color &pC){
  837. if(Bars<50){gP=50;rP=50;reason="Bars low";pC=NEON_YELLOW;return;}
  838. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  839. double green=0,red=0;
  840. double body1=MathAbs(Close[1]-Open[1]),range1=High[1]-Low[1];
  841. if(range1>0){double uw=High[1]-MathMax(Open[1],Close[1]),lw=MathMin(Open[1],Close[1])-Low[1];
  842. if(uw>range1*0.60&&Close[1]>Open[1])red+=22;else if(lw>range1*0.60&&Close[1]<Open[1])green+=22;
  843. else if((uw+lw)/range1>0.55){if(uw>lw)red+=12;else green+=12;}}
  844. 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);
  845. int os=0,ob=0;
  846. 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++;
  847. if(os>=3)green+=18;else if(os>=2)green+=12;else if(ob>=3)red+=18;else if(ob>=2)red+=12;
  848. double rsiPrev=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  849. double low1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],low2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  850. double high1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],high2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  851. if(low1<low2&&rsi>rsiPrev&&rsi<45)green+=15;if(high1>high2&&rsi<rsiPrev&&rsi>55)red+=15;
  852. 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;
  853. double vol_ratio=(vAvg>0)?v1/vAvg:1.0;
  854. 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;}
  855. 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;
  856. double m1_haO2=(Open[3]+Close[3])/2.0,m1_haO1=(m1_haO2+m1_haC2)/2.0;
  857. bool haBull1=(m1_haC1>m1_haO1);
  858. double haStr1=MathAbs(m1_haC1-m1_haO1)/(High[1]-Low[1]+0.00001);
  859. bool haBull5=false;double haStr5=0;
  860. if(iBars(NULL,PERIOD_M5)>=5){
  861. 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);
  862. 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);
  863. double o3=iOpen(NULL,PERIOD_M5,3),c3=iClose(NULL,PERIOD_M5,3);
  864. 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;
  865. haBull5=(haC1_5>haO1_5);haStr5=MathAbs(haC1_5-haO1_5)/(h1-l1+0.00001);}
  866. if(haBull1&&haBull5)green+=15;else if(!haBull1&&!haBull5)red+=15;
  867. else if(haBull1&&haStr1>0.5)green+=8;else if(!haBull1&&haStr1>0.5)red+=8;
  868. 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);
  869. double diDiff=plusDI-minusDI;
  870. 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;}
  871. else if(adx>15){if(plusDI>minusDI)green+=4;else red+=4;}
  872. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,20,2)],res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,20,2)];
  873. double dR=(res-Close[0])/pip,dS=(Close[0]-sup)/pip;
  874. if(dR<8&&dR>=0)red+=12;else if(dR<15&&dR>=0)red+=6;
  875. if(dS<8&&dS>=0)green+=12;else if(dS<15&&dS>=0)green+=6;
  876. 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;}}
  877. 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);
  878. 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);
  879. if(macdMain>macdSig&&macdPrev<=macdSigPrev)green+=10;else if(macdMain<macdSig&&macdPrev>=macdSigPrev)red+=10;
  880. else if(macdMain>macdSig)green+=5;else if(macdMain<macdSig)red+=5;
  881. if(ENABLE_BB_PULLBACK&&g_bbSignal=="CALL")green+=12; else if(ENABLE_BB_PULLBACK&&g_bbSignal=="PUT")red+=12;
  882. double diff=MathMax(-100.0,MathMin(100.0,green-red));
  883. gP=MathMax(8.0,MathMin(92.0,50.0+diff*0.65));rP=100.0-gP;
  884. double dom=MathMax(gP,rP);
  885. if(dom>=82){reason=(gP>rP)?"STRONG GREEN":"STRONG RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  886. else if(dom>=72){reason=(gP>rP)?"GREEN":"RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  887. else if(dom>=60){reason=(gP>rP)?"WEAK GREEN":"WEAK RED";pC=(gP>rP)?NEON_CYAN:NEON_ORANGE;}
  888. else{reason="WAIT";pC=NEON_YELLOW;}
  889. }
  890.  
  891. string DetectMyStrategy(){
  892. int cc=g_otcCallPct,cp=g_otcPutPct,thr=STRATEGY_THRESHOLD;
  893. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TRAP_ONLY"){
  894. if(cc>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TRAP";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA RED";return "PUT";}
  895. if(cp>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TRAP";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA GREEN";return "CALL";}}
  896. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TREND_ONLY"){
  897. if(cc>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TREND";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA GREEN";return "CALL";}
  898. if(cp>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TREND";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA RED";return "PUT";}}
  899. g_strategyType="NONE";g_strategyReason="Wait "+IntegerToString(thr)+"% + HA";return "WAIT";
  900. }
  901.  
  902. void CalcOTCCrowd(){
  903. int cS=0,pS=0;int weights[15];
  904. for(int w=0;w<15;w++)weights[w]=15-w*2;
  905. for(int w=0;w<15;w++)if(weights[w]<1)weights[w]=1;
  906. for(int i=1;i<=15&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  907. double uw=(High[i]-MathMax(Open[i],Close[i]))/rg,lw=(MathMin(Open[i],Close[i])-Low[i])/rg;int wgt=weights[i-1];
  908. if(uw>0.70&&Close[i]<Open[i])cS+=4*wgt;if(lw>0.70&&Close[i]>Open[i])pS+=4*wgt;
  909. if(uw>0.55&&Close[i]<Open[i])cS+=2*wgt;if(lw>0.55&&Close[i]>Open[i])pS+=2*wgt;
  910. if(Close[i]>Open[i])cS+=1*wgt;else if(Close[i]<Open[i])pS+=1*wgt;}
  911. int tot=cS+pS;if(tot==0){g_otcCallPct=50;g_otcPutPct=50;}
  912. else{int rC=(int)(cS*100.0/tot),rP=100-rC;
  913. if(rC>=rP){g_otcCallPct=MathMax(50,rC);g_otcPutPct=100-g_otcCallPct;}
  914. else{g_otcPutPct=MathMax(50,rP);g_otcCallPct=100-g_otcPutPct;}}
  915. }
  916.  
  917. // ============================================================
  918. // BRAIN AI
  919. // ============================================================
  920. double BrainSc(int &cp){
  921. double s=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  922. if(g_nearest_res>0){double dR=(g_nearest_res-Close[0])/pip; if(dR<5) s-=3; else if(dR<15) s-=1;}
  923. if(g_nearest_sup>0){double dS=(Close[0]-g_nearest_sup)/pip; if(dS<5) s+=3; else if(dS<15) s+=1;}
  924. if(g_nearest_res>0&&High[1]>g_nearest_res){double bodyH=MathMax(Open[1],Close[1]); if(bodyH>g_nearest_res+2*pip) s-=4; else s+=2;}
  925. if(g_nearest_sup>0&&Low[1]<g_nearest_sup){double bodyL=MathMin(Open[1],Close[1]); if(bodyL<g_nearest_sup-2*pip) s+=4; else s-=2;}
  926. double atr=iATR(NULL,PERIOD_M1,14,1);
  927. if(atr>0){double cn=(High[1]-Low[1])/atr; double v1=(double)iVolume(NULL,PERIOD_M1,1); double va=0; for(int i=2;i<=10;i++) va+=iVolume(NULL,PERIOD_M1,i); va/=9.0; double vr=(va>0)?v1/va:1.0; if(cn>1.3&&vr>1.8){if(Close[1]>Open[1]) s-=2; else s+=2;}}
  928. int c=0; for(int i=1;i<=30;i++) if(Close[i]>Open[i]) c++; cp=(int)(c*100.0/30.0);
  929. if(cp>=80) s-=4; else if(cp>=75) s-=2; else if(cp<=20) s+=4; else if(cp<=25) s+=2;
  930. int dj=0; double wickBull=0,wickBear=0;
  931. for(int i=1;i<=8;i++){double bd=MathAbs(Close[i]-Open[i]); double rg=High[i]-Low[i]; if(rg<=0) continue; if(bd<rg*0.2) dj++; double uw=High[i]-MathMax(Open[i],Close[i]); double lw=MathMin(Open[i],Close[i])-Low[i]; double w=(9.0-i)/8.0; if(uw>bd*2) wickBear+=w; if(lw>bd*2) wickBull+=w;}
  932. if(wickBull>wickBear+1.0) s+=3; else if(wickBear>wickBull+1.0) s-=3;
  933. if(dj>=4) s*=0.8;
  934. int bu=0,be=0; for(int i=1;i<=8;i++){if(Close[i]>Open[i]){bu++;be=0;} else if(Close[i]<Open[i]){be++;bu=0;} else {bu=0;be=0;} if(bu>=6) s-=3; if(be>=6) s+=3;}
  935. double ema10=0; for(int i=0;i<10&&i<Bars;i++) ema10+=Close[i]; ema10/=10.0; double ema20=0; for(int i=0;i<20&&i<Bars;i++) ema20+=Close[i]; ema20/=20.0;
  936. if(ema10>ema20&&ema10-ema20>3*pip&&s<-2) s*=0.7; if(ema10<ema20&&ema20-ema10>3*pip&&s>2) s*=0.7;
  937. int h=TimeHour(TimeCurrent()); double mul=1.0; if((h>=8&&h<=11)||(h>=14&&h<=17)) mul=1.1; if(h>=3&&h<=7) mul=0.9; return s*mul;
  938. }
  939.  
  940. // ============================================================
  941. // S/R LEVELS - STABLE VERSION WITH CHART LABELS (FIXED BOUNDS)
  942. // ============================================================
  943. void AddStableRes(double lv){if(lv<=0)return; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=5.0*pip; for(int i=0;i<g_stableResCount;i++){if(MathAbs(g_stableRes[i]-lv)<tol)return;} if(g_stableResCount<10){g_stableRes[g_stableResCount]=lv;g_stableResCount++;} else{for(int i=0;i<9;i++)g_stableRes[i]=g_stableRes[i+1]; g_stableRes[9]=lv;}}
  944. void AddStableSup(double lv){if(lv<=0)return; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=5.0*pip; for(int i=0;i<g_stableSupCount;i++){if(MathAbs(g_stableSup[i]-lv)<tol)return;} if(g_stableSupCount<10){g_stableSup[g_stableSupCount]=lv;g_stableSupCount++;} else{for(int i=0;i<9;i++)g_stableSup[i]=g_stableSup[i+1]; g_stableSup[9]=lv;}}
  945. void AddRes(double lv){AddStableRes(lv);} void AddSup(double lv){AddStableSup(lv);}
  946.  
  947. void UpdateSR(){
  948. if(Time[0]==g_lastSRScan) return; static int barCount=0; barCount++; if(barCount<g_srScanInterval) return; barCount=0; g_lastSRScan=Time[0]; if(Bars<30) return;
  949. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double cur=Close[0];
  950. for(int i=3;i<=25&&i<Bars-2;i++){double h=High[i]; if(h>High[i-1]&&h>High[i-2]&&h>High[i+1]&&h>High[i+2]){if(h>cur+3*pip){double body=MathMax(Open[i],Close[i]); if(body>h-10*pip){AddStableRes(h);}}}}
  951. for(int i=3;i<=25&&i<Bars-2;i++){double l=Low[i]; if(l<Low[i-1]&&l<Low[i-2]&&l<Low[i+1]&&l<Low[i+2]){if(l<cur-3*pip){double body=MathMin(Open[i],Close[i]); if(body<l+10*pip){AddStableSup(l);}}}}
  952. double rndStep=50*pip; double nearRnd=MathRound(cur/rndStep)*rndStep; for(int k=-1;k<=1;k++){double lv=nearRnd+k*rndStep; if(MathAbs(cur-lv)<30*pip){if(lv>cur)AddStableRes(lv); else AddStableSup(lv);}}
  953. DrawNearestSR(); CheckBRK();
  954. }
  955.  
  956. void DrawNearestSR(){
  957. for(int i=0;i<20;i++){SafeDel(PFX+"RES_"+IntegerToString(i));SafeDel(PFX+"SUP_"+IntegerToString(i));}
  958. SafeDel(PFX+"NEAREST_RES"); SafeDel(PFX+"NEAREST_SUP");
  959. SafeDel(PFX+"NEAREST_RES_LBL"); SafeDel(PFX+"NEAREST_SUP_LBL");
  960.  
  961. double cur=Close[0]; g_nearest_res=0; g_nearest_sup=0; double minResDist=999999; double minSupDist=999999;
  962. for(int i=0;i<g_stableResCount;i++){if(g_stableRes[i]>cur){double d=g_stableRes[i]-cur; if(d<minResDist){minResDist=d; g_nearest_res=g_stableRes[i];}}}
  963. for(int i=0;i<g_stableSupCount;i++){if(g_stableSup[i]<cur){double d=cur-g_stableSup[i]; if(d<minSupDist){minSupDist=d; g_nearest_sup=g_stableSup[i];}}}
  964.  
  965. // FIX: Check Bars > 5 before accessing Time[5]
  966. if(g_nearest_res > 0 && Bars > 5){
  967. DrawHLine(PFX+"NEAREST_RES", g_nearest_res, C'50,80,255', 2, STYLE_DASH);
  968. ObjectCreate(0, PFX+"NEAREST_RES_LBL", OBJ_TEXT, 0, Time[5], g_nearest_res);
  969. ObjectSetText(PFX+"NEAREST_RES_LBL", ShortPrice(g_nearest_res), 9, "Arial Bold", C'50,80,255');
  970. ObjectSetInteger(0, PFX+"NEAREST_RES_LBL", OBJPROP_BACK, false);
  971. }
  972. if(g_nearest_sup > 0 && Bars > 5){
  973. DrawHLine(PFX+"NEAREST_SUP", g_nearest_sup, C'50,80,255', 2, STYLE_DASH);
  974. ObjectCreate(0, PFX+"NEAREST_SUP_LBL", OBJ_TEXT, 0, Time[5], g_nearest_sup);
  975. ObjectSetText(PFX+"NEAREST_SUP_LBL", ShortPrice(g_nearest_sup), 9, "Arial Bold", C'50,80,255');
  976. ObjectSetInteger(0, PFX+"NEAREST_SUP_LBL", OBJPROP_BACK, false);
  977. }
  978. }
  979.  
  980. 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;}}
  981.  
  982. // ============================================================
  983. // MICRO WICK & VOLUME TRAP
  984. // ============================================================
  985. 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;}
  986.  
  987. double VolumeTrapScore(){
  988. if(!VOLUME_PROFILE_TRAP||Bars<50)return 0;
  989. double cur=Close[0],hi=High[iHighest(NULL,0,MODE_HIGH,50,1)],lo=Low[iLowest(NULL,0,MODE_LOW,50,1)];
  990. 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};
  991. 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]++;}
  992. for(int z=0;z<zn;z++)if(zc[z]>0)vz[z]/=zc[z];
  993. int cz=(int)((cur-lo)/zs);if(cz<0)cz=0;if(cz>=zn)cz=zn-1;
  994. double vr=(double)Volume[1]/(vz[cz]+0.001);double wr=MicroWick();
  995. if(vr>2.0&&wr>0.65)return 25;if(vr>1.8&&wr>0.55)return 15;return 0;
  996. }
  997.  
  998. double UltimateTrapScore(){double wr=MicroWick(),v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  999. double avg=v2>0?v2:1.0,vr=v1/avg,rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),sc=0.0;
  1000. if(wr>0.65)sc+=40;if(vr>2.0)sc+=30;if(rsi>75||rsi<25)sc+=20;
  1001. if((High[1]>g_nearest_res&&Close[1]<g_nearest_res)||(Low[1]<g_nearest_sup&&Close[1]>g_nearest_sup))sc+=25;
  1002. sc+=VolumeTrapScore();return MathMin(100.0,sc);}
  1003.  
  1004. bool IsBrokerForce(double dummy=0){
  1005. int sd=0;for(int i=1;i<=3;i++){if(Close[i]>Open[i])sd++;else sd--;}
  1006. double v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  1007. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  1008. return(MathAbs(sd)==3&&v1>v2*2.0&&sp>BROKER_SPREAD_THRESHOLD);
  1009. }
  1010.  
  1011. // ============================================================
  1012. // NEURAL AI (FIXED fVol AND fTick DUPLICATES)
  1013. // ============================================================
  1014. double NeuralBiasFast(){double r=NeuralBias(0)*0.3+NeuralBias(1)*0.7;if(r>96)r=96;if(r<4)r=4;return r;}
  1015.  
  1016. double NeuralBias(int s){
  1017. double f[8];
  1018. f[0]=fDoji(s);f[1]=fWick(s);f[2]=fVol();f[3]=fMom(s);f[4]=fSpread();f[5]=fMem(s);f[6]=fTick(s);f[7]=fFrac(s);
  1019. for(int i=0;i<8;i++) f[i]/=100.0;
  1020. double h[4];
  1021. for(int i=0;i<4;i++){
  1022. double sum=0;for(int j=0;j<8;j++) sum+=f[j]*NW[j*4+i];
  1023. h[i]=MathMax(0,sum-0.06);
  1024. }
  1025. double out=0;for(int i=0;i<4;i++) out+=h[i]*NW[32+i];
  1026. double result=50.0+out*22.0;
  1027. return(result>96)?96:((result<4)?4:result);
  1028. }
  1029.  
  1030. double fDoji(int s){
  1031. if(s+8>=Bars)return 0;double score=0;int streak=0;
  1032. for(int i=s;i<s+8&&i<Bars;i++){
  1033. double body=MathAbs(Open[i]-Close[i]);double range=High[i]-Low[i];if(range<=0)continue;
  1034. double ratio=body/range;double w=(9.0-(i-s))/8.0;
  1035. if(ratio<0.15){score+=18*w;streak++;
  1036. double lw=MathMin(Open[i],Close[i])-Low[i];if(lw>range*0.55)score+=12*w;
  1037. double uw=High[i]-MathMax(Open[i],Close[i]);if(uw>range*0.55)score-=8*w;}
  1038. else if(ratio<0.25){score+=8*w;streak++;}}
  1039. if(streak>=3)score+=15;else if(streak>=2)score+=8;
  1040. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1041. if(g_nearest_res>0&&(g_nearest_res-cur)<8*pip)score+=12;
  1042. if(g_nearest_sup>0&&(cur-g_nearest_sup)<8*pip)score+=12;
  1043. if(g_hrn_price>0&&MathAbs(cur-g_hrn_price)<5*pip)score+=10;
  1044. return MathMin(100,score);
  1045. }
  1046.  
  1047. double fWick(int s){
  1048. double range=High[s]-Low[s];if(range==0)return 0;
  1049. double u=(High[s]-MathMax(Open[s],Close[s]))/range;double l=(MathMin(Open[s],Close[s])-Low[s])/range;
  1050. bool closedRed=(Close[s]<Open[s]);double score=0;
  1051. if(u>0.65&&!closedRed)score=95;else if(u>0.50&&!closedRed)score=70;
  1052. else if(l>0.65&&closedRed)score=90;else if(l>0.50&&closedRed)score=65;
  1053. else if(u>0.65||l>0.65)score=50;else if(u>0.50||l>0.50)score=30;
  1054. if(score>=50){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1055. if(g_nearest_res>0&&(g_nearest_res-cur)<10*pip)score+=15;
  1056. if(g_nearest_sup>0&&(cur-g_nearest_sup)<10*pip)score+=15;}
  1057. return MathMin(100,score);
  1058. }
  1059.  
  1060. // FIX: Removed duplicate avg==0 check
  1061. double fVol(){
  1062. if(Bars<15)return 0;
  1063. double cur=(double)iVolume(NULL,PERIOD_M1,0);double avg=0;
  1064. for(int i=1;i<=10;i++)avg+=iVolume(NULL,PERIOD_M1,i);
  1065. if(avg==0)return 0;
  1066. avg/=10.0; // Clean division
  1067. double ratio=cur/avg;double score=0;
  1068. if(ratio>3.0)score=95;else if(ratio>2.5)score=85;else if(ratio>2.0)score=75;
  1069. else if(ratio>1.5)score=50;else if(ratio>1.2)score=30;
  1070. if(ratio<0.7)score=MathMin(score,15);
  1071. return MathMin(100,score);
  1072. }
  1073.  
  1074. double fMom(int s){
  1075. if(s+5>=Bars)return 0;
  1076. double m1=(Close[s]-Close[s+1]);double m2=(Close[s+1]-Close[s+2]);double m3=(Close[s+2]-Close[s+3]);
  1077. bool shift=false;if(m1>0&&m2<0&&m3<0)shift=true;if(m1<0&&m2>0&&m3>0)shift=true;
  1078. double accel=MathAbs(m1)-MathAbs(m2);
  1079. double body1=MathAbs(Close[s]-Open[s]);double body2=MathAbs(Close[s+1]-Open[s+1]);double body3=MathAbs(Close[s+2]-Open[s+2]);
  1080. double score=0;
  1081. if(shift){score=88;if(accel>0)score+=12;}
  1082. if(body1<body2&&body2<body3&&body3>0){score=60;if(body1<body2*0.5)score=80;}
  1083. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1084. if(MathAbs(m2)>3*pip&&MathAbs(m1)<pip)score=75;
  1085. return MathMin(100,score);
  1086. }
  1087.  
  1088. double fSpread(){
  1089. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);double typical=3.0;double ratio=sp/typical;double score=0;
  1090. if(ratio>3.0)score=95;else if(ratio>2.5)score=85;else if(ratio>2.0)score=75;
  1091. else if(ratio>1.5)score=50;else if(ratio>1.2)score=30;
  1092. int h=TimeHour(TimeGMT());if((h>=0&&h<=3)||(h>=12&&h<=14))score+=10;
  1093. return MathMin(100,score);
  1094. }
  1095.  
  1096. double fMem(int s){
  1097. if(s+10>=Bars)return 0;
  1098. bool bullEng=(Close[s]>Open[s])&&(Close[s+1]<Open[s+1])&&(Close[s]>=Open[s+1])&&(Open[s]<=Close[s+1]);
  1099. bool bearEng=(Close[s]<Open[s])&&(Close[s+1]>Open[s+1])&&(Close[s]<=Open[s+1])&&(Open[s]>=Close[s+1]);
  1100. double range=High[s]-Low[s];if(range<=0)return 0;
  1101. double body=MathAbs(Close[s]-Open[s]);double upperW=High[s]-MathMax(Open[s],Close[s]);double lowerW=MathMin(Open[s],Close[s])-Low[s];
  1102. bool pinUp=(body<range*0.3&&lowerW>range*0.5);bool pinDn=(body<range*0.3&&upperW>range*0.5);
  1103. double score=0;
  1104. if(bullEng)score=85;else if(bearEng)score=85;else if(pinUp)score=80;else if(pinDn)score=80;
  1105. if(score>=50){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1106. if(g_nearest_res>0&&(g_nearest_res-cur)<10*pip)score+=15;
  1107. if(g_nearest_sup>0&&(cur-g_nearest_sup)<10*pip)score+=15;}
  1108. return MathMin(100,score);
  1109. }
  1110.  
  1111. // FIX: Removed duplicate volP==0 check
  1112. double fTick(int s){
  1113. if(s+5>=Bars)return 0;
  1114. double volN=(double)iVolume(NULL,PERIOD_M1,s);double volP=(double)iVolume(NULL,PERIOD_M1,s+1);
  1115. if(volP==0)return 0; // Single clean check
  1116. double volRatio=volN/volP;double priceMove=MathAbs(Close[s]-Close[s+1]);
  1117. double pricePct=Close[s+1]>0?priceMove/Close[s+1]*100:0;double score=0;
  1118. if(volRatio>2.0&&pricePct<0.1)score=85;else if(volRatio>1.5&&pricePct<0.05)score=60;else if(volRatio>1.2&&pricePct<0.03)score=35;
  1119. return MathMin(100,score);
  1120. }
  1121.  
  1122. double fFrac(int s){
  1123. if(s+4>=Bars||s<2)return 0;
  1124. bool fHigh=(High[s]>High[s-1]&&High[s]>High[s-2]&&High[s]>High[s+1]&&High[s]>High[s+2]);
  1125. bool fLow=(Low[s]<Low[s-1]&&Low[s]<Low[s-2]&&Low[s]<Low[s+1]&&Low[s]<Low[s+2]);
  1126. if(!fHigh&&!fLow)return 0;double score=0;
  1127. if(fHigh){score=70;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double dist=MathAbs(High[s]-Close[0])/pip;
  1128. if(dist<15)score+=20;else if(dist<30)score+=10;if(Close[s]<High[s])score+=15;}
  1129. if(fLow){score=70;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double dist=MathAbs(Low[s]-Close[0])/pip;
  1130. if(dist<15)score+=20;else if(dist<30)score+=10;if(Close[s]>Low[s])score+=15;}
  1131. return MathMin(100,score);
  1132. }
  1133.  
  1134. void InitNW(){NW[0]=0.80;NW[1]=0.90;NW[2]=0.40;NW[3]=0.85;NW[4]=0.70;NW[5]=0.60;NW[6]=0.30;NW[7]=0.20;NW[8]=0.30;NW[9]=0.60;NW[10]=0.70;NW[11]=0.40;NW[12]=0.50;NW[13]=0.65;NW[14]=0.25;NW[15]=0.35;NW[16]=0.75;NW[17]=0.70;NW[18]=0.50;NW[19]=0.90;NW[20]=0.30;NW[21]=0.20;NW[22]=0.60;NW[23]=0.40;NW[24]=0.85;NW[25]=0.65;NW[26]=0.30;NW[27]=0.80;NW[28]=0.25;NW[29]=0.30;NW[30]=0.70;NW[31]=0.35;NW[32]=1.30;NW[33]=-0.80;NW[34]=1.10;NW[35]=-0.95;}
  1135.  
  1136. // ============================================================
  1137. // COMMON POINTS & WICK REJECTIONS
  1138. // ============================================================
  1139. void DetectCommonPoints(){
  1140. if(!SHOW_COMMON_POINTS){g_commonCount=0;return;}
  1141. if(Time[0]==g_lastCommonScan)return;g_lastCommonScan=Time[0];g_commonCount=0;
  1142. datetime nowBar=Time[0];int periodSec=PeriodSeconds(PERIOD_M1);
  1143. double m5h=iHigh(NULL,PERIOD_M5,iHighest(NULL,PERIOD_M5,MODE_HIGH,10,1));
  1144. double m5l=iLow(NULL,PERIOD_M5,iLowest(NULL,PERIOD_M5,MODE_LOW,10,1));
  1145. 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++;}
  1146. 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++;}
  1147. 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++;}
  1148. 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++;}
  1149. 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--;}
  1150. }
  1151.  
  1152. void DrawCommonPoints(){
  1153. 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));}
  1154. if(!SHOW_COMMON_POINTS||g_commonCount==0)return;
  1155. for(int i=0;i<g_commonCount;i++){
  1156. if(TimeCurrent()>g_commonExpire[i])continue;if(IsLineNearby(g_commonPrice[i],8.0))continue;
  1157. string id=PFX+"COMMON_"+IntegerToString(i),idL=PFX+"COMMON_L_"+IntegerToString(i),idH=PFX+"COMMON_HL_"+IntegerToString(i);color zc=DARK_BLUE_NEON;
  1158. 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);
  1159. ObjectCreate(0,id,OBJ_TEXT,0,Time[0],g_commonPrice[i]);ObjectSetText(id,"*",16,"Arial",zc);ObjectSetInteger(0,id,OBJPROP_BACK,false);
  1160. string lbl=(g_commonType[i]=="CALL")?"^ CALL ZONE":"v PUT ZONE";
  1161. 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);
  1162. }
  1163. }
  1164.  
  1165. void DetectWickRejections(){
  1166. g_isSideways=IsSidewaysMarket();
  1167. if(!SHOW_WICK_REJECT_LINES){g_wickLineCount=0;return;}
  1168. if(Time[0]==g_lastWickScan)return;g_lastWickScan=Time[0];
  1169. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double zone=WICK_ZONE_PIPS*pip*2;double cur=Close[0];
  1170. g_wickLineCount=0;datetime now=Time[0],expT=now+PeriodSeconds(PERIOD_M1)*WICK_EXPIRE_BARS*2;
  1171. for(int i=1;i<=40&&i<Bars;i++){
  1172. double rg=High[i]-Low[i];if(rg<=0)continue;
  1173. double uw=High[i]-MathMax(Open[i],Close[i]),lw=MathMin(Open[i],Close[i])-Low[i];double rl=0;bool fd=false;
  1174. if(uw>rg*0.30){rl=High[i];if(MathAbs(cur-rl)<zone*3)fd=true;}
  1175. if(lw>rg*0.30){rl=Low[i];if(MathAbs(cur-rl)<zone*3)fd=true;}
  1176. if(!fd)continue;bool ex=false;
  1177. for(int j=0;j<g_wickLineCount;j++)if(MathAbs(g_wickLinePrice[j]-rl)<zone){g_wickLineTouches[j]++;ex=true;break;}
  1178. if(!ex&&g_wickLineCount<MAX_WICK_LINES){g_wickLinePrice[g_wickLineCount]=rl;g_wickLineTouches[g_wickLineCount]=1;g_wickLineExpire[g_wickLineCount]=expT;g_wickLineCount++;}
  1179. }
  1180. 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--;}
  1181. }
  1182.  
  1183. void DrawWickRejectLines(){
  1184. for(int i=0;i<MAX_WICK_LINES;i++){SafeDel(PFX+"WICK_"+IntegerToString(i));SafeDel(PFX+"WICK_L_"+IntegerToString(i));}
  1185. if(!SHOW_WICK_REJECT_LINES||!g_isSideways)return;
  1186. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1187. for(int i=0;i<g_wickLineCount;i++){
  1188. if(TimeCurrent()>g_wickLineExpire[i])continue;if(MathAbs(cur-g_wickLinePrice[i])/pip>20.0)continue;if(IsLineNearby(g_wickLinePrice[i],5.0))continue;
  1189. string id=PFX+"WICK_"+IntegerToString(i),idL=PFX+"WICK_L_"+IntegerToString(i);color lc=C'0,180,255';
  1190. 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);
  1191. string lbl="W"+IntegerToString(g_wickLineTouches[i])+"x";
  1192. 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);
  1193. }
  1194. }
  1195.  
  1196. 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;for(int i=0;i<g_wickLineCount;i++){double d=MathAbs(Close[0]-g_wickLinePrice[i])/pip;bool iS=(g_wickLinePrice[i]<Close[0]);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));}
  1197. double GetCommonPointSignal(){if(g_commonCount==0)return 0;double sc=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;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));}
  1198.  
  1199. // ============================================================
  1200. // OTC BROKER KILLER v4.0 - PROFESSIONAL TRAP ENGINE
  1201. // ============================================================
  1202. void CalcVisualTrapPro(){
  1203. // Reset
  1204. g_visualTrapPro.boxStatus="NO BOX"; g_visualTrapPro.gannStatus="--";
  1205. g_visualTrapPro.gannColor=CGR; // FIX: Added missing initialization
  1206. g_visualTrapPro.m30Dir="M30: --"; g_visualTrapPro.m1Seq="M1: --";
  1207. g_visualTrapPro.verdict="SCANNING"; g_visualTrapPro.verdictColor=CGR;
  1208. g_visualTrapPro.callBias=50.0; g_visualTrapPro.putBias=50.0; g_visualTrapPro.trapScore=0;
  1209. g_visualTrapPro.buySignal=false; g_visualTrapPro.sellSignal=false;
  1210. SafeDel(PFX+"VBOX"); SafeDel(PFX+"VMID"); SafeDel(PFX+"VSIG");
  1211.  
  1212. bool isJpy=(StringFind(Symbol(),"JPY")>=0); double pip=isJpy?0.01:0.0001;
  1213. int BOX_C=25; double MIN_P=4.0, MAX_P=30.0;
  1214.  
  1215. string scanPairs[4] = {"EURUSD", "GBPUSD", "EURJPY", "AUDUSD"};
  1216. for(int p=0; p<4; p++){
  1217. if(StringFind(Symbol(), scanPairs[p]) >= 0) continue;
  1218. int bgH = iHighest(scanPairs[p], PERIOD_M1, MODE_HIGH, BOX_C, 1);
  1219. int bgL = iLowest(scanPairs[p], PERIOD_M1, MODE_LOW, BOX_C, 1);
  1220. if(bgH < 0 || bgL < 0) continue;
  1221. double bgHigh = iHigh(scanPairs[p], PERIOD_M1, bgH);
  1222. double bgLow = iLow(scanPairs[p], PERIOD_M1, bgL);
  1223. double bgG50 = bgLow + (bgHigh - bgLow)/2.0;
  1224. double bgCur = iClose(scanPairs[p], PERIOD_M1, 0);
  1225. double bgDist = MathAbs(bgCur - bgG50) / pip;
  1226. if(bgDist < 1.5){
  1227. g_visualTrapPro.boxStatus = "["+scanPairs[p]+"] MATCH!";
  1228. g_visualTrapPro.gannStatus = "["+scanPairs[p]+"] TRAP!";
  1229. g_visualTrapPro.gannColor = NEON_YELLOW;
  1230. g_visualTrapPro.trapScore += 30; break;
  1231. }
  1232. }
  1233.  
  1234. if(Bars<BOX_C+10) return;
  1235. int hIdx=iHighest(NULL,0,MODE_HIGH,BOX_C,1); int lIdx=iLowest(NULL,0,MODE_LOW,BOX_C,1);
  1236. double bH=High[hIdx], bL=Low[lIdx], bHt=bH-bL; double bPips=bHt/pip;
  1237.  
  1238. if(bPips>=MIN_P && bPips<=MAX_P){
  1239. double g50=bL+(bHt/2.0); double dist=MathAbs(Close[0]-g50)/pip;
  1240. double trapStrength = (bPips-10)/20.0 * 100; if(trapStrength<0) trapStrength=0;
  1241. g_visualTrapPro.boxStatus="BOX: "+DoubleToString(bPips,0)+"p (T"+DoubleToString(trapStrength,0)+"%)";
  1242. if(dist<1.2){
  1243. g_visualTrapPro.gannStatus="[!!!] GANN TRAP!"; g_visualTrapPro.gannColor=NEON_YELLOW;
  1244. g_visualTrapPro.trapScore += 35;
  1245. } else {
  1246. g_visualTrapPro.gannStatus="GANN: "+DoubleToString(dist,1)+"p";
  1247. g_visualTrapPro.gannColor=NEON_CYAN;
  1248. g_visualTrapPro.trapScore += dist>3 ? 10 : 5;
  1249. }
  1250. ObjectCreate(0, PFX+"VBOX", OBJ_RECTANGLE, 0, Time[hIdx], bH, Time[1], bL);
  1251. ObjectSetInteger(0, PFX+"VBOX", OBJPROP_COLOR, clrWhite);ObjectSetInteger(0, PFX+"VBOX", OBJPROP_WIDTH, 2);
  1252. ObjectSetInteger(0, PFX+"VBOX", OBJPROP_BACK, false);ObjectSetInteger(0, PFX+"VBOX", OBJPROP_FILL, false);
  1253. ObjectCreate(0, PFX+"VMID", OBJ_HLINE, 0, 0, g50);
  1254. ObjectSetInteger(0, PFX+"VMID", OBJPROP_COLOR, clrYellow);ObjectSetInteger(0, PFX+"VMID", OBJPROP_WIDTH, 1);
  1255. ObjectSetInteger(0, PFX+"VMID", OBJPROP_STYLE, STYLE_SOLID);ObjectSetInteger(0, PFX+"VMID", OBJPROP_BACK, false);
  1256. }
  1257.  
  1258. if(iBars(NULL,PERIOD_M30)<10) return;
  1259. int m30BullBars=0, m30BearBars=0;
  1260. for(int i=1; i<=8; i++){if(iClose(NULL,PERIOD_M30,i)>iOpen(NULL,PERIOD_M30,i)) m30BullBars++; else m30BearBars++;}
  1261. bool m30Bull = (m30BullBars >= m30BearBars + 2);
  1262. g_visualTrapPro.m30Dir = (m30Bull ? "M30: [UP] " : "M30: [DN] ") + IntegerToString(MathMax(m30BullBars,m30BearBars)) + "/8";
  1263.  
  1264. datetime m30Start = iTime(NULL,PERIOD_M30,1);
  1265. int m1Bull=0, m1Bear=0, dojiChain=0, fakeBreak=0; string m1Pattern = "";
  1266. for(int i=1; i<=60 && i<Bars; i++){
  1267. if(Time[i] >= m30Start){
  1268. double body = MathAbs(Close[i]-Open[i]); double range = High[i]-Low[i];
  1269. if(range > 0 && body < 0.3*range) dojiChain++;
  1270. else if(Close[i]>Open[i]) {m1Bull++; m1Pattern+="G";}
  1271. else {m1Bear++; m1Pattern+="R";}
  1272. if(i<60 && High[i]>High[i+1] && Close[i+1]<Open[i+1]) fakeBreak++;
  1273. }
  1274. }
  1275. string recentPattern = "";
  1276. for(int j=StringLen(m1Pattern)-1; j>=0 && StringLen(recentPattern)<8; j--) recentPattern += StringSubstr(m1Pattern,j,1);
  1277. g_visualTrapPro.m1Seq = "M1: " + recentPattern;
  1278.  
  1279. double totalCandles = (double)(m1Bull + m1Bear);
  1280. if(totalCandles > 0){g_visualTrapPro.callBias = NormalizeDouble((m1Bull/totalCandles)*100,1); g_visualTrapPro.putBias = NormalizeDouble((m1Bear/totalCandles)*100,1);}
  1281. else {g_visualTrapPro.callBias = 50.0; g_visualTrapPro.putBias = 50.0;}
  1282.  
  1283. g_visualTrapPro.trapScore += dojiChain * 8; g_visualTrapPro.trapScore += fakeBreak * 12; g_visualTrapPro.trapScore += m30Bull ? m1Bear*2 : m1Bull*2;
  1284. if(g_visualTrapPro.trapScore > 100) g_visualTrapPro.trapScore = 100;
  1285.  
  1286. if(m30Bull && g_visualTrapPro.callBias >= 60 && g_visualTrapPro.trapScore >= 40){g_visualTrapPro.verdict = "[DN] PUT NOW! " + DoubleToString(g_visualTrapPro.trapScore,0) + "%"; g_visualTrapPro.verdictColor = NEON_RED; g_visualTrapPro.sellSignal = true;}
  1287. else if(!m30Bull && g_visualTrapPro.putBias >= 60 && g_visualTrapPro.trapScore >= 40){g_visualTrapPro.verdict = "[UP] CALL NOW! " + DoubleToString(g_visualTrapPro.trapScore,0) + "%"; g_visualTrapPro.verdictColor = NEON_GREEN; g_visualTrapPro.buySignal = true;}
  1288. else if(g_visualTrapPro.trapScore >= 50){g_visualTrapPro.verdict = "[!!] TRAP FORM " + DoubleToString(g_visualTrapPro.trapScore,0) + "%"; g_visualTrapPro.verdictColor = NEON_ORANGE;}
  1289. else {g_visualTrapPro.verdict = "WAIT " + DoubleToString(g_visualTrapPro.callBias,0) + "/" + DoubleToString(g_visualTrapPro.putBias,0); g_visualTrapPro.verdictColor = CGR;}
  1290.  
  1291. if((g_visualTrapPro.buySignal || g_visualTrapPro.sellSignal) && g_lastTrapArrowTime != Time[0]){
  1292. g_lastTrapArrowTime = Time[0];
  1293. ObjectCreate(0, PFX+"VSIG", OBJ_ARROW, 0, Time[0], Low[0] - (isJpy?0.05:0.0005));
  1294. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_ARROWCODE, g_visualTrapPro.buySignal ? 233 : 234);
  1295. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_COLOR, g_visualTrapPro.buySignal ? NEON_GREEN : NEON_RED);
  1296. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_WIDTH, 3); ObjectSetInteger(0, PFX+"VSIG", OBJPROP_BACK, false);
  1297. }
  1298. }
  1299.  
  1300. // ============================================================
  1301. // HIDDEN LEVELS & HELPERS
  1302. // ============================================================
  1303. void DetectHiddenLevels(){
  1304. g_htfLevelCount=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double curP=Close[0];
  1305. double rU=MathCeil(curP/(10*pip))*(10*pip),rD=MathFloor(curP/(10*pip))*(10*pip);
  1306. if(MathAbs(curP-rU)/pip<=15)AddLevel(rU,"ROUND","RESISTANCE",TimeCurrent(),8,true);
  1307. if(MathAbs(curP-rD)/pip<=15)AddLevel(rD,"ROUND","SUPPORT",TimeCurrent(),8,true);
  1308. DetectHTFLevels(PERIOD_M5,"M5",3,pip);DetectHTFLevels(PERIOD_M15,"M15",5,pip);
  1309. DetectHTFLevels(PERIOD_M30,"M30",7,pip);DetectHTFLevels(PERIOD_H1,"H1",9,pip);
  1310. SortLevelsByStrength();
  1311. }
  1312.  
  1313. void DetectHTFLevels(ENUM_TIMEFRAMES tf,string tfN,int bS,double pip){
  1314. int bars=MathMin(50,iBars(NULL,tf));if(bars<10)return;double curP=Close[0];
  1315. for(int i=2;i<bars-2;i++){
  1316. 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);}
  1317. 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);}
  1318. }
  1319. }
  1320.  
  1321. bool IsSwingHigh(ENUM_TIMEFRAMES tf,int p,int lb){double h=iHigh(NULL,tf,p);for(int i=1;i<=lb;i++){if(p-i<0||p+i>=iBars(NULL,tf))return false;if(iHigh(NULL,tf,p-i)>=h||iHigh(NULL,tf,p+i)>=h)return false;}return true;}
  1322. bool IsSwingLow(ENUM_TIMEFRAMES tf,int p,int lb){double l=iLow(NULL,tf,p);for(int i=1;i<=lb;i++){if(p-i<0||p+i>=iBars(NULL,tf))return false;if(iLow(NULL,tf,p-i)<=l||iLow(NULL,tf,p+i)<=l)return false;}return true;}
  1323.  
  1324. void AddLevel(double price,string tf,string type,datetime time,int strength,bool isRound){
  1325. if(g_htfLevelCount>=50)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1326. for(int i=0;i<g_htfLevelCount;i++)if(MathAbs(g_htfLevels[i].price-price)/pip<5)return;
  1327. g_htfLevels[g_htfLevelCount].price=price;g_htfLevels[g_htfLevelCount].timeframe=tf;g_htfLevels[g_htfLevelCount].type=type;
  1328. g_htfLevels[g_htfLevelCount].time=time;g_htfLevels[g_htfLevelCount].strength=strength;g_htfLevels[g_htfLevelCount].isRoundNumber=isRound;g_htfLevelCount++;
  1329. }
  1330.  
  1331. void SortLevelsByStrength(){for(int i=0;i<g_htfLevelCount-1;i++)for(int j=0;j<g_htfLevelCount-i-1;j++)if(g_htfLevels[j].strength<g_htfLevels[j+1].strength){HTFLevel tmp=g_htfLevels[j];g_htfLevels[j]=g_htfLevels[j+1];g_htfLevels[j+1]=tmp;}}
  1332.  
  1333. void DrawHiddenLevels(){
  1334. for(int i=0;i<50;i++){SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i));SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i)+"_LBL");}
  1335. int dc=MathMin(10,g_htfLevelCount);int drawn=0;
  1336. for(int i=0;i<dc&&drawn<5;i++){
  1337. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1338. if(MathAbs(Close[0]-g_htfLevels[i].price)/pip>30)continue;if(IsLineNearby(g_htfLevels[i].price,5.0))continue;
  1339. string nm=PFX+"HTF_LEVEL_"+IntegerToString(drawn);
  1340. color lc=g_htfLevels[i].isRoundNumber?NEON_PURPLE:(StringFind(g_htfLevels[i].type,"SUPPORT")>=0?NEON_GREEN:NEON_RED);
  1341. 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);
  1342. string ln=nm+"_LBL";ObjectCreate(0,ln,OBJ_TEXT,0,Time[0],g_htfLevels[i].price);
  1343. ObjectSetText(ln,g_htfLevels[i].timeframe+" "+g_htfLevels[i].type+" S:"+IntegerToString(g_htfLevels[i].strength),9,"Arial",lc);drawn++;
  1344. }
  1345. }
  1346.  
  1347. string DetectSuddenReversal(){
  1348. if(Bars<10)return "";bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1349. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);double atr=iATR(NULL,PERIOD_M1,14,1);if(atr<=0)return "";
  1350. double rng1=High[1]-Low[1];double body1=MathAbs(Close[1]-Open[1]);
  1351. double uw1=(rng1>0)?(High[1]-MathMax(Open[1],Close[1]))/rng1:0;double lw1=(rng1>0)?(MathMin(Open[1],Close[1])-Low[1])/rng1:0;
  1352. bool bull1=(Close[1]>Open[1]);bool bear1=(Close[1]<Open[1]);
  1353. int bullScore=0,bearScore=0;
  1354. if(lw1>0.60&&body1<rng1*0.30&&rsi<48){bullScore+=30;}
  1355. if(uw1>0.60&&body1<rng1*0.30&&rsi>52){bearScore+=30;}
  1356. if(bull1&&body1>MathAbs(Close[2]-Open[2])*1.1&&Close[2]<Open[2]&&body1>atr*0.35){bullScore+=25;}
  1357. if(bear1&&body1>MathAbs(Close[2]-Open[2])*1.1&&Close[2]>Open[2]&&body1>atr*0.35){bearScore+=25;}
  1358. if(rsi<30&&bullScore>0){bullScore+=15;}if(rsi>70&&bearScore>0){bearScore+=15;}
  1359. if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)/pip<8&&bullScore>0){bullScore+=15;}
  1360. if(g_nearest_res>0&&(g_nearest_res-Close[0])/pip<8&&bearScore>0){bearScore+=15;}
  1361. if(bullScore>=40&&bullScore>bearScore){return "BULL REVERSAL";}
  1362. else if(bearScore>=40&&bearScore>bullScore){return "BEAR REVERSAL";}
  1363. return "";
  1364. }
  1365.  
  1366. void SafeDel(string id){if(ObjectFind(0,id)>=0)ObjectDelete(0,id);}
  1367. 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);}
  1368. void HideSPM(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)==0)continue;if(StringFind(nm,PFX+"candle_timer")>=0)continue;int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE);if(tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT)ObjectDelete(0,nm);}}
  1369. void NuclearDeleteAll(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX+"candle_timer")>=0)continue;int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE);if(tp==OBJ_HLINE||tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT)ObjectDelete(0,nm);}}
  1370. void DelDashboard(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)!=0)continue;if(StringFind(nm,"HRN_LINE")>=0)continue;if(StringFind(nm,"HRN_LBL")>=0)continue;if(StringFind(nm,"candle_timer")>=0)continue;if(StringFind(nm,"HTF_LEVEL")>=0)continue;if(StringFind(nm,"COMMON_")>=0)continue;if(StringFind(nm,"WICK_")>=0)continue;if(StringFind(nm,"BB_")>=0)continue;if(StringFind(nm,"NEAREST_RES")>=0)continue;if(StringFind(nm,"NEAREST_SUP")>=0)continue;if(StringFind(nm,"VBOX")>=0)continue;if(StringFind(nm,"VMID")>=0)continue;if(StringFind(nm,"VSIG")>=0)continue;ObjectDelete(nm);}}
  1371.  
  1372. // ============================================================
  1373. // ML & ACCURACY
  1374. // ============================================================
  1375. void LoadMLWeights(){if(!ML_ADAPTIVE)return;g_symbolKey=Symbol();string fn="ML_weights_"+g_symbolKey+".dat";int h=FileOpen(fn,FILE_READ|FILE_TXT);if(h!=INVALID_HANDLE){string d=FileReadString(h);FileClose(h);g_brokerBias=StringToDouble(d);if(g_brokerBias<-0.5)g_brokerBias=-0.5;if(g_brokerBias>0.5)g_brokerBias=0.5;}else g_brokerBias=0.0;}
  1376. void SaveMLWeights(){if(!ML_ADAPTIVE)return;string fn="ML_weights_"+g_symbolKey+".dat";int h=FileOpen(fn,FILE_WRITE|FILE_TXT);if(h!=INVALID_HANDLE){FileWriteString(h,DoubleToString(g_brokerBias,6));FileClose(h);}}
  1377. void UpdateMLWeights(bool win){if(!ML_ADAPTIVE)return;double lr=0.02;if(win)g_brokerBias+=lr*(g_frozen_gProb/100.0);else g_brokerBias-=lr*(g_frozen_rProb/100.0);if(g_brokerBias>0.5)g_brokerBias=0.5;if(g_brokerBias<-0.5)g_brokerBias=-0.5;SaveMLWeights();}
  1378. void UpdateAccuracy(){if(Bars<5||Time[0]==g_acc_lastBar)return;g_acc_lastBar=Time[0];if(g_lastPredBar==Time[1]&&MathAbs(g_lastPredGreen-50.0)>10.0){bool aG=(Close[1]>Open[1]),pG=(g_lastPredGreen>50.0),win=(aG==pG);if(win){g_acc_correct++;g_lossStreak=0;}else g_lossStreak++;g_acc_total++;if(g_acc_total>0)g_accuracy=MathMax(40.0,MathMin(90.0,(double)g_acc_correct/g_acc_total*100.0));if(ML_ADAPTIVE&&g_lastPredGreen>50.0&&g_lastPredGreen<100.0)UpdateMLWeights(win);}g_lastPredGreen=g_frozen_gProb;g_lastPredBar=Time[0];}
  1379. 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;}
  1380. 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]));}}
  1381.  
  1382. 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";}
  1383. 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;}
  1384. 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;}
  1385. 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;}
  1386. 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;}
  1387. double GetADXStrength(){if(Bars<20)return 0;return iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);}
  1388. 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;}
  1389. 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;}
  1390. 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;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++;}}}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;}}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;}
  1391.  
  1392. // ============================================================
  1393. // HRN LEVEL (Kept for chart line only, cube removed)
  1394. // ============================================================
  1395. double FindBestHiddenRoundNumber(double curPrice){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;double levels[];int levelCount=0;ArrayResize(levels,100);double b100=MathFloor(curPrice/(100*pip))*(100*pip);for(int i=-1;i<=2;i++)AddRNLevel(levels,levelCount,b100+i*100*pip);double b50=MathFloor(curPrice/(50*pip))*(50*pip);for(int i=-2;i<=3;i++)AddRNLevel(levels,levelCount,b50+i*50*pip);double b25=MathFloor(curPrice/(25*pip))*(25*pip);for(int i=-3;i<=4;i++)AddRNLevel(levels,levelCount,b25+i*25*pip);double b10=MathFloor(curPrice/(10*pip))*(10*pip);for(int i=-5;i<=6;i++)AddRNLevel(levels,levelCount,b10+i*10*pip);double b5=MathFloor(curPrice/(5*pip))*(5*pip);for(int i=-4;i<=5;i++)AddRNLevel(levels,levelCount,b5+i*5*pip);double bestLevel=0,bestScore=-1;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;}}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);double d100=MathAbs(curPrice-n100),d50=MathAbs(curPrice-n50),d25=MathAbs(curPrice-n25),d10=MathAbs(curPrice-n10);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;}g_hrn_score=bestScore;return NormalizeDouble(bestLevel,dg);}
  1396. 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++;}
  1397. double ScoreRoundNumber(double level,double pip){double score=0,tol=3*pip;int touches=0,ru=0,rd=0;for(int i=1;i<=LOOKBACK&&i<Bars;i++){double h=High[i],l=Low[i],c=Close[i],o=Open[i];if(h>=level-tol&&l<=level+tol){touches++;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;}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;}}}score+=touches*3;score+=ru*8+rd*8;if(touches>=4)score+=15;else if(touches>=3)score+=10;else if(touches>=2)score+=5;return score;}
  1398.  
  1399. void ScanHRNLevels(){g_rj_cnt=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];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];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++;}}}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++;}}}}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;}}
  1400.  
  1401. void UpdateHRN(){
  1402. if(Bars<LOOKBACK+10)return;
  1403. 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;
  1404. 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];}
  1405. double tol=1*pip;
  1406. 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;}}
  1407. 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;}}
  1408. 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;}}
  1409. g_hrn_str=DoubleToString(NormalizeDouble(g_hrn_price,dg),dg);
  1410. color hrnColor=g_hrn_is_sup?NEON_GREEN:NEON_RED;if(g_hrn_brk_bars==1)hrnColor=NEON_YELLOW;
  1411. DrawHLine(PFX+"HRN_LINE",g_hrn_price,hrnColor,3,STYLE_SOLID);
  1412. 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?" [SHIFT]":"");
  1413. ObjectCreate(0,ln,OBJ_TEXT,0,Time[0]+Period()*60*3,g_hrn_price);ObjectSetText(ln,"HRN "+ShortPrice(g_hrn_price)+" "+typeStr+confStr,9,"Arial Bold",hrnColor);ObjectSetInteger(0,ln,OBJPROP_BACK,false);
  1414. }
  1415.  
  1416. // ============================================================
  1417. // CANDLE PATTERN RECOGNITION (FIXED BUG)
  1418. // ============================================================
  1419. NCPPatternResult NCPCheckSinglePattern(int shift){
  1420. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="SINGLE";
  1421. if(shift+1>=Bars || shift < 0) return r;
  1422. double o=Open[shift],c=Close[shift],h=High[shift],l=Low[shift];
  1423. double body=MathAbs(c-o); double range=h-l;if(range<=0 || o==0 || c==0) return r;
  1424. double upperWick=h-MathMax(o,c); double lowerWick=MathMin(o,c)-l;
  1425. double bodyRatio=body/range; double uwRatio=upperWick/range; double lwRatio=lowerWick/range;
  1426. bool isBull=(c>o); bool isBear=(c<o);
  1427. if(bodyRatio<0.10){
  1428. if(uwRatio>0.35&&lwRatio>0.35){r.name="DOJI"; r.type=0; r.strength=2;if(uwRatio>0.60&&lwRatio<0.15){r.name="GRAVESTONE DOJI";r.type=-1;r.strength=4;}else if(lwRatio>0.60&&uwRatio<0.15){r.name="DRAGONFLY DOJI";r.type=1;r.strength=4;}else if(uwRatio>0.40&&lwRatio>0.40){r.name="LONG-LEG DOJI";r.type=0;r.strength=3;}return r;}
  1429. if(body<range*0.05&&upperWick<range*0.10&&lowerWick<range*0.10){r.name="4-PRICE DOJI";r.type=0;r.strength=1;return r;}}
  1430. if(lwRatio>0.55&&uwRatio<0.15&&bodyRatio>0.15&&bodyRatio<0.40){r.name="HAMMER";r.type=1;r.strength=4;if(g_nearest_sup>0&&MathAbs(l-g_nearest_sup)<5*(StringFind(Symbol(),"JPY")>=0?0.01:0.0001)){r.strength=5;r.name="HAMMER@SUP";}return r;}
  1431. if(uwRatio>0.55&&lwRatio<0.15&&isBull&&bodyRatio>0.10&&bodyRatio<0.35){r.name="INV HAMMER";r.type=1;r.strength=3;return r;}
  1432. if(uwRatio>0.55&&lwRatio<0.15&&isBear&&bodyRatio>0.15&&bodyRatio<0.40){r.name="SHOOT STAR";r.type=-1;r.strength=4;if(g_nearest_res>0&&MathAbs(h-g_nearest_res)<5*(StringFind(Symbol(),"JPY")>=0?0.01:0.0001)){r.strength=5;r.name="SHOOT@RES";}return r;}
  1433. if(lwRatio>0.55&&uwRatio<0.15&&isBear&&bodyRatio>0.15&&bodyRatio<0.40){r.name="HANG MAN";r.type=-1;r.strength=3;return r;}
  1434. if(bodyRatio>0.10&&bodyRatio<0.30&&uwRatio>0.25&&lwRatio>0.25){r.name="SPIN TOP";r.type=0;r.strength=1;return r;}
  1435. if(bodyRatio>0.75){if(isBull){r.name="BULL MARUBOZU";r.type=1;r.strength=5;}else{r.name="BEAR MARUBOZU";r.type=-1;r.strength=5;}return r;}
  1436. if(bodyRatio<0.20&&uwRatio>0.30&&lwRatio>0.30){r.name="HIGH WAVE";r.type=0;r.strength=2;return r;}
  1437. return r;
  1438. }
  1439.  
  1440. NCPPatternResult NCPCheckDualPattern(int shift){
  1441. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="DUAL";
  1442. if(shift+2>=Bars || shift < 0) return r;
  1443. if(Open[shift]==0||Close[shift]==0||Open[shift+1]==0||Close[shift+1]==0) return r;
  1444. double o1=Open[shift],c1=Close[shift],h1=High[shift],l1=Low[shift];
  1445. double o2=Open[shift+1],c2=Close[shift+1],h2=High[shift+1],l2=Low[shift+1];
  1446. double body1=MathAbs(c1-o1); double body2=MathAbs(c2-o2); if(body1<=0||body2<=0) return r;
  1447. bool bull1=(c1>o1), bear1=(c1<o1); bool bull2=(c2>o2), bear2=(c2<o2);
  1448. if(bull1&&bear2&&c1>=o2&&o1<=c2&&body1>body2){r.name="BULL ENGULF";r.type=1;r.strength=5;if(g_nearest_sup>0){double pip=(StringFind(Symbol(),"JPY")>=0)?0.01:0.0001;if(MathAbs(l1-g_nearest_sup)<8*pip||MathAbs(l2-g_nearest_sup)<8*pip){r.strength=6;r.name="BULL ENGULF@SUP";}}return r;}
  1449. if(bear1&&bull2&&c1<=o2&&o1>=c2&&body1>body2){r.name="BEAR ENGULF";r.type=-1;r.strength=5;if(g_nearest_res>0){double pip=(StringFind(Symbol(),"JPY")>=0)?0.01:0.0001;if(MathAbs(h1-g_nearest_res)<8*pip||MathAbs(h2-g_nearest_res)<8*pip){r.strength=6;r.name="BEAR ENGULF@RES";}}return r;}
  1450. double tol=(h1+l1)*0.001;
  1451. if(bull1&&bear2&&MathAbs(h1-h2)<tol&&h1>c1&&h2>c2){r.name="TWEEZER TOP";r.type=-1;r.strength=4;return r;}
  1452. if(bear1&&bull2&&MathAbs(l1-l2)<tol&&l1<c1&&l2<c2){r.name="TWEEZER BTM";r.type=1;r.strength=4;return r;}
  1453. if(bull1&&bear2&&o1<l2&&c1>(o2+c2)/2.0&&c1<o2){r.name="PIERCING";r.type=1;r.strength=3;return r;}
  1454. if(bear1&&bull2&&o1>h2&&c1<(o2+c2)/2.0&&c1>o2){r.name="DARK CLOUD";r.type=-1;r.strength=3;return r;}
  1455. if(h1<h2&&l1>l2){if(bull1&&bear2){r.name="BULL HARAMI";r.type=1;r.strength=2;}else if(bear1&&bull2){r.name="BEAR HARAMI";r.type=-1;r.strength=2;}return r;}
  1456. return r;
  1457. }
  1458.  
  1459. NCPPatternResult NCPCheckTriplePattern(int shift){
  1460. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="TRIPLE";
  1461. if(shift+3>=Bars || shift < 0) return r;
  1462. double o1=Open[shift],c1=Close[shift],h1=High[shift],l1=Low[shift];
  1463. double o2=Open[shift+1],c2=Close[shift+1],h2=High[shift+1],l2=Low[shift+1];
  1464. double o3=Open[shift+2],c3=Close[shift+2],h3=High[shift+2],l3=Low[shift+2];
  1465. double body1=MathAbs(c1-o1),body2=MathAbs(c2-o2),body3=MathAbs(c3-o3);double rng2=h2-l2;
  1466. bool bull1=(c1>o1),bear1=(c1<o1),bull3=(c3>o3),bear3=(c3<o3);
  1467. if(bull1&&bear3&&rng2>0&&body2<rng2*0.30&&c1>(o3+c3)/2.0){r.name="MORN STAR";r.type=1;r.strength=5;if(g_nearest_sup>0){double pip=(StringFind(Symbol(),"JPY")>=0)?0.01:0.0001;if(MathAbs(l2-g_nearest_sup)<8*pip){r.strength=6;r.name="MORN STAR@SUP";}}return r;}
  1468. if(bear1&&bull3&&rng2>0&&body2<rng2*0.30&&c1<(o3+c3)/2.0){r.name="EVE STAR";r.type=-1;r.strength=5;if(g_nearest_res>0){double pip=(StringFind(Symbol(),"JPY")>=0)?0.01:0.0001;if(MathAbs(h2-g_nearest_res)<8*pip){r.strength=6;r.name="EVE STAR@RES";}}return r;}
  1469. if(bull1&&c2>o2&&bull3&&c1>c2&&c2>c3&&o1>o2&&o2>o3){r.name="3 SOLDIERS";r.type=1;r.strength=5;if(body1<body2){r.strength=4;r.name="3 SOLDIERS-W";}return r;}
  1470. if(bear1&&c2<o2&&bear3&&c1<c2&&c2<c3&&o1<o2&&o2<o3){r.name="3 CROWS";r.type=-1;r.strength=5;if(body1<body2){r.strength=4;r.name="3 CROWS-W";}return r;}
  1471. if(bull1&&bear3&&h1<h2&&l1>l2&&c1>c2&&c2>c3){r.name="3 IN UP";r.type=1;r.strength=3;return r;}
  1472. if(bear1&&bull3&&h1<h2&&l1<l2&&c1<c2&&c2<c3){r.name="3 IN DN";r.type=-1;r.strength=3;return r;}
  1473. if(bull1&&bear3&&h1>h2&&l1<l2&&c1>o2){r.name="3 OUT UP";r.type=1;r.strength=4;return r;}
  1474. if(bear1&&bull3&&h1>h2&&l1<l2&&c1<o2){r.name="3 OUT DN";r.type=-1;r.strength=4;return r;}
  1475. return r;
  1476. }
  1477.  
  1478. NCPPatternResult NCPCheckColorPattern(){
  1479. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="MULTI";if(Bars<8)return r;
  1480. int bullRun=0,bearRun=0;
  1481. for(int i=1;i<=6&&i<Bars;i++){if(Close[i]>Open[i]){if(bearRun>0)break;bullRun++;}else if(Close[i]<Open[i]){if(bullRun>0)break;bearRun++;}else break;}
  1482. if(bullRun>=3){r.name="3G-RUN";r.type=-1;r.strength=3;double b1=MathAbs(Close[1]-Open[1]),b2=MathAbs(Close[2]-Open[2]),b3=MathAbs(Close[3]-Open[3]);if(b1<b2&&b2<b3){r.strength=4;r.name="3G-WEAK";}}
  1483. else if(bearRun>=3){r.name="3R-RUN";r.type=1;r.strength=3;double b1=MathAbs(Close[1]-Open[1]),b2=MathAbs(Close[2]-Open[2]),b3=MathAbs(Close[3]-Open[3]);if(b1<b2&&b2<b3){r.strength=4;r.name="3R-WEAK";}}
  1484. if(bullRun>=4){r.name="4G-RUN";r.type=-1;r.strength=4;}else if(bearRun>=4){r.name="4R-RUN";r.type=1;r.strength=4;}
  1485. if(bullRun>=5){r.name="5G-EXHAUST";r.type=-1;r.strength=5;double v1=(double)iVolume(NULL,PERIOD_M1,1),v5=(double)iVolume(NULL,PERIOD_M1,5);if(v5>0&&v1<v5*0.6){r.strength=6;r.name="5G-EXH+VOL";}}
  1486. else if(bearRun>=5){r.name="5R-EXHAUST";r.type=1;r.strength=5;double v1=(double)iVolume(NULL,PERIOD_M1,1),v5=(double)iVolume(NULL,PERIOD_M1,5);if(v5>0&&v1<v5*0.6){r.strength=6;r.name="5R-EXH+VOL";}}
  1487. return r;
  1488. }
  1489.  
  1490. void NCPScanAllPatterns(){g_ncpPatternBullScore=0;g_ncpPatternBearScore=0;g_ncpMainPattern="";int bestStrength=0;
  1491. for(int i=0;i<=2;i++){NCPPatternResult p=NCPCheckSinglePattern(i);if(p.type!=0&&p.strength>0){int weight=(i==0)?3:(i==1)?2:1;if(p.type==1)g_ncpPatternBullScore+=p.strength*weight;else if(p.type==-1)g_ncpPatternBearScore+=p.strength*weight;if(p.strength*weight>bestStrength){bestStrength=p.strength*weight;g_ncpMainPattern=p.name;}}}
  1492. for(int i=0;i<=1;i++){NCPPatternResult p=NCPCheckDualPattern(i);if(p.type!=0&&p.strength>0){int weight=(i==0)?4:2;if(p.type==1)g_ncpPatternBullScore+=p.strength*weight;else if(p.type==-1)g_ncpPatternBearScore+=p.strength*weight;if(p.strength*weight>bestStrength){bestStrength=p.strength*weight;g_ncpMainPattern=p.name;}}}
  1493. NCPPatternResult p3=NCPCheckTriplePattern(0);if(p3.type!=0&&p3.strength>0){if(p3.type==1)g_ncpPatternBullScore+=p3.strength*5;else if(p3.type==-1)g_ncpPatternBearScore+=p3.strength*5;if(p3.strength*5>bestStrength){bestStrength=p3.strength*5;g_ncpMainPattern=p3.name;}}
  1494. if(NCP8_UseColorPattern){NCPPatternResult pc=NCPCheckColorPattern();if(pc.type!=0&&pc.strength>0){if(pc.type==1)g_ncpPatternBullScore+=pc.strength*3;else if(pc.type==-1)g_ncpPatternBearScore+=pc.strength*3;if(pc.strength*3>bestStrength&&bestStrength<15){g_ncpMainPattern=pc.name;}}}
  1495. g_ncpPatternBullScore=MathMin(100,g_ncpPatternBullScore);g_ncpPatternBearScore=MathMin(100,g_ncpPatternBearScore);
  1496. }
  1497.  
  1498. int NCPCheckHRNRejection(){if(g_hrn_price<=0)return 0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];double dist=MathAbs(cur-g_hrn_price)/pip;if(dist>10)return 0;int score=0;if(g_hrn_is_sup){if(Low[1]<=g_hrn_price+2*pip&&Close[1]>g_hrn_price){score+=15;double rng=High[1]-Low[1];if(rng>0){double lw=MathMin(Open[1],Close[1])-Low[1];if(lw/rng>0.50)score+=10;}}if(Close[1]<g_hrn_price-2*pip)score-=12;}else{if(High[1]>=g_hrn_price-2*pip&&Close[1]<g_hrn_price){score-=15;double rng=High[1]-Low[1];if(rng>0){double uw=High[1]-MathMax(Open[1],Close[1]);if(uw/rng>0.50)score-=10;}}if(Close[1]>g_hrn_price+2*pip)score+=12;}return score;}
  1499. int NCPCheckDivergence(){if(!NCP8_UseDivergence||Bars<30)return 0;int score=0;double rsi1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);double rsi5=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);double low5=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)];double low10=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,10,6)];if(low5<low10&&rsi1>rsi5&&rsi1<45)score+=20;double high5=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)];double high10=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,10,6)];if(high5>high10&&rsi1<rsi5&&rsi1>55)score-=20;double macd1=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1);double macd5=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,5);if(macd1>macd5&&Close[1]<Close[5]&&macd1<0)score+=12;if(macd1<macd5&&Close[1]>Close[5]&&macd1>0)score-=12;return score;}
  1500.  
  1501. // ============================================================
  1502. // PSYCHE BREAKER v4.3 - FINAL POLISH EDITION
  1503. // ============================================================
  1504. void CalcPsycheBreaker(){
  1505. // RESET
  1506. g_psycheScore = 0; g_psycheDir = "NONE"; g_psycheWick = "--"; g_psycheVol = "--";
  1507. g_psycheHA = "--"; g_psycheSR = "--"; g_psycheSignal = "SCANNING"; g_psycheClr = NEON_WHITE;
  1508. g_psycheUpperWick = 0; g_psycheLowerWick = 0;
  1509. if(Bars < 50) return;
  1510. if(High[0] - Low[0] == 0) return;
  1511.  
  1512. bool jpy = (StringFind(Symbol(), "JPY") >= 0);
  1513. double pip = jpy ? 0.01 : 0.0001;
  1514.  
  1515. // UNIVERSAL BASESTEP
  1516. double curPrice = Close[0];
  1517. double baseStep = 0;
  1518. double stepGuess1 = MathPow(10, -MathFloor(MathLog10(pip)));
  1519. double stepGuess2 = MathPow(10, -MathFloor(MathLog10(pip)) + 1);
  1520. double rounded1 = MathFloor(curPrice / stepGuess1) * stepGuess1;
  1521. double rounded2 = MathFloor(curPrice / stepGuess2) * stepGuess2;
  1522.  
  1523. if(MathAbs(curPrice - rounded1) < pip * 0.5) baseStep = stepGuess1;
  1524. else if(MathAbs(curPrice - rounded2) < pip * 0.5) baseStep = stepGuess2;
  1525. else baseStep = stepGuess1;
  1526. if(baseStep == 0) baseStep = stepGuess1;
  1527.  
  1528. double multipliers[7] = {0.00, 0.25, 0.50, 0.60, 0.75, 1.00, 1.25};
  1529. double base = MathFloor(curPrice / baseStep) * baseStep;
  1530.  
  1531. double bestLevel = 0;
  1532. int bestTrapScore = 0;
  1533. int bestTouchScore = 0;
  1534. double tolerance = 6.0 * pip;
  1535.  
  1536. for(int h = 0; h < 7; h++){
  1537. double level = base + (multipliers[h] * baseStep);
  1538. double dist = MathAbs(curPrice - level) / pip;
  1539. if(dist > 15) continue;
  1540.  
  1541. int localScore = 0; int localTrap = 0;
  1542. for(int c = 1; c <= 20 && c < Bars; c++){
  1543. double uw = High[c] - MathMax(Open[c], Close[c]);
  1544. double lw = MathMin(Open[c], Close[c]) - Low[c];
  1545. double rng = High[c] - Low[c];
  1546. if(rng <= 0) continue;
  1547. if(MathAbs(High[c] - level) <= tolerance){ localScore += 12; if(rng > 3*pip && (uw/rng) > 0.45) localTrap += 25; }
  1548. if(MathAbs(Low[c] - level) <= tolerance){ localScore += 12; if(rng > 3*pip && (lw/rng) > 0.45) localTrap += 25; }
  1549. if(MathAbs(Close[c] - level) <= tolerance * 0.5){
  1550. if(Low[c] < level - tolerance && Close[c] > level) localTrap += 20;
  1551. if(High[c] > level + tolerance && Close[c] < level) localTrap += 20;
  1552. }
  1553. }
  1554. if(localScore > bestTouchScore || localTrap > bestTrapScore){
  1555. bestTouchScore = localScore; bestTrapScore = localTrap; bestLevel = level;
  1556. }
  1557. }
  1558.  
  1559. int otcTrapCubeScore = 0;
  1560. if(bestTrapScore > 100) otcTrapCubeScore = 40;
  1561. else if(bestTrapScore > 60) otcTrapCubeScore = 30;
  1562. else if(bestTrapScore > 30) otcTrapCubeScore = 20;
  1563. else if(bestTrapScore > 0) otcTrapCubeScore = 10;
  1564.  
  1565. string otcDirection = "NONE";
  1566. if(bestLevel > 0){
  1567. if(bestLevel > curPrice) otcDirection = "PUT";
  1568. else if(bestLevel < curPrice) otcDirection = "CALL";
  1569. }
  1570.  
  1571. // WICK CLUSTER
  1572. int upperWickCount = 0; int lowerWickCount = 0;
  1573. double totalUpperPct = 0; double totalLowerPct = 0;
  1574. for(int j = 1; j <= 12 && j < Bars; j++){
  1575. double rng = High[j] - Low[j];
  1576. if(rng <= 0 || rng < 2 * pip) continue;
  1577. double uw = High[j] - MathMax(Open[j], Close[j]);
  1578. double lw = MathMin(Open[j], Close[j]) - Low[j];
  1579. double uwPct = uw / rng, lwPct = lw / rng;
  1580. if(uwPct > 0.50 && uw > pip){ upperWickCount++; totalUpperPct += uwPct; }
  1581. if(lwPct > 0.50 && lw > pip){ lowerWickCount++; totalLowerPct += lwPct; }
  1582. }
  1583. g_psycheUpperWick = upperWickCount; g_psycheLowerWick = lowerWickCount;
  1584.  
  1585. int wickScore = 0;
  1586. if(upperWickCount > lowerWickCount){
  1587. double intensity = (totalUpperPct / (upperWickCount+0.1)) * 10;
  1588. wickScore = (int)(upperWickCount * 3 + intensity);
  1589. g_psycheWick = upperWickCount + "x UP TRAP";
  1590. if(otcDirection == "NONE") g_psycheDir = "PUT";
  1591. }
  1592. else if(lowerWickCount > upperWickCount){
  1593. double intensity = (totalLowerPct / (lowerWickCount+0.1)) * 10;
  1594. wickScore = (int)(lowerWickCount * 3 + intensity);
  1595. g_psycheWick = lowerWickCount + "x DN TRAP";
  1596. if(otcDirection == "NONE") g_psycheDir = "CALL";
  1597. }
  1598. if(upperWickCount >= 2 || lowerWickCount >= 2) wickScore += 15;
  1599. if(wickScore > 40) wickScore = 40;
  1600.  
  1601. // VOLUME SPIKE
  1602. double curVol = (double)iVolume(NULL, PERIOD_M1, 1);
  1603. double avgVol = 0; double maxVol = 0; int volCount = 0;
  1604. for(int j = 2; j <= 21 && j < Bars; j++){double v = (double)iVolume(NULL, PERIOD_M1, j); avgVol += v; if(v > maxVol) maxVol = v; volCount++;}
  1605. if(volCount > 0) avgVol /= (double)volCount;
  1606.  
  1607. int volScore = 0;
  1608. if(avgVol > 0 && curVol > maxVol * 0.7){
  1609. double volRatio = curVol / avgVol;
  1610. if(volRatio > 2.5){ volScore = 25; g_psycheVol = DoubleToString(volRatio,1) + "x SPIKE"; }
  1611. else if(volRatio > 1.8){ volScore = 20; g_psycheVol = DoubleToString(volRatio,1) + "x HIGH"; }
  1612. else if(volRatio > 1.3){ volScore = 12; g_psycheVol = DoubleToString(volRatio,1) + "x MED"; }
  1613. else { g_psycheVol = DoubleToString(volRatio,1) + "x --"; }
  1614. } else { g_psycheVol = "--"; }
  1615.  
  1616. // S/R & MTF
  1617. int srScore = 0;
  1618. if(g_nearest_res > 0){double distR = (g_nearest_res - curPrice) / pip;if(distR >= 0 && distR < 8){ srScore = 20; g_psycheSR = "AT RES!"; }else if(distR >= 0 && distR < 15){ srScore = 10; g_psycheSR = "NEAR RES"; }}
  1619. if(g_nearest_sup > 0){double distS = (curPrice - g_nearest_sup) / pip;if(distS >= 0 && distS < 8){ srScore = 20; g_psycheSR = "AT SUP!"; }else if(distS >= 0 && distS < 15){ srScore = 10; g_psycheSR = "NEAR SUP"; }}
  1620.  
  1621. int mtfScore = 0;
  1622. bool m1Bull = (g_haM1 == "HA BULLISH 1");
  1623. bool m1Bear = (g_haM1 == "HA BEARISH 1");
  1624. bool m5Bull = (g_haM5 == "HA BULLISH 5");
  1625. bool m5Bear = (g_haM5 == "HA BEARISH 5");
  1626.  
  1627. if(g_psycheDir == "PUT" && m1Bull){ mtfScore += 15; g_psycheHA = "FAKE BULL"; }
  1628. else if(g_psycheDir == "CALL" && m1Bear){ mtfScore += 15; g_psycheHA = "FAKE BEAR"; }
  1629. else if(m1Bull && m5Bull){ mtfScore += 8; g_psycheHA = "BULL ALIGN"; }
  1630. else if(m1Bear && m5Bear){ mtfScore += 8; g_psycheHA = "BEAR ALIGN"; }
  1631. else { g_psycheHA = "MIXED"; }
  1632. if(mtfScore > 15) mtfScore = 15;
  1633.  
  1634. // FINAL CUBE CALC & SMART DISPLAY
  1635. if(otcDirection != "NONE" && otcTrapCubeScore >= 20){
  1636. g_psycheDir = otcDirection;
  1637. if(otcDirection == "PUT") g_psycheWick = "OTC DEEP PUT";
  1638. if(otcDirection == "CALL") g_psycheWick = "OTC DEEP CALL";
  1639. }
  1640.  
  1641. g_psycheScore = (double)(otcTrapCubeScore + wickScore + volScore + srScore + mtfScore);
  1642. if(g_psycheScore > 130) g_psycheScore = 130;
  1643.  
  1644. // SMART SIGNAL LOGIC (Ab 50+ par hi strong color dikhega)
  1645. if(g_psycheScore >= 75 && g_psycheDir == "PUT"){g_psycheSignal = "STRONG PUT!"; g_psycheClr = NEON_RED;}
  1646. else if(g_psycheScore >= 75 && g_psycheDir == "CALL"){g_psycheSignal = "STRONG CALL!"; g_psycheClr = NEON_GREEN;}
  1647. else if(g_psycheScore >= 45 && g_psycheDir == "PUT"){g_psycheSignal = "PUT SETUP"; g_psycheClr = NEON_ORANGE;}
  1648. else if(g_psycheScore >= 45 && g_psycheDir == "CALL"){g_psycheSignal = "CALL SETUP"; g_psycheClr = C'0,200,150';}
  1649. else if(g_psycheDir == "PUT"){g_psycheSignal = "WEAK PUT"; g_psycheClr = NEON_ORANGE;}
  1650. else if(g_psycheDir == "CALL"){g_psycheSignal = "WEAK CALL"; g_psycheClr = C'0,200,150';}
  1651. else {g_psycheSignal = "NO TRAP"; g_psycheClr = NEON_WHITE;}
  1652. }
  1653.  
  1654. // ============================================================
  1655. // NCP PRO v8.0 CORE ENGINE
  1656. // ============================================================
  1657. NCPTrendInfo NCPDetectTrend(){NCPTrendInfo t;t.m15Direction="FLAT";t.m15Strength=0;t.m1Bias=0;t.m5Direction="FLAT";t.m5Strength=0;t.aligned=false;if(Bars<20)return t;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;int greenCount=0,redCount=0;double greenBody=0,redBody=0;for(int i=1;i<=15&&i<Bars;i++){double body=Close[i]-Open[i];double absBody=MathAbs(body);if(body>0){greenCount++;greenBody+=absBody;}else if(body<0){redCount++;redBody+=absBody;}}double netBody=greenBody-redBody;t.m1Bias=(int)((netBody/pip)*2);if(t.m1Bias>100)t.m1Bias=100;if(t.m1Bias<-100)t.m1Bias=-100;if(iBars(NULL,PERIOD_M15)>=3){double m15Open=iOpen(NULL,PERIOD_M15,1);double m15Close=iClose(NULL,PERIOD_M15,1);double m15High=iHigh(NULL,PERIOD_M15,1);double m15Low=iLow(NULL,PERIOD_M15,1);double m15Body=m15Close-m15Open;double m15Range=m15High-m15Low;if(m15Body>5*pip){t.m15Direction="UP";t.m15Strength=(m15Range>0)?(int)(MathAbs(m15Body)/m15Range*10):5;}else if(m15Body<-5*pip){t.m15Direction="DOWN";t.m15Strength=(m15Range>0)?(int)(MathAbs(m15Body)/m15Range*10):5;}else{t.m15Direction="FLAT";t.m15Strength=3;}for(int j=1;j<=3;j++){double m5c=iClose(NULL,PERIOD_M5,j);double m5o=iOpen(NULL,PERIOD_M5,j);if(m5c>m5o)t.m5Strength++;else if(m5c<m5o)t.m5Strength--;}t.m5Direction=(t.m5Strength>1)?"UP":(t.m5Strength<-1)?"DOWN":"FLAT";}else{if(greenCount>=10){t.m15Direction="UP";t.m15Strength=greenCount-7;}else if(redCount>=10){t.m15Direction="DOWN";t.m15Strength=redCount-7;}t.m5Direction=(greenCount>redCount+2)?"UP":(redCount>greenCount+2)?"DOWN":"FLAT";}bool m1Up=(greenCount>redCount+2);bool m1Dn=(redCount>greenCount+2); bool m5Up=(t.m5Direction=="UP"); bool m5Dn=(t.m5Direction=="DOWN"); bool m15Up=(t.m15Direction=="UP"); bool m15Dn=(t.m15Direction=="DOWN"); t.aligned=(m1Up&&m5Up&&m15Up)||(m1Dn&&m5Dn&&m15Dn); return t;}
  1658.  
  1659. void NCPDetectDynamicSR(){g_ncpSRCount=0;if(Bars<30)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];for(int i=3;i<=30&&i<Bars-2&&g_ncpSRCount<15;i++){if(High[i]>High[i-1]&&High[i]>High[i-2]&&High[i]>High[i+1]&&High[i]>High[i+2]){double lv=High[i];if(MathAbs(lv-cur)/pip<40)NCPAddSRZone(lv,"RESISTANCE",1,false,false,iTime(NULL,PERIOD_M1,i));}if(Low[i]<Low[i-1]&&Low[i]<Low[i-2]&&Low[i]<Low[i+1]&&Low[i]<Low[i+2]){double lv=Low[i];if(MathAbs(lv-cur)/pip<40)NCPAddSRZone(lv,"SUPPORT",1,false,false,iTime(NULL,PERIOD_M1,i));}}double rndSteps[]={5,10,25,50,100};for(int s=0;s<5;s++){double step=rndSteps[s]*pip;double nearRound=MathRound(cur/step)*step;for(int k=-1;k<=1;k++){double lv=nearRound+k*step;if(MathAbs(lv-cur)/pip<30){string type=(lv>cur)?"RESISTANCE":"SUPPORT";NCPAddSRZone(lv,type,(s<2)?3:(s<3)?2:1,true,false,TimeCurrent());}}}if(NCP8_UseOrderBlocks)NCPDetectOrderBlocks();}
  1660.  
  1661. void NCPAddSRZone(double price,string type,int strength,bool isRound,bool isOB,datetime lastTouch){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double tol=5*pip;for(int i=0;i<g_ncpSRCount;i++){if(MathAbs(g_ncpSRZones[i].price-price)<tol&&g_ncpSRZones[i].type==type){g_ncpSRZones[i].touches++;g_ncpSRZones[i].strength=MathMin(10,g_ncpSRZones[i].strength+1);g_ncpSRZones[i].lastTouch=lastTouch;if(isRound)g_ncpSRZones[i].isRoundNum=true;if(isOB)g_ncpSRZones[i].isOrderBlock=true;return;}}if(g_ncpSRCount<20){g_ncpSRZones[g_ncpSRCount].price=price;g_ncpSRZones[g_ncpSRCount].type=type;g_ncpSRZones[g_ncpSRCount].touches=1;g_ncpSRZones[g_ncpSRCount].strength=strength;g_ncpSRZones[g_ncpSRCount].isRoundNum=isRound;g_ncpSRZones[g_ncpSRCount].isOrderBlock=isOB;g_ncpSRZones[g_ncpSRCount].lastTouch=lastTouch;g_ncpSRCount++;}}
  1662.  
  1663. // FIX: Removed Array Access Risk
  1664. void NCPDetectOrderBlocks(){
  1665. if(Bars<30)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1666. for(int i=2;i<=20&&i<Bars&&g_ncpSRCount<18;i++){
  1667. int startJ = MathMax(1, i-3); // FIX: Ensure startJ doesn't go below 1
  1668. if(Close[i]<Open[i]){
  1669. double move=0;for(int j=i-1;j>=startJ;j--){if(Close[j]>Open[j])move+=Close[j]-Open[j];else break;}
  1670. if(move>8*pip){double obLow=Low[i];if(MathAbs(obLow-cur)/pip<20&&cur>obLow)NCPAddSRZone(obLow,"SUPPORT",4,false,true,iTime(NULL,PERIOD_M1,i));}
  1671. }
  1672. if(Close[i]>Open[i]){
  1673. double move=0;for(int j=i-1;j>=startJ;j--){if(Close[j]<Open[j])move+=Open[j]-Close[j];else break;}
  1674. if(move>8*pip){double obHigh=High[i];if(MathAbs(obHigh-cur)/pip<20&&cur<obHigh)NCPAddSRZone(obHigh,"RESISTANCE",4,false,true,iTime(NULL,PERIOD_M1,i));}
  1675. }
  1676. }
  1677. }
  1678.  
  1679. int NCPGetSRSignal(){if(g_ncpSRCount==0)return 0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];int score=0;for(int i=0;i<g_ncpSRCount;i++){double dist=MathAbs(g_ncpSRZones[i].price-cur)/pip;if(dist>15)continue;int weight=g_ncpSRZones[i].strength;if(g_ncpSRZones[i].isRoundNum)weight+=2;if(g_ncpSRZones[i].isOrderBlock)weight+=3;if(g_ncpSRZones[i].touches>=3)weight+=2;if(g_ncpSRZones[i].type=="SUPPORT"){if(dist<3)score+=weight*3;else if(dist<7)score+=weight*2;else if(dist<12)score+=weight;if(Low[1]<g_ncpSRZones[i].price+2*pip&&Close[1]>g_ncpSRZones[i].price)score+=weight*2;}else if(g_ncpSRZones[i].type=="RESISTANCE"){if(dist<3)score-=weight*3;else if(dist<7)score-=weight*2;else if(dist<12)score-=weight;if(High[1]>g_ncpSRZones[i].price-2*pip&&Close[1]<g_ncpSRZones[i].price)score-=weight*2;}}return MathMax(-50,MathMin(50,score));}
  1680.  
  1681. string NCPGetSRSummary(){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];double nearSup=0,nearRes=0;int supStr=0,resStr=0;for(int i=0;i<g_ncpSRCount;i++){double dist=MathAbs(g_ncpSRZones[i].price-cur)/pip;if(dist>15)continue;if(g_ncpSRZones[i].type=="SUPPORT"&&(nearSup==0||dist<MathAbs(nearSup-cur)/pip)){nearSup=g_ncpSRZones[i].price;supStr=g_ncpSRZones[i].strength;}if(g_ncpSRZones[i].type=="RESISTANCE"&&(nearRes==0||dist<MathAbs(nearRes-cur)/pip)){nearRes=g_ncpSRZones[i].price;resStr=g_ncpSRZones[i].strength;}}string result="";if(nearSup>0)result+="S:"+ShortPrice(nearSup)+"["+IntegerToString(supStr)+"] ";if(nearRes>0)result+="R:"+ShortPrice(nearRes)+"["+IntegerToString(resStr)+"]";if(result=="")result="No nearby SR";return result;}
  1682.  
  1683. // ============================================================
  1684. // LEARNING ENGINE v8.0
  1685. // ============================================================
  1686. void LoadBrainMemory(){if(!ENABLE_LEARNING) return;int h = FileOpen(MEMORY_FILE_NAME, FILE_READ|FILE_TXT|FILE_SHARE_READ);if(h != INVALID_HANDLE){if(FileSize(h) > 10){string line = FileReadString(h);StringReplace(line, " ", "");int p1 = StringFind(line, ","), p2 = StringFind(line, ",", p1+1);int p3 = StringFind(line, ",", p2+1), p4 = StringFind(line, ",", p3+1);int p5 = StringFind(line, ",", p4+1), p6 = StringFind(line, ",", p5+1);if(p6 > 0){g_totalTrades = (int)StringToInteger(StringSubstr(line, 0, p1));g_callTrades = (int)StringToInteger(StringSubstr(line, p1+1, p2-p1-1));g_putTrades = (int)StringToInteger(StringSubstr(line, p2+1, p3-p2-1));g_callWins = (int)StringToInteger(StringSubstr(line, p3+1, p4-p3-1));g_putWins = (int)StringToInteger(StringSubstr(line, p4+1, p5-p4-1));g_callWeight = StringToDouble(StringSubstr(line, p5+1, p6-p5-1));g_putWeight = StringToDouble(StringSubstr(line, p6+1));if(g_callWeight<0.2 || g_callWeight>1.8) g_callWeight = 1.0;if(g_putWeight<0.2 || g_putWeight>1.8) g_putWeight = 1.0;}}FileClose(h);} else g_brokerBias = 0.0;}
  1687. void SaveBrainMemory(){if(!ENABLE_LEARNING)return;int h=FileOpen(MEMORY_FILE_NAME,FILE_WRITE|FILE_TXT|FILE_SHARE_WRITE);if(h!=INVALID_HANDLE){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);FileWriteString(h,line);FileFlush(h);FileClose(h);}}
  1688. void UpdateBrain(string sig,bool win){if(!ENABLE_LEARNING)return;g_totalTrades++;if(sig=="CALL"){g_callTrades++;if(win)g_callWins++;}else if(sig=="PUT"){g_putTrades++;if(win)g_putWins++;}if(g_totalTrades<MIN_TRADES_TO_LEARN){SaveBrainMemory();return;}double adj=LEARNING_STEP;if(sig=="CALL"){double wr=(g_callTrades>0)?(double)g_callWins/g_callTrades:0.5;double adaptive=adj*(wr-0.5)*2.0;if(win)g_callWeight=MathMin(1.8,g_callWeight+adj+adaptive);else g_callWeight=MathMax(0.3,g_callWeight-adj*1.5+adaptive);if(g_callTrades<MIN_TRADES_TO_LEARN+5)g_callWeight=MathMax(0.6,g_callWeight);}else if(sig=="PUT"){double wr=(g_putTrades>0)?(double)g_putWins/g_putTrades:0.5;double adaptive=adj*(wr-0.5)*2.0;if(win)g_putWeight=MathMin(1.8,g_putWeight+adj+adaptive);else g_putWeight=MathMax(0.3,g_putWeight-adj*1.5+adaptive);if(g_putTrades<MIN_TRADES_TO_LEARN+5)g_putWeight=MathMax(0.6,g_putWeight);}SaveBrainMemory();}
  1689. void CheckPreviousResult(){if(g_ncpSignalProcessed||g_ncpLastSignalType==""||g_ncpLastSignalTime==0)return;if(Time[0]==g_ncpLastSignalTime)return;double sigOpen=iOpen(NULL,PERIOD_M1,1);double sigClose=iClose(NULL,PERIOD_M1,1);bool win=false;if(g_ncpLastSignalType=="CALL")win=(sigClose>sigOpen);else if(g_ncpLastSignalType=="PUT")win=(sigClose<sigOpen);g_ncpSignalProcessed=true;UpdateBrain(g_ncpLastSignalType,win);}
  1690.  
  1691. // ============================================================
  1692. // NCP PRO v8.0 MTG ENGINE
  1693. // ============================================================
  1694. void CalculateMTG(){
  1695. if(!ENABLE_MTG || Bars < 50){g_mtgState="OFF"; g_mtgReason=""; g_mtgClr=CGR; return;}
  1696. bool jpy = (StringFind(Symbol(), "JPY") >= 0); double pip = jpy ? 0.01 : 0.0001;
  1697. CheckPreviousResult();
  1698. int sec = (int)(TimeCurrent() - Time[0]);
  1699. if(sec < NCP_OpenNoiseSeconds){g_mtgState="..."; g_mtgReason="Bar open"; g_mtgClr=CGR; g_mtgHype=50; g_mtgBetrayal=50; return;}
  1700. if(sec >= NCP_KillZoneSeconds){g_mtgState="END"; g_mtgReason="Late"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  1701. double spPips = MarketInfo(Symbol(), MODE_SPREAD) * Point / pip;
  1702. if(spPips > NCP_MaxSpreadPips){g_mtgState="SPREAD"; g_mtgReason=DoubleToString(spPips,1)+"p"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  1703. double vol1 = (double)iVolume(NULL, PERIOD_M1, 1); double volAvg = 0;
  1704. for(int v = 2; v <= 21; v++) volAvg += (double)iVolume(NULL, PERIOD_M1, v); volAvg /= 20.0;
  1705. if(volAvg > 0 && vol1 < volAvg * 0.7){g_mtgState="WAIT"; g_mtgReason="LOW VOL"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  1706. double atr = iATR(Symbol(), PERIOD_M1, NCP_ATRPeriod, 1); double atrPips = atr / pip;
  1707. if(atrPips < NCP_MinATRPips){g_mtgState="FLAT"; g_mtgReason="Low ATR"; g_mtgClr=CGR; g_mtgHype=50; g_mtgBetrayal=50; return;}
  1708. g_ncpADX = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  1709. double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  1710. double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  1711. g_ncpPlusDI = plusDI; g_ncpMinusDI = minusDI;
  1712. if(g_ncpADX < 22){g_mtgState="WAIT"; g_mtgReason="ADX LOW"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  1713. if(NCP8_UseM15Trend) g_ncpTrend = NCPDetectTrend();
  1714. if(NCP8_UseDynamicSR) NCPDetectDynamicSR();
  1715. if(NCP8_UsePatterns) NCPScanAllPatterns();
  1716. double macd_main = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);
  1717. double macd_sig = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1);
  1718. bool closedBull = (Close[1] > Open[1]); bool closedBear = (Close[1] < Open[1]);
  1719. double body1 = MathAbs(Close[1] - Open[1]); double rng1 = High[1] - Low[1];
  1720. double dynamicBodyThresh = atr * (0.35 + (g_ncpADX - 20) / 100.0);
  1721. int callConfluence = 0, putConfluence = 0;
  1722. double weightMultiplier = 1.0 + (g_ncpADX - 20) / 50.0;
  1723. if(NCP8_UseM15Trend){if(g_ncpTrend.m15Direction == "UP") callConfluence += (int)(3 * weightMultiplier); else if(g_ncpTrend.m15Direction == "DOWN") putConfluence += (int)(3 * weightMultiplier);}
  1724. double eF = iMA(NULL, 0, NCP_FastEMA, 0, MODE_EMA, PRICE_CLOSE, 1), eM = iMA(NULL, 0, NCP_MidEMA, 0, MODE_EMA, PRICE_CLOSE, 1), eS = iMA(NULL, 0, NCP_SlowEMA, 0, MODE_EMA, PRICE_CLOSE, 1), eF_prev = iMA(NULL, 0, NCP_FastEMA, 0, MODE_EMA, PRICE_CLOSE, 2);
  1725. if(eF > eM && eM > eS && eF > eF_prev) callConfluence += (int)(2.5 * weightMultiplier); else if(eF < eM && eM < eS && eF < eF_prev) putConfluence += (int)(2.5 * weightMultiplier);
  1726. if(g_haM1 == "HA BULLISH 1") callConfluence += 1; else if(g_haM1 == "HA BEARISH 1") putConfluence += 1;
  1727. if(g_haM5 == "HA BULLISH 5") callConfluence += 1; else if(g_haM5 == "HA BEARISH 5") putConfluence += 1;
  1728. if(plusDI > minusDI + 5) callConfluence += 2; else if(minusDI > plusDI + 5) putConfluence += 2;
  1729. double rsi1 = iRSI(NULL, 0, NCP_RSIPeriod, PRICE_CLOSE, 1), rsi2 = iRSI(NULL, 0, NCP_RSIPeriod, PRICE_CLOSE, 2);
  1730. if(rsi1 > 55 && rsi1 > rsi2) callConfluence++; else if(rsi1 < 45 && rsi1 < rsi2) putConfluence++;
  1731. double bodyPct = (rng1 > 0) ? (body1 / rng1) * 100.0 : 0;
  1732. if(closedBull && body1 > dynamicBodyThresh && bodyPct > 60) callConfluence += 3; else if(closedBear && body1 > dynamicBodyThresh && bodyPct > 60) putConfluence += 3;
  1733. bool nearSup = (g_nearest_sup > 0 && MathAbs(Close[1] - g_nearest_sup) < atrPips * 1.2);
  1734. bool nearRes = (g_nearest_res > 0 && MathAbs(Close[1] - g_nearest_res) < atrPips * 1.2);
  1735. if(nearSup) callConfluence += 2; if(nearRes) putConfluence += 2;
  1736. if(g_ncpPatternBullScore > g_ncpPatternBearScore + 15 && vol1 > volAvg * 1.2) callConfluence += 2; else if(g_ncpPatternBearScore > g_ncpPatternBullScore + 15 && vol1 > volAvg * 1.2) putConfluence += 2;
  1737. if(macd_main > macd_sig && macd_main > 0) callConfluence += 1; if(macd_main < macd_sig && macd_main < 0) putConfluence += 1;
  1738. double totalPossible = callConfluence + putConfluence;
  1739. double callStrength = totalPossible > 0 ? (double)callConfluence / totalPossible * 100 : 50;
  1740. double smoothFactor = MathMin(0.65, 0.45 + (atrPips / 20.0) * 0.1);
  1741. g_smoothCallScore = g_smoothCallScore * (1.0 - smoothFactor) + callStrength * smoothFactor;
  1742. g_smoothPutScore = 100.0 - g_smoothCallScore;
  1743. g_mtgHype = NormalizeDouble(g_smoothCallScore, 1); g_mtgBetrayal = NormalizeDouble(g_smoothPutScore, 1);
  1744. string lockReason = ""; int minConfluence = 8;
  1745. if(callConfluence < minConfluence && putConfluence < minConfluence) lockReason = "LOW CONF";
  1746. if(lockReason != ""){g_mtgState = "WAIT"; g_mtgReason = lockReason; g_mtgAction = lockReason; g_mtgClr = NEON_YELLOW; g_mtgBullCount = callConfluence; g_mtgBearCount = putConfluence; g_mtgRecovery = NormalizeDouble(atrPips, 1); g_mtgPattern = "LOCK"; g_ncpSignalProcessed = true; return;}
  1747. int minP = 62; double edge = MathAbs(g_smoothCallScore - 50);
  1748. string str = "WEAK"; if(edge >= 28) str = "EXTREME"; else if(edge >= 22) str = "STRONG"; else if(edge >= 15) str = "MEDIUM";
  1749. if(Time[0] != g_ncpLastSignalTime){g_ncpLastSignalTime = Time[0]; g_ncpSignalProcessed = false;}
  1750. if(g_smoothCallScore >= minP && g_smoothCallScore > g_smoothPutScore){g_mtgState = "CALL"; g_mtgReason = g_ncpDetailLine1; g_mtgAction = "CALL " + DoubleToString(g_smoothCallScore, 1) + "% [" + str + "]"; g_mtgClr = (str == "EXTREME") ? NEON_GREEN : NEON_LIME; if(!g_ncpSignalProcessed){ g_ncpLastSignalType = "CALL"; g_ncpLastSignalTime = Time[0]; }}
  1751. else if(g_smoothPutScore >= minP && g_smoothPutScore > g_smoothCallScore){g_mtgState = "PUT"; g_mtgReason = g_ncpDetailLine1; g_mtgAction = "PUT " + DoubleToString(g_smoothPutScore, 1) + "% [" + str + "]"; g_mtgClr = (str == "EXTREME") ? NEON_RED : C'255,60,60'; if(!g_ncpSignalProcessed){ g_ncpLastSignalType = "PUT"; g_ncpLastSignalTime = Time[0]; }}
  1752. else{g_mtgState = "WAIT"; g_mtgReason = g_ncpDetailLine1; string edgeDir = (g_smoothCallScore > g_smoothPutScore) ? ">C" : ">P"; g_mtgAction = edgeDir + " " + DoubleToString(MathMax(g_smoothCallScore, g_smoothPutScore), 0) + "%"; g_mtgClr = NEON_YELLOW; g_ncpSignalProcessed = true;}
  1753. g_mtgBullCount = callConfluence; g_mtgBearCount = putConfluence; g_mtgRecovery = NormalizeDouble(atrPips, 1); g_mtgPattern = str; g_trapScore = 0;
  1754. }
  1755.  
  1756. // ============================================================
  1757. // DASHBOARD DRAWING HELPERS
  1758. // ============================================================
  1759. void DrawOtherPairsCube(int x,int y,int w,int h){
  1760. Bx("c20",x,y,w,h,BG_DARK2,NEON_GOLD);Tx("c20_l",x+8,y+4,"OTHER PAIRS",NEON_CYAN,10,true);
  1761. if(g_pairCount==0){if(StringFind(g_visualTrapPro.boxStatus, "[") >= 0){Tx("c20_v0",x+8,y+30,g_visualTrapPro.boxStatus,NEON_WHITE,11,true);Tx("c20_v1",x+8,y+52,"GANN BACKGROUND MATCH!",NEON_YELLOW,9,false);return;}Tx("c20_v0",x+8,y+30,"No signals yet",CGR,10,false);return;}
  1762. int lY=24;for(int i=0;i<g_pairCount&&i<5;i++){if(lY+16>h-4)break;string sp=g_pairNames[i];if(StringLen(sp)>9)sp=StringSubstr(sp,0,9);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]";bool isCallSig=(g_mtgState=="CALL");bool isPutSig=(g_mtgState=="PUT");bool ncpMatch=((isCallSig&&g_pairSigs[i]=="CALL")||(isPutSig&&g_pairSigs[i]=="PUT"));color dc;string prefix="";if(ncpMatch){dc=NEON_PURPLE;prefix="* ";}else{dc=(g_pairSigs[i]=="CALL")?NEON_GREEN:NEON_RED;}string txt=prefix+sp+" "+g_pairSigs[i]+" "+IntegerToString(qScore)+qLabel;Tx("c20_p"+IntegerToString(i),x+8,y+lY,txt,dc,10,true);lY+=20;}
  1763. }
  1764.  
  1765. void DrawOTCQuickCube(int x,int y,int w,int h){
  1766. 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);
  1767. int age=(int)(TimeCurrent()-Time[0]);int ps=Period()*60;int rem=ps-age;if(rem<0)rem=0;int mm=rem/60,ss2=rem%60;string tl=(mm>0?IntegerToString(mm)+"m ":"")+IntegerToString(ss2)+"s";
  1768. Tx("c_quick_t",x+8,y+20,"Time: "+tl,NEON_GOLD,11,true);
  1769. double spread=MarketInfo(Symbol(),MODE_SPREAD);color spC=(spread<=BROKER_SPREAD_THRESHOLD)?NEON_GREEN:NEON_ORANGE;Tx("c_quick_s",x+8,y+38,"Spread: "+DoubleToString(spread,0),spC,10,true);
  1770. double volLast=(double)iVolume(NULL,PERIOD_M1,1),volPrev=(double)iVolume(NULL,PERIOD_M1,2);double volRatio=(volPrev>0)?volLast/volPrev:1.0;color vColor;string vText;
  1771. if(volRatio>=2.0){vColor=NEON_GREEN;vText="VOL: "+DoubleToString(volRatio,1)+"x HIGH";}else if(volRatio>=1.3){vColor=NEON_LIME;vText="VOL: "+DoubleToString(volRatio,1)+"x UP";}else if(volRatio<=0.5){vColor=NEON_RED;vText="VOL: "+DoubleToString(volRatio,1)+"x LOW";}else{vColor=NEON_YELLOW;vText="VOL: "+DoubleToString(volRatio,1)+"x NORMAL";}
  1772. Tx("c_quick_v",x+8,y+56,vText,vColor,11,true);
  1773. string es=GetEntryStatus();color eC=GetEntryColor();Tx("c_quick_e",x+8,y+76,es,eC,10,true);
  1774. }
  1775.  
  1776. string GetEntryStatus(){int age=(int)(TimeCurrent()-Time[0]);int ps=Period()*60;int rem=ps-age;if(rem<0)rem=0;string ms=DetectMyStrategy();if(ms!="WAIT"){string type=(g_strategyType=="TRAP")?"TRAP":"TREND";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";}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";}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";}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";}
  1777. 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;return NEON_ORANGE;}
  1778. 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));return true;}
  1779. 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;}
  1780. 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;}
  1781. void SendTelegramAlert(string message){if(!ENABLE_TELEGRAM)return;if(StringLen(TELEGRAM_TOKEN)<10||StringLen(TELEGRAM_CHAT_ID)<5)return;string url="https://api.telegram.org/bot"+TELEGRAM_TOKEN+"/sendMessage?chat_id="+TELEGRAM_CHAT_ID+"&text="+message;char post[];char result_data[];string result_headers;int timeout=5000;int res=WebRequest("GET",url,"",timeout,post,result_data,result_headers);if(res==-1)Print("Telegram failed: ",GetLastError());}
  1782.  
  1783. 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);}
  1784. 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);}
  1785. 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);}
  1786. 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);}
  1787. // ============================================================
  1788. // MAIN PREDICTION ENGINE
  1789. // ============================================================
  1790. void CalcPrediction(double brain,double nb,int cp,double mai,int mts,double rsc,bool bf,double mw){
  1791. string ms=DetectMyStrategy();bool sA=(ms!="WAIT");
  1792. if(sA&&g_strategyType=="TRAP"){
  1793. 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;}
  1794. 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;}
  1795. }
  1796. double tS=UltimateTrapScore();bool bF2=IsBrokerForce();
  1797. 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;}}
  1798. 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;}
  1799. double gS=0,rS=0,ab=MathMax(0.70,MathMin(1.30,g_accuracy/65.0));
  1800. if(IsSidewaysMarket()){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;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);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;}if(nR)rS+=20;if(nS)gS+=20;}
  1801. 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;}}
  1802. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")gS+=60;else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")rS+=60;else if(g_haM1=="HA BULLISH 1")gS+=30;else if(g_haM1=="HA BEARISH 1")rS+=30;
  1803. if(HA_ALIGN_FILTER&&g_haBoth=="MIXED"){gS*=0.5;rS*=0.5;}
  1804. gS+=(nb-50)/50.0*22*ab;rS-=(nb-50)/50.0*22*ab;
  1805. double bn=MathMax(-1.0,MathMin(1.0,brain/10.0));gS+=bn*15*ab;rS-=bn*15*ab;
  1806. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1807. if(g_nearest_res>0&&(g_nearest_res-Close[0])<10*pip)rS+=12;if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)<10*pip)gS+=12;
  1808. double rsi1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);if(rsi1>70)rS+=6;if(rsi1<30)gS+=6;
  1809. double sn=MathMax(-1.0,MathMin(1.0,rsc/3.0));gS+=sn*8*ab;rS-=sn*8*ab;
  1810. if(ENABLE_BB_PULLBACK){if(g_bbSignal=="CALL")gS+=18*ab;else if(g_bbSignal=="PUT")rS+=18*ab;}
  1811. int rd=DetectRSIDivergence();if(rd==1)gS+=20;if(rd==-1)rS+=20;
  1812. int sk=StreakReversalSignal();if(sk==1)gS+=18;if(sk==-1)rS+=18;
  1813. 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;}
  1814. int vs=SmartVolumeSignal();if(vs==1)gS+=12;if(vs==-1)rS+=12;
  1815. if(!IsVolatilityGood()){gS*=0.5;rS*=0.5;}
  1816. double diff=MathMax(-100.0,MathMin(100.0,gS-rS));
  1817. g_gProb=MathMax(8.0,MathMin(92.0,50.0+(diff/1.8)));g_rProb=100.0-g_gProb;
  1818. double dom=MathMax(g_gProb,g_rProb);
  1819. 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;}}}
  1820. 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;}}}
  1821. else{if(!sA){g_pAction="WAIT";g_pColor=NEON_YELLOW;}}
  1822. g_calc_gProb=g_gProb;g_calc_rProb=g_rProb;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;
  1823. }
  1824. // ============================================================
  1825. // MAIN DASHBOARD DRAW (FIXED NEXT CANDLE CUBE)
  1826. // ============================================================
  1827. void Draw(){
  1828. HideSPM(); DelDashboard();
  1829. int W=DASH_W,G=8,CW=(W-2*G)/3,CH=110,cx=POS_X+G,yy=POS_Y;
  1830. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  1831. g_marketMode=DetectMarketMode(brain,g_rsc,cp,nb);
  1832. if(StringLen(g_prevMode)>0&&g_prevMode!=g_marketMode){g_signalTime=0;g_finalSignal="WAIT";}g_prevMode=g_marketMode;
  1833. CalcOTCCrowd();UpdateAccuracy();UpdateWeights();
  1834. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();
  1835. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  1836. UpdateRiskControl();CheckMTFConfirmation();
  1837. double tfaScore=CalcAdvancedTFA(g_tfa_detail);
  1838. color ha1C=(g_haM1=="HA BULLISH 1")?NEON_GREEN:(g_haM1=="HA BEARISH 1")?NEON_RED:NEON_YELLOW;
  1839. color ha5C=(g_haM5=="HA BULLISH 5")?NEON_GREEN:(g_haM5=="HA BEARISH 5")?NEON_RED:NEON_YELLOW;
  1840. color biasClr;string biasStr=CalcAdvancedMarketBias(biasClr,brain,g_rsc);
  1841. string stratLabel=(g_strategyType=="TRAP")?"TRAP":(g_strategyType=="TREND")?"TREND":"NO STRATEGY";
  1842. color stratC=(g_strategyType=="TRAP")?NEON_PURPLE:(g_strategyType=="TREND")?NEON_GREEN:CGR;
  1843.  
  1844. // ROW 1
  1845. Cube("c1",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"PAIR",NEON_CYAN,Symbol(),NEON_BLUE,13);
  1846.  
  1847. // --- PSYCHE BREAKER v3.0 CUBE ---
  1848. color psyBorder = g_psycheClr;
  1849. Bx("c2", cx+CW+G, yy, CW, CH, BG_DARK2, psyBorder);
  1850. Tx("c2_sc", cx+CW+G+10, yy+6, "Score: "+DoubleToString(g_psycheScore,0)+"/130", (g_psycheScore>=80)?psyBorder:(g_psycheScore>=60)?NEON_ORANGE:NEON_WHITE, 12, true);
  1851. Tx("c2_wk", cx+CW+G+10, yy+28, g_psycheWick, (g_psycheDir=="PUT")?NEON_RED:(g_psycheDir=="CALL")?NEON_GREEN:NEON_YELLOW, 11, true);
  1852. Tx("c2_ha", cx+CW+G+10, yy+50, "HA: "+g_psycheHA, NEON_WHITE, 11, false);
  1853. Tx("c2_dir", cx+CW+G+10, yy+70, "DIR: "+g_psycheDir, (g_psycheDir=="PUT")?NEON_RED:(g_psycheDir=="CALL")?NEON_GREEN:NEON_YELLOW, 11, false);
  1854. Tx("c2_v", cx+CW+G+10, yy+92, g_psycheSignal, psyBorder, 13, true);
  1855.  
  1856. // --- NEXT CANDLE CUBE (YOUR FIXED FORMULA) ---
  1857. double ecBody = MathAbs(Close[0] - Open[0]);
  1858. double ecRange = High[0] - Low[0];
  1859. double ecBR = (ecRange > 0) ? ecBody / ecRange : 1;
  1860. bool ecBear = (Close[0] < Open[0]);
  1861. double ecAvgB = 0, ecAvgR = 0; int ecBars = MathMin(25, Bars - 1);
  1862. for(int ei = 1; ei <= ecBars; ei++) { ecAvgB += MathAbs(Close[ei] - Open[ei]); ecAvgR += (High[ei] - Low[ei]); }
  1863. if(ecBars > 0) { ecAvgB /= ecBars; ecAvgR /= ecBars; }
  1864. double ecScore = 0;
  1865. if(ecBR < 0.20) ecScore += 40; else if(ecBR < 0.30) ecScore += 30; else if(ecBR < 0.45) ecScore += 20; else if(ecBR < 0.60) ecScore += 10;
  1866. if(ecAvgR > 0) { if(ecRange > ecAvgR * 1.4) ecScore += 30; else if(ecRange > ecAvgR * 1.2) ecScore += 20; else if(ecRange > ecAvgR * 1.0) ecScore += 10; }
  1867. if(ecBear) ecScore += 30; else ecScore += 10;
  1868. ecScore = MathMin(ecScore, 100);
  1869. int ecGr = 0, ecRd = 0;
  1870. for(int ei = 1; ei <= 3 && ei < Bars; ei++) { if(Close[ei] > Open[ei]) ecGr++; else if(Close[ei] < Open[ei]) ecRd++; }
  1871. double ecCALL = (ecGr + ecRd > 0) ? (ecGr * 100.0 / (ecGr + ecRd)) : 50; double ecPUT = 100 - ecCALL;
  1872. if(ecBear && ecCALL > 65) ecScore += 20; else if(!ecBear && ecPUT > 65) ecScore += 20; else if(ecBear && ecCALL > 55) ecScore += 10; else if(!ecBear && ecPUT > 55) ecScore += 10;
  1873. ecScore = MathMin(ecScore, 100);
  1874. double ecTrap = 0; int ecDoji = 0;
  1875. for(int ei = 1; ei <= 3 && ei < Bars; ei++) { double eb = MathAbs(Close[ei] - Open[ei]); double er = High[ei] - Low[ei]; if(er > 0 && (eb / er) < 0.25 && ecAvgB > 0 && eb < ecAvgB * 0.5) ecDoji++; }
  1876. ecTrap += (ecDoji * 12); if(ecCALL > 70) ecTrap += 20; else if(ecCALL > 60) ecTrap += 10; if(ecPUT > 70) ecTrap += 20; else if(ecPUT > 60) ecTrap += 10;
  1877. if(ecGr >= 3) ecTrap += 15; if(ecRd >= 3) ecTrap += 15; ecTrap = MathMin(ecTrap, 100);
  1878. double ecG = 50, ecR = 50; string ecRsn = "WAIT"; color ecClr = CGR;
  1879. if(ecScore >= 55 && ecBear) { if(ecCALL > 65 && ecTrap > 50) { ecG = 10; ecR = 90; ecRsn = "SELL (PUT)"; ecClr = NEON_RED; } else if(ecPUT > 65 && ecTrap > 50) { ecG = 90; ecR = 10; ecRsn = "BUY (CALL)"; ecClr = NEON_GREEN; } else if(ecScore >= 75) { ecG = 80; ecR = 20; ecRsn = "REVERSAL BUY"; ecClr = NEON_GREEN; } else { ecG = 50; ecR = 50; ecRsn = "WAIT - LOW CONF"; ecClr = NEON_YELLOW; } }
  1880. else if(ecScore >= 55 && !ecBear) { if(ecPUT > 65 && ecTrap > 50) { ecG = 15; ecR = 85; ecRsn = "SELL (PUT)"; ecClr = NEON_RED; } else { ecG = 50; ecR = 50; ecRsn = "WAIT"; ecClr = NEON_YELLOW; } }
  1881. else { ecRsn = "NO ERROR"; }
  1882. g_frozen_gProb = ecG; g_frozen_rProb = ecR; g_frozen_pAction = ecRsn; g_frozen_pColor = ecClr; g_last_freeze_bar = Time[0];
  1883.  
  1884. Bx("c_pred",cx+2*(CW+G),yy,CW,CH,BG_DARK2,ecClr);
  1885. Tx("c_pred_l",cx+2*(CW+G)+10,yy+3,"NEXT CANDLE",NEON_CYAN,10,true);
  1886. Tx("c_pred_e",cx+2*(CW+G)+10,yy+20,"E:"+DoubleToString(ecScore,0)+" T:"+DoubleToString(ecTrap,0)+" C:"+DoubleToString(ecCALL,0)+" P:"+DoubleToString(ecPUT,0),ecScore>=55?NEON_ORANGE:CGR,9,false);
  1887. int bW=CW-20,gBW=(int)(ecG/100.0*bW),rBW=(int)(ecR/100.0*bW);if(gBW<3)gBW=3;if(rBW<3)rBW=3;
  1888. Bx("c_pred_gbg",cx+2*(CW+G)+10,yy+38,bW,6,BG_DARK4,BG_DARK4);Bx("c_pred_gfg",cx+2*(CW+G)+10,yy+38,gBW,6,NEON_GREEN,NEON_GREEN);
  1889. Tx("c_pred_gp",cx+2*(CW+G)+10,yy+45,"G:"+DoubleToString(ecG,0)+"%",NEON_GREEN,10,true);
  1890. Bx("c_pred_rbg",cx+2*(CW+G)+10,yy+58,bW,6,BG_DARK4,BG_DARK4);Bx("c_pred_rfg",cx+2*(CW+G)+10,yy+58,rBW,6,NEON_RED,NEON_RED);
  1891. Tx("c_pred_rp",cx+2*(CW+G)+10,yy+65,"R:"+DoubleToString(ecR,0)+"%",NEON_RED,10,true);
  1892. Tx("c_pred_a",cx+2*(CW+G)+10,yy+82,ecRsn,ecClr,13,true);
  1893. yy+=CH+G;
  1894.  
  1895. // ROW 2
  1896. 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);
  1897. 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);
  1898. color sClr=CGR;string sName=GetCurrentSession(sClr);bool isAct=IsSessionActive();
  1899. 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);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;
  1900.  
  1901. // ROW 3
  1902. DrawOtherPairsCube(cx,yy,CW,CH);DrawOTCQuickCube(cx+CW+G,yy,CW,CH);
  1903. 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 AI",NEON_PURPLE,10,true);color brainClr3=(brain>0)?NEON_GREEN:(brain<0)?NEON_RED:NEON_YELLOW;double brainBar=MathMax(5,MathMin(95,50+brain*5));Tx("c_brain_r3_v",cx+2*(CW+G)+10,yy+25,(brain>=0?"+":"")+DoubleToString(brain,1),brainClr3,24,true);Tx("c_brain_r3_s",cx+2*(CW+G)+10,yy+58,stratLabel,stratC,10,false);string brainDir=(brain>2)?"BULL PRESSURE":(brain<-2)?"BEAR PRESSURE":"NEUTRAL";Tx("c_brain_r3_d",cx+2*(CW+G)+10,yy+76,brainDir,(brain>2)?NEON_GREEN:(brain<-2)?NEON_RED:NEON_YELLOW,9,false);NeonBar("c_brain_r3_b",cx+2*(CW+G)+12,yy+92,CW-24,7,brainBar,brainClr3);yy+=CH+G;
  1904.  
  1905. // ROW 4
  1906. 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;
  1907. 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);
  1908. 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);
  1909. 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{tfaLabel="WEAK";tfaColor=NEON_ORANGE;}
  1910. 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]";
  1911. 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);
  1912. 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;
  1913.  
  1914. // ROW 5
  1915. int CH5=140;
  1916. if(ENABLE_MTG){
  1917. bool isTrap=(g_mtgState=="PUT TRAP"||g_mtgState=="CALL TRAP");color mtgC=g_mtgClr;if(g_mtgState=="WAIT"||g_mtgState=="...")mtgC=NEON_YELLOW;color borderC=isTrap?NEON_PURPLE:mtgC;
  1918. Bx("c_mtg",cx,yy,CW,CH5,BG_DARK2,borderC);string runStr="";if(g_mtgBullCount>=2)runStr=" +"+IntegerToString(g_mtgBullCount)+"B";else if(g_mtgBearCount>=2)runStr=" +"+IntegerToString(g_mtgBearCount)+"R";
  1919. Tx("c_mtg_l",cx+10,yy+4,"NCP PRO v8"+runStr,NEON_PURPLE,10,true);Tx("c_mtg_s",cx+10,yy+18,g_mtgState,mtgC,isTrap?11:13,true);
  1920. int cW=(int)(g_mtgHype/100.0*(CW-22));if(cW<2)cW=2;if(cW>CW-22)cW=CW-22;Bx("c_mtg_cbb",cx+10,yy+37,CW-22,6,BG_DARK4,BG_DARK4);Bx("c_mtg_cbf",cx+10,yy+37,cW,6,(g_mtgHype>=g_mtgBetrayal)?NEON_GREEN:C'35,70,35',NEON_GREEN);
  1921. Tx("c_mtg_ct",cx+10,yy+43,"CALL: "+DoubleToString(g_mtgHype,1)+"%",NEON_GREEN,10,true);
  1922. int pW=(int)(g_mtgBetrayal/100.0*(CW-22));if(pW<2)pW=2;if(pW>CW-22)pW=CW-22;Bx("c_mtg_pbb",cx+10,yy+59,CW-22,6,BG_DARK4,BG_DARK4);Bx("c_mtg_pbf",cx+10,yy+59,pW,6,(g_mtgBetrayal>g_mtgHype)?NEON_RED:C'70,25,25',NEON_RED);
  1923. Tx("c_mtg_pt",cx+10,yy+65,"PUT: "+DoubleToString(g_mtgBetrayal,1)+"%",NEON_RED,10,true);
  1924. string actD=g_mtgAction;if(StringLen(actD)>28)actD=StringSubstr(actD,0,27);color actC=isTrap?NEON_PURPLE:(g_mtgState=="CALL")?NEON_GREEN:(g_mtgState=="PUT")?NEON_RED:NEON_YELLOW;
  1925. Tx("c_mtg_a",cx+10,yy+81,actD,actC,10,true);Tx("c_mtg_r",cx+10,yy+97,"ATR: "+DoubleToString(g_mtgRecovery,1)+"p",CGR,9,false);
  1926. } else {
  1927. 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";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);
  1928. }
  1929. 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);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);
  1930. 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);Tx("c18_r",cx+2*(CW+G)+10,yy+24,"R: "+(g_nearest_res>0?ShortPrice(g_nearest_res):"--"),NEON_RED,13,true);Tx("c18_s",cx+2*(CW+G)+10,yy+54,"S: "+(g_nearest_sup>0?ShortPrice(g_nearest_sup):"--"),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;
  1931.  
  1932. // ROW 6
  1933. int CH6 = 120;
  1934. Bx("c15", cx, yy, CW, CH6, BG_DARK2, g_visualTrapPro.verdictColor);
  1935. Tx("c15_l", cx+10, yy+4, "VISUAL TRAP", NEON_PURPLE, 10, true);
  1936. Tx("c15_box", cx+10, yy+22, g_visualTrapPro.boxStatus, CGR, 10, true);
  1937. Tx("c15_gann", cx+10, yy+38, g_visualTrapPro.gannStatus, g_visualTrapPro.gannColor, 10, true);
  1938. Tx("c15_m30", cx+10, yy+54, g_visualTrapPro.m30Dir, (StringFind(g_visualTrapPro.m30Dir,"UP")>=0)?NEON_GREEN:NEON_RED, 10, true);
  1939. Tx("c15_m1", cx+10, yy+70, g_visualTrapPro.m1Seq, CGR, 9, false);
  1940. Tx("c15_v", cx+10, yy+88, g_visualTrapPro.verdict, g_visualTrapPro.verdictColor, 13, true);
  1941.  
  1942. Bx("c_ha", cx+CW+G, yy, CW, CH6, BG_DARK2, ha1C);
  1943. Tx("c_ha_l", cx+CW+G+10, yy+4, "HA CANDLES", NEON_CYAN, 10, true);
  1944. string haM1txt = g_haM1, haM5txt = g_haM5;
  1945. if(StringLen(haM1txt) > 16) haM1txt = StringSubstr(haM1txt, 3);
  1946. if(StringLen(haM5txt) > 16) haM5txt = StringSubstr(haM5txt, 3);
  1947. Tx("c_ha_m1", cx+CW+G+10, yy+24, "M1: "+haM1txt, ha1C, 11, true);
  1948. Tx("c_ha_m5", cx+CW+G+10, yy+50, "M5: "+haM5txt, ha5C, 11, true);
  1949. string haComb = "";
  1950. color haCombC = NEON_YELLOW;
  1951. if(g_haM1 == "HA BULLISH 1" && g_haM5 == "HA BULLISH 5") {
  1952. haComb = "BOTH BULL"; haCombC = NEON_GREEN;
  1953. } else if(g_haM1 == "HA BEARISH 1" && g_haM5 == "HA BEARISH 5") {
  1954. haComb = "BOTH BEAR"; haCombC = NEON_RED;
  1955. } else haComb = g_haBoth;
  1956. Tx("c_ha_c", cx+CW+G+10, yy+76, haComb, haCombC, 11, true);
  1957.  
  1958. // ----- NCP ANALYSIS CUBE (PROFESSIONAL v2 - NEUTRAL = NEON FLOWER) -----
  1959. int ncpW = CW;
  1960. int ncpH = CH6;
  1961. int ncpX = cx + 2*(CW+G);
  1962. int ncpY = yy;
  1963.  
  1964. string patternName = (g_ncpMainPattern != "") ? g_ncpMainPattern : "NO PATTERN";
  1965. int bullScore = g_ncpPatternBullScore;
  1966. int bearScore = g_ncpPatternBearScore;
  1967. int totalStrength = MathMax(bullScore, bearScore);
  1968. int strengthPct = MathMin(100, (int)(totalStrength * 1.25));
  1969.  
  1970. bool isBullish = (bullScore > bearScore + 5);
  1971. bool isBearish = (bearScore > bullScore + 5);
  1972. bool isNeutral = (!isBullish && !isBearish);
  1973.  
  1974. color borderColor, textColor, barColor;
  1975. string dirSymbol;
  1976.  
  1977. if(isBullish) {
  1978. borderColor = NEON_GREEN;
  1979. textColor = NEON_GREEN;
  1980. barColor = NEON_GREEN;
  1981. dirSymbol = "▲";
  1982. } else if(isBearish) {
  1983. borderColor = NEON_RED;
  1984. textColor = NEON_RED;
  1985. barColor = NEON_RED;
  1986. dirSymbol = "▼";
  1987. } else {
  1988. borderColor = NEON_PINK;
  1989. textColor = NEON_PINK;
  1990. barColor = NEON_PINK;
  1991. dirSymbol = "●";
  1992. }
  1993.  
  1994. Bx("c_reason", ncpX, ncpY, ncpW, ncpH, BG_DARK2, borderColor);
  1995. Tx("c_reason_l", ncpX+10, ncpY+4, "NCP ANALYSIS", NEON_CYAN, 10, true);
  1996.  
  1997. string patternLine = dirSymbol + " " + patternName + " [" + IntegerToString(strengthPct) + "%]";
  1998. Tx("c_reason_p", ncpX+10, ncpY+22, patternLine, textColor, 12, true);
  1999.  
  2000. int barMaxWidth = ncpW - 24;
  2001. int barWidth = (int)(strengthPct / 100.0 * barMaxWidth);
  2002. if(barWidth < 2) barWidth = 2;
  2003. if(barWidth > barMaxWidth) barWidth = barMaxWidth;
  2004.  
  2005. Bx("c_reason_bar_bg", ncpX+10, ncpY+44, barMaxWidth, 8, BG_DARK4, BG_DARK4);
  2006. Bx("c_reason_bar_fill", ncpX+10, ncpY+44, barWidth, 8, barColor, barColor);
  2007.  
  2008. string strengthText = "";
  2009. if(strengthPct >= 70) strengthText = "STRONG";
  2010. else if(strengthPct >= 45) strengthText = "MEDIUM";
  2011. else if(strengthPct >= 20) strengthText = "WEAK";
  2012. else strengthText = "NONE";
  2013. Tx("c_reason_strength", ncpX+10, ncpY+62, "Str: " + strengthText, textColor, 9, false);
  2014.  
  2015. double adx = g_ncpADX;
  2016. double pDI = g_ncpPlusDI;
  2017. double mDI = g_ncpMinusDI;
  2018. string dirStr = (pDI > mDI) ? "DI+:BULL" : "DI-:BEAR";
  2019. color adxColor = GetADXColor(adx, pDI, mDI);
  2020. Tx("c_reason_r", ncpX+10, ncpY+82, "ADX:" + DoubleToString(adx,0) + " " + dirStr, adxColor, 11, false);
  2021.  
  2022. string revReason = DetectSuddenReversal();
  2023. color revColor = CGR;
  2024. if(StringFind(revReason, "BULL") >= 0) revColor = NEON_GREEN;
  2025. if(StringFind(revReason, "BEAR") >= 0) revColor = NEON_RED;
  2026. Tx("c_reason_v", ncpX+10, ncpY+102, (StringLen(revReason) > 0 ? "REV: "+revReason : "NO REVERSAL"), revColor, 10, false);
  2027.  
  2028. yy += ncpH + G;
  2029.  
  2030. // BB Row
  2031. if(ENABLE_BB_PULLBACK) {
  2032. int bbRowH = 52;
  2033. color bbRowBorder = (g_bbSignal == "CALL") ? NEON_GREEN : (g_bbSignal == "PUT") ? NEON_RED : BB_GREY;
  2034. Bx("c_bb_row", cx, yy, W-2*G, bbRowH, BG_DARK3, bbRowBorder);
  2035.  
  2036. string ha30Str = IsM30HABull() ? "BULL" : (IsM30HABear() ? "BEAR" : "DOJI");
  2037. color ha30C2 = IsM30HABull() ? NEON_GREEN : (IsM30HABear() ? NEON_RED : NEON_YELLOW);
  2038. double adxD = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  2039. double rsiD = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  2040.  
  2041. Tx("c_bb_row_l", cx+10, yy+4, "BB("+IntegerToString(BB_PERIOD)+") PULLBACK", BB_GREY, 9, true);
  2042. Tx("c_bb_ha2", cx+190, yy+4, "HA30:"+ha30Str, ha30C2, 9, true);
  2043. Tx("c_bb_adx", cx+310, yy+4, "ADX:"+DoubleToString(adxD,0), (adxD>=20) ? NEON_LIME : CGR, 9, false);
  2044. Tx("c_bb_rsi", cx+390, yy+4, "RSI:"+DoubleToString(rsiD,0), (rsiD>=70 || rsiD<=30) ? NEON_RED : CGR, 9, false);
  2045.  
  2046. if(g_bbSignal != "--") {
  2047. string sigTxt = "BB "+g_bbSignal+" | "+g_bbDetail;
  2048. if(StringLen(sigTxt) > 60) sigTxt = StringSubstr(sigTxt, 0, 58) + "..";
  2049. Tx("c_bb_sig2", cx+10, yy+22, sigTxt, g_bbColor, 10, true);
  2050. } else {
  2051. Tx("c_bb_sig2", cx+10, yy+22, "Waiting for BB touch + 2+ confirmations...", CGR, 9, false);
  2052. }
  2053. yy += bbRowH + G;
  2054. }
  2055.  
  2056. // Bottom Filter Status (using unique names to avoid conflict)
  2057. int filterWidth = W - 2*G;
  2058. color filterColor = (g_filterStatus == "ALL CLEAR") ? NEON_GREEN :
  2059. (StringFind(g_filterStatus, "ACTIVE") >= 0) ? NEON_LIME :
  2060. (StringFind(g_filterStatus, "LOCK") >= 0) ? NEON_RED : NEON_ORANGE;
  2061. Bx("c_filter", cx, yy, filterWidth, 22, BG_DARK3, filterColor);
  2062. Tx("c_filter_v", cx+10, yy+4, "FILTER: "+g_filterStatus, filterColor, 11, true);
  2063. yy += 22 + G;
  2064.  
  2065. // BB ROW
  2066. if(ENABLE_BB_PULLBACK){
  2067. 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);
  2068. string ha30Str=IsM30HABull()?"BULL":IsM30HABear()?"BEAR":"DOJI";color ha30C2=IsM30HABull()?NEON_GREEN:IsM30HABear()?NEON_RED:NEON_YELLOW;
  2069. double adxD=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);double rsiD=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  2070. 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);
  2071. 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);}else{Tx("c_bb_sig2",cx+10,yy+22,"Waiting for BB touch + 2+ confirmations...",CGR,9,false);}
  2072. yy+=bbRowH+G;
  2073. }
  2074.  
  2075. // BOTTOM FILTER STATUS
  2076. 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;
  2077. Bx("c_filter",cx,yy,fsW,22,BG_DARK3,fsC);Tx("c_filter_v",cx+10,yy+4,"FILTER: "+g_filterStatus,fsC,11,true);
  2078. HideSPM();ChartRedraw();
  2079. }
  2080.  
  2081. double CalcAdvancedFractal(){if(Bars<15)return 0;double score=0;for(int i=2;i<=8&&i+2<Bars;i++){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;}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;}}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++;}if(dj>=3)score+=25;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;}return MathMin(100,score);}
  2082.  
  2083. 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";}}}
  2084.  
  2085. void FinalSignalEngine(double brain,int cp,int mts){
  2086. g_filterStatus="ALL CLEAR";
  2087. 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;}
  2088. 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;}
  2089. 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;}
  2090. 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;}
  2091. 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;}}
  2092. 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;}
  2093. bool reverseSignal=(g_accuracy<45.0&&g_acc_total>20);if(reverseSignal)g_filterStatus="REVERSE MODE";
  2094. string ms=DetectMyStrategy();
  2095. if(ms!="WAIT"){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;}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;}if(!EntryPrecisionOK()){g_finalSignal="WAIT";g_finalColor=NEON_ORANGE;g_filterStatus="PRECISION FAIL";if(TimeCurrent()-g_signalTime>HOLD_SEC)g_signalTime=TimeCurrent();return;}if(reverseSignal){if(ms=="CALL")ms="PUT";else if(ms=="PUT")ms="CALL";}g_finalSignal=ms;g_finalColor=(ms=="CALL")?NEON_GREEN:NEON_RED;g_filterStatus=(g_strategyType=="TRAP")?"TRAP ACTIVE":"TREND ACTIVE";if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT"){g_finalSignal=ms;g_signalTime=TimeCurrent();}SendSignalNotification(ms,conf);return;}
  2096. double th=FAST_MODE?70:68;string rawSignal="WAIT";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";
  2097. 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";}
  2098. g_finalSignal=rawSignal;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;}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;}
  2099. if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT")g_signalTime=TimeCurrent();
  2100. if(g_finalSignal=="CALL"){g_finalColor=NEON_GREEN;g_filterStatus="GREEN SIGNAL";SendSignalNotification("CALL",conf);}else if(g_finalSignal=="PUT"){g_finalColor=NEON_RED;g_filterStatus="RED SIGNAL";SendSignalNotification("PUT",conf);}else if(g_finalSignal=="WEAK CALL"){g_finalColor=NEON_CYAN;g_filterStatus="WEAK GREEN";}else if(g_finalSignal=="WEAK PUT"){g_finalColor=NEON_ORANGE;g_filterStatus="WEAK RED";}else g_finalColor=NEON_YELLOW;
  2101. }
  2102.  
  2103. 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);}
  2104.  
  2105. void BroadcastSignal(){double conf=MathMax(g_frozen_gProb,g_frozen_rProb);if(conf<55)return;string fn="OTC_Signals_Master.txt",pair=Symbol();string sig=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";int exp=(int)(TimeCurrent()+65);string line=pair+"|"+sig+"|"+DoubleToString(conf,0)+"|"+IntegerToString((int)TimeCurrent())+"|"+IntegerToString(exp);int h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);if(h==INVALID_HANDLE){h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);if(h==INVALID_HANDLE)return;FileWriteString(h,line+"\n");FileClose(h);return;}string content="";while(!FileIsEnding(h)){string ex=FileReadString(h);if(StringLen(ex)>10&&StringFind(ex,pair+"|")!=0)content+=ex+"\n";}content=line+"\n"+content;FileSeek(h,0,SEEK_SET);FileWriteString(h,content);FileFlush(h);FileClose(h);}
  2106.  
  2107. int CalcPairQuality(string pair,string &outSig,string &outDetail){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);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);double o3=iOpen(pair,PERIOD_M1,3),c3=iClose(pair,PERIOD_M1,3);if(o1==0||c1==0||o2==0||c2==0||o3==0||c3==0){outSig="WAIT";return 0;}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;bool haM1Bull=(haC1>haO1);double haBody=MathAbs(haC1-haO1),haRange=(h1-l1);double haStrength=(haRange>0)?haBody/haRange:0;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);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);double m5_o3=iOpen(pair,PERIOD_M5,3),m5_c3=iClose(pair,PERIOD_M5,3);bool haM5Bull=false;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);}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);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;}bool bullDir=false,bearDir=false;if(haM1Bull&&haM5Bull)bullDir=true;else if(!haM1Bull&&!haM5Bull)bearDir=true;else{outSig="WAIT";return 0;}int score=0;string det="";if(bullDir&&haM1Bull){int s=(haStrength>0.6)?25:(haStrength>0.4)?18:12;score+=s;det+="HA1+";}if(bearDir&&!haM1Bull){int s=(haStrength>0.6)?25:(haStrength>0.4)?18:12;score+=s;det+="HA1+";}if(bullDir&&haM5Bull){score+=15;det+="HA5+";}else if(bearDir&&!haM5Bull){score+=15;det+="HA5+";}if(bullDir){if(rsi<30){score+=20;det+="RSI_OS ";}else if(rsi<40){score+=14;det+="RSI_low ";}else{score+=2;det+="RSI_hi ";}}else{if(rsi>70){score+=20;det+="RSI_OB ";}else if(rsi>60){score+=14;det+="RSI_hi ";}else{score+=2;det+="RSI_lo ";}}if(volRatio>=2.0){score+=15;det+="VOL_HI ";}else if(volRatio>=1.5){score+=10;det+="VOL_MD ";}int streak=(bullDir)?bullStreak:bearStreak;if(streak>=3){score+=15;det+="STK"+IntegerToString(streak);}else if(streak>=2){score+=10;det+="STK"+IntegerToString(streak);}if(spread<=3)score+=10;else if(spread<=6)score+=6;outSig=bullDir?"CALL":"PUT";outDetail=det;return MathMin(100,score);}
  2108.  
  2109. // FIX: Corrected undeclared 'cur' variable
  2110. void ScanSignals(){
  2111. g_pairCount=0;
  2112. string fn="OTC_Signals_Master.txt";
  2113. string cur=Symbol(); // FIX: Added string type
  2114. int h=FileOpen(fn,FILE_READ|FILE_TXT|FILE_SHARE_READ);
  2115. if(h==INVALID_HANDLE)return;
  2116. datetime now=TimeCurrent();
  2117. string tmpNames[8];string tmpSigs[8];double tmpConfs[8];int tmpScores[8];string tmpDetails[8];int tmpCount=0;
  2118. while(!FileIsEnding(h)&&tmpCount<8){
  2119. string ln=FileReadString(h);if(StringLen(ln)<15)continue;
  2120. int p1=StringFind(ln,"|"),p2=StringFind(ln,"|",p1+1),p3=StringFind(ln,"|",p2+1),p4=StringFind(ln,"|",p3+1);
  2121. if(p1<0||p2<0||p3<0||p4<0)continue;
  2122. string pair=StringSubstr(ln,0,p1);if(pair==cur)continue;
  2123. string sig=StringSubstr(ln,p1+1,p2-p1-1);double conf=StringToDouble(StringSubstr(ln,p2+1,p3-p2-1));
  2124. int expTime=(int)StringToInteger(StringSubstr(ln,p4+1));if(conf<60)continue;if(expTime<(int)(now-20))continue;
  2125. string qSig="WAIT",qDetail="";int qScore=CalcPairQuality(pair,qSig,qDetail);
  2126. if(qSig!=sig)continue;if(qScore<45)continue;
  2127. tmpNames[tmpCount]=pair;tmpSigs[tmpCount]=sig;tmpConfs[tmpCount]=conf;tmpScores[tmpCount]=qScore;tmpDetails[tmpCount]=qDetail;tmpCount++;
  2128. }
  2129. FileClose(h);
  2130. 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;}}}
  2131. 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];}
  2132. string curPred=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";int sameDir=0;double boostTotal=0;
  2133. for(int i=0;i<g_pairCount;i++){if(g_pairSigs[i]==curPred&&tmpScores[i]>=60){sameDir++;boostTotal+=tmpScores[i];}}
  2134. 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)+"%";}
  2135. }
  2136.  
  2137. void UpdateTimer(){if(!SHOW_TIMER)return;string nm=PFX+"candle_timer";int ps=Period()*60;int el=(int)(TimeCurrent()-Time[0]);int rem=ps-el;if(rem<=0)rem=ps;if(rem>ps)rem=ps;int mm=rem/60,ss=rem%60;string t=(mm>0?IntegerToString(mm)+":":"")+(ss<10?"0":"")+IntegerToString(ss)+"s";double atrVal=iATR(NULL,PERIOD_M1,14,0);double offset=(atrVal>0)?atrVal*0.25:Point*30;datetime tPos=Time[0]+ps*2;double pPos=High[0]+offset;if(ObjectFind(0,nm)<0){ObjectCreate(0,nm,OBJ_TEXT,0,tPos,pPos);ObjectSetInteger(0,nm,OBJPROP_BACK,false);}ObjectSetInteger(0,nm,OBJPROP_TIME,tPos);ObjectSetDouble(0,nm,OBJPROP_PRICE,pPos);ObjectSetText(nm,t,11,"Arial Bold",NEON_YELLOW);}
  2138.  
  2139. // ============================================================
  2140. // EVENT HANDLERS
  2141. // ============================================================
  2142. int OnInit(){
  2143. InitNW();NuclearDeleteAll();
  2144. g_hrn_price=0;g_hrn_brk_bars=0;g_hrn_scan_bar=0;g_hrn_score=0;g_hrn_confirmed_break=false;
  2145. g_nearest_res=0;g_nearest_sup=0;g_rj_cnt=0;g_pairCount=0;
  2146. g_marketMode="RANGE";g_prevMode="";g_last_freeze_bar=0;g_lastNotified="";
  2147. g_accuracy=ValidateHistoricalAccuracy();g_acc_correct=0;g_acc_total=0;g_acc_lastBar=0;
  2148. g_lastPredGreen=50.0;g_lastPredBar=0;g_lossStreak=0;g_tradingStopped=false;
  2149. g_strategyType="NONE";g_frozen_gProb=50;g_frozen_rProb=50;g_calc_gProb=50;g_calc_rProb=50;
  2150. g_commonCount=0;g_wickLineCount=0;g_tfa_detail="";g_htfLevelCount=0;g_mtfConfirmed=true;
  2151. g_filterStatus="ALL CLEAR";g_symbolKey="";g_brokerBias=0.0;
  2152. g_bbSignal="--";g_bbColor=NEON_YELLOW;g_bbTouchPrice=0.0;g_bbSignalTime=0;g_bbSignalBars=0;g_bbDetail="";g_bbLineCount=0;
  2153. 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="";g_mtgBullCount=0;g_mtgBearCount=0;g_trapScore=0;g_ncpADX=0;g_ncpPlusDI=0;g_ncpMinusDI=0;
  2154. g_smoothCallScore=50.0;g_smoothPutScore=50.0;g_callWeight=1.0;g_putWeight=1.0;
  2155. g_totalTrades=0;g_callTrades=0;g_putTrades=0;g_callWins=0;g_putWins=0;
  2156. g_ncpLastSignalTime=0;g_ncpLastSignalType="";g_ncpLastEntryPrice=0.0;g_ncpSignalProcessed=true;
  2157. g_ncpTrend.m15Direction="FLAT";g_ncpTrend.m15Strength=0;g_ncpTrend.aligned=false;
  2158. g_ncpSRCount=0;g_ncpDetailLine1="";g_ncpDetailLine2="";g_ncpDetailLine3="";
  2159. g_ncpPatternBullScore=0;g_ncpPatternBearScore=0;g_ncpMainPattern="";
  2160. g_stableResCount=0;g_stableSupCount=0;g_lastSRScan=0;
  2161. g_ha30_open=0;g_ha30_close=0;g_ha30_high=0;g_ha30_low=0;g_ha30_bar=0;
  2162. g_rsc=0; g_psycheScore=0; g_psycheDir="NONE"; g_psycheSignal="SCANNING"; g_psycheClr=CGR;
  2163.  
  2164. if(ENABLE_LEARNING)LoadBrainMemory();LoadMLWeights();EventSetTimer(1);
  2165. Print("===========================================");
  2166. Print("AIBRAIN v46.3 - NCP PRO v8.0 (ALL ERRORS FIXED)");
  2167. Print("Added: PSYCHE BREAKER v3.0 Cube");
  2168. Print("Replaced: MTF ANALYSIS with PSYCHE BREAKER");
  2169. Print("===========================================");
  2170. return INIT_SUCCEEDED;
  2171. }
  2172.  
  2173. 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);}}
  2174.  
  2175. void OnTimer(){
  2176. if(Bars<50)return;
  2177. static datetime last5min=0;
  2178. if(Time[0]/300!=last5min/300){DetectHiddenLevels();last5min=Time[0];}
  2179. CalcVisualTrapPro();CalcHA();UpdateHRN();UpdateSR();DetectCommonPoints();DetectWickRejections();
  2180. DrawCommonPoints();DrawWickRejectLines();DrawHiddenLevels();
  2181. if(ENABLE_BB_PULLBACK)DetectBBPullback();
  2182. if(ENABLE_MTG)CalculateMTG();
  2183. CalcPsycheBreaker();
  2184.  
  2185. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  2186. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();
  2187. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  2188. ScanSignals();FinalSignalEngine(brain,cp,mts);BroadcastSignal();UpdateTimer();Draw();
  2189. }
  2190.  
  2191. 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);}
  2192. //+------------------------------------------------------------------+