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. // ============================================================
  21. // WEIGHTED PATTERN STRUCT & LOGIC (PRO FORMULA)
  22. // ============================================================
  23. struct WPattern {
  24. string sig; // CALL, PUT, 50/50, WAIT
  25. double conf; // 0 - 100
  26. bool isTrap; // Broker trap detected?
  27. string pat; // Current Pattern e.g. GGR
  28. string str; // STRONG, WEAK, MEDIUM
  29. double trapScr;// 0 - 100
  30. };
  31.  
  32. WPattern GetWeightedPattern(int pSize, int &colArr[], int totalCandles) {
  33. WPattern r;
  34. r.sig="WAIT"; r.conf=50; r.isTrap=false; r.pat=""; r.str="NONE"; r.trapScr=0;
  35. if(totalCandles < 30) return r;
  36.  
  37. r.pat = "";
  38. for(int j=0; j<pSize; j++) r.pat += (colArr[j]==1) ? "G" : "R";
  39.  
  40. int cw=0, pw=0, tw=0, cm=0, pm=0, tm=0;
  41.  
  42. for(int i=2; i<=totalCandles-pSize; i++) {
  43. string hp="";
  44. for(int j=0; j<pSize; j++) hp += (colArr[i+j]==1) ? "G" : "R";
  45.  
  46. if(hp == r.pat) {
  47. double rw = 1.0 + ((double)(totalCandles - i) / totalCandles) * 3.0;
  48. double sw = 1.0;
  49. if(i-1 >= 0) {
  50. double nb = MathAbs(Close[i-1]-Open[i-1]);
  51. double nr = High[i-1]-Low[i-1];
  52. if(nr>0) {
  53. double br = nb/nr;
  54. if(br>0.65) sw=2.0;
  55. else if(br>0.40) sw=1.5;
  56. else if(br>0.15) sw=1.0;
  57. else sw=0.5;
  58. }
  59. }
  60. double fw = rw * sw;
  61. tm++; tw += (int)fw;
  62. if(colArr[i-1]==1) { cm++; cw+=(int)fw; }
  63. else { pm++; pw+=(int)fw; }
  64. }
  65. }
  66.  
  67. if(tw > 0) {
  68. double domPct = (double)MathMax(cw, pw) / tw * 100.0;
  69. int wk=0;
  70. for(int i=0; i<MathMin(3, totalCandles); i++) {
  71. double b=MathAbs(Close[i]-Open[i]), rng=High[i]-Low[i];
  72. if(rng>0 && (b/rng)<0.35) wk++;
  73. }
  74. r.trapScr = domPct * 0.6 + ((double)wk/3.0)*100.0*0.4;
  75. if(r.trapScr > 100) r.trapScr = 100;
  76. r.isTrap = (domPct > 78.0 && wk >= 2);
  77. }
  78.  
  79. if(tm < 3) return r;
  80. double cP = (tw>0) ? ((double)cw/tw)*100.0 : 50.0;
  81. double pP = (tw>0) ? ((double)pw/tw)*100.0 : 50.0;
  82.  
  83. if(r.isTrap && cP > 80.0 && cP > pP) { r.sig="PUT"; r.conf=MathMin(95.0, cP); }
  84. else if(r.isTrap && pP > 80.0 && pP > cP) { r.sig="CALL"; r.conf=MathMin(95.0, pP); }
  85. else if(cP >= 55.0 && cP > pP) { r.sig="CALL"; r.conf=cP; }
  86. else if(pP >= 55.0 && pP > cP) { r.sig="PUT"; r.conf=pP; }
  87. else { r.sig="50/50"; r.conf=50.0; }
  88.  
  89. if(r.conf >= 85.0) r.str="V.STRONG";
  90. else if(r.conf >= 72.0) r.str="STRONG";
  91. else if(r.conf >= 60.0) r.str="MEDIUM";
  92. else r.str="WEAK";
  93.  
  94. return r;
  95. }
  96.  
  97. input string SPM_FILE = "KM RANA";
  98. input int HOLD_SEC = 60;
  99. input int POS_X = 4;
  100. input int POS_Y = 20;
  101. input int DASH_W = 660;
  102. input bool SHOW_TIMER = true;
  103. input bool SHOW_SR_LINES = true;
  104. input string ENTRY_MODE = "TIME";
  105. input int FLAG_MIN_SEC = 10;
  106. input int FLAG_MAX_SEC = 35;
  107. input int TIME_MIN_SEC = 10;
  108. input int TIME_MAX_SEC = 35;
  109. input int MIN_REMAINING_SEC = 15;
  110. input double REVERSAL_PCT = 30.0;
  111. input double WICK_PCT = 0.65;
  112. input int HRN_CONFIRM_BARS = 2;
  113. input bool HA_ALIGN_FILTER = false;
  114. input bool CONSENSUS_FILTER = false;
  115. input bool ENABLE_NOTIFY = true;
  116. input bool FAST_MODE = false;
  117. input int BROKER_SPREAD_THRESHOLD= 6;
  118. input double OTC_TRAP_WEIGHT = 15.0;
  119. input int CROWD_EXTREME_PCT = 70;
  120. input bool ENABLE_BROKER_KILLER = true;
  121. input bool ENABLE_SESSION_FILTER = true;
  122. input bool ENABLE_SPIKE_FILTER = true;
  123. input bool ENABLE_LAST_SEC_BLOCK = true;
  124. input bool ENABLE_RISK_CONTROL = true;
  125. input bool ENABLE_ENTRY_ZONE = true;
  126. input bool ML_ADAPTIVE = true;
  127. input bool VOLUME_PROFILE_TRAP = true;
  128. input bool MTF_CONFIRM = false;
  129. input bool ENABLE_TELEGRAM = false;
  130. input string TELEGRAM_TOKEN = "";
  131. input string TELEGRAM_CHAT_ID = "";
  132. input string TRADE_MODE = "NORMAL";
  133. input string STRATEGY_MODE = "TRAP_ONLY";
  134. input int STRATEGY_THRESHOLD = 75;
  135. input int MAX_LOSS_STREAK = 2;
  136. input double MIN_CONFIDENCE = 75.0;
  137. input bool ENABLE_RISK_LOCK = true;
  138. input double PATTERN_TOLERANCE_PIPS = 8.0;
  139. input int MIN_PATTERN_SEPARATION = 5;
  140. input bool SHOW_COMMON_POINTS = true;
  141. input double COMMON_POINT_TOL_PIPS = 15.0;
  142. input bool SHOW_WICK_REJECT_LINES = true;
  143. input int WICK_MIN_TOUCHES = 1;
  144. input double WICK_ZONE_PIPS = 15.0;
  145. input int WICK_EXPIRE_BARS = 60;
  146.  
  147. // ============================================================
  148. // BB PULLBACK SETTINGS
  149. // ============================================================
  150. input bool ENABLE_BB_PULLBACK = true;
  151. input int BB_PERIOD = 20;
  152. input double BB_DEVIATION = 2.0;
  153. input int BB_SIGNAL_EXPIRE_BARS = 5;
  154.  
  155. // ============================================================
  156. // NCP PRO v8.0 ADVANCED SETTINGS
  157. // ============================================================
  158. input bool ENABLE_MTG = true;
  159. input int NCP_OpenNoiseSeconds = 3;
  160. input int NCP_KillZoneSeconds = 55;
  161. input double NCP_MaxSpreadPips = 4.0;
  162. input int NCP_ATRPeriod = 14;
  163. input double NCP_MinATRPips = 0.4;
  164. input int NCP_FastEMA = 3;
  165. input int NCP_MidEMA = 7;
  166. input int NCP_SlowEMA = 15;
  167. input bool NCP_UseM5Confirm = true;
  168. input bool NCP_UseVolume = true;
  169. input double NCP_RoundStepPips = 10.0;
  170. input double NCP_RoundTolPips = 4.0;
  171. input int NCP_MinProbMedium = 57;
  172. input int NCP_MinProbStrong = 63;
  173. input int NCP_MinProbExtreme = 70;
  174. input bool NCP_UseRSINorm = true;
  175. input int NCP_RSIPeriod = 10;
  176. input double NCP_RSIBase = 50.0;
  177. input double NCP_RSIM5Target = 45.0;
  178. input double NCP_RSIM15Target = 40.0;
  179. input bool ENABLE_LEARNING = true;
  180. input string MEMORY_FILE_NAME = "NCP_Brain_v8.csv";
  181. input int MIN_TRADES_TO_LEARN = 15;
  182. input double LEARNING_STEP = 0.025;
  183. input bool ENABLE_TRAP_DETECTION = true;
  184. input int TRAP_LOOKBACK = 30;
  185.  
  186. double GetUniversalPip(){
  187. double pt=MarketInfo(Symbol(),MODE_POINT);
  188. if(pt<=0) pt=0.00001;
  189. int dg=(int)MarketInfo(Symbol(),MODE_DIGITS);
  190. if(dg==6) return pt*100;
  191. if(dg==5||dg==3||dg==1) return pt*10;
  192. return pt;
  193. }
  194. double GetAutoBoxMin(){double a=iATR(Symbol(),0,14,1);double p=GetUniversalPip();return p>0?MathMax(3.0,a/p*0.3):4.0;}
  195. double GetAutoBoxMax(){double a=iATR(Symbol(),0,14,1);double p=GetUniversalPip();return p>0?MathMax(20.0,a/p*3.0):30.0;}
  196.  
  197. // ===== NEW NCP v8.0 ADVANCED SETTINGS =====
  198. input string NCP8_SECTION = "=== NCP v8.0 ADVANCED ===";
  199. input bool NCP8_UseM15Trend = true;
  200. input bool NCP8_UseDynamicSR = true;
  201. input bool NCP8_UsePatterns = true;
  202. input bool NCP8_UseMultiTF = true;
  203. input bool NCP8_UseColorPattern = true;
  204. input bool NCP8_UseHRNReject = true;
  205. input bool NCP8_UseOrderBlocks = true;
  206. input bool NCP8_UseDivergence = true;
  207. input int NCP8_MinConfidence = 65;
  208. input int NCP8_StrongConfidence = 78;
  209. input int NCP8_ExtremeConfidence = 88;
  210.  
  211. static bool g_m30Bull = false;
  212.  
  213. // ============================================================
  214. // PSYCHE BREAKER CONSTANTS
  215. // ============================================================
  216. #define PSYCHE_DOJI_THRESHOLD 0.10
  217. #define PSYCHE_WICK_THRESHOLD 0.55
  218. #define PSYCHE_WICK_CANDLES 12
  219. #define PSYCHE_VOL_SPIKE_MULT 3.0
  220. #define PSYCHE_SR_CLOSE_PIPS 3.0
  221. #define PSYCHE_SR_NEAR_PIPS 8.0
  222. #define PSYCHE_SR_FAR_PIPS 15.0
  223. #define PSYCHE_STRONG_THRESHOLD 80
  224.  
  225. #define NEON_GREEN C'0,255,100'
  226. #define NEON_RED C'255,40,80'
  227. #define NEON_YELLOW C'255,220,0'
  228. #define NEON_ORANGE C'255,120,0'
  229. #define NEON_CYAN C'0,255,200'
  230. #define NEON_PURPLE C'200,0,255'
  231. #define NEON_PINK C'255,80,180'
  232. #define NEON_BLUE C'0,200,255'
  233. #define NEON_LIME C'80,255,80'
  234. #define NEON_GOLD C'255,180,0'
  235. #define DARK_BLUE_NEON C'0,100,255'
  236. #define NEON_WHITE C'220,230,255'
  237. #define CGR C'160,170,190'
  238. #define BB_GREY C'180,180,190'
  239. #define BG_DARK1 C'6,8,16'
  240. #define BG_DARK2 C'10,14,24'
  241. #define BG_DARK3 C'14,20,32'
  242. #define BG_DARK4 C'18,26,40'
  243.  
  244. struct HTFLevel{ double price; string timeframe; string type; datetime time; int strength; bool isRoundNumber; };
  245.  
  246. struct NCPPatternResult {
  247. string name;
  248. int type;
  249. int strength;
  250. string category;
  251. };
  252.  
  253. struct NCPSRZone {
  254. double price;
  255. string type;
  256. int touches;
  257. int strength;
  258. bool isRoundNum;
  259. bool isOrderBlock;
  260. datetime lastTouch;
  261. };
  262.  
  263. struct NCPTrendInfo {
  264. string m15Direction;
  265. int m15Strength;
  266. int m1Bias;
  267. string m5Direction;
  268. int m5Strength;
  269. bool aligned;
  270. };
  271.  
  272.  
  273.  
  274. struct NCPMultiTF {
  275. double rsi_m1;
  276. double rsi_m5;
  277. double rsi_m15;
  278. int cci_m1;
  279. int cci_m5;
  280. int macd_m1_dir;
  281. int macd_m5_dir;
  282. double atr_m1;
  283. double atr_m5;
  284. bool ha_m1_bull;
  285. bool ha_m1_bear;
  286. bool ha_m5_bull;
  287. bool ha_m5_bear;
  288. int bullCount;
  289. int bearCount;
  290. };
  291.  
  292. //+------------------------------------------------------------------+
  293. // GLOBAL VARIABLES
  294. //+------------------------------------------------------------------+
  295. string g_haM1="",g_haM5="",g_haBoth="";
  296. color g_haM1Color=clrGray,g_haM5Color=clrGray;
  297. static double NW[36];
  298. static double g_rsc=0,g_tfa=3;
  299. static datetime g_spm_t=0,g_last_bar=0;
  300. static double g_nearest_res=0,g_nearest_sup=0;
  301. static string g_brk_str="NO BRK";
  302. static color g_brk_color=CGR;
  303. struct RejLevel{double price;int touches;};
  304. static RejLevel g_rj[MAX_REJ];
  305. static int g_rj_cnt=0;
  306.  
  307. static double g_hrn_price=0;
  308. static bool g_hrn_is_sup=true;
  309. static int g_hrn_brk_bars=0;
  310. static datetime g_hrn_scan_bar=0;
  311. static string g_hrn_str="--";
  312. static double g_hrn_score=0;
  313. static bool g_hrn_confirmed_break=false;
  314.  
  315. static int g_otcCallPct=50,g_otcPutPct=50;
  316. static string g_pairNames[8],g_pairSigs[8];
  317. static double g_pairConfs[8];
  318. static int g_pairCount=0;
  319. static double g_frozen_gProb=50,g_frozen_rProb=50;
  320. static string g_frozen_pAction="UNCERTAIN";
  321. static color g_frozen_pColor=NEON_YELLOW;
  322. static double g_calc_gProb=50,g_calc_rProb=50;
  323. static string g_calc_pAction="UNCERTAIN";
  324. static color g_calc_pColor=NEON_YELLOW;
  325. static double g_gProb=50,g_rProb=50;
  326. static string g_pAction="UNCERTAIN";
  327. static color g_pColor=NEON_YELLOW;
  328. static datetime g_last_freeze_bar=0;
  329. static double g_accuracy=65.0;
  330. static int g_acc_correct=0,g_acc_total=0;
  331. static datetime g_acc_lastBar=0;
  332. static double g_lastPredGreen=50.0;
  333. static datetime g_lastPredBar=0;
  334. static string g_finalSignal="WAIT";
  335. static color g_finalColor=NEON_YELLOW;
  336. static datetime g_signalTime=0;
  337. static string g_lastNotified="";
  338. static string g_marketMode="RANGE",g_prevMode="";
  339. static int g_lossStreak=0;
  340. static bool g_tradingStopped=false;
  341. static string g_strategyType="NONE";
  342. static string g_strategyReason="";
  343. static double qmrA=0,qmrB=0,qmrC=0,qmrD=0;
  344. static bool qmrActive=false;
  345. static datetime qmrExpire=0;
  346. #define MAX_COMMON_PTS 5
  347. static double g_commonPrice[MAX_COMMON_PTS];
  348. static datetime g_commonTime[MAX_COMMON_PTS];
  349. static int g_commonCount=0;
  350. static datetime g_commonExpire[MAX_COMMON_PTS];
  351. static string g_commonType[MAX_COMMON_PTS];
  352. static datetime g_lastCommonScan=0;
  353. #define MAX_WICK_LINES 5
  354. static double g_wickLinePrice[MAX_WICK_LINES];
  355. static int g_wickLineTouches[MAX_WICK_LINES];
  356. static datetime g_wickLineExpire[MAX_WICK_LINES];
  357. static int g_wickLineCount=0;
  358. static datetime g_lastWickScan=0;
  359. static bool g_isSideways=false;
  360. static string g_tfa_detail="";
  361. static HTFLevel g_htfLevels[50];
  362. static int g_htfLevelCount=0;
  363. static bool g_mtfConfirmed=true;
  364. static string g_filterStatus="ALL CLEAR";
  365. static string g_adv1="WAIT KAR";
  366. static string g_symbolKey="";
  367. static double g_brokerBias=0.0;
  368.  
  369. double g_stableRes[10];
  370. double g_stableSup[10];
  371. int g_stableResCount = 0;
  372. int g_stableSupCount = 0;
  373. datetime g_lastSRScan = 0;
  374. int g_srScanInterval = 5;
  375.  
  376. static double g_fibBestScore = 0;
  377. static double g_fibBestProb = 0;
  378. static string g_fibBestDir = "WAIT";
  379. static int g_fibConfidence = 0;
  380. static double g_fibBestPrice = 0;
  381. static string g_fibPattern = "";
  382. static string g_fibFibLevel = "";
  383. static string g_bbSignal = "--";
  384. static color g_bbColor = CGR;
  385. static double g_bbTouchPrice = 0.0;
  386. static datetime g_bbSignalTime = 0;
  387. static int g_bbSignalBars = 0;
  388. static string g_bbDetail = "";
  389.  
  390. static double g_ha30_open = 0.0;
  391. static double g_ha30_close = 0.0;
  392. static double g_ha30_high = 0.0;
  393. static double g_ha30_low = 0.0;
  394. static datetime g_ha30_bar = 0;
  395.  
  396. // === OTC FIB v3.0 NEW GLOBALS ===
  397. static double g_otcFibPrice = 0;
  398. static string g_otcFibDir = "WAIT";
  399. static int g_otcFibStrength = 0;
  400. static string g_otcFibPattern = "--";
  401. static string g_otcFibLevel = "--";
  402. static datetime g_otcFibSignalTime = 0;
  403. static bool g_otcHasSignal = false;
  404. double g_gannBoxHigh = 0;
  405. double g_gannBoxLow = 0;
  406.  
  407. static int g_buyCountCache = 0;
  408. static int g_sellCountCache = 0;
  409. static datetime g_cacheConfluenceTime = 0;
  410.  
  411.  
  412.  
  413. static int g_otcPreCloseWindow = 3; // 3 seconds before close
  414.  
  415.  
  416.  
  417. static datetime g_last_m5_bar = 0; // FOR STABLE M5 S/R
  418.  
  419. #define MAX_BB_LINES 8
  420. static double g_bbLinePrice[MAX_BB_LINES];
  421. static datetime g_bbLineExpire[MAX_BB_LINES];
  422. static string g_bbLineType[MAX_BB_LINES];
  423. static int g_bbLineCount=0;
  424.  
  425. // NCP PRO v8.0 GLOBALS
  426. static string g_mtgState = "INIT";
  427. static string g_mtgReason = "";
  428. static string g_mtgAction = "";
  429. static color g_mtgClr = CGR;
  430. static double g_mtgHype = 50.0;
  431. static double g_mtgBetrayal = 50.0;
  432. static string g_mtgPattern = "";
  433. static int g_mtgBullCount = 0;
  434. static int g_mtgBearCount = 0;
  435. static double g_mtgRecovery = 0.0;
  436. static datetime g_mtg_lastBar = 0;
  437. static double g_trapScore = 0;
  438. static double g_ncpADX = 0.0;
  439. static double g_ncpPlusDI = 0.0;
  440. static double g_ncpMinusDI = 0.0;
  441.  
  442. static double g_callWeight = 1.0;
  443. static double g_putWeight = 1.0;
  444. static int g_totalTrades = 0;
  445. static int g_callTrades = 0;
  446. static int g_putTrades = 0;
  447. static int g_callWins = 0;
  448. static int g_putWins = 0;
  449. static datetime g_ncpLastSignalTime = 0;
  450. static string g_ncpLastSignalType = "";
  451. static double g_ncpLastEntryPrice = 0.0;
  452. static bool g_ncpSignalProcessed = true;
  453. static double g_smoothCallScore = 50.0;
  454. static double g_smoothPutScore = 50.0;
  455.  
  456. static NCPTrendInfo g_ncpTrend;
  457. static NCPMultiTF g_ncpMultiTF;
  458. static NCPSRZone g_ncpSRZones[20];
  459. static int g_ncpSRCount = 0;
  460. static string g_ncpDetailLine1 = "";
  461. static string g_ncpDetailLine2 = "";
  462. static string g_ncpDetailLine3 = "";
  463. static int g_ncpPatternBullScore = 0;
  464. static int g_ncpPatternBearScore = 0;
  465. static string g_ncpMainPattern = "";
  466.  
  467. // ============================================================
  468. // OTC NEXT CANDLE PREDICTOR (REPLACES PSYCHE BREAKER)
  469. // ============================================================
  470. static string g_otpSignal = "WAIT";
  471. static double g_otpConf = 50.0;
  472. static string g_otpRsi = "--";
  473. static string g_otpWick = "--";
  474. static string g_otpReason = "";
  475. static color g_otpColor = NEON_YELLOW;
  476.  
  477. // ============================================================
  478. // MHI-QUANTUM v9.1 PRO GLOBALS
  479. // ============================================================
  480. static string g_qSignal = "WAIT";
  481. static double g_qConf = 50.0;
  482. static string g_qPattern = "---";
  483. static string g_qStatus = "SCANNING";
  484. static color g_qColor = NEON_YELLOW;
  485. static string g_qReason = "";
  486. static bool g_qIsTrap = false;
  487. static double g_qCallScore = 50.0;
  488. static double g_qPutScore = 50.0;
  489. static string g_qConfluence = "";
  490. static int g_qHistoryScore = 0;
  491. static double g_qTimeProb = 50.0;
  492. static double g_qSpreadPenalty = 0.0;
  493.  
  494. // Auto-learning globals
  495. static double g_qWeightMHI = 0.25;
  496. static double g_qWeightNCP = 0.20;
  497. static double g_qWeightTrap = 0.15;
  498. static double g_qWeightFib = 0.15;
  499. static double g_qWeightBB = 0.10;
  500. static double g_qWeightNeural = 0.10;
  501. static double g_qWeightHA = 0.05;
  502. static int g_qTotalTrades = 0;
  503. static int g_qWinTrades = 0;
  504. static string g_qLearnFile = "Quantum_Learn_v91.dat";
  505.  
  506. // 150-candle history
  507. static int g_histPatterns[150];
  508. static int g_histResults[150];
  509. static int g_histCount = 0;
  510.  
  511. // Multi-pair MHI
  512. static string g_bgMHI_Signal[8];
  513. static double g_bgMHI_Conf[8];
  514. static int g_bgMHI_Count = 0;
  515.  
  516. static string g_bgMHI_Pair[8];
  517.  
  518.  
  519. // Time phase
  520. static string g_qTimePhase = "EARLY";
  521.  
  522. // Tracking
  523. static string g_qLastSignal = "";
  524. static datetime g_qLastSignalBar = 0;
  525.  
  526.  
  527. // BACKGROUND PAIRS NEXT CANDLE DATA
  528. static string g_bgOtpSignal[8];
  529. static int g_bgOtpCount = 0;
  530. static string g_bgOB_Pair[8];
  531. static string g_bgOB_Signal[8];
  532. static int g_bgOB_Count = 0;
  533.  
  534. // ============================================================
  535. // PSYCHE BREAKER v3.0 GLOBALS
  536. // ============================================================
  537. static double g_psycheScore = 0;
  538. static string g_psycheDir = "NONE";
  539. static string g_psycheWick = "--";
  540. static string g_psycheVol = "--";
  541. static string g_psycheHA = "--";
  542. static string g_psycheSR = "--";
  543. static string g_psycheSignal = "SCANNING";
  544. static color g_psycheClr = CGR;
  545. static int g_psycheUpperWick= 0;
  546. static int g_psycheLowerWick= 0;
  547.  
  548. // ============================================================
  549. // OTC BROKER KILLER v4.0 - PROFESSIONAL TRAP ENGINE
  550. // ============================================================
  551. struct VisualTrapPro {
  552. string boxStatus, gannStatus, m30Dir, m1Seq, verdict;
  553. color gannColor, verdictColor;
  554. double callBias, putBias, trapScore;
  555. bool buySignal, sellSignal;
  556. };
  557. VisualTrapPro g_visualTrapPro;
  558. static datetime g_lastTrapArrowTime = 0;
  559.  
  560. //+------------------------------------------------------------------+
  561. // SHORT PRICE FUNCTION - For chart S/R labels
  562. //+------------------------------------------------------------------+
  563. string ShortPrice(double price){
  564. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS);
  565. if(dg < 2) dg = 5;
  566. return DoubleToString(price, dg);
  567. }
  568. string SRPrice(double price){ return ShortPrice(price); }
  569.  
  570. //+------------------------------------------------------------------+
  571. // DYNAMIC ADX COLOR FUNCTION
  572. //+------------------------------------------------------------------+
  573. color GetADXColor(double adx, double plusDI, double minusDI){
  574. if(adx < 15) return CGR;
  575. if(adx < 22) return NEON_ORANGE;
  576. double diDiff = plusDI - minusDI;
  577. if(diDiff > 10) return NEON_GREEN;
  578. if(diDiff > 5) return NEON_LIME;
  579. if(diDiff < -10) return NEON_RED;
  580. if(diDiff < -5) return C'255,100,100';
  581. return NEON_YELLOW;
  582. }
  583.  
  584. //+------------------------------------------------------------------+
  585. // M30 HA CANDLE (FIXED NAME)
  586. //+------------------------------------------------------------------+
  587. void CalcM30HACandle(){
  588. if(Bars < 5) return;
  589. if(iBars(NULL, PERIOD_M30) >= 2){
  590. g_ha30_open = iOpen(NULL, PERIOD_M30, 1);
  591. g_ha30_close = iClose(NULL, PERIOD_M30, 1);
  592. g_ha30_high = iHigh(NULL, PERIOD_M30, 1);
  593. g_ha30_low = iLow(NULL, PERIOD_M30, 1);
  594. g_ha30_bar = iTime(NULL, PERIOD_M30, 1);
  595. }
  596. else {
  597. g_ha30_open = Open[0];
  598. g_ha30_close = Close[0];
  599. g_ha30_high = High[0];
  600. g_ha30_low = Low[0];
  601. g_ha30_bar = Time[0];
  602. }
  603. }
  604.  
  605. bool IsM30HABull(){ return (g_ha30_close > g_ha30_open); }
  606. bool IsM30HABear(){ return (g_ha30_close < g_ha30_open); }
  607.  
  608. //+------------------------------------------------------------------+
  609. // UPGRADED BB PULLBACK - M30 HA PHOOLBAG ENGINE (FIXED REFS)
  610. //+------------------------------------------------------------------+
  611. void DetectBBPullback(){
  612. if(!ENABLE_BB_PULLBACK || Bars < BB_PERIOD + 5) return;
  613. CalcM30HACandle();
  614. double bbUpper0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 0);
  615. double bbLower0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 0);
  616. double bbMid0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_MAIN, 0);
  617. double bbUpper1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 1);
  618. double bbLower1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 1);
  619. if(bbUpper1 <= 0 || bbLower1 <= 0) return;
  620.  
  621. bool isHaM30Bull = IsM30HABull();
  622. bool isHaM30Bear = IsM30HABear();
  623. bool topPhoolbag = (g_ha30_high >= bbUpper0 * 0.9998) && (g_ha30_close < bbUpper0) && isHaM30Bear;
  624. bool bottomPhoolbag = (g_ha30_low <= bbLower0 * 1.0002) && (g_ha30_close > bbLower0) && isHaM30Bull;
  625.  
  626. double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  627. double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  628. double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  629. double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  630. bool adxValid = (adx >= 18);
  631. bool diBull = (plusDI > minusDI);
  632. bool diBear = (minusDI > plusDI);
  633.  
  634. double ha30Range = g_ha30_high - g_ha30_low;
  635. double topWick = (ha30Range > 0) ? (g_ha30_high - MathMax(g_ha30_open, g_ha30_close)) / ha30Range : 0;
  636. double bottomWick = (ha30Range > 0) ? (MathMin(g_ha30_open, g_ha30_close) - g_ha30_low) / ha30Range : 0;
  637.  
  638. bool isStrongTopPhoolbag = topPhoolbag && (topWick > 0.50);
  639. bool isStrongBottomPhoolbag = bottomPhoolbag && (bottomWick > 0.50);
  640.  
  641. int putConfirm = 0;
  642. if(isStrongTopPhoolbag) putConfirm += 3;
  643. else if(topPhoolbag) putConfirm += 2;
  644. if(diBear) putConfirm++;
  645. if(rsi > 55) putConfirm++;
  646. if(rsi > 65) putConfirm++;
  647.  
  648. int callConfirm = 0;
  649. if(isStrongBottomPhoolbag) callConfirm += 3;
  650. else if(bottomPhoolbag) callConfirm += 2;
  651. if(diBull) callConfirm++;
  652. if(rsi < 45) callConfirm++;
  653. if(rsi < 35) callConfirm++;
  654.  
  655. if(!adxValid) { putConfirm = 0; callConfirm = 0; }
  656.  
  657. string adxStr = "ADX:"+DoubleToString(adx,0)+(adxValid?"*":"");
  658. string rsiStr = "RSI:"+DoubleToString(rsi,0);
  659. string diStr = (diBull?"DI^":diBear?"DIv":"DI=");
  660. string haStr = isHaM30Bull?"HA30:BULL":isHaM30Bear?"HA30:BEAR":"HA30:DOJI";
  661.  
  662. if(g_bbSignal != "--" && g_bbSignalTime > 0){
  663. int barsElapsed = (int)((TimeCurrent() - g_bbSignalTime) / (Period() * 60));
  664. if(barsElapsed > BB_SIGNAL_EXPIRE_BARS){
  665. g_bbSignal = "--"; g_bbColor = NEON_YELLOW;
  666. g_bbDetail = ""; g_bbTouchPrice = 0.0;
  667. }
  668. }
  669.  
  670. string newSignal = "--";
  671. double touchPriceNew = 0.0;
  672. string detailNew = "";
  673. color newColor = NEON_YELLOW;
  674.  
  675. if(putConfirm >= 2){
  676. newSignal = "PUT";
  677. touchPriceNew = bbUpper0;
  678. string conf = (putConfirm>=4)?"STRONG PB":(putConfirm>=3)?"GOOD PB":"WEAK PB";
  679. detailNew = "PB UP|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr+"|"+haStr;
  680. newColor = (putConfirm >= 3) ? NEON_RED : NEON_ORANGE;
  681. }
  682. else if(callConfirm >= 2){
  683. newSignal = "CALL";
  684. touchPriceNew = bbLower0;
  685. string conf = (callConfirm>=4)?"STRONG PB":(callConfirm>=3)?"GOOD PB":"WEAK PB";
  686. detailNew = "PB LO|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr+"|"+haStr;
  687. newColor = (callConfirm >= 3) ? NEON_GREEN : NEON_CYAN;
  688. }
  689.  
  690. if(newSignal != "--"){
  691. bool isNew = (newSignal != g_bbSignal || touchPriceNew != g_bbTouchPrice);
  692. if(isNew){
  693. g_bbSignal = newSignal;
  694. g_bbTouchPrice = touchPriceNew;
  695. g_bbSignalTime = TimeCurrent();
  696. g_bbDetail = detailNew;
  697. g_bbColor = newColor;
  698. AddBBLine(touchPriceNew, newSignal);
  699. Print("BB PHOOLBAG: ",newSignal," | ",detailNew," Conf:",(newSignal=="PUT"?putConfirm:callConfirm),"/5");
  700. }
  701. } else if(g_bbSignal == "--"){
  702. g_bbColor = NEON_YELLOW;
  703. }
  704. DrawBBLines(bbUpper0, bbLower0, bbMid0);
  705. }
  706.  
  707. void DrawBBLines(double upper, double lower, double mid){
  708. if(!ENABLE_BB_PULLBACK) return;
  709. string nmU = PFX+"BB_UPPER"; SafeDel(nmU);
  710. 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); }
  711. string nmL = PFX+"BB_LOWER"; SafeDel(nmL);
  712. 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); }
  713. string nmM = PFX+"BB_MID"; SafeDel(nmM);
  714. 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); }
  715. int dg = (int)MarketInfo(Symbol(), MODE_DIGITS); if(dg <= 0) dg = 5;
  716. string lblU = PFX+"BB_U_LBL"; SafeDel(lblU);
  717. 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); }
  718. }
  719.  
  720. void AddBBLine(double price, string sigType){
  721. if(price <= 0) return;
  722. for(int i = 0; i < MAX_BB_LINES; i++){ SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i)); SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i)); }
  723. g_bbLineCount = 0; g_bbLinePrice[0] = price; g_bbLineExpire[0] = TimeCurrent() + 60 * BB_SIGNAL_EXPIRE_BARS; g_bbLineType[0] = sigType; g_bbLineCount = 1;
  724. DrawAllBBTouchLines();
  725. }
  726.  
  727. void DrawAllBBTouchLines(){
  728. for(int i = 0; i < MAX_BB_LINES; i++){ SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i)); SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i)); }
  729. if(g_bbLineCount > 0 && TimeCurrent() > g_bbLineExpire[0]){ g_bbLineCount = 0; return; }
  730. if(g_bbLineCount <= 0) return;
  731. string nm = PFX+"BB_TOUCH_0";
  732. string lbl = PFX+"BB_TOUCH_LBL_0";
  733. color lineColor = (g_bbLineType[0]=="CALL") ? NEON_GREEN : NEON_RED;
  734. ObjectCreate(0, nm, OBJ_HLINE, 0, 0, g_bbLinePrice[0]);
  735. ObjectSetInteger(0, nm, OBJPROP_COLOR, lineColor);
  736. ObjectSetInteger(0, nm, OBJPROP_WIDTH, 2);
  737. ObjectSetInteger(0, nm, OBJPROP_STYLE, STYLE_SOLID);
  738. ObjectSetInteger(0, nm, OBJPROP_BACK, false);
  739. if(Bars > 3){
  740. string txt = (g_bbLineType[0]=="CALL") ? "PB^ CALL" : "PBv PUT";
  741. ObjectCreate(0, lbl, OBJ_TEXT, 0, Time[3], g_bbLinePrice[0]);
  742. ObjectSetText(lbl, txt, 8, "Arial Bold", lineColor);
  743. ObjectSetInteger(0, lbl, OBJPROP_BACK, false);
  744. }
  745. }
  746.  
  747. // ============================================================
  748. // BROKER TRAP CALCULATOR
  749. // ============================================================
  750. double CalculateBrokerTrap(double callBias,double putBias){
  751. if(!ENABLE_TRAP_DETECTION||Bars<20) return 0;
  752. double trapScore=0;
  753. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  754. double pip=jpy?0.01:0.0001;
  755. for(int i=1;i<=15&&i<Bars-1;i++){
  756. bool bullEngulf=(Close[i]>Open[i])&&(Close[i-1]<Open[i-1])&&(Close[i]>=Open[i-1])&&(Open[i]<=Close[i-1]);
  757. bool bearEngulf=(Close[i]<Open[i])&&(Close[i-1]>Open[i-1])&&(Close[i]<=Open[i-1])&&(Open[i]>=Close[i-1]);
  758. if(i>=2){
  759. bool mornStar=(Close[i-2]<Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])<pip*3)&&(Close[i]>Open[i]);
  760. bool eveStar =(Close[i-2]>Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])<pip*3)&&(Close[i]<Open[i]);
  761. if(i>=3){
  762. if(bullEngulf&&Close[i-3]<Close[i-2]) trapScore+=3.5;
  763. if(bearEngulf&&Close[i-3]>Close[i-2]) trapScore+=3.5;
  764. if(mornStar&&Close[i-3]<Close[i-2]) trapScore+=3.0;
  765. if(eveStar&&Close[i-3]>Close[i-2]) trapScore+=3.0;
  766. }
  767. }
  768. double rng=High[i]-Low[i];
  769. if(rng<=0) continue;
  770. double uw=(High[i]-MathMax(Open[i],Close[i]))/rng;
  771. double lw=(MathMin(Open[i],Close[i])-Low[i])/rng;
  772. if(uw>0.55&&Close[i]<Open[i]) trapScore+=2.0;
  773. if(lw>0.55&&Close[i]>Open[i]) trapScore+=2.0;
  774. }
  775. double rng0=High[0]-Low[0];
  776. if(rng0>0){
  777. double uw0=(High[0]-MathMax(Open[0],Close[0]))/rng0;
  778. double lw0=(MathMin(Open[0],Close[0])-Low[0])/rng0;
  779. if(uw0>0.65&&Close[0]<Open[0]) trapScore+=4.0;
  780. if(lw0>0.65&&Close[0]>Open[0]) trapScore+=4.0;
  781. if(Close[0]>Open[0]&&Close[1]<Open[1]){
  782. if(Close[0]>Open[1]&&Open[0]<Close[1]) trapScore+=3.0;
  783. }
  784. if(Close[0]<Open[0]&&Close[1]>Open[1]){
  785. if(Close[0]<Open[1]&&Open[0]>Close[1]) trapScore+=3.0;
  786. }
  787. }
  788. double biasStr=MathMax(callBias,putBias)-50;
  789. double biasMul=1.0+biasStr/150.0;
  790. if(biasMul>1.5) biasMul=1.5;
  791. if(biasMul<0.5) biasMul=0.5;
  792. trapScore*=biasMul;
  793. return MathMin(100,trapScore);
  794. }
  795.  
  796. // ============================================================
  797. // HA CANDLE CALCULATION (FIXED ARRAY BOUNDS)
  798. // ============================================================
  799. void CalcHA(){
  800. if(Bars<10) return;
  801. bool wasOpenSeries=ArrayGetAsSeries(Open), wasHighSeries=ArrayGetAsSeries(High),
  802. wasLowSeries=ArrayGetAsSeries(Low), wasCloseSeries=ArrayGetAsSeries(Close);
  803. ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true);
  804. ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true);
  805.  
  806. static double haO1[500], haC1[500];
  807. static datetime lb1=0;
  808. ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true);
  809. datetime c1=iTime(NULL,PERIOD_M1,0);
  810. if(c1!=lb1){
  811. lb1=c1;
  812. int lim=MathMin(iBars(NULL,PERIOD_M1), 499); // FIX: Use 499
  813. for(int i=lim; i>=0; i--){ // FIX: Start from lim
  814. haC1[i] = (Open[i]+High[i]+Low[i]+Close[i])/4.0;
  815. if(i==lim) haO1[i] = (Open[i]+Close[i])/2.0; // FIX: Use lim
  816. else haO1[i] = (haO1[i+1] + haC1[i+1])/2.0;
  817. }
  818. }
  819.  
  820. double d1=MathAbs(haC1[1]-haO1[1]), r1=High[1]-Low[1];
  821. bool dz=(r1>0 && d1<r1*0.1), b1=(!dz && haC1[1]>haO1[1]), be1=(!dz && haC1[1]<haO1[1]);
  822. if(b1){ g_haM1="HA BULLISH 1"; g_haM1Color=clrLime; }
  823. else if(be1){ g_haM1="HA BEARISH 1"; g_haM1Color=clrRed; }
  824. else{ g_haM1="HA DOJI 1"; g_haM1Color=clrYellow; }
  825.  
  826. if(iBars(NULL,PERIOD_M5)>=10){
  827. static double haO5[200], haC5[200];
  828. static datetime lb5=0;
  829. ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true);
  830. datetime c5=iTime(NULL,PERIOD_M5,0);
  831. if(c5!=lb5){
  832. lb5=c5;
  833. int lim5=MathMin(iBars(NULL,PERIOD_M5), 199); // FIX: Use 199
  834. for(int i=lim5; i>=0; i--){ // FIX: Start from lim5
  835. double o=iOpen(NULL,PERIOD_M5,i), h=iHigh(NULL,PERIOD_M5,i),
  836. l=iLow(NULL,PERIOD_M5,i), c=iClose(NULL,PERIOD_M5,i);
  837. haC5[i]=(o+h+l+c)/4.0;
  838. if(i==lim5) haO5[i]=(o+c)/2.0; // FIX: Use lim5
  839. else haO5[i]=(haO5[i+1]+haC5[i+1])/2.0;
  840. }
  841. }
  842. double d5=MathAbs(haC5[1]-haO5[1]), r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1);
  843. bool dz5=(r5>0 && d5<r5*0.1), b5=(!dz5 && haC5[1]>haO5[1]), be5=(!dz5 && haC5[1]<haO5[1]);
  844. if(b5){ g_haM5="HA BULLISH 5"; g_haM5Color=clrLime; }
  845. else if(be5){ g_haM5="HA BEARISH 5"; g_haM5Color=clrRed; }
  846. else{ g_haM5="HA DOJI 5"; g_haM5Color=clrYellow; }
  847. if(b1&&b5) g_haBoth="BOTH BULL";
  848. else if(be1&&be5) g_haBoth="BOTH BEAR";
  849. else g_haBoth="MIXED";
  850. } else {
  851. g_haM5="5 --"; g_haM5Color=clrGray; g_haBoth="HA --";
  852. }
  853.  
  854. if(!wasOpenSeries) ArraySetAsSeries(Open,false);
  855. if(!wasHighSeries) ArraySetAsSeries(High,false);
  856. if(!wasLowSeries) ArraySetAsSeries(Low,false);
  857. if(!wasCloseSeries) ArraySetAsSeries(Close,false);
  858. }
  859.  
  860. // ============================================================
  861. // HELPERS
  862. // ============================================================
  863. bool IsLineNearby(double price,double pipTol=3.0){
  864. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip;
  865. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i);
  866. if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE){
  867. double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)<tol) return true; }}
  868. return false;
  869. }
  870.  
  871. string GetCurrentSession(color &sC){
  872. int h=TimeHour(TimeGMT());
  873. if(h>=12&&h<16){sC=NEON_GOLD;return "LON+NY";}
  874. if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";}
  875. if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";}
  876. if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";}
  877. if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";}
  878. sC=C'100,100,120'; return "SYDNEY";
  879. }
  880.  
  881. bool IsSessionActive(){int h=TimeHour(TimeGMT());return(h>=7&&h<=21);}
  882. 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);}
  883.  
  884. bool CheckMTFConfirmation(){
  885. if(!MTF_CONFIRM) return true;
  886. bool m1Bull=(Close[1]>Open[1]);
  887. bool m5Bull=false,m15Bull=false;
  888. if(iBars(NULL,PERIOD_M5)>=3) m5Bull=(iClose(NULL,PERIOD_M5,1)>iOpen(NULL,PERIOD_M5,1));
  889. if(iBars(NULL,PERIOD_M15)>=3) m15Bull=(iClose(NULL,PERIOD_M15,1)>iOpen(NULL,PERIOD_M15,1));
  890. int bullCount=0,bearCount=0;
  891. if(m1Bull) bullCount++; else bearCount++;
  892. if(m5Bull) bullCount++; else bearCount++;
  893. if(m15Bull) bullCount++; else bearCount++;
  894. g_mtfConfirmed=(bullCount>=2 || bearCount>=2);
  895. return g_mtfConfirmed;
  896. }
  897.  
  898. double Tanh(double x){double e=MathExp(2.0*x);return(e-1.0)/(e+1.0);}
  899.  
  900. double CalcAdvancedMicroAI(){
  901. if(Bars<20) return 50.0;
  902. double score=50.0;
  903. bool jpy=(StringFind(Symbol(),"JPY")>=0);
  904. double pip=jpy?0.01:0.0001;
  905. for(int i=1;i<=5;i++){
  906. double r=High[i]-Low[i]; if(r<=0) continue;
  907. double uw=(High[i]-MathMax(Open[i],Close[i]))/r;
  908. double lw=(MathMin(Open[i],Close[i])-Low[i])/r;
  909. double w=(6.0-i)/5.0;
  910. if(uw>0.65) score-=w*18; else if(uw>0.50) score-=w*10;
  911. if(lw>0.65) score+=w*18; else if(lw>0.50) score+=w*10;
  912. }
  913. double pos5=0;
  914. for(int i=1;i<=5;i++){double r=High[i]-Low[i]; if(r<=0) continue; pos5+=(Close[i]-Low[i])/r; }
  915. score+=(pos5/5.0-0.5)*25.0;
  916. double gc=0,rc=0;
  917. 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;}
  918. score+=(gc-rc)*4.0;
  919. double vl1=(double)iVolume(NULL,PERIOD_M1,1),vA=0;
  920. for(int i=2;i<=6;i++) vA+=iVolume(NULL,PERIOD_M1,i);
  921. vA/=5.0;
  922. 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;}
  923. double r1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  924. double r5=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  925. if(r1<30) score+=15; else if(r1<40) score+=7;
  926. if(r1>70) score-=15; else if(r1>60) score-=7;
  927. if(r1>r5&&Close[1]<Close[5]) score+=8;
  928. if(r1<r5&&Close[1]>Close[5]) score-=8;
  929. if(g_nearest_res>0){double distR=(g_nearest_res-Close[0])/pip; if(distR<5) score-=12; else if(distR<10) score-=6;}
  930. if(g_nearest_sup>0){double distS=(Close[0]-g_nearest_sup)/pip; if(distS<5) score+=12; else if(distS<10) score+=6;}
  931. if(Close[0]>Open[0]&&Close[1]>Open[1]) score+=5;
  932. if(Close[0]<Open[0]&&Close[1]<Open[1]) score-=5;
  933. return MathMax(5.0,MathMin(95.0,score));
  934. }
  935.  
  936. // ============================================================
  937. // BAYESIAN PROBABILITY ENGINE (MQL4)
  938. // ============================================================
  939. struct BayesianResult
  940. {
  941. double posteriorReal;
  942. double posteriorTrap;
  943. bool isTrap;
  944. string recommendation;
  945. };
  946.  
  947. BayesianResult CalcBayesianProbability(
  948. int direction,
  949. double priorReal,
  950. double priorTrap,
  951. bool hasPinBar,
  952. bool hasDoji,
  953. bool hasEngulf,
  954. bool hasFakeBreakout,
  955. bool hasWickReversal,
  956. bool hasLiquiditySweep
  957. )
  958. {
  959. BayesianResult result;
  960.  
  961. double pinBarLikelyReal, pinBarLikelyTrap;
  962. double dojiLikelyReal, dojiLikelyTrap;
  963. double engulfLikelyReal, engulfLikelyTrap;
  964. double fakeLikelyReal, fakeLikelyTrap;
  965. double wickLikelyReal, wickLikelyTrap;
  966. double liqLikelyReal, liqLikelyTrap;
  967.  
  968. if(direction == 0) // CALL
  969. {
  970. pinBarLikelyReal = 0.15; pinBarLikelyTrap = 0.55;
  971. dojiLikelyReal = 0.08; dojiLikelyTrap = 0.42;
  972. engulfLikelyReal = 0.32; engulfLikelyTrap = 0.12;
  973. fakeLikelyReal = 0.05; fakeLikelyTrap = 0.35;
  974. wickLikelyReal = 0.22; wickLikelyTrap = 0.52;
  975. liqLikelyReal = 0.18; liqLikelyTrap = 0.62;
  976. }
  977. else // PUT
  978. {
  979. pinBarLikelyReal = 0.18; pinBarLikelyTrap = 0.58;
  980. dojiLikelyReal = 0.10; dojiLikelyTrap = 0.45;
  981. engulfLikelyReal = 0.30; engulfLikelyTrap = 0.10;
  982. fakeLikelyReal = 0.06; fakeLikelyTrap = 0.38;
  983. wickLikelyReal = 0.25; wickLikelyTrap = 0.55;
  984. liqLikelyReal = 0.20; liqLikelyTrap = 0.65;
  985. }
  986.  
  987. double likeReal = 1.0;
  988. double likeTrap = 1.0;
  989.  
  990. likeReal *= hasPinBar ? pinBarLikelyReal : (1 - pinBarLikelyReal);
  991. likeTrap *= hasPinBar ? pinBarLikelyTrap : (1 - pinBarLikelyTrap);
  992.  
  993. likeReal *= hasDoji ? dojiLikelyReal : (1 - dojiLikelyReal);
  994. likeTrap *= hasDoji ? dojiLikelyTrap : (1 - dojiLikelyTrap);
  995.  
  996. likeReal *= hasEngulf ? engulfLikelyReal : (1 - engulfLikelyReal);
  997. likeTrap *= hasEngulf ? engulfLikelyTrap : (1 - engulfLikelyTrap);
  998.  
  999. likeReal *= hasFakeBreakout ? fakeLikelyReal : (1 - fakeLikelyReal);
  1000. likeTrap *= hasFakeBreakout ? fakeLikelyTrap : (1 - fakeLikelyTrap);
  1001.  
  1002. likeReal *= hasWickReversal ? wickLikelyReal : (1 - wickLikelyReal);
  1003. likeTrap *= hasWickReversal ? wickLikelyTrap : (1 - wickLikelyTrap);
  1004.  
  1005. likeReal *= hasLiquiditySweep ? liqLikelyReal : (1 - liqLikelyReal);
  1006. likeTrap *= hasLiquiditySweep ? liqLikelyTrap : (1 - liqLikelyTrap);
  1007.  
  1008. double evidence = (likeReal * priorReal) + (likeTrap * priorTrap);
  1009.  
  1010. if(evidence <= 0)
  1011. {
  1012. result.posteriorReal = 0.5;
  1013. result.posteriorTrap = 0.5;
  1014. result.isTrap = false;
  1015. result.recommendation = "WAIT";
  1016. return result;
  1017. }
  1018.  
  1019. result.posteriorReal = (likeReal * priorReal) / evidence;
  1020. result.posteriorTrap = (likeTrap * priorTrap) / evidence;
  1021.  
  1022. if(result.posteriorReal < 0.30)
  1023. {
  1024. result.isTrap = true;
  1025. result.recommendation = (direction == 0) ? "PUT" : "CALL";
  1026. }
  1027. else if(result.posteriorReal > 0.70)
  1028. {
  1029. result.isTrap = false;
  1030. result.recommendation = (direction == 0) ? "CALL" : "PUT";
  1031. }
  1032. else
  1033. {
  1034. result.isTrap = false;
  1035. result.recommendation = "WAIT";
  1036. }
  1037.  
  1038. return result;
  1039. }
  1040.  
  1041. double g_priorReal = 0.35;
  1042. double g_priorTrap = 0.65;
  1043.  
  1044. void UpdateBayesianPrior(bool tradeWon, bool wasTrapSignal)
  1045. {
  1046. if(wasTrapSignal)
  1047. {
  1048. g_priorTrap = tradeWon ? MathMin(g_priorTrap + 0.02, 0.90) : MathMax(g_priorTrap - 0.02, 0.10);
  1049. g_priorReal = 1.0 - g_priorTrap;
  1050. }
  1051. else
  1052. {
  1053. g_priorReal = tradeWon ? MathMin(g_priorReal + 0.02, 0.90) : MathMax(g_priorReal - 0.02, 0.10);
  1054. g_priorTrap = 1.0 - g_priorReal;
  1055. }
  1056. }
  1057.  
  1058. // === FIB v2.0 GLOBALS ===
  1059. static double g_fibV2_BestScore = 0;
  1060. static double g_fibV2_BestProb = 0;
  1061. static string g_fibV2_BestDir = "WAIT";
  1062. static int g_fibV2_Confidence = 0;
  1063. static double g_fibV2_BestPrice = 0;
  1064. static string g_fibV2_Pattern = "--";
  1065. static string g_fibV2_FibLevel = "--";
  1066. static string g_fibV2_Reason = "";
  1067. static datetime g_fibV2_SignalTime = 0;
  1068. static int g_fibV2_SignalBars = 0;
  1069.  
  1070. struct SwingPoint {
  1071. double price;
  1072. int index;
  1073. bool isHigh;
  1074. int strength;
  1075. };
  1076.  
  1077. struct FibSignal {
  1078. string direction;
  1079. double price;
  1080. double score;
  1081. string pattern;
  1082. string level;
  1083. double confidence;
  1084. string reason;
  1085. int swingPair;
  1086. };
  1087.  
  1088. int CalcSwingStrength(int index, bool isHigh)
  1089. {
  1090. if(index < 2 || index >= Bars - 2) return 1;
  1091. int strength = 5;
  1092. double range = High[index] - Low[index];
  1093. if(range <= 0) return 1;
  1094. int startIdx = MathMax(0, index - 4);
  1095. if(isHigh) {
  1096. double leftRange = High[index] - MathMax(High[index-1], High[index-2]);
  1097. double rightRange = High[index] - MathMax(High[index+1], High[index+2]);
  1098. if(leftRange > range * 0.3) strength += 2;
  1099. if(rightRange > range * 0.3) strength += 2;
  1100. if(index == iHighest(NULL, PERIOD_M1, MODE_HIGH, 10, startIdx)) strength += 3;
  1101. } else {
  1102. double leftRange = MathMin(Low[index-1], Low[index-2]) - Low[index];
  1103. double rightRange = MathMin(Low[index+1], Low[index+2]) - Low[index];
  1104. if(leftRange > range * 0.3) strength += 2;
  1105. if(rightRange > range * 0.3) strength += 2;
  1106. if(index == iLowest(NULL, PERIOD_M1, MODE_LOW, 10, startIdx)) strength += 3;
  1107. }
  1108. return MathMin(10, strength);
  1109. }
  1110.  
  1111. double GetPatternWeight(string pattern)
  1112. {
  1113. if(pattern == "PIN") return 1.0;
  1114. if(pattern == "ENGULF") return 1.2;
  1115. if(pattern == "FAKE") return 1.1;
  1116. if(pattern == "EXHAUST") return 0.9;
  1117. if(pattern == "DOJI") return 0.7;
  1118. if(pattern == "WICK") return 0.6;
  1119. if(pattern == "LIQSWEEP") return 1.3;
  1120. return 0.8;
  1121. }
  1122.  
  1123. //+------------------------------------------------------------------+
  1124. //| OTC FIB REJECTION v4.3 - HIGH SIGNAL FREQUENCY EDITION |
  1125. //| Relaxed Timing + Gann Buffer + Better Swing Detection |
  1126. //+------------------------------------------------------------------+
  1127. void CalcFibRejectionHunter()
  1128. {
  1129. // ==========================================================
  1130. // SECTION 1: RESET ALL GLOBALS
  1131. // ==========================================================
  1132. g_fibV2_BestScore = 0; g_fibV2_BestProb = 0; g_fibV2_BestDir = "WAIT";
  1133. g_fibV2_Confidence = 0; g_fibV2_BestPrice = 0; g_fibV2_Pattern = "--";
  1134. g_fibV2_FibLevel = "--"; g_fibV2_Reason = "";
  1135.  
  1136. g_fibBestScore = 0; g_fibBestDir = "WAIT"; g_fibBestPrice = 0;
  1137. g_fibPattern = "--"; g_fibFibLevel = "--"; g_fibConfidence = 0;
  1138.  
  1139. // ==========================================================
  1140. // SECTION 2: EXPIRE OLD SIGNAL (60 seconds max life)
  1141. // ==========================================================
  1142. if(g_otcFibSignalTime > 0) {
  1143. int secElapsed = (int)(TimeCurrent() - g_otcFibSignalTime);
  1144. if(secElapsed > 60) { // 50 -> 60
  1145. g_otcFibSignalTime = 0;
  1146. g_otcHasSignal = false;
  1147. DeleteOTCFibLine();
  1148. }
  1149. }
  1150.  
  1151. // ==========================================================
  1152. // SECTION 3: TIMING WINDOW (FIX: 20 seconds before close)
  1153. // ==========================================================
  1154. int candleAge = (int)(TimeCurrent() - Time[0]);
  1155. int candleTotal = Period() * 60;
  1156. int remaining = candleTotal - candleAge;
  1157.  
  1158. // ✅ FIX: 3 second ki jagah 20 second ki window rakh di
  1159. if(remaining > 20 || remaining < 0) {
  1160. if(g_otcHasSignal) DrawOTCFibLine();
  1161. return;
  1162. }
  1163.  
  1164. if(Bars < 15) return;
  1165.  
  1166. // ==========================================================
  1167. // SECTION 4: BASIC CALCULATIONS
  1168. // ==========================================================
  1169. double pip = GetUniversalPip();
  1170. if(pip <= 0) pip = 0.0001;
  1171.  
  1172. double atrVal = iATR(NULL, 0, 14, 1);
  1173. if(atrVal <= 0) atrVal = pip * 8;
  1174.  
  1175. // ==========================================================
  1176. // SECTION 5: GANN BOX OR FRACTAL SWING COLLECTION
  1177. // ==========================================================
  1178. double sHighs[3]; sHighs[0]=0; sHighs[1]=0; sHighs[2]=0;
  1179. double sLows[3]; sLows[0]=0; sLows[1]=0; sLows[2]=0;
  1180. int hIdx[3]; hIdx[0]=0; hIdx[1]=0; hIdx[2]=0;
  1181. int lIdx[3]; lIdx[0]=0; lIdx[1]=0; lIdx[2]=0;
  1182. int hCnt = 0, lCnt = 0;
  1183.  
  1184. bool useGannBox = false;
  1185.  
  1186. // ✅ FIX: Minimum Box Size Filter (Chhote box = Noise, Fib nahi banani chahiye)
  1187. double gannBuffer = pip * 3;
  1188. double boxRange = g_gannBoxHigh - g_gannBoxLow;
  1189. double minBoxSizeForFib = pip * 12; // Box kam se kam 12 pips ka hona chahiye
  1190.  
  1191. if(g_gannBoxHigh > 0 && g_gannBoxLow > 0 && boxRange >= minBoxSizeForFib) {
  1192. // Box bada hai, aur candle andar hai
  1193. if(Close[0] <= (g_gannBoxHigh + gannBuffer) && Close[0] >= (g_gannBoxLow - gannBuffer)) {
  1194. useGannBox = true;
  1195. }
  1196. }
  1197.  
  1198. if(useGannBox) {
  1199. sHighs[0] = g_gannBoxHigh;
  1200. sLows[0] = g_gannBoxLow;
  1201. hIdx[0] = iHighest(Symbol(), PERIOD_M1, MODE_HIGH, 25, 1);
  1202. lIdx[0] = iLowest(Symbol(), PERIOD_M1, MODE_LOW, 25, 1);
  1203. hCnt = 1;
  1204. lCnt = 1;
  1205. }
  1206. else {
  1207. // Box chhota hai ya candle bahar hai, toh Fractal/Swing logic use karo
  1208. int maxLB = MathMin(60, Bars - 3);
  1209. double swingDupTol = atrVal * 0.4;
  1210. int i;
  1211.  
  1212. for(i = 2; i < maxLB && hCnt < 3; i++) {
  1213. if(High[i] > High[i-1] && High[i] > High[i-2] &&
  1214. High[i] > High[i+1] && High[i] > High[i+2]) {
  1215.  
  1216. bool dup = false;
  1217. for(int k = 0; k < hCnt; k++) {
  1218. if(MathAbs(High[i] - sHighs[k]) < swingDupTol) { dup = true; break; }
  1219. }
  1220.  
  1221. if(!dup && (High[i] - Low[i]) > atrVal * 0.3) {
  1222. sHighs[hCnt] = High[i]; hIdx[hCnt] = i; hCnt++;
  1223. }
  1224. }
  1225. }
  1226.  
  1227. for(i = 2; i < maxLB && lCnt < 3; i++) {
  1228. if(Low[i] < Low[i-1] && Low[i] < Low[i-2] &&
  1229. Low[i] < Low[i+1] && Low[i] < Low[i+2]) {
  1230.  
  1231. bool dup2 = false;
  1232. for(int k2 = 0; k2 < lCnt; k2++) {
  1233. if(MathAbs(Low[i] - sLows[k2]) < swingDupTol) { dup2 = true; break; }
  1234. }
  1235.  
  1236. if(!dup2 && (High[i] - Low[i]) > pip * 2) {
  1237. sLows[lCnt] = Low[i]; lIdx[lCnt] = i; lCnt++;
  1238. }
  1239. }
  1240. }
  1241. }
  1242.  
  1243. if(hCnt < 1 || lCnt < 1) return;
  1244.  
  1245. // ==========================================================
  1246. // SECTION 6: INDICATORS
  1247. // ==========================================================
  1248. double ema10 = iMA(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, 0);
  1249. double ema20 = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0);
  1250. bool emaBull = (ema10 > ema20);
  1251. bool emaBear = (ema10 < ema20);
  1252. bool emaFlat = (MathAbs(ema10 - ema20) < atrVal * 0.15);
  1253.  
  1254. double rsi0 = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
  1255. double rsi1 = iRSI(NULL, 0, 14, PRICE_CLOSE, 1);
  1256.  
  1257. double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  1258. double pDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  1259. double mDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  1260. double diGap = MathAbs(pDI - mDI);
  1261.  
  1262. // ==========================================================
  1263. // SECTION 7: FIB LEVELS SETUP
  1264. // ==========================================================
  1265. double touchTol = MathMax(atrVal * 0.25, pip * 8); // ✅ FIX: 0.20->0.25 | 6->8 pips (Wider touch)
  1266. double fibLvls[4];
  1267. fibLvls[0] = 0.886; fibLvls[1] = 0.500; fibLvls[2] = 0.618; fibLvls[3] = 0.786;
  1268.  
  1269. string fibNms[4];
  1270. fibNms[0] = "88.6%"; fibNms[1] = "50.0%"; fibNms[2] = "61.8%"; fibNms[3] = "78.6%";
  1271.  
  1272. // ==========================================================
  1273. // SECTION 8: BEST SIGNAL TRACKER
  1274. // ==========================================================
  1275. double bestScore = 0;
  1276. double bestPrice = 0;
  1277. string bestPat = "NONE";
  1278. string bestLvl = "--";
  1279. string bestDir = "WAIT";
  1280.  
  1281. // ==========================================================
  1282. // SECTION 9: MAIN COMBINATION LOOP
  1283. // ==========================================================
  1284. for(int h = 0; h < hCnt; h++) {
  1285. for(int l = 0; l < lCnt; l++) {
  1286.  
  1287. double swingH = sHighs[h];
  1288. double swingL = sLows[l];
  1289. int idxH = hIdx[h];
  1290. int idxL = lIdx[l];
  1291.  
  1292. if(idxH == idxL && !useGannBox) continue;
  1293.  
  1294. double range = MathAbs(swingH - swingL);
  1295. if(range <= pip * 2 || range > pip * 500) continue; // 3->2 min, 400->500 max
  1296.  
  1297. string dir;
  1298. // ✅ FIX: Use Close[1] instead of Close[0] to lock direction.
  1299. // Close[0] changes every tick causing flicker. Close[1] is stable.
  1300. double refPrice = Close[1];
  1301. double pricePos = (refPrice - MathMin(swingH, swingL)) / range;
  1302. pricePos = MathMax(0.0, MathMin(1.0, pricePos));
  1303.  
  1304. bool highFirst = (idxH < idxL);
  1305.  
  1306. if(useGannBox) {
  1307. // ✅ FIX: Direction locked based on last completed candle
  1308. if(Close[1] > Open[1]) dir = "CALL"; // Pichli candle Green thi toh CALL pullback
  1309. else if(Close[1] < Open[1]) dir = "PUT"; // Pichli candle Red thi toh PUT pullback
  1310. else dir = (pricePos < 0.50) ? "CALL" : "PUT"; // Doji ho toh price position se
  1311. } else {
  1312. if(highFirst) {
  1313. dir = (pricePos < 0.65) ? "CALL" : "PUT";
  1314. } else {
  1315. dir = (pricePos > 0.35) ? "PUT" : "CALL";
  1316. }
  1317. }
  1318.  
  1319. if(!emaFlat) {
  1320. if(emaBull && dir == "PUT" && pricePos < 0.25) dir = "CALL";
  1321. if(emaBear && dir == "CALL" && pricePos > 0.75) dir = "PUT";
  1322. }
  1323.  
  1324. if(adx > 25) {
  1325. if(emaBull && dir == "PUT" && pricePos < 0.35) dir = "CALL";
  1326. if(emaBear && dir == "CALL" && pricePos > 0.65) dir = "PUT";
  1327. }
  1328.  
  1329. // ==========================================================
  1330. // SECTION 10: FIB LEVEL LOOP
  1331. // ==========================================================
  1332. for(int f = 0; f < 4; f++) {
  1333. double fibPrice;
  1334.  
  1335. if(dir == "CALL") {
  1336. fibPrice = swingH - (range * fibLvls[f]);
  1337. } else {
  1338. fibPrice = swingL + (range * fibLvls[f]);
  1339. }
  1340.  
  1341. // ==========================================================
  1342. // SECTION 11: TOUCH CHECK [0]
  1343. // ==========================================================
  1344. double touchQ = 0;
  1345. bool touched = false;
  1346.  
  1347. if(dir == "CALL") {
  1348. double d = Low[0] - fibPrice;
  1349. if(d <= touchTol && d >= -touchTol * 2.0) { // 1.5 -> 2.0 (More forgiving)
  1350. touched = true;
  1351. touchQ = MathMax(0, 100 - MathAbs(d) / touchTol * 100);
  1352. double rng = High[0] - Low[0];
  1353. if(rng > 0) {
  1354. double lw = MathMin(Open[0], Close[0]) - Low[0];
  1355. if(lw / rng > 0.25) touchQ += 12; // 0.30 -> 0.25
  1356. }
  1357. }
  1358. } else {
  1359. double d2 = fibPrice - High[0];
  1360. if(d2 <= touchTol && d2 >= -touchTol * 2.0) { // 1.5 -> 2.0
  1361. touched = true;
  1362. touchQ = MathMax(0, 100 - MathAbs(d2) / touchTol * 100);
  1363. double rng2 = High[0] - Low[0];
  1364. if(rng2 > 0) {
  1365. double uw = High[0] - MathMax(Open[0], Close[0]);
  1366. if(uw / rng2 > 0.25) touchQ += 12; // 0.30 -> 0.25
  1367. }
  1368. }
  1369. }
  1370.  
  1371. // ==========================================================
  1372. // SECTION 12: TOUCH CHECK [1]
  1373. // ==========================================================
  1374. if(!touched) {
  1375. if(dir == "CALL") {
  1376. double d3 = Low[1] - fibPrice;
  1377. if(d3 <= touchTol && d3 >= -touchTol * 1.5) { // More forgiving
  1378. touched = true;
  1379. touchQ = MathMax(0, 75 - MathAbs(d3) / touchTol * 50);
  1380. if(Close[1] >= fibPrice - touchTol * 0.5) touchQ += 10;
  1381. }
  1382. } else {
  1383. double d4 = fibPrice - High[1];
  1384. if(d4 <= touchTol && d4 >= -touchTol * 1.5) { // More forgiving
  1385. touched = true;
  1386. touchQ = MathMax(0, 75 - MathAbs(d4) / touchTol * 50);
  1387. if(Close[1] <= fibPrice + touchTol * 0.5) touchQ += 10;
  1388. }
  1389. }
  1390. }
  1391.  
  1392. if(!touched) continue;
  1393.  
  1394. // ==========================================================
  1395. // SECTION 13: PATTERN DETECTION
  1396. // ==========================================================
  1397. string pat = "NONE";
  1398. double rng0 = High[0] - Low[0];
  1399.  
  1400. if(rng0 > 0) {
  1401. double bdy0 = MathAbs(Close[0] - Open[0]);
  1402. double uw0 = High[0] - MathMax(Open[0], Close[0]);
  1403. double lw0 = MathMin(Open[0], Close[0]) - Low[0];
  1404.  
  1405. if(dir == "CALL" && lw0 > bdy0 * 1.0 && lw0 / rng0 > 0.40) pat = "PIN"; // 1.2->1.0 | 0.45->0.40
  1406. else if(dir == "PUT" && uw0 > bdy0 * 1.0 && uw0 / rng0 > 0.40) pat = "PIN";
  1407.  
  1408. double bdy1 = MathAbs(Close[1] - Open[1]);
  1409. if(bdy1 > 0) {
  1410. if(dir == "CALL" && Close[0] > Open[0] && Close[1] < Open[1] && bdy0 > bdy1 * 1.0) pat = "ENGULF"; // 1.1->1.0
  1411. else if(dir == "PUT" && Close[0] < Open[0] && Close[1] > Open[1] && bdy0 > bdy1 * 1.0) pat = "ENGULF";
  1412. }
  1413.  
  1414. if(dir == "CALL" && Low[0] < fibPrice && Close[0] > fibPrice) pat = "FAKE";
  1415. else if(dir == "PUT" && High[0] > fibPrice && Close[0] < fibPrice) pat = "FAKE";
  1416.  
  1417. if(bdy0 / rng0 < 0.15 && rng0 > pip * 4) pat = "DOJI"; // 0.12->0.15 | 5->4
  1418.  
  1419. if(pat == "NONE") {
  1420. if(dir == "CALL" && lw0 > uw0 && lw0 / rng0 > 0.25) pat = "WICK"; // 0.30->0.25
  1421. else if(dir == "PUT" && uw0 > lw0 && uw0 / rng0 > 0.25) pat = "WICK";
  1422. }
  1423. }
  1424.  
  1425. // ==========================================================
  1426. // SECTION 14: BAYESIAN TRAP DETECTION
  1427. // ==========================================================
  1428. bool isTrap = false;
  1429. double trapPenalty = 0;
  1430. string trapReason = "";
  1431.  
  1432. if(dir == "CALL" && rsi0 < 35 && rsi1 > rsi0 && Low[0] < Low[1]) {
  1433. isTrap = true; trapReason = "RSI_DIV";
  1434. }
  1435. if(dir == "PUT" && rsi0 > 65 && rsi1 < rsi0 && High[0] > High[1]) {
  1436. isTrap = true; trapReason = "RSI_DIV";
  1437. }
  1438.  
  1439. if(adx < 18) {
  1440. if(dir == "CALL" && mDI > pDI + 8) { isTrap = true; trapReason = "ADX_WEAK"; }
  1441. if(dir == "PUT" && pDI > mDI + 8) { isTrap = true; trapReason = "ADX_WEAK"; }
  1442. }
  1443.  
  1444. double v0 = (double)iVolume(NULL, PERIOD_M1, 0);
  1445. double vAvg = 0;
  1446. for(int vi = 1; vi <= 5; vi++) vAvg += (double)iVolume(NULL, PERIOD_M1, vi);
  1447. vAvg /= 5.0;
  1448. if(vAvg > 0 && v0 > vAvg * 2.0) {
  1449. double rngV = High[0] - Low[0];
  1450. if(rngV > 0 && MathAbs(Close[0] - Open[0]) / rngV < 0.30) {
  1451. isTrap = true; trapReason = "VOL_SPIKE";
  1452. }
  1453. }
  1454.  
  1455. bool threeGreen = (Close[2] > Open[2] && Close[1] > Open[1] && Close[0] > Open[0]);
  1456. bool threeRed = (Close[2] < Open[2] && Close[1] < Open[1] && Close[0] < Open[0]);
  1457. if(dir == "CALL" && threeGreen) { isTrap = true; trapReason = "3GREEN"; }
  1458. if(dir == "PUT" && threeRed) { isTrap = true; trapReason = "3RED"; }
  1459.  
  1460. if(isTrap) {
  1461. trapPenalty = 10; // 15 -> 10 (Less penalty so lines still appear)
  1462. pat = "TRAP_" + trapReason + "_" + pat;
  1463. }
  1464.  
  1465. // ==========================================================
  1466. // SECTION 15: SCORING
  1467. // ==========================================================
  1468. double score = touchQ * 0.50; // 0.45 -> 0.50 (More weight to touch)
  1469.  
  1470. if(pat == "PIN" || StringFind(pat, "PIN") >= 0) score += 22;
  1471. else if(pat == "ENGULF" || StringFind(pat, "ENGULF") >= 0) score += 20;
  1472. else if(pat == "FAKE" || StringFind(pat, "FAKE") >= 0) score += 18;
  1473. else if(pat == "DOJI" || StringFind(pat, "DOJI") >= 0) score += 14;
  1474. else if(pat == "WICK" || StringFind(pat, "WICK") >= 0) score += 12;
  1475.  
  1476. if(f == 0) score += 10; // 88.6% (Deep trap, high bonus!)
  1477. else if(f == 1) score += 5; // 50.0%
  1478. else if(f == 2) score += 12; // 61.8% (Golden Ratio)
  1479. else if(f == 3) score += 6; // 78.6%
  1480.  
  1481. if(useGannBox) score += 10; // 8 -> 10
  1482.  
  1483. if(dir == "CALL" && emaBull) score += 10;
  1484. if(dir == "PUT" && emaBear) score += 10;
  1485.  
  1486. if(!isTrap) {
  1487. if(dir == "CALL" && rsi0 < 28) score += 14;
  1488. else if(dir == "CALL" && rsi0 < 35) score += 8;
  1489. if(dir == "PUT" && rsi0 > 72) score += 14;
  1490. else if(dir == "PUT" && rsi0 > 65) score += 8;
  1491. }
  1492.  
  1493. if(adx > 22 && diGap > 10) score += 5;
  1494.  
  1495. score -= trapPenalty;
  1496. score = MathMax(0, MathMin(100, score));
  1497.  
  1498. // ==========================================================
  1499. // SECTION 16: SAVE BEST
  1500. // ==========================================================
  1501. if(score > bestScore) {
  1502. bestScore = score;
  1503. bestPrice = fibPrice;
  1504. bestPat = pat;
  1505. bestLvl = fibNms[f];
  1506. bestDir = dir;
  1507. }
  1508. }
  1509. }
  1510. }
  1511.  
  1512. // ==========================================================
  1513. // SECTION 17: FINAL SIGNAL SET (Threshold 35)
  1514. // ==========================================================
  1515. if(bestScore >= 35 && bestPrice > 0) { // 38 -> 35
  1516. g_otcFibPrice = bestPrice;
  1517. g_otcFibDir = bestDir;
  1518. g_otcFibStrength = (int)bestScore;
  1519. g_otcFibPattern = bestPat;
  1520. g_otcFibLevel = bestLvl;
  1521. g_otcFibSignalTime = TimeCurrent();
  1522. g_otcHasSignal = true;
  1523.  
  1524. g_fibV2_BestScore = bestScore;
  1525. g_fibV2_BestProb = bestScore;
  1526. g_fibV2_BestDir = bestDir;
  1527. g_fibV2_Confidence = (int)bestScore;
  1528. g_fibV2_Pattern = bestPat;
  1529. g_fibV2_FibLevel = bestLvl;
  1530. g_fibV2_BestPrice = bestPrice;
  1531. g_fibV2_Reason = (useGannBox ? "GANB_v4.3_" : "FRC_v4.3_") + bestPat;
  1532.  
  1533. g_fibBestScore = bestScore;
  1534. g_fibBestProb = bestScore;
  1535. g_fibBestDir = bestDir;
  1536. g_fibConfidence = (int)bestScore;
  1537. g_fibBestPrice = bestPrice;
  1538. g_fibPattern = bestPat;
  1539. g_fibFibLevel = bestLvl;
  1540.  
  1541. DrawOTCFibLine();
  1542.  
  1543. Print("OTC FIB v4.3 ✅ ", bestDir, " | ", bestLvl,
  1544. " | Score:", (int)bestScore, "% | Pat:", bestPat,
  1545. " | Mode:", (useGannBox ? "GANN_BOX" : "FRACTAL"),
  1546. " | Trap:", (StringFind(bestPat, "TRAP_") >= 0 ? "YES" : "NO"));
  1547. }
  1548. }
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555. void DrawFibRejectionLine()
  1556. {
  1557. DrawOTCFibLine();
  1558. }
  1559.  
  1560. //+------------------------------------------------------------------+
  1561. //| DRAW OTC FIB LINE (v3.5 - 200px RIGHT - PERFECT SPACING) |
  1562. //+------------------------------------------------------------------+
  1563. void DrawOTCFibLine()
  1564. {
  1565. if(!g_otcHasSignal || g_otcFibPrice <= 0) {
  1566. DeleteOTCFibLine();
  1567. return;
  1568. }
  1569.  
  1570. string lineName = PFX + "OTC_FIB_LINE";
  1571. string lblName = PFX + "OTC_FIB_LBL";
  1572.  
  1573. // --- LINE COLOR ---
  1574. color lineColor;
  1575. if(g_otcFibDir == "CALL")
  1576. lineColor = (g_otcFibStrength >= 70) ? C'0,255,100' : C'0,200,150';
  1577. else
  1578. lineColor = (g_otcFibStrength >= 70) ? C'255,50,50' : C'255,100,100';
  1579.  
  1580. // --- DRAW DOTTED LINE ---
  1581. SafeDel(lineName);
  1582. ObjectCreate(0, lineName, OBJ_HLINE, 0, 0, g_otcFibPrice);
  1583. ObjectSetInteger(0, lineName, OBJPROP_COLOR, lineColor);
  1584. ObjectSetInteger(0, lineName, OBJPROP_WIDTH, 1);
  1585. ObjectSetInteger(0, lineName, OBJPROP_STYLE, STYLE_DOT);
  1586. ObjectSetInteger(0, lineName, OBJPROP_BACK, false);
  1587.  
  1588. // --- LABEL (200px RIGHT - PERFECT BALANCE) ---
  1589. SafeDel(lblName);
  1590.  
  1591. int subWindow = 0;
  1592. int xCurr = 0, yCurr = 0;
  1593. datetime labelTime = 0;
  1594. double labelPrice = 0;
  1595. bool posOK = false;
  1596.  
  1597. // Current candle position se start karo
  1598. if(ChartTimePriceToXY(0, subWindow, Time[0], g_otcFibPrice, xCurr, yCurr)) {
  1599. int xLabel = xCurr + 200; // ✅ 200px RIGHT (Pehle 275 tha, ab 200 perfect rahega)
  1600. if(ChartXYToTimePrice(0, xLabel, yCurr, subWindow, labelTime, labelPrice)) {
  1601. posOK = true;
  1602. }
  1603. }
  1604.  
  1605. // Fallback (Agar pixels se time na mile toh 4 candle aage lagao)
  1606. if(!posOK && Bars > 3) {
  1607. int candleShift = 4;
  1608. labelTime = Time[0] + PeriodSeconds() * candleShift;
  1609. posOK = true;
  1610. }
  1611.  
  1612. if(posOK) {
  1613. string lblText = "FIB " + g_otcFibLevel + " | " + g_otcFibDir + " " +
  1614. IntegerToString(g_otcFibStrength) + "% [" + g_otcFibPattern + "]";
  1615. color lblColor = C'255,50,255';
  1616.  
  1617. ObjectCreate(0, lblName, OBJ_TEXT, 0, labelTime, g_otcFibPrice);
  1618. ObjectSetText(lblName, lblText, 12, "Arial Bold", lblColor);
  1619. ObjectSetInteger(0, lblName, OBJPROP_BACK, false);
  1620. }
  1621. }
  1622.  
  1623. //+------------------------------------------------------------------+
  1624. //| DELETE OTC FIB LINE |
  1625. //+------------------------------------------------------------------+
  1626. void DeleteOTCFibLine()
  1627. {
  1628. SafeDel(PFX + "OTC_FIB_LINE");
  1629. SafeDel(PFX + "OTC_FIB_LBL");
  1630. }
  1631.  
  1632. void CalcAdvancedPrediction(double &gP,double &rP,string &reason,color &pC){
  1633. if(Bars<50){gP=50;rP=50;reason="Bars low";pC=NEON_YELLOW;return;}
  1634. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1635. double green=0,red=0;
  1636. double body1=MathAbs(Close[1]-Open[1]),range1=High[1]-Low[1];
  1637. if(range1>0){double uw=High[1]-MathMax(Open[1],Close[1]),lw=MathMin(Open[1],Close[1])-Low[1];
  1638. if(uw>range1*0.60&&Close[1]>Open[1])red+=22;else if(lw>range1*0.60&&Close[1]<Open[1])green+=22;
  1639. else if((uw+lw)/range1>0.55){if(uw>lw)red+=12;else green+=12;}}
  1640. 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);
  1641. int os=0,ob=0;
  1642. 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++;
  1643. if(os>=3)green+=18;else if(os>=2)green+=12;else if(ob>=3)red+=18;else if(ob>=2)red+=12;
  1644. double rsiPrev=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  1645. double low1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],low2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  1646. double high1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],high2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  1647. if(low1<low2&&rsi>rsiPrev&&rsi<45)green+=15;if(high1>high2&&rsi<rsiPrev&&rsi>55)red+=15;
  1648. 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;
  1649. double vol_ratio=(vAvg>0)?v1/vAvg:1.0;
  1650. 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;}
  1651. 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;
  1652. double m1_haO2=(Open[3]+Close[3])/2.0,m1_haO1=(m1_haO2+m1_haC2)/2.0;
  1653. bool haBull1=(m1_haC1>m1_haO1);
  1654. double haStr1=MathAbs(m1_haC1-m1_haO1)/(High[1]-Low[1]+0.00001);
  1655. bool haBull5=false;double haStr5=0;
  1656. if(iBars(NULL,PERIOD_M5)>=5){
  1657. 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);
  1658. 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);
  1659. double o3=iOpen(NULL,PERIOD_M5,3),c3=iClose(NULL,PERIOD_M5,3);
  1660. 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;
  1661. haBull5=(haC1_5>haO1_5);haStr5=MathAbs(haC1_5-haO1_5)/(h1-l1+0.00001);}
  1662. if(haBull1&&haBull5)green+=15;else if(!haBull1&&!haBull5)red+=15;
  1663. else if(haBull1&&haStr1>0.5)green+=8;else if(!haBull1&&haStr1>0.5)red+=8;
  1664. 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);
  1665. double diDiff=plusDI-minusDI;
  1666. 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;}
  1667. else if(adx>15){if(plusDI>minusDI)green+=4;else red+=4;}
  1668. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,20,2)],res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,20,2)];
  1669. double dR=(res-Close[0])/pip,dS=(Close[0]-sup)/pip;
  1670. if(dR<8&&dR>=0)red+=12;else if(dR<15&&dR>=0)red+=6;
  1671. if(dS<8&&dS>=0)green+=12;else if(dS<15&&dS>=0)green+=6;
  1672. 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;}}
  1673. 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);
  1674. 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);
  1675. if(macdMain>macdSig&&macdPrev<=macdSigPrev)green+=10;else if(macdMain<macdSig&&macdPrev>=macdSigPrev)red+=10;
  1676. else if(macdMain>macdSig)green+=5;else if(macdMain<macdSig)red+=5;
  1677. if(ENABLE_BB_PULLBACK&&g_bbSignal=="CALL")green+=12; else if(ENABLE_BB_PULLBACK&&g_bbSignal=="PUT")red+=12;
  1678. double diff=MathMax(-100.0,MathMin(100.0,green-red));
  1679. gP=MathMax(8.0,MathMin(92.0,50.0+diff*0.65));rP=100.0-gP;
  1680. double dom=MathMax(gP,rP);
  1681. if(dom>=82){reason=(gP>rP)?"STRONG GREEN":"STRONG RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  1682. else if(dom>=72){reason=(gP>rP)?"GREEN":"RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  1683. else if(dom>=60){reason=(gP>rP)?"WEAK GREEN":"WEAK RED";pC=(gP>rP)?NEON_CYAN:NEON_ORANGE;}
  1684. else{reason="WAIT";pC=NEON_YELLOW;}
  1685. }
  1686.  
  1687. string DetectMyStrategy(){
  1688. int cc=g_otcCallPct,cp=g_otcPutPct,thr=STRATEGY_THRESHOLD;
  1689. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TRAP_ONLY"){
  1690. if(cc>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TRAP";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA RED";return "PUT";}
  1691. if(cp>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TRAP";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA GREEN";return "CALL";}}
  1692. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TREND_ONLY"){
  1693. if(cc>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TREND";g_strategyReason="CALL "+IntegerToString(cc)+"% + HA GREEN";return "CALL";}
  1694. if(cp>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TREND";g_strategyReason="PUT "+IntegerToString(cp)+"% + HA RED";return "PUT";}}
  1695. g_strategyType="NONE";g_strategyReason="Wait "+IntegerToString(thr)+"% + HA";return "WAIT";
  1696. }
  1697.  
  1698. void CalcOTCCrowd(){
  1699. int cS=0,pS=0;int weights[15];
  1700. for(int w=0;w<15;w++)weights[w]=15-w*2;
  1701. for(int w=0;w<15;w++)if(weights[w]<1)weights[w]=1;
  1702. for(int i=1;i<=15&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  1703. double uw=(High[i]-MathMax(Open[i],Close[i]))/rg,lw=(MathMin(Open[i],Close[i])-Low[i])/rg;int wgt=weights[i-1];
  1704. if(uw>0.70&&Close[i]<Open[i])cS+=4*wgt;if(lw>0.70&&Close[i]>Open[i])pS+=4*wgt;
  1705. if(uw>0.55&&Close[i]<Open[i])cS+=2*wgt;if(lw>0.55&&Close[i]>Open[i])pS+=2*wgt;
  1706. if(Close[i]>Open[i])cS+=1*wgt;else if(Close[i]<Open[i])pS+=1*wgt;}
  1707. int tot=cS+pS;if(tot==0){g_otcCallPct=50;g_otcPutPct=50;}
  1708. else{int rC=(int)(cS*100.0/tot),rP=100-rC;
  1709. if(rC>=rP){g_otcCallPct=MathMax(50,rC);g_otcPutPct=100-g_otcCallPct;}
  1710. else{g_otcPutPct=MathMax(50,rP);g_otcCallPct=100-g_otcPutPct;}}
  1711. }
  1712.  
  1713. // ============================================================
  1714. // BRAIN AI
  1715. // ============================================================
  1716. double BrainSc(int &cp){
  1717. double s=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  1718. if(g_nearest_res>0){double dR=(g_nearest_res-Close[0])/pip; if(dR<5) s-=3; else if(dR<15) s-=1;}
  1719. if(g_nearest_sup>0){double dS=(Close[0]-g_nearest_sup)/pip; if(dS<5) s+=3; else if(dS<15) s+=1;}
  1720. 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;}
  1721. 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;}
  1722. double atr=iATR(NULL,PERIOD_M1,14,1);
  1723. 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;}}
  1724. int c=0; for(int i=1;i<=30;i++) if(Close[i]>Open[i]) c++; cp=(int)(c*100.0/30.0);
  1725. if(cp>=80) s-=4; else if(cp>=75) s-=2; else if(cp<=20) s+=4; else if(cp<=25) s+=2;
  1726. int dj=0; double wickBull=0,wickBear=0;
  1727. 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;}
  1728. if(wickBull>wickBear+1.0) s+=3; else if(wickBear>wickBull+1.0) s-=3;
  1729. if(dj>=4) s*=0.8;
  1730. 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;}
  1731. 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;
  1732. if(ema10>ema20&&ema10-ema20>3*pip&&s<-2) s*=0.7; if(ema10<ema20&&ema20-ema10>3*pip&&s>2) s*=0.7;
  1733. 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;
  1734. }
  1735.  
  1736. // ============================================================
  1737. // STABLE M5 SUPPORT & RESISTANCE (FIXED FLICKERING)
  1738. // ============================================================
  1739. void UpdateStableM5SR(){
  1740. // Sirf tab update karo jab naya 5-minute candle ban jaaye
  1741. if(iTime(NULL, PERIOD_M5, 0) == g_last_m5_bar) return;
  1742. g_last_m5_bar = iTime(NULL, PERIOD_M5, 0);
  1743.  
  1744. if(iBars(NULL, PERIOD_M5) < 20) return;
  1745.  
  1746. double cur = Close[0];
  1747.  
  1748. // Last 10 completed M5 candles me se sabse bada High (Resistance) aur sabse chhota Low (Support) dhundho
  1749. int highestIdx = iHighest(NULL, PERIOD_M5, MODE_HIGH, 10, 1);
  1750. int lowestIdx = iLowest(NULL, PERIOD_M5, MODE_LOW, 10, 1);
  1751.  
  1752. double potential_res = iHigh(NULL, PERIOD_M5, highestIdx);
  1753. double potential_sup = iLow(NULL, PERIOD_M5, lowestIdx);
  1754.  
  1755. // Sirf wahi line set karo jo current price ke upper ya neeche ho
  1756. g_nearest_res = (potential_res > cur) ? potential_res : 0;
  1757. g_nearest_sup = (potential_sup < cur) ? potential_sup : 0;
  1758.  
  1759. // Drawing call karo
  1760. DrawStableM5Lines();
  1761. CheckBRK(); // Breakout check normal rahega
  1762. }
  1763.  
  1764. void DrawStableM5Lines(){
  1765. return; // ✅ S/R LINES BAND - Order Blocks replace karenge
  1766. // Purani lines delete karo
  1767. SafeDel(PFX+"NEAREST_RES"); SafeDel(PFX+"NEAREST_SUP");
  1768. SafeDel(PFX+"NEAREST_RES_LBL"); SafeDel(PFX+"NEAREST_SUP_LBL");
  1769.  
  1770.  
  1771.  
  1772. // sirf tab draw karo agar lines exist karti hon aur chart par jagah ho (Bars > 5)
  1773. if(g_nearest_res > 0 && Bars > 5){
  1774. DrawHLine(PFX+"NEAREST_RES", g_nearest_res, C'50,80,255', 2, STYLE_DASH); // Strict Blue Color
  1775. ObjectCreate(0, PFX+"NEAREST_RES_LBL", OBJ_TEXT, 0, Time[5], g_nearest_res);
  1776. ObjectSetText(PFX+"NEAREST_RES_LBL", "M5 RES " + ShortPrice(g_nearest_res), 9, "Arial Bold", C'50,80,255');
  1777. ObjectSetInteger(0, PFX+"NEAREST_RES_LBL", OBJPROP_BACK, false);
  1778. }
  1779. if(g_nearest_sup > 0 && Bars > 5){
  1780. DrawHLine(PFX+"NEAREST_SUP", g_nearest_sup, C'50,80,255', 2, STYLE_DASH); // Strict Blue Color
  1781. ObjectCreate(0, PFX+"NEAREST_SUP_LBL", OBJ_TEXT, 0, Time[5], g_nearest_sup);
  1782. ObjectSetText(PFX+"NEAREST_SUP_LBL", "M5 SUP " + ShortPrice(g_nearest_sup), 9, "Arial Bold", C'50,80,255');
  1783. ObjectSetInteger(0, PFX+"NEAREST_SUP_LBL", OBJPROP_BACK, false);
  1784. }
  1785. }
  1786.  
  1787.  
  1788. 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;}}
  1789.  
  1790. // ============================================================
  1791. // MICRO WICK & VOLUME TRAP
  1792. // ============================================================
  1793. 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;}
  1794.  
  1795. double VolumeTrapScore(){
  1796. if(!VOLUME_PROFILE_TRAP||Bars<50)return 0;
  1797. double cur=Close[0],hi=High[iHighest(NULL,0,MODE_HIGH,50,1)],lo=Low[iLowest(NULL,0,MODE_LOW,50,1)];
  1798. 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};
  1799. 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]++;}
  1800. for(int z=0;z<zn;z++)if(zc[z]>0)vz[z]/=zc[z];
  1801. int cz=(int)((cur-lo)/zs);if(cz<0)cz=0;if(cz>=zn)cz=zn-1;
  1802. double vr=(double)Volume[1]/(vz[cz]+0.001);double wr=MicroWick();
  1803. if(vr>2.0&&wr>0.65)return 25;if(vr>1.8&&wr>0.55)return 15;return 0;
  1804. }
  1805.  
  1806. double UltimateTrapScore(){double wr=MicroWick(),v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  1807. double avg=v2>0?v2:1.0,vr=v1/avg,rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1),sc=0.0;
  1808. if(wr>0.65)sc+=40;if(vr>2.0)sc+=30;if(rsi>75||rsi<25)sc+=20;
  1809. if((High[1]>g_nearest_res&&Close[1]<g_nearest_res)||(Low[1]<g_nearest_sup&&Close[1]>g_nearest_sup))sc+=25;
  1810. sc+=VolumeTrapScore();return MathMin(100.0,sc);}
  1811.  
  1812. bool IsBrokerForce(double dummy=0){
  1813. int sd=0;for(int i=1;i<=3;i++){if(Close[i]>Open[i])sd++;else sd--;}
  1814. double v1=(double)iVolume(NULL,PERIOD_M1,1),v2=(double)iVolume(NULL,PERIOD_M1,2);
  1815. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  1816. return(MathAbs(sd)==3&&v1>v2*2.0&&sp>BROKER_SPREAD_THRESHOLD);
  1817. }
  1818.  
  1819. // ============================================================
  1820. // NEURAL AI (FIXED fVol AND fTick DUPLICATES)
  1821. // ============================================================
  1822. double NeuralBiasFast(){double r=NeuralBias(0)*0.3+NeuralBias(1)*0.7;if(r>96)r=96;if(r<4)r=4;return r;}
  1823.  
  1824. double NeuralBias(int s){
  1825. double f[8];
  1826. 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);
  1827. for(int i=0;i<8;i++) f[i]/=100.0;
  1828. double h[4];
  1829. for(int i=0;i<4;i++){
  1830. double sum=0;for(int j=0;j<8;j++) sum+=f[j]*NW[j*4+i];
  1831. h[i]=MathMax(0,sum-0.06);
  1832. }
  1833. double out=0;for(int i=0;i<4;i++) out+=h[i]*NW[32+i];
  1834. double result=50.0+out*22.0;
  1835. return(result>96)?96:((result<4)?4:result);
  1836. }
  1837.  
  1838. double fDoji(int s){
  1839. if(s+8>=Bars)return 0;double score=0;int streak=0;
  1840. for(int i=s;i<s+8&&i<Bars;i++){
  1841. double body=MathAbs(Open[i]-Close[i]);double range=High[i]-Low[i];if(range<=0)continue;
  1842. double ratio=body/range;double w=(9.0-(i-s))/8.0;
  1843. if(ratio<0.15){score+=18*w;streak++;
  1844. double lw=MathMin(Open[i],Close[i])-Low[i];if(lw>range*0.55)score+=12*w;
  1845. double uw=High[i]-MathMax(Open[i],Close[i]);if(uw>range*0.55)score-=8*w;}
  1846. else if(ratio<0.25){score+=8*w;streak++;}}
  1847. if(streak>=3)score+=15;else if(streak>=2)score+=8;
  1848. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1849. if(g_nearest_res>0&&(g_nearest_res-cur)<8*pip)score+=12;
  1850. if(g_nearest_sup>0&&(cur-g_nearest_sup)<8*pip)score+=12;
  1851. if(g_hrn_price>0&&MathAbs(cur-g_hrn_price)<5*pip)score+=10;
  1852. return MathMin(100,score);
  1853. }
  1854.  
  1855. double fWick(int s){
  1856. double range=High[s]-Low[s];if(range==0)return 0;
  1857. double u=(High[s]-MathMax(Open[s],Close[s]))/range;double l=(MathMin(Open[s],Close[s])-Low[s])/range;
  1858. bool closedRed=(Close[s]<Open[s]);double score=0;
  1859. if(u>0.65&&!closedRed)score=95;else if(u>0.50&&!closedRed)score=70;
  1860. else if(l>0.65&&closedRed)score=90;else if(l>0.50&&closedRed)score=65;
  1861. else if(u>0.65||l>0.65)score=50;else if(u>0.50||l>0.50)score=30;
  1862. if(score>=50){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1863. if(g_nearest_res>0&&(g_nearest_res-cur)<10*pip)score+=15;
  1864. if(g_nearest_sup>0&&(cur-g_nearest_sup)<10*pip)score+=15;}
  1865. return MathMin(100,score);
  1866. }
  1867.  
  1868. // FIX: Removed duplicate avg==0 check
  1869. double fVol(){
  1870. if(Bars<15)return 0;
  1871. double cur=(double)iVolume(NULL,PERIOD_M1,0);double avg=0;
  1872. for(int i=1;i<=10;i++)avg+=iVolume(NULL,PERIOD_M1,i);
  1873. if(avg==0)return 0;
  1874. avg/=10.0; // Clean division
  1875. double ratio=cur/avg;double score=0;
  1876. if(ratio>3.0)score=95;else if(ratio>2.5)score=85;else if(ratio>2.0)score=75;
  1877. else if(ratio>1.5)score=50;else if(ratio>1.2)score=30;
  1878. if(ratio<0.7)score=MathMin(score,15);
  1879. return MathMin(100,score);
  1880. }
  1881.  
  1882. double fMom(int s){
  1883. if(s+5>=Bars)return 0;
  1884. double m1=(Close[s]-Close[s+1]);double m2=(Close[s+1]-Close[s+2]);double m3=(Close[s+2]-Close[s+3]);
  1885. bool shift=false;if(m1>0&&m2<0&&m3<0)shift=true;if(m1<0&&m2>0&&m3>0)shift=true;
  1886. double accel=MathAbs(m1)-MathAbs(m2);
  1887. 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]);
  1888. double score=0;
  1889. if(shift){score=88;if(accel>0)score+=12;}
  1890. if(body1<body2&&body2<body3&&body3>0){score=60;if(body1<body2*0.5)score=80;}
  1891. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1892. if(MathAbs(m2)>3*pip&&MathAbs(m1)<pip)score=75;
  1893. return MathMin(100,score);
  1894. }
  1895.  
  1896. double fSpread(){
  1897. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);double typical=3.0;double ratio=sp/typical;double score=0;
  1898. if(ratio>3.0)score=95;else if(ratio>2.5)score=85;else if(ratio>2.0)score=75;
  1899. else if(ratio>1.5)score=50;else if(ratio>1.2)score=30;
  1900. int h=TimeHour(TimeGMT());if((h>=0&&h<=3)||(h>=12&&h<=14))score+=10;
  1901. return MathMin(100,score);
  1902. }
  1903.  
  1904. double fMem(int s){
  1905. if(s+10>=Bars)return 0;
  1906. bool bullEng=(Close[s]>Open[s])&&(Close[s+1]<Open[s+1])&&(Close[s]>=Open[s+1])&&(Open[s]<=Close[s+1]);
  1907. bool bearEng=(Close[s]<Open[s])&&(Close[s+1]>Open[s+1])&&(Close[s]<=Open[s+1])&&(Open[s]>=Close[s+1]);
  1908. double range=High[s]-Low[s];if(range<=0)return 0;
  1909. 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];
  1910. bool pinUp=(body<range*0.3&&lowerW>range*0.5);bool pinDn=(body<range*0.3&&upperW>range*0.5);
  1911. double score=0;
  1912. if(bullEng)score=85;else if(bearEng)score=85;else if(pinUp)score=80;else if(pinDn)score=80;
  1913. if(score>=50){bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  1914. if(g_nearest_res>0&&(g_nearest_res-cur)<10*pip)score+=15;
  1915. if(g_nearest_sup>0&&(cur-g_nearest_sup)<10*pip)score+=15;}
  1916. return MathMin(100,score);
  1917. }
  1918.  
  1919. // FIX: Removed duplicate volP==0 check
  1920. double fTick(int s){
  1921. if(s+5>=Bars)return 0;
  1922. double volN=(double)iVolume(NULL,PERIOD_M1,s);double volP=(double)iVolume(NULL,PERIOD_M1,s+1);
  1923. if(volP==0)return 0; // Single clean check
  1924. double volRatio=volN/volP;double priceMove=MathAbs(Close[s]-Close[s+1]);
  1925. double pricePct=Close[s+1]>0?priceMove/Close[s+1]*100:0;double score=0;
  1926. 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;
  1927. return MathMin(100,score);
  1928. }
  1929.  
  1930. double fFrac(int s){
  1931. if(s+4>=Bars||s<2)return 0;
  1932. bool fHigh=(High[s]>High[s-1]&&High[s]>High[s-2]&&High[s]>High[s+1]&&High[s]>High[s+2]);
  1933. bool fLow=(Low[s]<Low[s-1]&&Low[s]<Low[s-2]&&Low[s]<Low[s+1]&&Low[s]<Low[s+2]);
  1934. if(!fHigh&&!fLow)return 0;double score=0;
  1935. 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;
  1936. if(dist<15)score+=20;else if(dist<30)score+=10;if(Close[s]<High[s])score+=15;}
  1937. 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;
  1938. if(dist<15)score+=20;else if(dist<30)score+=10;if(Close[s]>Low[s])score+=15;}
  1939. return MathMin(100,score);
  1940. }
  1941.  
  1942. 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;}
  1943.  
  1944. // ============================================================
  1945. // COMMON POINTS & WICK REJECTIONS
  1946. // ============================================================
  1947. void DetectCommonPoints(){
  1948. if(!SHOW_COMMON_POINTS){g_commonCount=0;return;}
  1949. if(Time[0]==g_lastCommonScan)return;g_lastCommonScan=Time[0];g_commonCount=0;
  1950. datetime nowBar=Time[0];int periodSec=PeriodSeconds(PERIOD_M1);
  1951. double m5h=iHigh(NULL,PERIOD_M5,iHighest(NULL,PERIOD_M5,MODE_HIGH,10,1));
  1952. double m5l=iLow(NULL,PERIOD_M5,iLowest(NULL,PERIOD_M5,MODE_LOW,10,1));
  1953. 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++;}
  1954. 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++;}
  1955. 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++;}
  1956. 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++;}
  1957. 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--;}
  1958. }
  1959.  
  1960. void DrawCommonPoints(){
  1961. return; // BLUE CALL/PUT ZONE LINES REMOVED
  1962. 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));}
  1963. if(!SHOW_COMMON_POINTS||g_commonCount==0)return;
  1964. for(int i=0;i<g_commonCount;i++){
  1965. if(TimeCurrent()>g_commonExpire[i])continue;if(IsLineNearby(g_commonPrice[i],8.0))continue;
  1966. string id=PFX+"COMMON_"+IntegerToString(i),idL=PFX+"COMMON_L_"+IntegerToString(i),idH=PFX+"COMMON_HL_"+IntegerToString(i);color zc=DARK_BLUE_NEON;
  1967. 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);
  1968. ObjectCreate(0,id,OBJ_TEXT,0,Time[0],g_commonPrice[i]);ObjectSetText(id,"*",16,"Arial",zc);ObjectSetInteger(0,id,OBJPROP_BACK,false);
  1969. string lbl=(g_commonType[i]=="CALL")?"^ CALL ZONE":"v PUT ZONE";
  1970. 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);
  1971. }
  1972. }
  1973.  
  1974.  
  1975.  
  1976.  
  1977. int CalcAdvancedMicroTrap(){
  1978. if(Bars<20) return 0;
  1979. int score=0;
  1980. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  1981. double r1=High[1]-Low[1];
  1982. if(r1>0){
  1983. double uw1=(High[1]-MathMax(Open[1],Close[1]))/r1;
  1984. double lw1=(MathMin(Open[1],Close[1])-Low[1])/r1;
  1985. if(uw1>0.65) score+=35; else if(uw1>0.50) score+=18;
  1986. if(lw1>0.65) score+=25; else if(lw1>0.50) score+=12;
  1987. }
  1988. double r0=High[0]-Low[0];
  1989. 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;}
  1990. 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;
  1991. 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;}
  1992. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  1993. if(rsi>82||rsi<18) score+=25; else if(rsi>75||rsi<25) score+=18; else if(rsi>70||rsi<30) score+=10;
  1994. if(g_nearest_res>0 && (High[1]>g_nearest_res && Close[1]<g_nearest_res)) score+=30;
  1995. if(g_nearest_sup>0 && (Low[1]<g_nearest_sup && Close[1]>g_nearest_sup)) score+=30;
  1996. bool aG=(Close[1]>Open[1] && Close[2]>Open[2] && Close[3]>Open[3]);
  1997. bool aR=(Close[1]<Open[1] && Close[2]<Open[2] && Close[3]<Open[3]);
  1998. if(aG||aR) score+=18;
  1999. if(Bars>=5){bool aG4=(aG && Close[4]>Open[4]); bool aR4=(aR && Close[4]<Open[4]); if(aG4||aR4) score+=10;}
  2000. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  2001. if(sp>BROKER_SPREAD_THRESHOLD*2.0) score+=15; else if(sp>BROKER_SPREAD_THRESHOLD*1.5) score+=8;
  2002. 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;}
  2003. return MathMin(100,score);
  2004. }
  2005.  
  2006. double CalcAdvancedTFA(string &detail){
  2007. if(Bars<30){detail="Bars low";return 3.0;}
  2008. double score=0;string p="";
  2009. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);
  2010. double adxSc=(adx>=25)?1.0:(adx>=20)?0.6:(adx>=15)?0.3:0.1;
  2011. score+=adxSc;p+="ADX:"+((adxSc>=0.6)?"+":"-")+" ";
  2012. double v1=iVolume(NULL,PERIOD_M1,1),vA=0;
  2013. for(int i=2;i<=6;i++)vA+=iVolume(NULL,PERIOD_M1,i);
  2014. vA=(vA>0)?vA/5.0:1;double vr=v1/vA;
  2015. double volSc=(vr>=2.0)?1.0:(vr>=1.5)?0.7:(vr>=1.1)?0.4:0.1;
  2016. score+=volSc;p+="VOL:"+((volSc>=0.5)?"+":"-")+" ";
  2017. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  2018. double rsiSc=0.2;if(rsi>=60||rsi<=40)rsiSc=1.0;else if(rsi>=55||rsi<=45)rsiSc=0.6;
  2019. score+=rsiSc;p+="RSI:"+((rsiSc>=0.6)?"+":"-")+" ";
  2020. double atr=iATR(NULL,PERIOD_M1,14,1),cs=High[1]-Low[1],atrSc=0.2;
  2021. 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;}
  2022. score+=atrSc;p+="ATR:"+((atrSc>=0.6)?"+":"-")+" ";
  2023. double body=MathAbs(Close[1]-Open[1]),range=High[1]-Low[1],bdySc=0.2;
  2024. 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;}
  2025. score+=bdySc;p+="BODY:"+((bdySc>=0.6)?"+":"-")+" ";
  2026. double sesSc=IsSessionActive()?1.0:0.4;
  2027. score+=sesSc;p+="SES:"+((sesSc>=0.7)?"+":"-");
  2028. double finalScore=MathMin(6.0,score);int rounded=(int)MathRound(finalScore);
  2029. string dir="MIX";
  2030. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")dir="STRONG UP";
  2031. else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")dir="STRONG DOWN";
  2032. else if(g_haM1=="HA BULLISH 1")dir="UP";
  2033. else if(g_haM1=="HA BEARISH 1")dir="DOWN";
  2034. detail=p+" | "+IntegerToString(rounded)+"/6 "+dir;
  2035. g_tfa_detail=detail;return finalScore;
  2036. }
  2037.  
  2038. string CalcAdvancedMarketBias(color &bC,double brain,double rsc){
  2039. if(Bars<30){bC=NEON_YELLOW;return "CALCULATING";}
  2040. double score=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  2041. double pc=Close[0]-Close[10];
  2042. 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;
  2043. double hh1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)],hh2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  2044. double ll1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)],ll2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  2045. 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;
  2046. double ema20=0,ema20p=0;for(int i=0;i<20;i++)ema20+=Close[i];ema20/=20;
  2047. for(int i=1;i<=20&&i<Bars;i++)ema20p+=Close[i];ema20p/=20;
  2048. if(ema20>ema20p)score+=3;else if(ema20<ema20p)score-=3;
  2049. double ema50=0;for(int i=0;i<50&&i<Bars;i++)ema50+=Close[i];ema50/=MathMin(50,Bars);
  2050. if(ema20>ema50)score+=3;else score-=3;
  2051. 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++;}
  2052. if(gC>=7)score+=3;else if(rC>=7)score-=3;else if(gC>=5)score+=1;else if(rC>=5)score-=1;
  2053. 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");
  2054. if(m1B&&m5B)score+=4;else if(m1Be&&m5Be)score-=4;else if(m1B)score+=2;else if(m1Be)score-=2;
  2055. 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);
  2056. if(adx>20){if(pDI>mDI+5)score+=4;else if(mDI>pDI+5)score-=4;}
  2057. if(brain>3)score-=2;else if(brain<-3)score+=2;
  2058. if(Close[1]>Open[1])score+=1;else if(Close[1]<Open[1])score-=1;
  2059. if(rsc>2)score+=1;else if(rsc<-2)score-=1;
  2060. 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";}
  2061. 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";}
  2062. bC=NEON_YELLOW;return "NEUTRAL";
  2063. }
  2064.  
  2065.  
  2066.  
  2067. // ============================================================
  2068. // OTC BROKER KILLER v4.0 - FIXED GANN STATIC TRAP ENGINE
  2069. // ============================================================
  2070. void CalcVisualTrapPro(){
  2071. // --- INITIAL RESETS ---
  2072. g_visualTrapPro.boxStatus = "NO BOX";
  2073. g_visualTrapPro.gannStatus = "--";
  2074. g_visualTrapPro.gannColor = CGR;
  2075. g_visualTrapPro.m30Dir = "M30:NOT NEEDED";
  2076. g_visualTrapPro.m1Seq = "M1:--";
  2077. g_visualTrapPro.verdict = "SCANNING";
  2078. g_visualTrapPro.verdictColor = CGR;
  2079. g_visualTrapPro.callBias = 50;
  2080. g_visualTrapPro.putBias = 50;
  2081. g_visualTrapPro.trapScore = 0;
  2082. g_visualTrapPro.buySignal = false;
  2083. g_visualTrapPro.sellSignal = false;
  2084.  
  2085. SafeDel(PFX+"VBOX");
  2086. SafeDel(PFX+"VMID");
  2087. SafeDel(PFX+"VSIG");
  2088.  
  2089. int m1B = 0, m1R = 0;
  2090. for(int i = 1; i <= 8 && i < Bars; i++){
  2091. if(Close[i] > Open[i]) m1B++;
  2092. else if(Close[i] < Open[i]) m1R++;
  2093. }
  2094. int total = m1B + m1R;
  2095. if(total > 0){
  2096. g_visualTrapPro.callBias = NormalizeDouble((double)m1B / total * 100.0, 1);
  2097. g_visualTrapPro.putBias = NormalizeDouble((double)m1R / total * 100.0, 1);
  2098. }
  2099.  
  2100. string seq = "";
  2101. for(int i = 1; i <= 8 && i < Bars; i++){
  2102. if(Close[i] > Open[i]) seq += "G";
  2103. else if(Close[i] < Open[i]) seq += "R";
  2104. else seq += "D";
  2105. }
  2106. g_visualTrapPro.m1Seq = "M1:" + seq;
  2107.  
  2108. double pip = GetUniversalPip();
  2109. if(pip <= 0) pip = Point;
  2110. if(pip <= 0) pip = 0.0001;
  2111.  
  2112. static double s_boxHigh = 0;
  2113. static double s_boxLow = 0;
  2114. static datetime s_boxTime = 0;
  2115.  
  2116. int hI = iHighest(Symbol(), PERIOD_M1, MODE_HIGH, 25, 1);
  2117. int lI = iLowest(Symbol(), PERIOD_M1, MODE_LOW, 25, 1);
  2118.  
  2119. if(hI >= 0 && lI >= 0 && Bars > 25) {
  2120. double currentHigh = High[hI];
  2121. double currentLow = Low[lI];
  2122.  
  2123. bool newExtreme = (s_boxHigh == 0) ||
  2124. (currentHigh > s_boxHigh) ||
  2125. (currentLow < s_boxLow) ||
  2126. (Time[0] - s_boxTime > 900);
  2127.  
  2128. if(newExtreme) {
  2129. s_boxHigh = currentHigh;
  2130. s_boxLow = currentLow;
  2131. s_boxTime = Time[0];
  2132. }
  2133.  
  2134. // ✅ NEW: Gann Box boundaries ko global mein save karo Fib ke liye
  2135. g_gannBoxHigh = s_boxHigh;
  2136. g_gannBoxLow = s_boxLow;
  2137.  
  2138. double bH = s_boxHigh;
  2139. double bL = s_boxLow;
  2140. double bHt = bH - bL;
  2141. double bP = bHt / pip;
  2142.  
  2143. g_visualTrapPro.boxStatus = "GANN:" + DoubleToString(bP,1) + "p";
  2144.  
  2145. double mid = bL + (bHt / 2.0);
  2146. double dist = MathAbs(Close[0] - mid) / pip;
  2147. double pricePos = ((Close[0] - bL) / bHt) * 100.0;
  2148. double body = MathAbs(Close[0] - Open[0]) / pip;
  2149.  
  2150. g_visualTrapPro.trapScore = 0;
  2151.  
  2152. if(dist < 1.5) g_visualTrapPro.trapScore += 30;
  2153. else if(dist < 3.0) g_visualTrapPro.trapScore += 15;
  2154. else g_visualTrapPro.trapScore += 5;
  2155.  
  2156. if(pricePos > 40 && pricePos < 60) g_visualTrapPro.trapScore += 20;
  2157.  
  2158. if(bP < 10) g_visualTrapPro.trapScore += 20;
  2159. else if(bP < 18) g_visualTrapPro.trapScore += 10;
  2160.  
  2161. if(body < 1.0) g_visualTrapPro.trapScore += 15;
  2162. else if(body < 2.0) g_visualTrapPro.trapScore += 10;
  2163.  
  2164. double upperWick = (High[0] - MathMax(Open[0], Close[0])) / pip;
  2165. double lowerWick = (MathMin(Open[0], Close[0]) - Low[0]) / pip;
  2166. if(upperWick > 1.0 && lowerWick > 1.0) g_visualTrapPro.trapScore += 15;
  2167.  
  2168. if(g_visualTrapPro.trapScore > 100) g_visualTrapPro.trapScore = 100;
  2169.  
  2170. if(g_visualTrapPro.trapScore >= 70) {
  2171. g_visualTrapPro.gannStatus = "[TRAP " + DoubleToString(g_visualTrapPro.trapScore,0) + "%]";
  2172. g_visualTrapPro.gannColor = NEON_YELLOW;
  2173. }
  2174. else if(g_visualTrapPro.trapScore >= 45) {
  2175. g_visualTrapPro.gannStatus = "[WEAK " + DoubleToString(g_visualTrapPro.trapScore,0) + "%]";
  2176. g_visualTrapPro.gannColor = NEON_ORANGE;
  2177. }
  2178. else {
  2179. g_visualTrapPro.gannStatus = "[GANN " + DoubleToString(g_visualTrapPro.trapScore,0) + "%]";
  2180. g_visualTrapPro.gannColor = NEON_CYAN;
  2181. }
  2182.  
  2183. datetime tStart = Time[25];
  2184. datetime tEnd = Time[0] + 60;
  2185.  
  2186. ObjectCreate(0, PFX+"VBOX", OBJ_RECTANGLE, 0, tStart, bH, tEnd, bL);
  2187. ObjectSetInteger(0, PFX+"VBOX", OBJPROP_COLOR, clrWhite);
  2188. ObjectSetInteger(0, PFX+"VBOX", OBJPROP_WIDTH, 2);
  2189. ObjectSetInteger(0, PFX+"VBOX", OBJPROP_BACK, false);
  2190.  
  2191. ObjectCreate(0, PFX+"VMID", OBJ_HLINE, 0, 0, mid);
  2192. ObjectSetInteger(0, PFX+"VMID", OBJPROP_COLOR, clrYellow);
  2193. ObjectSetInteger(0, PFX+"VMID", OBJPROP_WIDTH, 1);
  2194. ObjectSetInteger(0, PFX+"VMID", OBJPROP_BACK, false);
  2195.  
  2196. } else {
  2197. g_visualTrapPro.boxStatus = "GANN:NO DATA";
  2198. g_gannBoxHigh = 0; // ✅ No box, reset globals
  2199. g_gannBoxLow = 0;
  2200. }
  2201.  
  2202. if(g_visualTrapPro.trapScore >= 70) {
  2203. if(g_visualTrapPro.callBias >= 60) {
  2204. g_visualTrapPro.verdict = "PUT " + DoubleToString(g_visualTrapPro.putBias,0) + "%";
  2205. g_visualTrapPro.verdictColor = NEON_RED;
  2206. g_visualTrapPro.sellSignal = true;
  2207. g_visualTrapPro.buySignal = false;
  2208. }
  2209. else if(g_visualTrapPro.putBias >= 60) {
  2210. g_visualTrapPro.verdict = "CALL " + DoubleToString(g_visualTrapPro.callBias,0) + "%";
  2211. g_visualTrapPro.verdictColor = NEON_GREEN;
  2212. g_visualTrapPro.buySignal = true;
  2213. g_visualTrapPro.sellSignal = false;
  2214. }
  2215. else {
  2216. g_visualTrapPro.verdict = "TRAP " + DoubleToString(g_visualTrapPro.trapScore,0) + "%";
  2217. g_visualTrapPro.verdictColor = NEON_YELLOW;
  2218. }
  2219. }
  2220. else if(g_visualTrapPro.callBias >= 65) {
  2221. g_visualTrapPro.verdict = "CALL " + DoubleToString(g_visualTrapPro.callBias,0) + "%";
  2222. g_visualTrapPro.verdictColor = NEON_GREEN;
  2223. g_visualTrapPro.buySignal = true;
  2224. }
  2225. else if(g_visualTrapPro.putBias >= 65) {
  2226. g_visualTrapPro.verdict = "PUT " + DoubleToString(g_visualTrapPro.putBias,0) + "%";
  2227. g_visualTrapPro.verdictColor = NEON_RED;
  2228. g_visualTrapPro.sellSignal = true;
  2229. }
  2230. else {
  2231. g_visualTrapPro.verdict = "WAIT " + DoubleToString(g_visualTrapPro.callBias,0) + "/" + DoubleToString(g_visualTrapPro.putBias,0);
  2232. g_visualTrapPro.verdictColor = CGR;
  2233. }
  2234.  
  2235. if((g_visualTrapPro.buySignal || g_visualTrapPro.sellSignal) && g_lastTrapArrowTime != Time[0]){
  2236. g_lastTrapArrowTime = Time[0];
  2237. double arrowY = g_visualTrapPro.buySignal ? Low[0] - pip*5 : High[0] + pip*5;
  2238. ObjectCreate(0, PFX+"VSIG", OBJ_ARROW, 0, Time[0], arrowY);
  2239. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_ARROWCODE, g_visualTrapPro.buySignal ? 233 : 234);
  2240. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_COLOR, g_visualTrapPro.buySignal ? NEON_GREEN : NEON_RED);
  2241. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_WIDTH, 3);
  2242. ObjectSetInteger(0, PFX+"VSIG", OBJPROP_BACK, false);
  2243. }
  2244. }
  2245.  
  2246. // ============================================================
  2247. // HIDDEN LEVELS & HELPERS
  2248. // ============================================================
  2249. void DetectHiddenLevels(){
  2250. g_htfLevelCount=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double curP=Close[0];
  2251. double rU=MathCeil(curP/(10*pip))*(10*pip),rD=MathFloor(curP/(10*pip))*(10*pip);
  2252. if(MathAbs(curP-rU)/pip<=15)AddLevel(rU,"ROUND","RESISTANCE",TimeCurrent(),8,true);
  2253. if(MathAbs(curP-rD)/pip<=15)AddLevel(rD,"ROUND","SUPPORT",TimeCurrent(),8,true);
  2254. DetectHTFLevels(PERIOD_M5,"M5",3,pip);DetectHTFLevels(PERIOD_M15,"M15",5,pip);
  2255. DetectHTFLevels(PERIOD_M30,"M30",7,pip);DetectHTFLevels(PERIOD_H1,"H1",9,pip);
  2256. SortLevelsByStrength();
  2257. }
  2258.  
  2259. void DetectHTFLevels(ENUM_TIMEFRAMES tf,string tfN,int bS,double pip){
  2260. int bars=MathMin(50,iBars(NULL,tf));if(bars<10)return;double curP=Close[0];
  2261. for(int i=2;i<bars-2;i++){
  2262. 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);}
  2263. 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);}
  2264. }
  2265. }
  2266.  
  2267. 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;}
  2268. 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;}
  2269.  
  2270. void AddLevel(double price,string tf,string type,datetime time,int strength,bool isRound){
  2271. if(g_htfLevelCount>=50)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  2272. for(int i=0;i<g_htfLevelCount;i++)if(MathAbs(g_htfLevels[i].price-price)/pip<5)return;
  2273. g_htfLevels[g_htfLevelCount].price=price;g_htfLevels[g_htfLevelCount].timeframe=tf;g_htfLevels[g_htfLevelCount].type=type;
  2274. g_htfLevels[g_htfLevelCount].time=time;g_htfLevels[g_htfLevelCount].strength=strength;g_htfLevels[g_htfLevelCount].isRoundNumber=isRound;g_htfLevelCount++;
  2275. }
  2276.  
  2277. 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;}}
  2278.  
  2279. void DrawHiddenLevels(){
  2280. for(int i=0;i<50;i++){SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i));SafeDel(PFX+"HTF_LEVEL_"+IntegerToString(i)+"_LBL");}
  2281. int dc=MathMin(10,g_htfLevelCount);int drawn=0;
  2282. for(int i=0;i<dc&&drawn<5;i++){
  2283. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  2284. if(MathAbs(Close[0]-g_htfLevels[i].price)/pip>30)continue;if(IsLineNearby(g_htfLevels[i].price,5.0))continue;
  2285. string nm=PFX+"HTF_LEVEL_"+IntegerToString(drawn);
  2286. color lc=g_htfLevels[i].isRoundNumber?NEON_PURPLE:(StringFind(g_htfLevels[i].type,"SUPPORT")>=0?NEON_GREEN:NEON_RED);
  2287. 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);
  2288. string ln=nm+"_LBL";ObjectCreate(0,ln,OBJ_TEXT,0,Time[0],g_htfLevels[i].price);
  2289. ObjectSetText(ln,g_htfLevels[i].timeframe+" "+g_htfLevels[i].type+" S:"+IntegerToString(g_htfLevels[i].strength),9,"Arial",lc);drawn++;
  2290. }
  2291. }
  2292.  
  2293. string DetectSuddenReversal(){
  2294. if(Bars<10)return "";bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  2295. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);double atr=iATR(NULL,PERIOD_M1,14,1);if(atr<=0)return "";
  2296. double rng1=High[1]-Low[1];double body1=MathAbs(Close[1]-Open[1]);
  2297. 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;
  2298. bool bull1=(Close[1]>Open[1]);bool bear1=(Close[1]<Open[1]);
  2299. int bullScore=0,bearScore=0;
  2300. if(lw1>0.60&&body1<rng1*0.30&&rsi<48){bullScore+=30;}
  2301. if(uw1>0.60&&body1<rng1*0.30&&rsi>52){bearScore+=30;}
  2302. if(bull1&&body1>MathAbs(Close[2]-Open[2])*1.1&&Close[2]<Open[2]&&body1>atr*0.35){bullScore+=25;}
  2303. if(bear1&&body1>MathAbs(Close[2]-Open[2])*1.1&&Close[2]>Open[2]&&body1>atr*0.35){bearScore+=25;}
  2304. if(rsi<30&&bullScore>0){bullScore+=15;}if(rsi>70&&bearScore>0){bearScore+=15;}
  2305. if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)/pip<8&&bullScore>0){bullScore+=15;}
  2306. if(g_nearest_res>0&&(g_nearest_res-Close[0])/pip<8&&bearScore>0){bearScore+=15;}
  2307. if(bullScore>=40&&bullScore>bearScore){return "BULL REVERSAL";}
  2308. else if(bearScore>=40&&bearScore>bullScore){return "BEAR REVERSAL";}
  2309. return "";
  2310. }
  2311.  
  2312. void SafeDel(string id){if(ObjectFind(0,id)>=0)ObjectDelete(0,id);}
  2313. 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);}
  2314. 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);}}
  2315. 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);}}
  2316. void DelDashboard(){for(int i=ObjectsTotal()-1;i>=0;i--){string nm=ObjectName(i);if(StringFind(nm,PFX)!=0)continue;if(StringFind(nm,"OBP3_")>=0)continue;if(StringFind(nm,"HRN_LINE")>=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;if(StringFind(nm,"FIB_REJ")>=0)continue;ObjectDelete(nm);}}
  2317.  
  2318.  
  2319.  
  2320. // ============================================================
  2321. // ML & ACCURACY
  2322. // ============================================================
  2323. 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;}
  2324. 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);}}
  2325. 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();}
  2326. 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++;bool wasFibTrap=(g_fibV2_Pattern=="FAKE"||g_fibV2_Pattern=="EXHAUST");UpdateBayesianPrior(win,wasFibTrap);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];}
  2327. 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;}
  2328. 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]));}}
  2329.  
  2330. 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";}
  2331. 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;}
  2332. 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;}
  2333. 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;}
  2334. 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;}
  2335. double GetADXStrength(){if(Bars<20)return 0;return iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);}
  2336. 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;}
  2337. 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;}
  2338. 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;}
  2339.  
  2340. // ============================================================
  2341. // HRN LEVEL (Kept for chart line only, cube removed)
  2342. // ============================================================
  2343. 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);}
  2344. 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++;}
  2345. 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;}
  2346.  
  2347. 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;}}
  2348.  
  2349. void UpdateHRN(){
  2350. if(Bars<LOOKBACK+10)return;
  2351. 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;
  2352. 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];}
  2353. double tol=1*pip;
  2354. 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;}}
  2355. 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;}}
  2356. 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;}}
  2357. g_hrn_str=DoubleToString(NormalizeDouble(g_hrn_price,dg),dg);
  2358. color hrnColor=g_hrn_is_sup?NEON_GREEN:NEON_RED;if(g_hrn_brk_bars==1)hrnColor=NEON_YELLOW;
  2359. DrawHLine(PFX+"HRN_LINE",g_hrn_price,hrnColor,3,STYLE_SOLID);
  2360. 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]":"");
  2361. SafeDel(PFX+"HRN_LBL");
  2362. 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);
  2363. }
  2364.  
  2365. // ============================================================
  2366. // CANDLE PATTERN RECOGNITION (FIXED BUG)
  2367. // ============================================================
  2368. NCPPatternResult NCPCheckSinglePattern(int shift){
  2369. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="SINGLE";
  2370. if(shift+1>=Bars || shift < 0) return r;
  2371. double o=Open[shift],c=Close[shift],h=High[shift],l=Low[shift];
  2372. double body=MathAbs(c-o); double range=h-l;if(range<=0 || o==0 || c==0) return r;
  2373. double upperWick=h-MathMax(o,c); double lowerWick=MathMin(o,c)-l;
  2374. double bodyRatio=body/range; double uwRatio=upperWick/range; double lwRatio=lowerWick/range;
  2375. bool isBull=(c>o); bool isBear=(c<o);
  2376. if(bodyRatio<0.10){
  2377. 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;}
  2378. 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;}}
  2379. 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;}
  2380. 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;}
  2381. 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;}
  2382. 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;}
  2383. 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;}
  2384. 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;}
  2385. if(bodyRatio<0.20&&uwRatio>0.30&&lwRatio>0.30){r.name="HIGH WAVE";r.type=0;r.strength=2;return r;}
  2386. return r;
  2387. }
  2388.  
  2389. NCPPatternResult NCPCheckDualPattern(int shift){
  2390. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="DUAL";
  2391. if(shift+2>=Bars || shift < 0) return r;
  2392. if(Open[shift]==0||Close[shift]==0||Open[shift+1]==0||Close[shift+1]==0) return r;
  2393. double o1=Open[shift],c1=Close[shift],h1=High[shift],l1=Low[shift];
  2394. double o2=Open[shift+1],c2=Close[shift+1],h2=High[shift+1],l2=Low[shift+1];
  2395. double body1=MathAbs(c1-o1); double body2=MathAbs(c2-o2); if(body1<=0||body2<=0) return r;
  2396. bool bull1=(c1>o1), bear1=(c1<o1); bool bull2=(c2>o2), bear2=(c2<o2);
  2397. 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;}
  2398. 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;}
  2399. double tol=(h1+l1)*0.001;
  2400. if(bull1&&bear2&&MathAbs(h1-h2)<tol&&h1>c1&&h2>c2){r.name="TWEEZER TOP";r.type=-1;r.strength=4;return r;}
  2401. if(bear1&&bull2&&MathAbs(l1-l2)<tol&&l1<c1&&l2<c2){r.name="TWEEZER BTM";r.type=1;r.strength=4;return r;}
  2402. if(bull1&&bear2&&o1<l2&&c1>(o2+c2)/2.0&&c1<o2){r.name="PIERCING";r.type=1;r.strength=3;return r;}
  2403. if(bear1&&bull2&&o1>h2&&c1<(o2+c2)/2.0&&c1>o2){r.name="DARK CLOUD";r.type=-1;r.strength=3;return r;}
  2404. 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;}
  2405. return r;
  2406. }
  2407.  
  2408. NCPPatternResult NCPCheckTriplePattern(int shift){
  2409. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="TRIPLE";
  2410. if(shift+3>=Bars || shift < 0) return r;
  2411. double o1=Open[shift],c1=Close[shift],h1=High[shift],l1=Low[shift];
  2412. double o2=Open[shift+1],c2=Close[shift+1],h2=High[shift+1],l2=Low[shift+1];
  2413. double o3=Open[shift+2],c3=Close[shift+2],h3=High[shift+2],l3=Low[shift+2];
  2414. double body1=MathAbs(c1-o1),body2=MathAbs(c2-o2),body3=MathAbs(c3-o3);double rng2=h2-l2;
  2415. bool bull1=(c1>o1),bear1=(c1<o1),bull3=(c3>o3),bear3=(c3<o3);
  2416. 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;}
  2417. 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;}
  2418. 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;}
  2419. 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;}
  2420. if(bull1&&bear3&&h1<h2&&l1>l2&&c1>c2&&c2>c3){r.name="3 IN UP";r.type=1;r.strength=3;return r;}
  2421. if(bear1&&bull3&&h1<h2&&l1<l2&&c1<c2&&c2<c3){r.name="3 IN DN";r.type=-1;r.strength=3;return r;}
  2422. if(bull1&&bear3&&h1>h2&&l1<l2&&c1>o2){r.name="3 OUT UP";r.type=1;r.strength=4;return r;}
  2423. if(bear1&&bull3&&h1>h2&&l1<l2&&c1<o2){r.name="3 OUT DN";r.type=-1;r.strength=4;return r;}
  2424. return r;
  2425. }
  2426.  
  2427. NCPPatternResult NCPCheckColorPattern(){
  2428. NCPPatternResult r; r.name=""; r.type=0; r.strength=0; r.category="MULTI";if(Bars<8)return r;
  2429. int bullRun=0,bearRun=0;
  2430. 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;}
  2431. 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";}}
  2432. 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";}}
  2433. 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;}
  2434. 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";}}
  2435. 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";}}
  2436. return r;
  2437. }
  2438.  
  2439. void NCPScanAllPatterns(){g_ncpPatternBullScore=0;g_ncpPatternBearScore=0;g_ncpMainPattern="";int bestStrength=0;
  2440. 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;}}}
  2441. 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;}}}
  2442. 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;}}
  2443. 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;}}}
  2444. g_ncpPatternBullScore=MathMin(100,g_ncpPatternBullScore);g_ncpPatternBearScore=MathMin(100,g_ncpPatternBearScore);
  2445. }
  2446.  
  2447. 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;}
  2448. 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;}
  2449.  
  2450. // ============================================================
  2451. // PSYCHE BREAKER v4.3 - FINAL POLISH EDITION
  2452. // ============================================================
  2453. void CalcOTCNextCandlePredictor(){
  2454. g_otpSignal = "WAIT"; g_otpConf = 50.0; g_otpColor = NEON_YELLOW;
  2455. g_otpRsi = "--"; g_otpWick = "--"; g_otpReason = "";
  2456. if(Bars < 15) return;
  2457.  
  2458. // 1. RSI CHECK
  2459. double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  2460. g_otpRsi = DoubleToString(rsi, 1);
  2461. int score = 0;
  2462. string reasons = "";
  2463.  
  2464. // 2. WICK REJECTION
  2465. double rng = High[1] - Low[1];
  2466. if(rng > 0){
  2467. double uw = (High[1] - MathMax(Open[1], Close[1])) / rng;
  2468. double lw = (MathMin(Open[1], Close[1]) - Low[1]) / rng;
  2469. if(uw > 0.65) { score -= 15; g_otpWick = "UP TRAP"; reasons += "WickUp "; }
  2470. if(lw > 0.65) { score += 15; g_otpWick = "DN TRAP"; reasons += "WickDn "; }
  2471. }
  2472.  
  2473. // 3. CANDLE PATTERNS
  2474. double body = MathAbs(Close[1] - Open[1]);
  2475. double pBody = MathAbs(Close[2] - Open[2]);
  2476. bool bull = (Close[1] > Open[1]), bear = (Close[1] < Open[1]);
  2477.  
  2478. if(bull && pBody < body && Close[1] >= Open[2] && Open[1] <= Close[2]) { score += 25; reasons += "BullEngulf "; }
  2479. if(bear && pBody < body && Close[1] <= Open[2] && Open[1] >= Close[2]) { score -= 25; reasons += "BearEngulf "; }
  2480. if(rng > 0 && (MathMin(Open[1],Close[1])-Low[1])/rng > 0.60 && body < rng*0.30 && bear) { score += 20; reasons += "Hammer "; }
  2481. if(rng > 0 && (High[1]-MathMax(Open[1],Close[1]))/rng > 0.60 && body < rng*0.30 && bull) { score -= 20; reasons += "ShootingSt "; }
  2482.  
  2483. // 4. RSI CONFIRM
  2484. if(rsi < 30) { score += 20; reasons += "RSI_OS "; }
  2485. else if(rsi < 40) { score += 10; reasons += "RSI_Low "; }
  2486. else if(rsi > 70) { score -= 20; reasons += "RSI_OB "; }
  2487. else if(rsi > 60) { score -= 10; reasons += "RSI_High "; }
  2488.  
  2489. // 5. MOMENTUM TRAP
  2490. if(Close[1]>Open[1] && Close[2]>Open[2] && Close[3]>Open[3]) { score -= 10; reasons += "3GreenTrap "; }
  2491. if(Close[1]<Open[1] && Close[2]<Open[2] && Close[3]<Open[3]) { score += 10; reasons += "3RedTrap "; }
  2492.  
  2493. // ✅ FIXED LOGIC (MathAbs use kiya)
  2494. double absScore = MathAbs(score);
  2495. g_otpConf = MathMax(5.0, MathMin(95.0, 50.0 + absScore));
  2496. g_otpReason = (reasons == "") ? "NO CONFIRMATION" : reasons;
  2497.  
  2498. if(g_otpConf >= 72){
  2499. g_otpSignal = (score > 0) ? "CALL" : "PUT";
  2500. g_otpColor = (score > 0) ? NEON_GREEN : NEON_RED;
  2501. } else if(g_otpConf >= 60){
  2502. g_otpSignal = (score > 0) ? "WEAK CALL" : "WEAK PUT";
  2503. g_otpColor = (score > 0) ? NEON_CYAN : NEON_ORANGE;
  2504. } else {
  2505. g_otpSignal = "WAIT";
  2506. g_otpColor = NEON_YELLOW;
  2507. }
  2508. }
  2509.  
  2510. // ============================================================
  2511. // NCP PRO v8.0 CORE ENGINE
  2512. // ============================================================
  2513. 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;}
  2514.  
  2515. 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();}
  2516.  
  2517. 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++;}}
  2518.  
  2519. // FIX: Removed Array Access Risk
  2520. void NCPDetectOrderBlocks(){
  2521. if(Bars<30)return;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;double cur=Close[0];
  2522. for(int i=2;i<=20&&i<Bars&&g_ncpSRCount<18;i++){
  2523. int startJ = MathMax(1, i-3); // FIX: Ensure startJ doesn't go below 1
  2524. if(Close[i]<Open[i]){
  2525. double move=0;for(int j=i-1;j>=startJ;j--){if(Close[j]>Open[j])move+=Close[j]-Open[j];else break;}
  2526. 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));}
  2527. }
  2528. if(Close[i]>Open[i]){
  2529. double move=0;for(int j=i-1;j>=startJ;j--){if(Close[j]<Open[j])move+=Open[j]-Close[j];else break;}
  2530. 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));}
  2531. }
  2532. }
  2533. }
  2534.  
  2535. 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));}
  2536.  
  2537. 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;}
  2538.  
  2539. // ============================================================
  2540. // LEARNING ENGINE v8.0
  2541. // ============================================================
  2542. 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;}
  2543. 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);}}
  2544. 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();}
  2545. 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);}
  2546.  
  2547. // ============================================================
  2548. // NCP PRO v8.0 MTG ENGINE
  2549. // ============================================================
  2550. void CalculateMTG(){
  2551. if(!ENABLE_MTG || Bars < 50){g_mtgState="OFF"; g_mtgReason=""; g_mtgClr=CGR; return;}
  2552. double pip=GetUniversalPip();
  2553. CheckPreviousResult();
  2554. int sec = (int)(TimeCurrent() - Time[0]);
  2555. if(sec < NCP_OpenNoiseSeconds){g_mtgState="..."; g_mtgReason="Bar open"; g_mtgClr=CGR; g_mtgHype=50; g_mtgBetrayal=50; return;}
  2556. if(sec >= NCP_KillZoneSeconds){g_mtgState="END"; g_mtgReason="Late"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  2557. double spPips = MarketInfo(Symbol(), MODE_SPREAD) * Point / pip;
  2558. if(spPips > NCP_MaxSpreadPips){g_mtgState="SPREAD"; g_mtgReason=DoubleToString(spPips,1)+"p"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  2559. double vol1 = (double)iVolume(NULL, PERIOD_M1, 1); double volAvg = 0;
  2560. for(int v = 2; v <= 21; v++) volAvg += (double)iVolume(NULL, PERIOD_M1, v); volAvg /= 20.0;
  2561. 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;}
  2562. double atr = iATR(Symbol(), PERIOD_M1, NCP_ATRPeriod, 1); double atrPips = atr / pip;
  2563. if(atrPips < NCP_MinATRPips){g_mtgState="FLAT"; g_mtgReason="Low ATR"; g_mtgClr=CGR; g_mtgHype=50; g_mtgBetrayal=50; return;}
  2564. g_ncpADX = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  2565. double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1);
  2566. double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1);
  2567. g_ncpPlusDI = plusDI; g_ncpMinusDI = minusDI;
  2568. if(g_ncpADX < 22){g_mtgState="WAIT"; g_mtgReason="ADX LOW"; g_mtgClr=NEON_ORANGE; g_mtgHype=50; g_mtgBetrayal=50; return;}
  2569. if(NCP8_UseM15Trend) g_ncpTrend = NCPDetectTrend();
  2570. if(NCP8_UseDynamicSR) NCPDetectDynamicSR();
  2571. if(NCP8_UsePatterns) NCPScanAllPatterns();
  2572. double macd_main = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);
  2573. double macd_sig = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1);
  2574. bool closedBull = (Close[1] > Open[1]); bool closedBear = (Close[1] < Open[1]);
  2575. double body1 = MathAbs(Close[1] - Open[1]); double rng1 = High[1] - Low[1];
  2576. double dynamicBodyThresh = atr * (0.35 + (g_ncpADX - 20) / 100.0);
  2577. int callConfluence = 0, putConfluence = 0;
  2578. double weightMultiplier = 1.0 + (g_ncpADX - 20) / 50.0;
  2579. if(NCP8_UseM15Trend){if(g_ncpTrend.m15Direction == "UP") callConfluence += (int)(3 * weightMultiplier); else if(g_ncpTrend.m15Direction == "DOWN") putConfluence += (int)(3 * weightMultiplier);}
  2580. 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);
  2581. 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);
  2582. if(g_haM1 == "HA BULLISH 1") callConfluence += 1; else if(g_haM1 == "HA BEARISH 1") putConfluence += 1;
  2583. if(g_haM5 == "HA BULLISH 5") callConfluence += 1; else if(g_haM5 == "HA BEARISH 5") putConfluence += 1;
  2584. if(plusDI > minusDI + 5) callConfluence += 2; else if(minusDI > plusDI + 5) putConfluence += 2;
  2585. double rsi1 = iRSI(NULL, 0, NCP_RSIPeriod, PRICE_CLOSE, 1), rsi2 = iRSI(NULL, 0, NCP_RSIPeriod, PRICE_CLOSE, 2);
  2586. if(rsi1 > 55 && rsi1 > rsi2) callConfluence++; else if(rsi1 < 45 && rsi1 < rsi2) putConfluence++;
  2587. double bodyPct = (rng1 > 0) ? (body1 / rng1) * 100.0 : 0;
  2588. if(closedBull && body1 > dynamicBodyThresh && bodyPct > 60) callConfluence += 3; else if(closedBear && body1 > dynamicBodyThresh && bodyPct > 60) putConfluence += 3;
  2589. bool nearSup = (g_nearest_sup > 0 && MathAbs(Close[1] - g_nearest_sup) < atrPips * 1.2);
  2590. bool nearRes = (g_nearest_res > 0 && MathAbs(Close[1] - g_nearest_res) < atrPips * 1.2);
  2591. if(nearSup) callConfluence += 2; if(nearRes) putConfluence += 2;
  2592. 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;
  2593. if(macd_main > macd_sig && macd_main > 0) callConfluence += 1; if(macd_main < macd_sig && macd_main < 0) putConfluence += 1;
  2594. double totalPossible = callConfluence + putConfluence;
  2595. double callStrength = totalPossible > 0 ? (double)callConfluence / totalPossible * 100 : 50;
  2596. double smoothFactor = MathMin(0.65, 0.45 + (atrPips / 20.0) * 0.1);
  2597. g_smoothCallScore = g_smoothCallScore * (1.0 - smoothFactor) + callStrength * smoothFactor;
  2598. g_smoothPutScore = 100.0 - g_smoothCallScore;
  2599. g_mtgHype = NormalizeDouble(g_smoothCallScore, 1); g_mtgBetrayal = NormalizeDouble(g_smoothPutScore, 1);
  2600. string lockReason = ""; int minConfluence = 8;
  2601. if(callConfluence < minConfluence && putConfluence < minConfluence) lockReason = "LOW CONF";
  2602. 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;}
  2603. int minP = 62; double edge = MathAbs(g_smoothCallScore - 50);
  2604. string str = "WEAK"; if(edge >= 28) str = "EXTREME"; else if(edge >= 22) str = "STRONG"; else if(edge >= 15) str = "MEDIUM";
  2605. if(Time[0] != g_ncpLastSignalTime){g_ncpLastSignalTime = Time[0]; g_ncpSignalProcessed = false;}
  2606. 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]; }}
  2607. 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]; }}
  2608. 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;}
  2609. g_mtgBullCount = callConfluence; g_mtgBearCount = putConfluence; g_mtgRecovery = NormalizeDouble(atrPips, 1); g_mtgPattern = str; g_trapScore = 0;
  2610. }
  2611.  
  2612. // ============================================================
  2613. // DASHBOARD DRAWING HELPERS
  2614. // ============================================================
  2615. void DrawOtherPairsCube(int x,int y,int w,int h){
  2616. Bx("c20",x,y,w,h,BG_DARK2,NEON_GOLD);Tx("c20_l",x+8,y+4,"OTHER PAIRS",NEON_CYAN,10,true);
  2617.  
  2618. int lY=24;
  2619.  
  2620. // --- 1. CURRENT PAIR SIGNAL (WHITE) ---
  2621. if(g_otpSignal != "WAIT" && g_otpSignal != "") {
  2622. string curPairName = Symbol();
  2623. if(StringLen(curPairName) > 9) curPairName = StringSubstr(curPairName, 0, 9);
  2624. string mySigText = "* " + curPairName + " " + g_otpSignal + " " + DoubleToString(g_otpConf, 0) + "%";
  2625. Tx("c20_my_sig", x+8, y+lY, mySigText, NEON_WHITE, 10, true);
  2626. lY += 20;
  2627. }
  2628.  
  2629. // --- 2. MHI BACKGROUND PAIRS (WHITE COLOR) ---
  2630. for(int i=0; i<g_bgMHI_Count; i++){
  2631. if(lY+16>h-4) break;
  2632. string sp = g_bgMHI_Pair[i];
  2633. if(StringLen(sp) > 9) sp = StringSubstr(sp, 0, 9);
  2634. string mhiText = sp + " " + g_bgMHI_Signal[i] + " " + DoubleToString(g_bgMHI_Conf[i], 0) + "%";
  2635. Tx("c20_mhi_bg"+IntegerToString(i), x+8, y+lY, mhiText, NEON_WHITE, 10, true);
  2636. lY += 20;
  2637. }
  2638.  
  2639. // --- 3. NORMAL NCP PAIRS (GREEN/RED/PURPLE) ---
  2640. if(g_pairCount==0){
  2641. if(lY+16>h-4) return;
  2642. if(StringFind(g_visualTrapPro.boxStatus, "[") >= 0){Tx("c20_v0",x+8,y+lY,g_visualTrapPro.boxStatus,NEON_WHITE,11,true);return;}
  2643. Tx("c20_v0",x+8,y+lY,"No signals yet",CGR,10,false);return;
  2644. }
  2645.  
  2646. for(int i=0;i<g_pairCount&&i<5;i++){
  2647. if(lY+16>h-4)break;
  2648. string sp=g_pairNames[i];if(StringLen(sp)>9)sp=StringSubstr(sp,0,9);
  2649. 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]";
  2650. bool isCallSig=(g_mtgState=="CALL");bool isPutSig=(g_mtgState=="PUT");bool ncpMatch=((isCallSig&&g_pairSigs[i]=="CALL")||(isPutSig&&g_pairSigs[i]=="PUT"));
  2651. color dc;string prefix="";if(ncpMatch){dc=NEON_PURPLE;prefix="* ";}else{dc=(g_pairSigs[i]=="CALL")?NEON_GREEN:NEON_RED;}
  2652. string txt=prefix+sp+" "+g_pairSigs[i]+" "+IntegerToString(qScore)+qLabel;
  2653. Tx("c20_p"+IntegerToString(i),x+8,y+lY,txt,dc,10,true);
  2654. lY+=20;
  2655. }
  2656. }
  2657.  
  2658.  
  2659.  
  2660. 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";}
  2661. 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;}
  2662. 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;}
  2663. 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;}
  2664. 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;}
  2665. 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());}
  2666.  
  2667. 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);}
  2668. 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);}
  2669. 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);}
  2670. 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);}
  2671. // ============================================================
  2672. // MAIN PREDICTION ENGINE
  2673. // ============================================================
  2674. void CalcPrediction(double brain,double nb,int cp,double mai,int mts,double rsc,bool bf,double mw){
  2675. string ms=DetectMyStrategy();bool sA=(ms!="WAIT");
  2676. if(sA&&g_strategyType=="TRAP"){
  2677. 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;}
  2678. 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;}
  2679. }
  2680. double tS=UltimateTrapScore();bool bF2=IsBrokerForce();
  2681. 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;}}
  2682. 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;}
  2683. double gS=0,rS=0,ab=MathMax(0.70,MathMin(1.30,g_accuracy/65.0));
  2684. g_isSideways = IsSidewaysMarket();if(g_isSideways){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;}
  2685. 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;}}
  2686. 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;
  2687. if(HA_ALIGN_FILTER&&g_haBoth=="MIXED"){gS*=0.5;rS*=0.5;}
  2688. gS+=(nb-50)/50.0*22*ab;rS-=(nb-50)/50.0*22*ab;
  2689. double bn=MathMax(-1.0,MathMin(1.0,brain/10.0));gS+=bn*15*ab;rS-=bn*15*ab;
  2690. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  2691. 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;
  2692. double rsi1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);if(rsi1>70)rS+=6;if(rsi1<30)gS+=6;
  2693. double sn=MathMax(-1.0,MathMin(1.0,rsc/3.0));gS+=sn*8*ab;rS-=sn*8*ab;
  2694. if(ENABLE_BB_PULLBACK){if(g_bbSignal=="CALL")gS+=18*ab;else if(g_bbSignal=="PUT")rS+=18*ab;}
  2695. int rd=DetectRSIDivergence();if(rd==1)gS+=20;if(rd==-1)rS+=20;
  2696. int sk=StreakReversalSignal();if(sk==1)gS+=18;if(sk==-1)rS+=18;
  2697. 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;}
  2698. int vs=SmartVolumeSignal();if(vs==1)gS+=12;if(vs==-1)rS+=12;
  2699. if(!IsVolatilityGood()){gS*=0.5;rS*=0.5;}
  2700. double diff=MathMax(-100.0,MathMin(100.0,gS-rS));
  2701. g_gProb=MathMax(8.0,MathMin(92.0,50.0+(diff/1.8)));g_rProb=100.0-g_gProb;
  2702. double dom=MathMax(g_gProb,g_rProb);
  2703. 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;}}}
  2704. 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;}}}
  2705. else{if(!sA){g_pAction="WAIT";g_pColor=NEON_YELLOW;}}
  2706. g_calc_gProb=g_gProb;g_calc_rProb=g_rProb;g_calc_pAction=g_pAction;g_calc_pColor=g_pColor;
  2707. }
  2708.  
  2709. // --- Safe Division Helper ---
  2710. double Div(double a, double b) {
  2711. if(b == 0) return 0;
  2712. return a / b;
  2713. }
  2714.  
  2715. // --- MAIN FORMULA: Buy aur Sell Count (ULTIMATE STABLE VERSION) ---
  2716. void GetConfluenceScores(int &buyCount, int &sellCount) {
  2717.  
  2718. // Caching
  2719. if(Time[0] == g_cacheConfluenceTime) {
  2720. buyCount = g_buyCountCache;
  2721. sellCount = g_sellCountCache;
  2722. return;
  2723. }
  2724.  
  2725. g_cacheConfluenceTime = Time[0];
  2726. buyCount = 0;
  2727. sellCount = 0;
  2728.  
  2729. int i = 1;
  2730. if(i >= Bars) return;
  2731.  
  2732. double atr = iATR(NULL, 0, 14, i);
  2733. if(atr <= 0) atr = Point * 10;
  2734.  
  2735. // ========== 22 INDICATORS (STRICT +1 LOGIC) ==========
  2736.  
  2737. // 1. RSI
  2738. double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, i);
  2739. if(rsi < 30) buyCount++;
  2740. else if(rsi > 70) sellCount++;
  2741. else if(rsi < 50 && rsi > iRSI(NULL, 0, 14, PRICE_CLOSE, i+1)) buyCount++;
  2742. else if(rsi > 50 && rsi < iRSI(NULL, 0, 14, PRICE_CLOSE, i+1)) sellCount++;
  2743.  
  2744. // 2. Stochastic
  2745. double stoch = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, i);
  2746. double stochSig = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, i);
  2747. if(stoch < 20 && stoch > stochSig) buyCount++;
  2748. else if(stoch > 80 && stoch < stochSig) sellCount++;
  2749.  
  2750. // 3. MACD
  2751. double macd = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, i);
  2752. double macdSig = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, i);
  2753. if(macd > macdSig && macd < 0) buyCount++;
  2754. else if(macd < macdSig && macd > 0) sellCount++;
  2755.  
  2756. // 4. MA Crossover (5 EMA vs 10 EMA)
  2757. double ma5 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, i);
  2758. double ma10 = iMA(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, i);
  2759. if(ma5 > ma10) buyCount++;
  2760. else if(ma5 < ma10) sellCount++;
  2761.  
  2762. // 5. Triple MA (5 > 10 > 20)
  2763. double ma20 = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, i);
  2764. if(ma5 > ma10 && ma10 > ma20) buyCount++;
  2765. else if(ma5 < ma10 && ma10 < ma20) sellCount++;
  2766.  
  2767. // 6. Bollinger Bands
  2768. double bbLow = iBands(NULL, 0, 20, 2.0, 0, PRICE_CLOSE, MODE_LOWER, i);
  2769. double bbUpp = iBands(NULL, 0, 20, 2.0, 0, PRICE_CLOSE, MODE_UPPER, i);
  2770. if(Close[i] <= bbLow) buyCount++;
  2771. else if(Close[i] >= bbUpp) sellCount++;
  2772.  
  2773. // 7. ADX
  2774. double adx = iADX(NULL, 0, 14, PRICE_CLOSE, MODE_MAIN, i);
  2775. double pdi = iADX(NULL, 0, 14, PRICE_CLOSE, MODE_PLUSDI, i);
  2776. double mdi = iADX(NULL, 0, 14, PRICE_CLOSE, MODE_MINUSDI, i);
  2777. if(adx > 20) {
  2778. if(pdi > mdi) buyCount++;
  2779. else if(mdi > pdi) sellCount++;
  2780. }
  2781.  
  2782. // 8. CCI
  2783. double cci = iCCI(NULL, 0, 14, PRICE_TYPICAL, i);
  2784. if(cci < -100) buyCount++;
  2785. else if(cci > 100) sellCount++;
  2786.  
  2787. // 9. Parabolic SAR
  2788. double sar = iSAR(NULL, 0, 0.02, 0.2, i);
  2789. if(sar < Low[i]) buyCount++;
  2790. else if(sar > High[i]) sellCount++;
  2791.  
  2792. // 10. MFI
  2793. double mfi = iMFI(NULL, 0, 14, i);
  2794. if(mfi < 20) buyCount++;
  2795. else if(mfi > 80) sellCount++;
  2796.  
  2797. // 11. Williams %R
  2798. double wpr = iWPR(NULL, 0, 14, i);
  2799. if(wpr < -80) buyCount++;
  2800. else if(wpr > -20) sellCount++;
  2801.  
  2802. // 12. Momentum
  2803. double mom = iMomentum(NULL, 0, 10, PRICE_CLOSE, i);
  2804. if(mom > 100) buyCount++;
  2805. else if(mom < 100) sellCount++;
  2806.  
  2807. // 13. ATR Breakout
  2808. if(Close[i] > Open[i] + atr * 0.5) buyCount++;
  2809. else if(Close[i] < Open[i] - atr * 0.5) sellCount++;
  2810.  
  2811. // 14. Envelopes
  2812. double envLow = iEnvelopes(NULL, 0, 10, MODE_EMA, 0, PRICE_CLOSE, 0.002, MODE_LOWER, i);
  2813. double envUpp = iEnvelopes(NULL, 0, 10, MODE_EMA, 0, PRICE_CLOSE, 0.002, MODE_UPPER, i);
  2814. if(Close[i] <= envLow) buyCount++;
  2815. else if(Close[i] >= envUpp) sellCount++;
  2816.  
  2817. // 15. OsMA
  2818. double osma = iOsMA(NULL, 0, 12, 26, 9, PRICE_CLOSE, i);
  2819. if(osma > 0) buyCount++;
  2820. else if(osma < 0) sellCount++;
  2821.  
  2822. // 16. Force Index
  2823. double force = iForce(NULL, 0, 13, MODE_SMA, PRICE_CLOSE, i);
  2824. if(force > 0) buyCount++;
  2825. else if(force < 0) sellCount++;
  2826.  
  2827. // 17. Volume (FIXED AVERAGE LOGIC - NO HARD CODE)
  2828. double vol = (double)Volume[i];
  2829. double volMA = 0; int volCnt = 0;
  2830. for(int v = i; v < i+20 && v < Bars; v++) { volMA += (double)Volume[v]; volCnt++; }
  2831. if(volCnt > 0) volMA /= volCnt;
  2832. if(vol > volMA && Close[i] > Open[i]) buyCount++;
  2833. else if(vol > volMA && Close[i] < Open[i]) sellCount++;
  2834.  
  2835. // 18. Price Action (Candle Pattern)
  2836. double range = High[i] - Low[i];
  2837. double body = MathAbs(Close[i] - Open[i]);
  2838. double lowWick = MathMin(Close[i], Open[i]) - Low[i];
  2839. double upWick = High[i] - MathMax(Close[i], Open[i]);
  2840. if(body > range * 0.6 && Close[i] > Open[i]) buyCount++;
  2841. else if(body > range * 0.6 && Close[i] < Open[i]) sellCount++;
  2842. else if(lowWick > body * 2 && upWick < body) buyCount++;
  2843. else if(upWick > body * 2 && lowWick < body) sellCount++;
  2844.  
  2845. // 19. Price vs MA20
  2846. if(Close[i] > ma20) buyCount++;
  2847. else if(Close[i] < ma20) sellCount++;
  2848.  
  2849. // 20. Candle Streak (Exhaustion)
  2850. int green = 0, red = 0;
  2851. for(int j = i; j < i+3 && j < Bars; j++) {
  2852. if(Close[j] > Open[j]) green++;
  2853. else if(Close[j] < Open[j]) red++;
  2854. }
  2855. if(green >= 3) sellCount++;
  2856. if(red >= 3) buyCount++;
  2857.  
  2858. // 21. Dynamic S/R Position (STABLE 25%/75% ZONES)
  2859. int highIdx = iHighest(NULL, 0, MODE_HIGH, 20, i);
  2860. int lowIdx = iLowest(NULL, 0, MODE_LOW, 20, i);
  2861. if(highIdx >= 0 && lowIdx >= 0) {
  2862. double high20 = High[highIdx];
  2863. double low20 = Low[lowIdx];
  2864. double pos = Div(Close[i] - low20, high20 - low20);
  2865. if(pos < 0.25) buyCount++;
  2866. else if(pos > 0.75) sellCount++;
  2867. }
  2868.  
  2869. // 22. Current Candle Body vs Previous
  2870. double prevBody = MathAbs(Close[i+1] - Open[i+1]);
  2871. if(body > prevBody * 1.5 && Close[i] > Open[i]) buyCount++;
  2872. else if(body > prevBody * 1.5 && Close[i] < Open[i]) sellCount++;
  2873.  
  2874. // Cache store
  2875. g_buyCountCache = buyCount;
  2876. g_sellCountCache = sellCount;
  2877. }
  2878.  
  2879. //+------------------------------------------------------------------+
  2880. //| CONFLUENCE SCORE CUBE (FIXED OVERLAP - CLEAN LAYOUT) |
  2881. //+------------------------------------------------------------------+
  2882. void DrawConfluenceCube(int x, int y, int w, int h) {
  2883. int buyCount, sellCount;
  2884. GetConfluenceScores(buyCount, sellCount);
  2885.  
  2886. int total = buyCount + sellCount;
  2887. if(total == 0) total = 1;
  2888.  
  2889. double buyPct = (double)buyCount / total * 100.0;
  2890. double sellPct = (double)sellCount / total * 100.0;
  2891.  
  2892. // Background
  2893. Bx("conf_bg", x, y, w, h, BG_DARK2, NEON_PURPLE);
  2894. Tx("conf_title", x+10, y+4, "CONFLUENCE SCORE", NEON_CYAN, 10, true);
  2895.  
  2896. // --- BUY SECTION ---
  2897. Tx("conf_buy_t", x+10, y+24, "BUY", NEON_GREEN, 11, true);
  2898. Tx("conf_buy_v", x+w-70, y+22, DoubleToString(buyPct,0)+"%",
  2899. (buyPct>=60)?NEON_GREEN:(buyPct>=40)?NEON_YELLOW:NEON_RED, 14, true); // Right side pe %
  2900.  
  2901. int barW = w - 24;
  2902. int buyFill = (int)(buyPct/100.0 * barW);
  2903. if(buyFill < 2) buyFill = 2;
  2904. Bx("conf_buy_bg", x+10, y+42, barW, 8, BG_DARK4, BG_DARK4); // 6 se 8 moti kiya
  2905. Bx("conf_buy_fill", x+10, y+42, buyFill, 8, NEON_GREEN, NEON_GREEN);
  2906.  
  2907. // --- SELL SECTION ---
  2908. Tx("conf_sell_t", x+10, y+60, "SELL", NEON_RED, 11, true);
  2909. Tx("conf_sell_v", x+w-70, y+58, DoubleToString(sellPct,0)+"%",
  2910. (sellPct>=60)?NEON_RED:(sellPct>=40)?NEON_YELLOW:NEON_GREEN, 14, true); // Right side pe %
  2911.  
  2912. int sellFill = (int)(sellPct/100.0 * barW);
  2913. if(sellFill < 2) sellFill = 2;
  2914. Bx("conf_sell_bg", x+10, y+78, barW, 8, BG_DARK4, BG_DARK4); // 6 se 8 moti kiya
  2915. Bx("conf_sell_fill", x+10, y+78, sellFill, 8, NEON_RED, NEON_RED);
  2916.  
  2917. // --- TOTAL INDICATORS (Bada aur Saaf Dikhega) ---
  2918. Tx("conf_total", x+10, y+96, IntegerToString(total)+"/22 Indicators", NEON_PURPLE, 12, true); // Size 9 se 12 badha diya
  2919.  
  2920. // --- SIGNAL TEXT ---
  2921. string signal = "";
  2922. color sigColor = NEON_YELLOW;
  2923. if(buyCount >= 14 && buyCount > sellCount) { signal = "STRONG BUY SIGNAL"; sigColor = NEON_GREEN; }
  2924. else if(sellCount >= 14 && buyCount > sellCount) { signal = "STRONG SELL SIGNAL"; sigColor = NEON_RED; }
  2925. else if(buyCount >= 10 && buyCount > sellCount) { signal = "BUY SIGNAL"; sigColor = NEON_CYAN; }
  2926. else if(sellCount >= 10 && sellCount > buyCount) { signal = "SELL SIGNAL"; sigColor = NEON_ORANGE; }
  2927. else if(buyCount > sellCount) { signal = "WEAK BUY BIAS"; sigColor = NEON_YELLOW; }
  2928. else if(sellCount > buyCount) { signal = "WEAK SELL BIAS"; sigColor = NEON_YELLOW; }
  2929. else { signal = "NO CLEAR SIGNAL"; sigColor = NEON_RED; }
  2930.  
  2931. Tx("conf_sig", x+10, y+118, signal, sigColor, 10, true);
  2932. }
  2933.  
  2934. // ============================================================
  2935. // AUTO-LEARNING: Load/Save/Update
  2936. // ============================================================
  2937. void QuantumLoadLearning()
  2938. {
  2939. int h = FileOpen(g_qLearnFile, FILE_READ|FILE_TXT|FILE_COMMON);
  2940. if(h != INVALID_HANDLE)
  2941. {
  2942. string line = FileReadString(h);
  2943. FileClose(h);
  2944.  
  2945. int p1 = StringFind(line, ",");
  2946. int p2 = StringFind(line, ",", p1+1);
  2947. int p3 = StringFind(line, ",", p2+1);
  2948. int p4 = StringFind(line, ",", p3+1);
  2949. int p5 = StringFind(line, ",", p4+1);
  2950. int p6 = StringFind(line, ",", p5+1);
  2951. int p7 = StringFind(line, ",", p6+1);
  2952. int p8 = StringFind(line, ",", p7+1);
  2953.  
  2954. if(p8 > 0)
  2955. {
  2956. g_qWeightMHI = StringToDouble(StringSubstr(line, 0, p1));
  2957. g_qWeightNCP = StringToDouble(StringSubstr(line, p1+1, p2-p1-1));
  2958. g_qWeightTrap = StringToDouble(StringSubstr(line, p2+1, p3-p2-1));
  2959. g_qWeightFib = StringToDouble(StringSubstr(line, p3+1, p4-p3-1));
  2960. g_qWeightBB = StringToDouble(StringSubstr(line, p4+1, p5-p4-1));
  2961. g_qWeightNeural = StringToDouble(StringSubstr(line, p5+1, p6-p5-1));
  2962. g_qWeightHA = StringToDouble(StringSubstr(line, p6+1, p7-p6-1));
  2963. g_qTotalTrades = (int)StringToInteger(StringSubstr(line, p7+1, p8-p7-1));
  2964. g_qWinTrades = (int)StringToInteger(StringSubstr(line, p8+1));
  2965. }
  2966. }
  2967. }
  2968.  
  2969. void QuantumSaveLearning()
  2970. {
  2971. int h = FileOpen(g_qLearnFile, FILE_WRITE|FILE_TXT|FILE_COMMON);
  2972. if(h != INVALID_HANDLE)
  2973. {
  2974. string line = DoubleToString(g_qWeightMHI,4) + "," +
  2975. DoubleToString(g_qWeightNCP,4) + "," +
  2976. DoubleToString(g_qWeightTrap,4) + "," +
  2977. DoubleToString(g_qWeightFib,4) + "," +
  2978. DoubleToString(g_qWeightBB,4) + "," +
  2979. DoubleToString(g_qWeightNeural,4) + "," +
  2980. DoubleToString(g_qWeightHA,4) + "," +
  2981. IntegerToString(g_qTotalTrades) + "," +
  2982. IntegerToString(g_qWinTrades);
  2983. FileWriteString(h, line);
  2984. FileClose(h);
  2985. }
  2986. }
  2987.  
  2988. void QuantumUpdateLearning(bool win)
  2989. {
  2990. g_qTotalTrades++;
  2991. if(win) g_qWinTrades++;
  2992.  
  2993. double lr = 0.015;
  2994. double adj = win ? lr : -lr * 1.5;
  2995.  
  2996. if(g_qIsTrap) g_qWeightTrap += adj;
  2997. else {
  2998. if(g_qPattern == "GGG" || g_qPattern == "RRR" || g_qPattern == "GGR" || g_qPattern == "RRG")
  2999. g_qWeightMHI += adj;
  3000. if(g_otcHasSignal) g_qWeightFib += adj;
  3001. }
  3002.  
  3003. g_qWeightMHI = MathMax(0.05, MathMin(0.50, g_qWeightMHI));
  3004. g_qWeightNCP = MathMax(0.05, MathMin(0.50, g_qWeightNCP));
  3005. g_qWeightTrap = MathMax(0.05, MathMin(0.50, g_qWeightTrap));
  3006. g_qWeightFib = MathMax(0.05, MathMin(0.50, g_qWeightFib));
  3007. g_qWeightBB = MathMax(0.05, MathMin(0.50, g_qWeightBB));
  3008. g_qWeightNeural = MathMax(0.05, MathMin(0.50, g_qWeightNeural));
  3009. g_qWeightHA = MathMax(0.05, MathMin(0.50, g_qWeightHA));
  3010.  
  3011. double totalW = g_qWeightMHI + g_qWeightNCP + g_qWeightTrap +
  3012. g_qWeightFib + g_qWeightBB + g_qWeightNeural + g_qWeightHA;
  3013. if(totalW > 0)
  3014. {
  3015. g_qWeightMHI /= totalW;
  3016. g_qWeightNCP /= totalW;
  3017. g_qWeightTrap /= totalW;
  3018. g_qWeightFib /= totalW;
  3019. g_qWeightBB /= totalW;
  3020. g_qWeightNeural /= totalW;
  3021. g_qWeightHA /= totalW;
  3022. }
  3023.  
  3024. QuantumSaveLearning();
  3025. }
  3026.  
  3027. // ============================================================
  3028. // 150 CANDLE HISTORY: Build & Analyze
  3029. // ============================================================
  3030. void QuantumBuildHistory()
  3031. {
  3032. g_histCount = 0;
  3033. int maxBars = MathMin(150, Bars - 5);
  3034.  
  3035. for(int i = 5; i < 5 + maxBars && i < Bars; i++)
  3036. {
  3037. int c1 = (Close[i] > Open[i]) ? 1 : (Close[i] < Open[i]) ? -1 : 0;
  3038. int c2 = (Close[i+1] > Open[i+1]) ? 1 : (Close[i+1] < Open[i+1]) ? -1 : 0;
  3039. int c3 = (Close[i+2] > Open[i+2]) ? 1 : (Close[i+2] < Open[i+2]) ? -1 : 0;
  3040.  
  3041. int result = (Close[i-1] > Open[i-1]) ? 1 : (Close[i-1] < Open[i-1]) ? -1 : 0;
  3042.  
  3043. int patternCode = (c3+1)*100 + (c2+1)*10 + (c1+1);
  3044.  
  3045. g_histPatterns[g_histCount] = patternCode;
  3046. g_histResults[g_histCount] = result;
  3047. g_histCount++;
  3048. }
  3049. }
  3050.  
  3051. int QuantumCheckHistory(int currentPattern)
  3052. {
  3053. if(g_histCount < 20) return 0;
  3054.  
  3055. int matchCall = 0, matchPut = 0, totalMatch = 0;
  3056.  
  3057. for(int i = 0; i < g_histCount; i++)
  3058. {
  3059. if(g_histPatterns[i] == currentPattern)
  3060. {
  3061. totalMatch++;
  3062. if(g_histResults[i] == 1) matchCall++;
  3063. else if(g_histResults[i] == -1) matchPut++;
  3064. }
  3065. }
  3066.  
  3067. if(totalMatch < 3) return 0;
  3068.  
  3069. double callPct = (double)matchCall / totalMatch * 100.0;
  3070. double putPct = (double)matchPut / totalMatch * 100.0;
  3071.  
  3072. g_qHistoryScore = totalMatch;
  3073.  
  3074. if(callPct >= 60) return (int)callPct;
  3075. else if(putPct >= 60) return -(int)putPct;
  3076. return 0;
  3077. }
  3078.  
  3079. // ============================================================
  3080. // TIME-BASED PROBABILITY
  3081. // ============================================================
  3082. void QuantumCalcTimeProb()
  3083. {
  3084. int age = (int)(TimeCurrent() - Time[0]);
  3085. int ps = Period() * 60;
  3086. double pct = (double)age / ps * 100.0;
  3087.  
  3088. if(pct < 20)
  3089. {
  3090. g_qTimePhase = "EARLY";
  3091. g_qTimeProb = 45.0;
  3092. }
  3093. else if(pct < 50)
  3094. {
  3095. g_qTimePhase = "MID";
  3096. g_qTimeProb = 65.0;
  3097. }
  3098. else if(pct < 80)
  3099. {
  3100. g_qTimePhase = "LATE";
  3101. g_qTimeProb = 75.0;
  3102. }
  3103. else
  3104. {
  3105. g_qTimePhase = "LAST";
  3106. g_qTimeProb = 55.0;
  3107. }
  3108.  
  3109. double spread = (double)MarketInfo(Symbol(), MODE_SPREAD);
  3110. double pip = GetUniversalPip();
  3111. double spreadPips = spread * Point / pip;
  3112.  
  3113. if(spreadPips > 5) g_qSpreadPenalty = 15.0;
  3114. else if(spreadPips > 3) g_qSpreadPenalty = 8.0;
  3115. else g_qSpreadPenalty = 0.0;
  3116. }
  3117.  
  3118. // ============================================================
  3119. // BACKGROUND PAIRS MHI SCAN
  3120. // ============================================================
  3121. void QuantumScanBackgroundMHI()
  3122. {
  3123. g_bgMHI_Count = 0;
  3124.  
  3125. if(g_pairCount == 0) return;
  3126.  
  3127. for(int i = 0; i < g_pairCount && i < 8; i++)
  3128. {
  3129. string pair = g_pairNames[i];
  3130. if(pair == Symbol()) continue;
  3131.  
  3132. double c1 = iClose(pair, PERIOD_M1, 1);
  3133. double o1 = iOpen(pair, PERIOD_M1, 1);
  3134. double c2 = iClose(pair, PERIOD_M1, 2);
  3135. double o2 = iOpen(pair, PERIOD_M1, 2);
  3136. double c3 = iClose(pair, PERIOD_M1, 3);
  3137. double o3 = iOpen(pair, PERIOD_M1, 3);
  3138.  
  3139. if(c1 == 0 || o1 == 0) continue;
  3140.  
  3141. string pColors = "";
  3142. if(c1 > o1) pColors += "G"; else if(c1 < o1) pColors += "R"; else pColors += "D";
  3143. if(c2 > o2) pColors += "G"; else if(c2 < o2) pColors += "R"; else pColors += "D";
  3144. if(c3 > o3) pColors += "G"; else if(c3 < o3) pColors += "R"; else pColors += "D";
  3145.  
  3146. string sig = "WAIT";
  3147. double conf = 50;
  3148.  
  3149. if(pColors == "GGR") { sig = "PUT"; conf = 70; }
  3150. else if(pColors == "RRG") { sig = "CALL"; conf = 70; }
  3151. else if(pColors == "GGG") { sig = "PUT"; conf = 85; }
  3152. else if(pColors == "RRR") { sig = "CALL"; conf = 85; }
  3153.  
  3154. if(sig != "WAIT")
  3155. {
  3156. g_bgMHI_Signal[g_bgMHI_Count] = sig;
  3157. g_bgMHI_Conf[g_bgMHI_Count] = conf;
  3158. g_bgMHI_Pair[g_bgMHI_Count] = pair;
  3159. g_bgMHI_Count++;
  3160. }
  3161. }
  3162. }
  3163.  
  3164. // ============================================================
  3165. // MAIN QUANTUM v9.1 PRO ENGINE
  3166. // ============================================================
  3167. void CalculateQuantumEngine()
  3168. {
  3169. g_qSignal = "WAIT";
  3170. g_qConf = 50.0;
  3171. g_qPattern = "---";
  3172. g_qStatus = "SCANNING";
  3173. g_qColor = NEON_YELLOW;
  3174. g_qReason = "";
  3175. g_qIsTrap = false;
  3176. g_qCallScore = 50.0;
  3177. g_qPutScore = 50.0;
  3178. g_qConfluence = "";
  3179. g_qHistoryScore = 0;
  3180.  
  3181. if(Bars < 20) return;
  3182.  
  3183. static datetime lastHistBuild = 0;
  3184. if(Time[0] != lastHistBuild)
  3185. {
  3186. QuantumBuildHistory();
  3187. lastHistBuild = Time[0];
  3188. }
  3189.  
  3190. QuantumCalcTimeProb();
  3191. QuantumScanBackgroundMHI();
  3192.  
  3193. // MODULE 1: MHI PATTERN
  3194. double mhiCall = 0, mhiPut = 0;
  3195. string colors = "";
  3196. for(int i = 1; i <= 3; i++)
  3197. {
  3198. if(Close[i] > Open[i]) colors += "G";
  3199. else if(Close[i] < Open[i]) colors += "R";
  3200. else colors += "D";
  3201. }
  3202. g_qPattern = colors;
  3203.  
  3204. if(colors == "GGR") { mhiPut = 85; mhiCall = 15; }
  3205. else if(colors == "RRG") { mhiCall = 85; mhiPut = 15; }
  3206. else if(colors == "GGG") { mhiPut = 90; mhiCall = 10; }
  3207. else if(colors == "RRR") { mhiCall = 90; mhiPut = 10; }
  3208. else if(colors == "GRG") { mhiCall = 40; mhiPut = 40; }
  3209. else if(colors == "RGR") { mhiCall = 40; mhiPut = 40; }
  3210. else if(colors == "GRR") { mhiCall = 65; mhiPut = 35; }
  3211. else if(colors == "RGG") { mhiPut = 65; mhiCall = 35; }
  3212.  
  3213. if(StringFind(colors, "D") >= 0) { mhiCall -= 10; mhiPut -= 10; }
  3214.  
  3215. int currentPat = ((Close[3]>Open[3]?1:Close[3]<Open[3]?-1:0)+1)*100 +
  3216. ((Close[2]>Open[2]?1:Close[2]<Open[2]?-1:0)+1)*10 +
  3217. ((Close[1]>Open[1]?1:Close[1]<Open[1]?-1:0)+1);
  3218. int histBoost = QuantumCheckHistory(currentPat);
  3219.  
  3220. if(histBoost > 0) { mhiCall += histBoost * 0.3; mhiPut -= histBoost * 0.3; }
  3221. else if(histBoost < 0) { mhiPut += MathAbs(histBoost) * 0.3; mhiCall -= MathAbs(histBoost) * 0.3; }
  3222.  
  3223. int bgAgreeCall = 0, bgAgreePut = 0;
  3224. for(int b = 0; b < g_bgMHI_Count; b++)
  3225. {
  3226. if(g_bgMHI_Signal[b] == "CALL") bgAgreeCall++;
  3227. else if(g_bgMHI_Signal[b] == "PUT") bgAgreePut++;
  3228. }
  3229.  
  3230. if(bgAgreeCall >= 2) { mhiCall += 10; mhiPut -= 5; }
  3231. if(bgAgreePut >= 2) { mhiPut += 10; mhiCall -= 5; }
  3232.  
  3233. // MODULE 2: NCP PRO v8
  3234. double ncpCall = 50, ncpPut = 50;
  3235. if(ENABLE_MTG && g_mtgState != "INIT")
  3236. {
  3237. ncpCall = g_smoothCallScore;
  3238. ncpPut = g_smoothPutScore;
  3239. }
  3240.  
  3241. // MODULE 3: VISUAL TRAP
  3242. double trapCall = 50, trapPut = 50;
  3243. if(g_visualTrapPro.callBias > 0 || g_visualTrapPro.putBias > 0)
  3244. {
  3245. trapCall = g_visualTrapPro.callBias;
  3246. trapPut = g_visualTrapPro.putBias;
  3247. }
  3248. if(g_visualTrapPro.trapScore >= 70)
  3249. {
  3250. double temp = trapCall; trapCall = trapPut; trapPut = temp;
  3251. g_qIsTrap = true;
  3252. }
  3253.  
  3254. // MODULE 4: FIB REJECTION
  3255. double fibCall = 50, fibPut = 50;
  3256. if(g_otcHasSignal && g_otcFibStrength > 0)
  3257. {
  3258. if(g_otcFibDir == "CALL") { fibCall = g_otcFibStrength; fibPut = 100 - g_otcFibStrength; }
  3259. else if(g_otcFibDir == "PUT") { fibPut = g_otcFibStrength; fibCall = 100 - g_otcFibStrength; }
  3260. }
  3261.  
  3262. // MODULE 5: BB PULLBACK
  3263. double bbCall = 50, bbPut = 50;
  3264. if(ENABLE_BB_PULLBACK && g_bbSignal != "--")
  3265. {
  3266. if(g_bbSignal == "CALL") { bbCall = 80; bbPut = 20; }
  3267. else if(g_bbSignal == "PUT") { bbPut = 80; bbCall = 20; }
  3268. }
  3269.  
  3270. // MODULE 6: NEURAL AI
  3271. double neuralCall = 50, neuralPut = 50;
  3272. double nb = NeuralBiasFast();
  3273. if(nb > 50) { neuralCall = nb; neuralPut = 100 - nb; }
  3274. else { neuralPut = 100 - nb; neuralCall = nb; }
  3275.  
  3276. // MODULE 7: HA CANDLES
  3277. double haCall = 50, haPut = 50;
  3278. if(g_haM1 == "HA BULLISH 1") haCall += 20;
  3279. else if(g_haM1 == "HA BEARISH 1") haPut += 20;
  3280. if(g_haM5 == "HA BULLISH 5") haCall += 15;
  3281. else if(g_haM5 == "HA BEARISH 5") haPut += 15;
  3282. if(g_haBoth == "BOTH BULL") haCall += 25;
  3283. else if(g_haBoth == "BOTH BEAR") haPut += 25;
  3284.  
  3285. // QUANTUM CONFLUENCE (Dynamic Weights)
  3286. g_qCallScore = (
  3287. mhiCall * g_qWeightMHI +
  3288. ncpCall * g_qWeightNCP +
  3289. trapCall * g_qWeightTrap +
  3290. fibCall * g_qWeightFib +
  3291. bbCall * g_qWeightBB +
  3292. neuralCall * g_qWeightNeural +
  3293. haCall * g_qWeightHA
  3294. );
  3295.  
  3296. g_qPutScore = (
  3297. mhiPut * g_qWeightMHI +
  3298. ncpPut * g_qWeightNCP +
  3299. trapPut * g_qWeightTrap +
  3300. fibPut * g_qWeightFib +
  3301. bbPut * g_qWeightBB +
  3302. neuralPut * g_qWeightNeural +
  3303. haPut * g_qWeightHA
  3304. );
  3305.  
  3306. // Time & Spread Adjustments
  3307. double timeBoost = (g_qTimeProb - 50) * 0.3;
  3308. if(g_qCallScore > g_qPutScore) g_qCallScore += timeBoost;
  3309. else g_qPutScore += timeBoost;
  3310.  
  3311. if(g_qCallScore > g_qPutScore) g_qCallScore -= g_qSpreadPenalty;
  3312. else g_qPutScore -= g_qSpreadPenalty;
  3313.  
  3314. // Normalize
  3315. double total = g_qCallScore + g_qPutScore;
  3316. if(total > 0)
  3317. {
  3318. g_qCallScore = (g_qCallScore / total) * 100;
  3319. g_qPutScore = (g_qPutScore / total) * 100;
  3320. }
  3321.  
  3322. // CONFLUENCE CHECK
  3323. string agreeSources = "";
  3324. int agreeCount = 0;
  3325.  
  3326. if(mhiCall > 60 && g_qCallScore > 55) { agreeSources += "MHI+"; agreeCount++; }
  3327. if(mhiPut > 60 && g_qPutScore > 55) { agreeSources += "MHI+"; agreeCount++; }
  3328. if(ncpCall > 60 && g_qCallScore > 55) { agreeSources += "NCP+"; agreeCount++; }
  3329. if(ncpPut > 60 && g_qPutScore > 55) { agreeSources += "NCP+"; agreeCount++; }
  3330. if(trapCall > 60 && g_qCallScore > 55) { agreeSources += "TRP+"; agreeCount++; }
  3331. if(trapPut > 60 && g_qPutScore > 55) { agreeSources += "TRP+"; agreeCount++; }
  3332. if(fibCall > 60 && g_qCallScore > 55) { agreeSources += "FIB+"; agreeCount++; }
  3333. if(fibPut > 60 && g_qPutScore > 55) { agreeSources += "FIB+"; agreeCount++; }
  3334. if(bbCall > 60 && g_qCallScore > 55) { agreeSources += "BB+"; agreeCount++; }
  3335. if(bbPut > 60 && g_qPutScore > 55) { agreeSources += "BB+"; agreeCount++; }
  3336.  
  3337. g_qConfluence = agreeSources + " (" + IntegerToString(agreeCount) + "/7)";
  3338.  
  3339. // FINAL DECISION
  3340. double dominant = MathMax(g_qCallScore, g_qPutScore);
  3341. int minAgree = 3;
  3342.  
  3343. if(agreeCount < minAgree || dominant < 58)
  3344. {
  3345. g_qSignal = "WAIT";
  3346. g_qConf = dominant;
  3347. g_qStatus = "LOW CONF";
  3348. g_qColor = NEON_YELLOW;
  3349. g_qReason = "Need " + IntegerToString(minAgree) + "+ src | Got:" + IntegerToString(agreeCount);
  3350. return;
  3351. }
  3352.  
  3353. // TRAP OVERRIDE
  3354. if(g_qIsTrap && dominant >= 75)
  3355. {
  3356. if(g_qCallScore > g_qPutScore)
  3357. {
  3358. g_qSignal = "TRAP_PUT";
  3359. g_qColor = NEON_PURPLE;
  3360. g_qStatus = "QUANTUM TRAP";
  3361. }
  3362. else
  3363. {
  3364. g_qSignal = "TRAP_CALL";
  3365. g_qColor = NEON_PURPLE;
  3366. g_qStatus = "QUANTUM TRAP";
  3367. }
  3368. g_qConf = dominant;
  3369. g_qReason = "TRAP:" + IntegerToString((int)g_visualTrapPro.trapScore) + "% | " + g_qConfluence;
  3370. return;
  3371. }
  3372.  
  3373. // NORMAL SIGNAL
  3374. if(g_qCallScore > g_qPutScore)
  3375. {
  3376. g_qSignal = "CALL";
  3377. g_qConf = g_qCallScore;
  3378. if(g_qCallScore >= 85) { g_qStatus = "QUANTUM STRONG"; g_qColor = NEON_GREEN; }
  3379. else if(g_qCallScore >= 72) { g_qStatus = "QUANTUM GOOD"; g_qColor = NEON_LIME; }
  3380. else { g_qStatus = "QUANTUM WEAK"; g_qColor = NEON_CYAN; }
  3381. }
  3382. else
  3383. {
  3384. g_qSignal = "PUT";
  3385. g_qConf = g_qPutScore;
  3386. if(g_qPutScore >= 85) { g_qStatus = "QUANTUM STRONG"; g_qColor = NEON_RED; }
  3387. else if(g_qPutScore >= 72) { g_qStatus = "QUANTUM GOOD"; g_qColor = C'255,100,100'; }
  3388. else { g_qStatus = "QUANTUM WEAK"; g_qColor = NEON_ORANGE; }
  3389. }
  3390.  
  3391. g_qReason = g_qConfluence;
  3392.  
  3393. if(g_qHistoryScore > 0)
  3394. {
  3395. g_qReason += " | HIST:" + IntegerToString(g_qHistoryScore);
  3396. }
  3397. }
  3398.  
  3399. // ============================================================
  3400. // v9.1 PRO DASHBOARD DRAW (WIDE GAP & BIG FONTS)
  3401. // ============================================================
  3402. void DrawQuantumCube(int x, int y, int w, int h)
  3403. {
  3404. color borderC = g_qIsTrap ? NEON_PURPLE : g_qColor;
  3405. if(g_qSignal == "WAIT") borderC = C'80,80,90';
  3406.  
  3407. Bx("c_quantum", x, y, w, h, BG_DARK2, borderC);
  3408.  
  3409. // 1. Title (Bada)
  3410. Tx("c_quantum_l", x+10, y+5, "MHI-QUANTUM v9.1", NEON_CYAN, 10, true);
  3411.  
  3412. // 2. MAIN LINE: Signal (Left) + Conf/Phase (Right) - WIDE GAP
  3413. string sigDisplay = g_qSignal;
  3414. if(StringFind(g_qSignal, "TRAP_") == 0)
  3415. sigDisplay = "!" + StringSubstr(g_qSignal, 5);
  3416.  
  3417. // Signal left side (Font 16)
  3418. Tx("c_quantum_sig", x+10, y+22, sigDisplay, g_qColor, 16, true);
  3419.  
  3420. // Conf & Time right side mein (Font 12, Gap x+105)
  3421. string confText = DoubleToString(g_qConf, 0) + "% " + g_qTimePhase;
  3422. Tx("c_quantum_conf", x+105, y+24, confText, NEON_WHITE, 12, true);
  3423.  
  3424. // 3. Pattern & History (Font 11)
  3425. color patC = (g_qPattern == "GGG" || g_qPattern == "GGR") ? NEON_RED :
  3426. (g_qPattern == "RRR" || g_qPattern == "RRG") ? NEON_GREEN : CGR;
  3427. string patText = "PATTERN: " + g_qPattern;
  3428. if(g_qHistoryScore > 0) patText += " [H" + IntegerToString(g_qHistoryScore) + "]";
  3429. Tx("c_quantum_pat", x+10, y+46, patText, patC, 11, true);
  3430.  
  3431. // 4. Status (Font 12)
  3432. Tx("c_quantum_stat", x+10, y+68, g_qStatus, g_qColor, 12, true);
  3433.  
  3434. // 5. Confluence Sources (Font 10)
  3435. string confl = g_qConfluence;
  3436. if(StringLen(confl) > 28) confl = StringSubstr(confl, 0, 26) + "..";
  3437. Tx("c_quantum_src", x+10, y+90, confl, NEON_GOLD, 10, true);
  3438.  
  3439. // 6. Spread Warning
  3440. if(g_qSpreadPenalty > 0)
  3441. {
  3442. Tx("c_quantum_spd", x+10, y+110, "SPREAD -" + DoubleToString(g_qSpreadPenalty,0) + "%", NEON_ORANGE, 10, true);
  3443. }
  3444.  
  3445. // 7. Background Pairs Sync
  3446. if(g_bgMHI_Count > 0)
  3447. {
  3448. string bgText = "BG PAIRS: " + IntegerToString(g_bgMHI_Count);
  3449. Tx("c_quantum_bg", x+10, y+126, bgText, NEON_PURPLE, 10, true);
  3450. }
  3451.  
  3452. // 8. Dual Bar - Call vs Put (Bottom)
  3453. int barW = w - 20;
  3454. int barY = y + h - 10;
  3455.  
  3456. Bx("c_quantum_bar_bg", x+10, barY, barW, 6, BG_DARK4, BG_DARK4);
  3457.  
  3458. int callW = (int)(g_qCallScore / 100.0 * barW);
  3459. if(callW < 1) callW = 1; if(callW > barW) callW = barW;
  3460. Bx("c_quantum_call", x+10, barY, callW, 6, C'0,180,90', C'0,180,90');
  3461.  
  3462. int putW = (int)(g_qPutScore / 100.0 * barW);
  3463. if(putW < 1) putW = 1; if(putW > barW) putW = barW;
  3464. int putX = x + 10 + barW - putW;
  3465. Bx("c_quantum_put", putX, barY, putW, 6, C'200,50,50', C'200,50,50');
  3466.  
  3467. int centerX = x + 10 + barW/2 - 1;
  3468. Bx("c_quantum_ctr", centerX, barY-1, 2, 8, NEON_WHITE, NEON_WHITE);
  3469. }
  3470.  
  3471. // ============================================================
  3472. // ACCURACY TRACKING FOR AUTO-LEARNING
  3473. // ============================================================
  3474. void QuantumCheckResult()
  3475. {
  3476. static datetime lastCheckBar = 0;
  3477. if(Time[0] == lastCheckBar) return;
  3478. lastCheckBar = Time[0];
  3479.  
  3480. if(g_qSignal != "WAIT" && g_qLastSignalBar == Time[1])
  3481. {
  3482. bool wasCall = (g_qLastSignal == "CALL" || g_qLastSignal == "TRAP_PUT");
  3483. bool wasPut = (g_qLastSignal == "PUT" || g_qLastSignal == "TRAP_CALL");
  3484.  
  3485. bool greenBar = (Close[1] > Open[1]);
  3486. bool redBar = (Close[1] < Open[1]);
  3487.  
  3488. bool win = false;
  3489. if(wasCall && greenBar) win = true;
  3490. if(wasPut && redBar) win = true;
  3491.  
  3492. QuantumUpdateLearning(win);
  3493. }
  3494.  
  3495. if(g_qSignal != "WAIT")
  3496. {
  3497. g_qLastSignal = g_qSignal;
  3498. g_qLastSignalBar = Time[0];
  3499. }
  3500. }
  3501.  
  3502. // ============================================================
  3503. // MAIN DASHBOARD DRAW (FIXED NEXT CANDLE CUBE)
  3504. // ============================================================
  3505. void Draw(){
  3506. HideSPM(); DelDashboard();
  3507. int W=DASH_W,G=8,CW=(W-2*G)/3,CH=110,cx=POS_X+G,yy=POS_Y;
  3508. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  3509. g_marketMode=DetectMarketMode(brain,g_rsc,cp,nb);
  3510. if(StringLen(g_prevMode)>0&&g_prevMode!=g_marketMode){g_signalTime=0;g_finalSignal="WAIT";}g_prevMode=g_marketMode;
  3511. CalcOTCCrowd();UpdateAccuracy();UpdateWeights();
  3512. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();
  3513. CalcFibRejectionHunter();
  3514. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  3515. UpdateRiskControl();CheckMTFConfirmation();
  3516. double tfaScore=CalcAdvancedTFA(g_tfa_detail);
  3517. color ha1C=(g_haM1=="HA BULLISH 1")?NEON_GREEN:(g_haM1=="HA BEARISH 1")?NEON_RED:NEON_YELLOW;
  3518. color ha5C=(g_haM5=="HA BULLISH 5")?NEON_GREEN:(g_haM5=="HA BEARISH 5")?NEON_RED:NEON_YELLOW;
  3519. color biasClr;string biasStr=CalcAdvancedMarketBias(biasClr,brain,g_rsc);
  3520. string stratLabel=(g_strategyType=="TRAP")?"TRAP":(g_strategyType=="TREND")?"TREND":"NO STRATEGY";
  3521. color stratC=(g_strategyType=="TRAP")?NEON_PURPLE:(g_strategyType=="TREND")?NEON_GREEN:CGR;
  3522.  
  3523. g_rsc = brain * 0.5;
  3524.  
  3525. g_frozen_gProb = g_calc_gProb;
  3526. g_frozen_rProb = g_calc_rProb;
  3527. g_frozen_pAction = g_calc_pAction;
  3528. g_frozen_pColor = g_calc_pColor;
  3529.  
  3530.  
  3531.  
  3532. // ROW 1
  3533. Cube("c1",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"PAIR",NEON_CYAN,Symbol(),NEON_BLUE,13);
  3534.  
  3535. DrawQuantumCube(cx+CW+G, yy, CW, 130);
  3536.  
  3537. // ----- TIMER & STRENGTH CUBE (NEW) -----
  3538. int tfSec=300; datetime tnow=TimeCurrent(); datetime tbar=(datetime)((int)tnow/300*300); int trem=(int)(tbar+300-tnow); if(trem<0)trem=0; if(trem>=tfSec)trem=tfSec-1; string timerStr=StringFormat("%02d:%02d", trem/60, trem%60);
  3539.  
  3540. // --- M5 STRENGTH ---
  3541. double m5H=iHigh(NULL,PERIOD_M5,1), m5L=iLow(NULL,PERIOD_M5,1), m5O=iOpen(NULL,PERIOD_M5,1), m5C=iClose(NULL,PERIOD_M5,1);
  3542. double m5Rng=m5H-m5L; if(m5Rng<=Point) m5Rng=Point;
  3543. double m5Body=MathAbs(m5C-m5O);
  3544. double m5Uw=m5H-MathMax(m5O,m5C), m5Lw=MathMin(m5O,m5C)-m5L;
  3545. double m5Str=MathMax(0, MathMin(100, (m5Body/m5Rng)*100.0 - ((m5Uw+m5Lw)/m5Rng)*25.0));
  3546. bool m5Bull=m5C>m5O; string m5Txt="M5: "+DoubleToString(m5Str,0)+"% "+(m5Bull?"UP":"DN");
  3547. color m5Clr=(m5Str>=70)?((m5Bull)?NEON_GREEN:NEON_RED):((m5Str>=40)?NEON_YELLOW:CGR);
  3548.  
  3549. // --- M1 STRENGTH ---
  3550. double m1Rng=High[1]-Low[1]; if(m1Rng<=Point) m1Rng=Point;
  3551. double m1Body=MathAbs(Close[1]-Open[1]);
  3552. double m1Uw=High[1]-MathMax(Open[1],Close[1]), m1Lw=MathMin(Open[1],Close[1])-Low[1];
  3553. double m1Str=MathMax(0, MathMin(100, (m1Body/m1Rng)*100.0 - ((m1Uw+m1Lw)/m1Rng)*25.0));
  3554. bool m1Bull=Close[1]>Open[1]; string m1Txt="M1: "+DoubleToString(m1Str,0)+"% "+(m1Bull?"UP":"DN");
  3555. color m1Clr=(m1Str>=70)?((m1Bull)?NEON_GREEN:NEON_RED):((m1Str>=40)?NEON_YELLOW:CGR);
  3556.  
  3557. // --- M2 STRENGTH (Last 2 M1 Candles Combined) ---
  3558. double m2H=MathMax(High[1],High[2]), m2L=MathMin(Low[1],Low[2]);
  3559. double m2O=Open[2], m2C=Close[1];
  3560. double m2Rng=m2H-m2L; if(m2Rng<=Point) m2Rng=Point;
  3561. double m2Body=MathAbs(m2C-m2O);
  3562. double m2Uw=m2H-MathMax(m2O,m2C), m2Lw=MathMin(m2O,m2C)-m2L;
  3563. double m2Str=MathMax(0, MathMin(100, (m2Body/m2Rng)*100.0 - ((m2Uw+m2Lw)/m2Rng)*25.0));
  3564. bool m2Bull=m2C>m2O; string m2Txt="M2: "+DoubleToString(m2Str,0)+"% "+(m2Bull?"UP":"DN");
  3565. color m2Clr=(m2Str>=70)?((m2Bull)?NEON_GREEN:NEON_RED):((m2Str>=40)?NEON_YELLOW:CGR);
  3566.  
  3567. // --- DRAW CUBE ---
  3568. Bx("c_str",cx+2*(CW+G),yy,CW,CH,BG_DARK2,NEON_CYAN);
  3569. Bx("c_str_acc",cx+2*(CW+G),yy,3,CH,NEON_CYAN,NEON_CYAN);
  3570. Tx("c_str_t",cx+2*(CW+G)+10,yy+5,timerStr,NEON_GREEN,12,true);
  3571. Tx("c_str_m5",cx+2*(CW+G)+10,yy+24,m5Txt,m5Clr,11,true);
  3572. Tx("c_str_m2",cx+2*(CW+G)+10,yy+48,m2Txt,m2Clr,11,true);
  3573. Tx("c_str_m1",cx+2*(CW+G)+10,yy+72,m1Txt,m1Clr,11,true);
  3574.  
  3575. // --- AVERAGE STRENGTH BAR ---
  3576. int barY=yy+CH-8; int barW=CW-24;
  3577. double avgStr=(m5Str+m2Str+m1Str)/3.0;
  3578. Bx("c_str_bg",cx+2*(CW+G)+10,barY,barW,4,BG_DARK4,BG_DARK4);
  3579. int fillW=(int)(avgStr/100.0*barW); if(fillW<2)fillW=2; if(fillW>barW)fillW=barW;
  3580. color avgClr=(avgStr>=60)?NEON_GREEN:((avgStr>=40)?NEON_YELLOW:NEON_RED);
  3581. Bx("c_str_fg",cx+2*(CW+G)+10,barY,fillW,4,avgClr,avgClr);
  3582. yy += CH + G;
  3583.  
  3584.  
  3585.  
  3586.  
  3587. // ROW 2
  3588. 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);
  3589. 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);
  3590. color sClr=CGR;string sName=GetCurrentSession(sClr);bool isAct=IsSessionActive();
  3591. 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;
  3592.  
  3593. // ROW 3
  3594. DrawOtherPairsCube(cx,yy,CW,CH);DrawConfluenceCube(cx+CW+G,yy,CW,140);
  3595. 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;
  3596.  
  3597. // ROW 4
  3598. int CH4=120;color fibC;if(g_fibBestDir=="CALL")fibC=NEON_GREEN;else if(g_fibBestDir=="PUT")fibC=NEON_RED;else fibC=NEON_YELLOW;
  3599. Bx("c_fib",cx,yy,CW,CH4,BG_DARK2,fibC);Tx("c_fib_l",cx+10,yy+4,"FIB REJECTION",NEON_PURPLE,10,true);Tx("c_fib_dir",cx+10,yy+22,g_fibBestDir,fibC,16,true);
  3600. string confTxt="CONF: "+IntegerToString(g_fibConfidence)+"%";color confC=(g_fibConfidence>=70)?NEON_GREEN:(g_fibConfidence>=50)?NEON_YELLOW:CGR;Tx("c_fib_conf",cx+10,yy+46,confTxt,confC,11,true);
  3601. color patC=(g_fibPattern=="PIN"||g_fibPattern=="FAKE")?NEON_GOLD:(g_fibPattern=="ENGULF")?NEON_PURPLE:CGR;Tx("c_fib_pat",cx+10,yy+64,"PAT: "+g_fibPattern,patC,10,false);Tx("c_fib_lev",cx+10,yy+82,"FIB: "+g_fibFibLevel,NEON_CYAN,10,false);
  3602. double fibBarPct=MathMin(100,g_fibBestScore);color fibBarC=(g_fibBestDir=="CALL")?NEON_GREEN:(g_fibBestDir=="PUT")?NEON_RED:NEON_YELLOW;NeonBar("c_fib_b",cx+12,yy+104,CW-24,7,fibBarPct,fibBarC);
  3603. 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);
  3604. 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;}
  3605. 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]";
  3606. 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);
  3607. 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;
  3608.  
  3609. // ROW 5
  3610. int CH5=140;
  3611. if(ENABLE_MTG){
  3612. 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;
  3613. 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";
  3614. 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);
  3615. 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);
  3616. Tx("c_mtg_ct",cx+10,yy+43,"CALL: "+DoubleToString(g_mtgHype,1)+"%",NEON_GREEN,10,true);
  3617. 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);
  3618. Tx("c_mtg_pt",cx+10,yy+65,"PUT: "+DoubleToString(g_mtgBetrayal,1)+"%",NEON_RED,10,true);
  3619. 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;
  3620. 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);
  3621. } else {
  3622. 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);
  3623. }
  3624. 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);
  3625. Bx("c18",cx+2*(CW+G),yy,CW,CH5,BG_DARK2,NEON_CYAN);Tx("c18_l",cx+2*(CW+G)+10,yy+4,"ORDER BLOCK v3",NEON_CYAN,10,true);double obBullLow=0,obBearHigh=0;GetNearestOBs(obBullLow,obBearHigh);Tx("c18_r",cx+2*(CW+G)+10,yy+24,"R: "+(obBearHigh>0?ShortPrice(obBearHigh):"--"),NEON_RED,13,true);Tx("c18_s",cx+2*(CW+G)+10,yy+54,"S: "+(obBullLow>0?ShortPrice(obBullLow):"--"),NEON_GREEN,13,true);int activeOBs=0;for(int oi=0;oi<g_OB_Count;oi++)if(!g_OB[oi].broken)activeOBs++;Tx("c18_b",cx+2*(CW+G)+10,yy+86,"Zones: "+IntegerToString(activeOBs),NEON_GOLD,11,true);yy+=CH5+G;
  3626.  
  3627. // ROW 6
  3628. int CH6 = 120;
  3629. Bx("c15", cx, yy, CW, CH6, BG_DARK2, g_visualTrapPro.verdictColor);
  3630. Tx("c15_l", cx+10, yy+4, "VISUAL TRAP", NEON_PURPLE, 10, true);
  3631. Tx("c15_box", cx+10, yy+22, g_visualTrapPro.boxStatus, CGR, 10, true);
  3632. Tx("c15_gann", cx+10, yy+38, g_visualTrapPro.gannStatus, g_visualTrapPro.gannColor, 10, true);
  3633. Tx("c15_m30", cx+10, yy+54, g_visualTrapPro.m30Dir, (StringFind(g_visualTrapPro.m30Dir,"UP")>=0)?NEON_GREEN:NEON_RED, 10, true);
  3634. Tx("c15_m1", cx+10, yy+70, g_visualTrapPro.m1Seq, CGR, 9, false);
  3635. Tx("c15_v", cx+10, yy+88, g_visualTrapPro.verdict, g_visualTrapPro.verdictColor, 13, true);
  3636.  
  3637. Bx("c_ha", cx+CW+G, yy, CW, CH6, BG_DARK2, ha1C);
  3638. Tx("c_ha_l", cx+CW+G+10, yy+4, "HA CANDLES", NEON_CYAN, 10, true);
  3639. string haM1txt = g_haM1, haM5txt = g_haM5;
  3640. if(StringLen(haM1txt) > 16) haM1txt = StringSubstr(haM1txt, 3);
  3641. if(StringLen(haM5txt) > 16) haM5txt = StringSubstr(haM5txt, 3);
  3642. Tx("c_ha_m1", cx+CW+G+10, yy+24, "M1: "+haM1txt, ha1C, 11, true);
  3643. Tx("c_ha_m5", cx+CW+G+10, yy+50, "M5: "+haM5txt, ha5C, 11, true);
  3644. string haComb = "";
  3645. color haCombC = NEON_YELLOW;
  3646. if(g_haM1 == "HA BULLISH 1" && g_haM5 == "HA BULLISH 5") {
  3647. haComb = "BOTH BULL"; haCombC = NEON_GREEN;
  3648. } else if(g_haM1 == "HA BEARISH 1" && g_haM5 == "HA BEARISH 5") {
  3649. haComb = "BOTH BEAR"; haCombC = NEON_RED;
  3650. } else haComb = g_haBoth;
  3651. Tx("c_ha_c", cx+CW+G+10, yy+76, haComb, haCombC, 11, true);
  3652.  
  3653. // ----- NCP ANALYSIS CUBE (PROFESSIONAL v2 - NEUTRAL = NEON FLOWER) -----
  3654. int ncpW = CW;
  3655. int ncpH = CH6;
  3656. int ncpX = cx + 2*(CW+G);
  3657. int ncpY = yy;
  3658.  
  3659. string patternName = (g_ncpMainPattern != "") ? g_ncpMainPattern : "NO PATTERN";
  3660. int bullScore = g_ncpPatternBullScore;
  3661. int bearScore = g_ncpPatternBearScore;
  3662. int totalStrength = MathMax(bullScore, bearScore);
  3663. int strengthPct = MathMin(100, (int)(totalStrength * 1.25));
  3664.  
  3665. bool isBullish = (bullScore > bearScore + 5);
  3666. bool isBearish = (bearScore > bullScore + 5);
  3667. bool isNeutral = (!isBullish && !isBearish);
  3668.  
  3669. color borderColor, textColor, barColor;
  3670. string dirSymbol;
  3671.  
  3672. if(isBullish) {
  3673. borderColor = NEON_GREEN;
  3674. textColor = NEON_GREEN;
  3675. barColor = NEON_GREEN;
  3676. dirSymbol = "▲";
  3677. } else if(isBearish) {
  3678. borderColor = NEON_RED;
  3679. textColor = NEON_RED;
  3680. barColor = NEON_RED;
  3681. dirSymbol = "▼";
  3682. } else {
  3683. borderColor = NEON_PINK;
  3684. textColor = NEON_PINK;
  3685. barColor = NEON_PINK;
  3686. dirSymbol = "●";
  3687. }
  3688.  
  3689. Bx("c_reason", ncpX, ncpY, ncpW, ncpH, BG_DARK2, borderColor);
  3690. Tx("c_reason_l", ncpX+10, ncpY+4, "NCP ANALYSIS", NEON_CYAN, 10, true);
  3691.  
  3692. string patternLine = dirSymbol + " " + patternName + " [" + IntegerToString(strengthPct) + "%]";
  3693. Tx("c_reason_p", ncpX+10, ncpY+22, patternLine, textColor, 12, true);
  3694.  
  3695. int barMaxWidth = ncpW - 24;
  3696. int barWidth = (int)(strengthPct / 100.0 * barMaxWidth);
  3697. if(barWidth < 2) barWidth = 2;
  3698. if(barWidth > barMaxWidth) barWidth = barMaxWidth;
  3699.  
  3700. Bx("c_reason_bar_bg", ncpX+10, ncpY+44, barMaxWidth, 8, BG_DARK4, BG_DARK4);
  3701. Bx("c_reason_bar_fill", ncpX+10, ncpY+44, barWidth, 8, barColor, barColor);
  3702.  
  3703. string strengthText = "";
  3704. if(strengthPct >= 70) strengthText = "STRONG";
  3705. else if(strengthPct >= 45) strengthText = "MEDIUM";
  3706. else if(strengthPct >= 20) strengthText = "WEAK";
  3707. else strengthText = "NONE";
  3708. Tx("c_reason_strength", ncpX+10, ncpY+62, "Str: " + strengthText, textColor, 9, false);
  3709.  
  3710. double adx = g_ncpADX;
  3711. double pDI = g_ncpPlusDI;
  3712. double mDI = g_ncpMinusDI;
  3713. string dirStr = (pDI > mDI) ? "DI+:BULL" : "DI-:BEAR";
  3714. color adxColor = GetADXColor(adx, pDI, mDI);
  3715. Tx("c_reason_r", ncpX+10, ncpY+82, "ADX:" + DoubleToString(adx,0) + " " + dirStr, adxColor, 11, false);
  3716.  
  3717. string revReason = DetectSuddenReversal();
  3718. color revColor = CGR;
  3719. if(StringFind(revReason, "BULL") >= 0) revColor = NEON_GREEN;
  3720. if(StringFind(revReason, "BEAR") >= 0) revColor = NEON_RED;
  3721. Tx("c_reason_v", ncpX+10, ncpY+102, (StringLen(revReason) > 0 ? "REV: "+revReason : "NO REVERSAL"), revColor, 10, false);
  3722.  
  3723. yy += ncpH + G;
  3724.  
  3725. // BB Row
  3726. if(ENABLE_BB_PULLBACK) {
  3727. int bbRowH = 52;
  3728. color bbRowBorder = (g_bbSignal == "CALL") ? NEON_GREEN : (g_bbSignal == "PUT") ? NEON_RED : BB_GREY;
  3729. Bx("c_bb_row", cx, yy, W-2*G, bbRowH, BG_DARK3, bbRowBorder);
  3730.  
  3731. string ha30Str = IsM30HABull() ? "BULL" : (IsM30HABear() ? "BEAR" : "DOJI");
  3732. color ha30C2 = IsM30HABull() ? NEON_GREEN : (IsM30HABear() ? NEON_RED : NEON_YELLOW);
  3733. double adxD = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1);
  3734. double rsiD = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1);
  3735.  
  3736. Tx("c_bb_row_l", cx+10, yy+4, "BB("+IntegerToString(BB_PERIOD)+") PULLBACK", BB_GREY, 9, true);
  3737. Tx("c_bb_ha2", cx+190, yy+4, "HA30:"+ha30Str, ha30C2, 9, true);
  3738. Tx("c_bb_adx", cx+310, yy+4, "ADX:"+DoubleToString(adxD,0), (adxD>=20) ? NEON_LIME : CGR, 9, false);
  3739. Tx("c_bb_rsi", cx+390, yy+4, "RSI:"+DoubleToString(rsiD,0), (rsiD>=70 || rsiD<=30) ? NEON_RED : CGR, 9, false);
  3740.  
  3741. if(g_bbSignal != "--") {
  3742. string sigTxt = "BB "+g_bbSignal+" | "+g_bbDetail;
  3743. if(StringLen(sigTxt) > 60) sigTxt = StringSubstr(sigTxt, 0, 58) + "..";
  3744. Tx("c_bb_sig2", cx+10, yy+22, sigTxt, g_bbColor, 10, true);
  3745. } else {
  3746. Tx("c_bb_sig2", cx+10, yy+22, "Waiting for BB touch + 2+ confirmations...", CGR, 9, false);
  3747. }
  3748. yy += bbRowH + G;
  3749. }
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755. // BOTTOM FILTER STATUS
  3756. 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;
  3757. Bx("c_filter",cx,yy,fsW,22,BG_DARK3,fsC);Tx("c_filter_v",cx+10,yy+4,"FILTER: "+g_filterStatus,fsC,11,true);
  3758. HideSPM();ChartRedraw();
  3759. }
  3760.  
  3761. 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);}
  3762.  
  3763. 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";}}}
  3764.  
  3765. void FinalSignalEngine(double brain,int cp,int mts){
  3766. g_filterStatus="ALL CLEAR";
  3767. 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;}
  3768. 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;}
  3769. 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;}
  3770. 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;}
  3771. 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;}}
  3772. 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;}
  3773. bool reverseSignal=(g_accuracy<45.0&&g_acc_total>20);if(reverseSignal)g_filterStatus="REVERSE MODE";
  3774. string ms=DetectMyStrategy();
  3775. 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;}
  3776. 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";
  3777. 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";}
  3778. 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;}
  3779. if(TimeCurrent()-g_signalTime>HOLD_SEC||g_finalSignal=="WAIT")g_signalTime=TimeCurrent();
  3780. 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;
  3781. }
  3782.  
  3783. 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);}
  3784.  
  3785. void BroadcastSignal(){
  3786. string fn="OTC_Signals_Master.txt",pair=Symbol();
  3787. int exp=(int)(TimeCurrent()+65);int now=(int)TimeCurrent();
  3788. string content="";
  3789.  
  3790. int h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);
  3791. if(h==INVALID_HANDLE){h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);if(h==INVALID_HANDLE)return;}
  3792. while(!FileIsEnding(h)){string ex=FileReadString(h);if(StringLen(ex)>10&&StringFind(ex,pair+"|")!=0)content+=ex+"\n";}
  3793.  
  3794. // 1. Normal Pattern Signal
  3795. double conf1=MathMax(g_frozen_gProb,g_frozen_rProb);
  3796. if(conf1>=55){
  3797. string sig1=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";
  3798. content=pair+"|"+sig1+"|"+DoubleToString(conf1,0)+"|"+IntegerToString(now)+"|"+IntegerToString(exp)+"\n"+content;
  3799. }
  3800.  
  3801. // 2. NEXT CANDLE PREDICTOR SIGNAL (New Code)
  3802. if(g_otpSignal != "WAIT" && g_otpSignal != "" && g_otpConf >= 60){
  3803. string sig2 = (StringFind(g_otpSignal, "PUT") >= 0) ? "OTP_PUT" : "OTP_CALL";
  3804. content=pair+"|"+sig2+"|"+DoubleToString(g_otpConf,0)+"|"+IntegerToString(now)+"|"+IntegerToString(exp)+"\n"+content;
  3805. }
  3806.  
  3807. FileSeek(h,0,SEEK_SET);FileWriteString(h,content);FileFlush(h);FileClose(h);
  3808. }
  3809.  
  3810. 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);}
  3811.  
  3812. // FIX: Corrected undeclared 'cur' variable
  3813. void ScanSignals(){
  3814. g_pairCount=0;
  3815. string fn="OTC_Signals_Master.txt";
  3816. string cur=Symbol(); // FIX: Added string type
  3817. int h=FileOpen(fn,FILE_READ|FILE_TXT|FILE_SHARE_READ);
  3818. if(h==INVALID_HANDLE)return;
  3819. datetime now=TimeCurrent();
  3820. string tmpNames[8];string tmpSigs[8];double tmpConfs[8];int tmpScores[8];string tmpDetails[8];int tmpCount=0;
  3821. while(!FileIsEnding(h)&&tmpCount<8){
  3822. string ln=FileReadString(h);if(StringLen(ln)<15)continue;
  3823. int p1=StringFind(ln,"|"),p2=StringFind(ln,"|",p1+1),p3=StringFind(ln,"|",p2+1),p4=StringFind(ln,"|",p3+1);
  3824. if(p1<0||p2<0||p3<0||p4<0)continue;
  3825. string pair=StringSubstr(ln,0,p1);if(pair==cur)continue;
  3826. string sig=StringSubstr(ln,p1+1,p2-p1-1);
  3827. double conf=StringToDouble(StringSubstr(ln,p2+1,p3-p2-1));
  3828. int expTime=(int)StringToInteger(StringSubstr(ln,p4+1));
  3829. if(expTime<(int)(now-20)) continue;
  3830.  
  3831. // --- OTP SIGNAL HANDLER ---
  3832. bool isOtp = (StringFind(sig, "OTP_") == 0);
  3833. string pureSig = sig;
  3834. if(isOtp) {
  3835. pureSig = StringSubstr(sig, 4);
  3836. if(conf < 60) continue;
  3837. } else {
  3838. if(conf < 60) continue;
  3839. }
  3840.  
  3841. string qSig="WAIT",qDetail="";int qScore=CalcPairQuality(pair,qSig,qDetail);
  3842.  
  3843. if(isOtp) {
  3844. qScore = (int)conf;
  3845. sig = pureSig;
  3846. } else {
  3847. if(qSig!=pureSig) continue;
  3848. if(qScore<45) continue;
  3849. }
  3850.  
  3851. tmpNames[tmpCount]=pair;tmpSigs[tmpCount]=sig;tmpConfs[tmpCount]=conf;tmpScores[tmpCount]=qScore;tmpDetails[tmpCount]=qDetail;tmpCount++;
  3852. }
  3853. FileClose(h);
  3854. 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;}}}
  3855. 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];}
  3856. string curPred=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";int sameDir=0;double boostTotal=0;
  3857. for(int i=0;i<g_pairCount;i++){if(g_pairSigs[i]==curPred&&tmpScores[i]>=60){sameDir++;boostTotal+=tmpScores[i];}}
  3858. 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)+"%";}
  3859. }
  3860.  
  3861. 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);}
  3862.  
  3863. // ============================================================
  3864. // EVENT HANDLERS
  3865. // ============================================================
  3866. int OnInit(){
  3867. InitNW();NuclearDeleteAll();
  3868. g_hrn_price=0;g_hrn_brk_bars=0;g_hrn_scan_bar=0;g_hrn_score=0;g_hrn_confirmed_break=false;
  3869. g_nearest_res=0;g_nearest_sup=0;g_rj_cnt=0;g_pairCount=0;
  3870. g_marketMode="RANGE";g_prevMode="";g_last_freeze_bar=0;g_lastNotified="";
  3871. g_accuracy=ValidateHistoricalAccuracy();g_acc_correct=0;g_acc_total=0;g_acc_lastBar=0;
  3872. g_lastPredGreen=50.0;g_lastPredBar=0;g_lossStreak=0;g_tradingStopped=false;
  3873. g_strategyType="NONE";g_frozen_gProb=50;g_frozen_rProb=50;g_calc_gProb=50;g_calc_rProb=50;
  3874. g_commonCount=0;g_wickLineCount=0;g_tfa_detail="";g_htfLevelCount=0;g_mtfConfirmed=true;
  3875. g_filterStatus="ALL CLEAR";g_symbolKey="";g_brokerBias=0.0;
  3876. g_bbSignal="--";g_bbColor=NEON_YELLOW;g_bbTouchPrice=0.0;g_bbSignalTime=0;g_bbSignalBars=0;g_bbDetail="";g_bbLineCount=0;
  3877. 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;
  3878. g_smoothCallScore=50.0;g_smoothPutScore=50.0;g_callWeight=1.0;g_putWeight=1.0;
  3879. g_totalTrades=0;g_callTrades=0;g_putTrades=0;g_callWins=0;g_putWins=0;
  3880. g_ncpLastSignalTime=0;g_ncpLastSignalType="";g_ncpLastEntryPrice=0.0;g_ncpSignalProcessed=true;
  3881. g_ncpTrend.m15Direction="FLAT";g_ncpTrend.m15Strength=0;g_ncpTrend.aligned=false;
  3882. g_ncpSRCount=0;g_ncpDetailLine1="";g_ncpDetailLine2="";g_ncpDetailLine3="";
  3883. g_ncpPatternBullScore=0;g_ncpPatternBearScore=0;g_ncpMainPattern="";
  3884. g_stableResCount=0;g_stableSupCount=0;g_lastSRScan=0;
  3885. g_ha30_open=0;g_ha30_close=0;g_ha30_high=0;g_ha30_low=0;g_ha30_bar=0;
  3886. g_rsc=0; g_psycheScore=0; g_psycheDir="NONE"; g_psycheSignal="SCANNING"; g_psycheClr=CGR;
  3887.  
  3888. // OTC FIB v3.0 INIT
  3889. g_otcFibPrice = 0;
  3890. g_otcFibDir = "WAIT";
  3891. g_otcFibStrength = 0;
  3892. g_otcFibPattern = "--";
  3893. g_otcFibLevel = "--";
  3894. g_otcFibSignalTime = 0;
  3895. g_otcHasSignal = false;
  3896. DeleteOTCFibLine();
  3897.  
  3898. QuantumLoadLearning();
  3899. Print("Quantum v9.1 PRO | Weights loaded | TotalTrades:", g_qTotalTrades);
  3900.  
  3901. if(ENABLE_LEARNING)LoadBrainMemory();LoadMLWeights();EventSetTimer(1);
  3902. Print("===========================================");
  3903. Print("AIBRAIN v46.3 - NCP PRO v8.0 (ALL ERRORS FIXED)");
  3904. Print("Added: PSYCHE BREAKER v3.0 Cube");
  3905. Print("Replaced: MTF ANALYSIS with PSYCHE BREAKER");
  3906. Print("===========================================");
  3907. return INIT_SUCCEEDED;
  3908. }
  3909.  
  3910.  
  3911.  
  3912.  
  3913. string CheckPairOB(string pair) {
  3914. int bars = iBars(pair, PERIOD_M1); if(bars < 5) return "";
  3915. for(int i = 1; i <= 3; i++) {
  3916. double o1=iOpen(pair,PERIOD_M1,i+1), c1=iClose(pair,PERIOD_M1,i+1);
  3917. double o2=iOpen(pair,PERIOD_M1,i), c2=iClose(pair,PERIOD_M1,i);
  3918. if(o1==0||c1==0||o2==0||c2==0) continue;
  3919. if(c1<o1 && c2>o2 && MathAbs(c2-o2)>MathAbs(c1-o1)) return "BUY OB";
  3920. if(c1>o1 && c2<o2 && MathAbs(c2-o2)>MathAbs(c1-o1)) return "SELL OB";
  3921. }
  3922. return "";
  3923. }
  3924.  
  3925. void ScanBackgroundOBs() {
  3926. g_bgOB_Count = 0;
  3927. for(int i = 0; i < g_pairCount && i < 8; i++) {
  3928. string pair = g_pairNames[i];
  3929. if(pair == Symbol()) continue;
  3930. string obSig = CheckPairOB(pair);
  3931. if(obSig != "") {
  3932. g_bgOB_Pair[g_bgOB_Count] = pair;
  3933. g_bgOB_Signal[g_bgOB_Count] = obSig;
  3934. g_bgOB_Count++;
  3935. }
  3936. }
  3937. }
  3938.  
  3939. // ============================================================
  3940. // BACKGROUND PAIRS NEXT CANDLE CHECKER
  3941. // ============================================================
  3942. void CheckBackgroundNextCandleSignals(){
  3943. g_bgOtpCount = 0;
  3944. if(g_pairCount == 0) return;
  3945.  
  3946. for(int i=0; i<g_pairCount && i<8; i++){
  3947. string pair = g_pairNames[i];
  3948. if(pair == Symbol()) continue;
  3949.  
  3950. // ✅ FIX: PERIOD_M1 parameter add kiya sabhi functions mein
  3951. double o1 = iOpen(pair, PERIOD_M1, 1);
  3952. double c1 = iClose(pair, PERIOD_M1, 1);
  3953. double h1 = iHigh(pair, PERIOD_M1, 1);
  3954. double l1 = iLow(pair, PERIOD_M1, 1);
  3955.  
  3956. double o2 = iOpen(pair, PERIOD_M1, 2);
  3957. double c2 = iClose(pair, PERIOD_M1, 2);
  3958. double o3 = iOpen(pair, PERIOD_M1, 3);
  3959. double c3 = iClose(pair, PERIOD_M1, 3);
  3960.  
  3961. if(o1==0 || c1==0 || o2==0 || c3==0) continue;
  3962.  
  3963. // ✅ FIX: iRSI mein bhi PERIOD_M1 confirm
  3964. double rsi = iRSI(pair, PERIOD_M1, 14, PRICE_CLOSE, 1);
  3965. int score = 0;
  3966.  
  3967. double rng = h1 - l1;
  3968. if(rng > 0){
  3969. double uw = (h1 - MathMax(o1, c1)) / rng;
  3970. double lw = (MathMin(o1, c1) - l1) / rng;
  3971. if(uw > 0.65) score -= 15;
  3972. if(lw > 0.65) score += 15;
  3973. }
  3974.  
  3975. double body = MathAbs(c1 - o1), pBody = MathAbs(c2 - o2);
  3976. bool bull = (c1 > o1), bear = (c1 < o1);
  3977.  
  3978. if(bull && pBody < body && c1 >= o2 && o1 <= c2) score += 25;
  3979. if(bear && pBody < body && c1 <= o2 && o1 >= c2) score -= 25;
  3980.  
  3981. if(rng > 0 && (MathMin(o1,c1)-l1)/rng > 0.60 && body < rng*0.30 && bear) score += 20;
  3982. if(rng > 0 && (h1-MathMax(o1,c1))/rng > 0.60 && body < rng*0.30 && bull) score -= 20;
  3983.  
  3984. if(rsi < 30) score += 20; else if(rsi < 40) score += 10;
  3985. else if(rsi > 70) score -= 20; else if(rsi > 60) score -= 10;
  3986.  
  3987. if(c1>o1 && c2>o2 && c3>o3) score -= 10;
  3988. if(c1<o1 && c2<o2 && c3<o3) score += 10;
  3989.  
  3990. // ✅ FIXED LOGIC (MathAbs use kiya)
  3991. double absScore = MathAbs(score);
  3992. double conf = MathMax(5.0, MathMin(95.0, 50.0 + absScore));
  3993. string sig = "WAIT";
  3994.  
  3995. if(conf >= 72) sig = (score > 0) ? "CALL" : "PUT";
  3996. else if(conf >= 60) sig = (score > 0) ? "WEAK CALL" : "WEAK PUT";
  3997.  
  3998. if(sig != "WAIT"){
  3999. string sp = pair;
  4000. if(StringLen(sp) > 9) sp = StringSubstr(sp, 0, 9);
  4001. g_bgOtpSignal[g_bgOtpCount] = "* " + sp + " " + sig + " " + DoubleToString((int)conf, 0) + "%";
  4002. g_bgOtpCount++;
  4003. }
  4004. }
  4005. }
  4006.  
  4007.  
  4008.  
  4009. // ============================================================
  4010. // CHART CLEANER & DYNAMIC S/R SHIFT ENGINE
  4011. // ============================================================
  4012. void CleanChartAndShiftSR(){
  4013. // 1. REMOVE BLUE ZONE LINES (CALL ZONE / PUT ZONE)
  4014. for(int i = ObjectsTotal() - 1; i >= 0; i--){
  4015. string nm = ObjectName(i);
  4016. if(StringFind(nm, "CALL ZONE") >= 0 || StringFind(nm, "PUT ZONE") >= 0){
  4017. ObjectDelete(0, nm);
  4018. }
  4019. }
  4020.  
  4021. // 2. HIDE OLD S/R LINES (Keep only current top 2, but don't delete for background math)
  4022. int hiddenCount = 0;
  4023. for(int i = ObjectsTotal() - 1; i >= 0; i--){
  4024. string nm = ObjectName(i);
  4025. // Jo lines PFX (AIB9_) se start nahi hoti, unhe hide karo
  4026. if(StringFind(nm, PFX) < 0){
  4027. int objType = (int)ObjectGetInteger(0, nm, OBJPROP_TYPE);
  4028. if(objType == OBJ_HLINE){
  4029. if(hiddenCount > 4){ // Purani lines hide kar do
  4030. ObjectSetInteger(0, nm, OBJPROP_COLOR, clrNONE);
  4031. }
  4032. hiddenCount++;
  4033. }
  4034. }
  4035. }
  4036.  
  4037. // 3. DYNAMIC 1-MINUTE S/R SHIFT LOGIC (Ek Line Upar Neeche)
  4038. if(Bars < 10) return;
  4039.  
  4040. // Check all non-indicator HLines for closest match
  4041. double closestSR = 0;
  4042. bool isRes = false;
  4043. double minDist = 999999;
  4044.  
  4045. for(int i = ObjectsTotal() - 1; i >= 0; i--){
  4046. string nm = ObjectName(i);
  4047. if(StringFind(nm, PFX) >= 0) continue; // Apne indicator ke lines chhod do
  4048.  
  4049. int objType = (int)ObjectGetInteger(0, nm, OBJPROP_TYPE);
  4050. if(objType == OBJ_HLINE){
  4051. double linePrice = ObjectGetDouble(0, nm, OBJPROP_PRICE);
  4052. if(linePrice <= 0) continue;
  4053.  
  4054. bool jpy = (StringFind(Symbol(), "JPY") >= 0);
  4055. double pip = jpy ? 0.01 : 0.0001;
  4056. double dist = MathAbs(Close[0] - linePrice) / pip;
  4057.  
  4058. // Sabse paas wali line dhundho (15 pips ke andar)
  4059. if(dist < minDist && dist < 15){
  4060. minDist = dist;
  4061. closestSR = linePrice;
  4062. isRes = (linePrice > Close[0]); // Agar upar hai toh Resistance
  4063. }
  4064. }
  4065. }
  4066.  
  4067. // Agar koi line mile toh usko shift karo (Sirf ek line ko target banao)
  4068. if(closestSR > 0){
  4069. string shiftLineName = "DYN_SHIFT_SR";
  4070. SafeDel(shiftLineName);
  4071.  
  4072. // Agar candle Green hai toh line ko Resistance maan lo
  4073. // Agar candle Red hai toh line ko Support maan lo
  4074. bool treatAsRes = (Close[0] > Open[0]) ? true : isRes;
  4075.  
  4076. color shiftColor = treatAsRes ? C'255,80,80' : C'80,255,80'; // Faint Red/Green
  4077. ObjectCreate(0, shiftLineName, OBJ_HLINE, 0, 0, closestSR);
  4078. ObjectSetInteger(0, shiftLineName, OBJPROP_COLOR, shiftColor);
  4079. ObjectSetInteger(0, shiftLineName, OBJPROP_WIDTH, 2);
  4080. ObjectSetInteger(0, shiftLineName, OBJPROP_STYLE, STYLE_SOLID);
  4081. ObjectSetInteger(0, shiftLineName, OBJPROP_BACK, false);
  4082.  
  4083. // Label lagao (Premium Style - Bada aur Chamakdaar)
  4084. string lblName = "DYN_SHIFT_SR_LBL";
  4085. SafeDel(lblName);
  4086. string lblText = treatAsRes ? "RES" : "SUP";
  4087. if(Bars > 3){
  4088. ObjectCreate(0, lblName, OBJ_TEXT, 0, Time[3], closestSR);
  4089. color dynLabelColor = C'255,50,255'; // Neon Magenta (Aankhon mein padne wala chamak!)
  4090. ObjectSetText(lblName, lblText, 11, "Arial Bold", dynLabelColor);
  4091. ObjectSetInteger(0, lblName, OBJPROP_BACK, false);
  4092. }
  4093. }
  4094. }
  4095.  
  4096.  
  4097.  
  4098.  
  4099. 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);}}
  4100.  
  4101.  
  4102.  
  4103. void OnTimer(){
  4104. if(Bars<50)return;
  4105. RunOBEngine(); // ✅ Order Block Engine Run
  4106. CalcVisualTrapPro();CalcHA();UpdateHRN();UpdateStableM5SR();DetectCommonPoints();
  4107. DrawCommonPoints();
  4108. if(ENABLE_BB_PULLBACK)DetectBBPullback();
  4109. if(ENABLE_MTG)CalculateMTG();
  4110. CalculateQuantumEngine();
  4111. QuantumCheckResult();
  4112. CleanChartAndShiftSR();
  4113. int cp=0;double brain=BrainSc(cp);double nb=NeuralBiasFast();double mw=MicroWick();bool bf=IsBrokerForce();
  4114. double mai=CalcAdvancedMicroAI();int mts=CalcAdvancedMicroTrap();
  4115.  
  4116. CalcFibRejectionHunter();
  4117.  
  4118. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  4119. ScanSignals();CheckBackgroundNextCandleSignals();ScanBackgroundOBs();FinalSignalEngine(brain,cp,mts);BroadcastSignal();UpdateTimer();Draw();
  4120.  
  4121. DrawFibRejectionLine();
  4122. }
  4123.  
  4124.  
  4125.  
  4126. //+------------------------------------------------------------------+
  4127. // ORDER BLOCK v3 - MINIMAL CLEAN (ONLY LATEST 3, DOTTED ONLY)
  4128. //+------------------------------------------------------------------+
  4129. #define MAX_OB_OBS 5
  4130. #define MAX_OB_AGE 30
  4131.  
  4132. struct OB_Record {
  4133. int type;
  4134. double high;
  4135. double low;
  4136. datetime ob_time;
  4137. bool broken;
  4138. double quality;
  4139. string nm_rect;
  4140. string nm_mid;
  4141. string nm_lbl;
  4142. };
  4143.  
  4144. OB_Record g_OB[MAX_OB_OBS];
  4145. int g_OB_Count = 0;
  4146. string g_OB_prefix = "OBP3_";
  4147.  
  4148. input string OB_SECTION = "=== ORDER BLOCK v3 ===";
  4149. input int Inp_LookBack = 50;
  4150. input double Inp_TL_Tol = 1.2;
  4151. input int Inp_RectBars = 10;
  4152.  
  4153. bool OB_IsBull(int tf, int i) { return iClose(NULL,tf,i) > iOpen(NULL,tf,i); }
  4154. bool OB_IsBear(int tf, int i) { return iClose(NULL,tf,i) < iOpen(NULL,tf,i); }
  4155. double OB_BodyPts(int tf, int i) { return MathAbs(iClose(NULL,tf,i)-iOpen(NULL,tf,i))/Point; }
  4156. double OB_RangePts(int tf, int i){ return (iHigh(NULL,tf,i)-iLow(NULL,tf,i))/Point; }
  4157.  
  4158. bool OBExists(datetime t){ for(int i=0;i<g_OB_Count;i++) if(g_OB[i].ob_time==t) return true; return false; }
  4159.  
  4160. void OB_DrawRect(string nm, double hi, double lo, datetime t_from, color clr){
  4161. datetime t_to = t_from + PeriodSeconds(PERIOD_M1)*Inp_RectBars;
  4162. if(ObjectFind(0,nm)<0) ObjectCreate(0,nm,OBJ_RECTANGLE,0,t_from,hi,t_to,lo);
  4163. else { ObjectMove(0,nm,0,t_from,hi); ObjectMove(0,nm,1,t_to,lo); }
  4164. ObjectSetInteger(0,nm,OBJPROP_COLOR,clr);
  4165. ObjectSetInteger(0,nm,OBJPROP_FILL,false); // NO FILL - Sirf Dotted Border
  4166. ObjectSetInteger(0,nm,OBJPROP_BACK,false);
  4167. ObjectSetInteger(0,nm,OBJPROP_WIDTH,1);
  4168. ObjectSetInteger(0,nm,OBJPROP_STYLE,STYLE_DOT);
  4169. ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false);
  4170. }
  4171.  
  4172. void OB_DrawMidLine(string nm, double mid_price, datetime t_from, color clr){
  4173. datetime t_to = t_from + PeriodSeconds(PERIOD_M1)*Inp_RectBars;
  4174. if(ObjectFind(0,nm)<0) ObjectCreate(0,nm,OBJ_TREND,0,t_from,mid_price,t_to,mid_price);
  4175. else { ObjectMove(0,nm,0,t_from,mid_price); ObjectMove(0,nm,1,t_to,mid_price); }
  4176. ObjectSetInteger(0,nm,OBJPROP_COLOR,clr);
  4177. ObjectSetInteger(0,nm,OBJPROP_WIDTH,1);
  4178. ObjectSetInteger(0,nm,OBJPROP_STYLE,STYLE_DOT);
  4179. ObjectSetInteger(0,nm,OBJPROP_RAY_RIGHT,false);
  4180. ObjectSetInteger(0,nm,OBJPROP_BACK,false);
  4181. ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false);
  4182. }
  4183.  
  4184. void OB_DrawLabel(string nm, datetime t, double price, string txt, color clr){
  4185. if(ObjectFind(0,nm)<0){ ObjectCreate(0,nm,OBJ_TEXT,0,t,price);
  4186. ObjectSetString(0,nm,OBJPROP_TEXT,txt); ObjectSetInteger(0,nm,OBJPROP_COLOR,clr);
  4187. ObjectSetInteger(0,nm,OBJPROP_FONTSIZE,8); ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false); }
  4188. }
  4189.  
  4190. void RunOBEngine(){
  4191. static datetime lastOBBar = 0;
  4192. if(Time[0] == lastOBBar) return; // ✅ Sirf 1 baar per minute chalega, crash nahi hoga
  4193. lastOBBar = Time[0];
  4194. // 1. Scan Major Swing Breaks Only
  4195. if(g_OB_Count < MAX_OB_OBS){
  4196. int max_i = MathMin(Inp_LookBack, iBars(NULL,PERIOD_M1)-5);
  4197. for(int i=3; i<max_i; i++){
  4198. bool isSwingHigh = (High[i] >= High[i-1] && High[i] >= High[i-2] && High[i] >= High[i+1] && High[i] >= High[i+2]);
  4199. if(isSwingHigh){
  4200. for(int b=i-1; b>=1; b--){
  4201. if(Close[b] > High[i]){
  4202. datetime m1_ob_time = iTime(NULL,PERIOD_M1,i);
  4203. if(!OBExists(m1_ob_time)){
  4204. string uid = IntegerToString((int)m1_ob_time) + "-1";
  4205. g_OB[g_OB_Count].type = -1; g_OB[g_OB_Count].high = High[i]; g_OB[g_OB_Count].low = Low[i];
  4206. g_OB[g_OB_Count].ob_time = m1_ob_time; g_OB[g_OB_Count].broken = false; g_OB[g_OB_Count].quality = 75;
  4207. g_OB[g_OB_Count].nm_rect = g_OB_prefix+"R_"+uid; g_OB[g_OB_Count].nm_mid = g_OB_prefix+"M_"+uid;
  4208. g_OB[g_OB_Count].nm_lbl = g_OB_prefix+"L_"+uid;
  4209. g_OB_Count++;
  4210. }
  4211. break;
  4212. }
  4213. }
  4214. }
  4215. bool isSwingLow = (Low[i] <= Low[i-1] && Low[i] <= Low[i-2] && Low[i] <= Low[i+1] && Low[i] <= Low[i+2]);
  4216. if(isSwingLow){
  4217. for(int b=i-1; b>=1; b--){
  4218. if(Close[b] < Low[i]){
  4219. datetime m1_ob_time = iTime(NULL,PERIOD_M1,i);
  4220. if(!OBExists(m1_ob_time)){
  4221. string uid = IntegerToString((int)m1_ob_time) + "1";
  4222. g_OB[g_OB_Count].type = 1; g_OB[g_OB_Count].high = High[i]; g_OB[g_OB_Count].low = Low[i];
  4223. g_OB[g_OB_Count].ob_time = m1_ob_time; g_OB[g_OB_Count].broken = false; g_OB[g_OB_Count].quality = 75;
  4224. g_OB[g_OB_Count].nm_rect = g_OB_prefix+"R_"+uid; g_OB[g_OB_Count].nm_mid = g_OB_prefix+"M_"+uid;
  4225. g_OB[g_OB_Count].nm_lbl = g_OB_prefix+"L_"+uid;
  4226. g_OB_Count++;
  4227. }
  4228. break;
  4229. }
  4230. }
  4231. }
  4232. }
  4233. }
  4234.  
  4235. // 2. Check Breaks & Draw
  4236. double price = iClose(NULL,PERIOD_M1,0);
  4237. for(int i=0; i<g_OB_Count; i++){
  4238. if(g_OB[i].type == -1 && price > g_OB[i].high) g_OB[i].broken = true;
  4239. if(g_OB[i].type == 1 && price < g_OB[i].low) g_OB[i].broken = true;
  4240.  
  4241. if(g_OB[i].broken){
  4242. ObjectDelete(0, g_OB[i].nm_rect); ObjectDelete(0, g_OB[i].nm_mid); ObjectDelete(0, g_OB[i].nm_lbl);
  4243. continue;
  4244. }
  4245.  
  4246. color rect_clr = (g_OB[i].type==1) ? C'0,220,100' : C'255,50,80'; // Green or Red Dotted
  4247. OB_DrawRect(g_OB[i].nm_rect, g_OB[i].high, g_OB[i].low, g_OB[i].ob_time, rect_clr);
  4248. OB_DrawMidLine(g_OB[i].nm_mid, (g_OB[i].high+g_OB[i].low)/2.0, g_OB[i].ob_time, C'120,120,120');
  4249.  
  4250. string dir_txt = (g_OB[i].type==1) ? "▲ BUY OB" : "▼ SELL OB";
  4251. color lbl_clr = (g_OB[i].type==1) ? clrLime : clrTomato;
  4252. OB_DrawLabel(g_OB[i].nm_lbl, g_OB[i].ob_time, g_OB[i].high + 3*Point, dir_txt, lbl_clr);
  4253. }
  4254.  
  4255. // 3. Cleanup Old & Broken (Auto Delete)
  4256. for(int i=g_OB_Count-1; i>=0; i--){
  4257. int age = iBarShift(NULL,PERIOD_M1,g_OB[i].ob_time); if(age<0) age=999;
  4258. if(g_OB[i].broken || age > MAX_OB_AGE){
  4259. ObjectDelete(0, g_OB[i].nm_rect); ObjectDelete(0, g_OB[i].nm_mid); ObjectDelete(0, g_OB[i].nm_lbl);
  4260. for(int j=i; j<g_OB_Count-1; j++) g_OB[j] = g_OB[j+1];
  4261. g_OB_Count--;
  4262. }
  4263. }
  4264. }
  4265.  
  4266. void GetNearestOBs(double &bullLow, double &bearHigh){
  4267. bullLow = 0; bearHigh = 0; double cur = Close[0]; double minDistB = 99999, minDistR = 99999;
  4268. for(int i=0; i<g_OB_Count; i++){
  4269. if(g_OB[i].broken) continue;
  4270. if(g_OB[i].type == 1 && g_OB[i].low < cur){ double d = cur - g_OB[i].low; if(d < minDistB){ minDistB = d; bullLow = g_OB[i].low; } }
  4271. if(g_OB[i].type == -1 && g_OB[i].high > cur){ double d = g_OB[i].high - cur; if(d < minDistR){ minDistR = d; bearHigh = g_OB[i].high; } }
  4272. }
  4273. }
  4274.  
  4275.  
  4276. 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);}
  4277. //+------------------------------------------------------------------+