dumpykhan970

Untitled 1316

Apr 14th, 2026
6
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
None 107.63 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| AIBRAIN OTC v45.0 - ULTIMATE ADVANCED (MQL4 COMPATIBLE) |
  3. //| Features: Advanced TFA, Micro AI, ScanFilters, No Footer |
  4. //+------------------------------------------------------------------+
  5. #property copyright "AIBRAIN ULTIMATE - KM RANA"
  6. #property version "45.0"
  7. #property strict
  8. #property indicator_chart_window
  9.  
  10. #define PFX "AIB9_"
  11. #define VER "v45.0 ULTIMATE"
  12. #define LB 18
  13. #define MAX_LEVELS 5
  14. #define MAX_REJ 50
  15. #define LOOKBACK 20
  16.  
  17. // --- INPUTS ---
  18. input string SPM_FILE = "KM RANA";
  19. input int HOLD_SEC = 60;
  20. input int POS_X = 4;
  21. input int POS_Y = 20;
  22. input int DASH_W = 650;
  23. input bool SHOW_TIMER = true;
  24. input bool SHOW_SR_LINES = true;
  25. input string ENTRY_MODE = "TIME";
  26. input int FLAG_MIN_SEC = 10;
  27. input int FLAG_MAX_SEC = 35;
  28. input int TIME_MIN_SEC = 10;
  29. input int TIME_MAX_SEC = 35;
  30. input int MIN_REMAINING_SEC = 15;
  31. input double REVERSAL_PCT = 30.0;
  32. input double WICK_PCT = 0.65;
  33. input int HRN_CONFIRM_BARS = 2;
  34. input bool HA_ALIGN_FILTER = false;
  35. input bool CONSENSUS_FILTER = false;
  36. input bool ENABLE_NOTIFY = false; // Sound/popup band
  37. input bool FAST_MODE = false;
  38. input int BROKER_SPREAD_THRESHOLD= 6;
  39. input double OTC_TRAP_WEIGHT = 15.0;
  40. input int CROWD_EXTREME_PCT = 70;
  41. input bool ENABLE_BROKER_KILLER = true;
  42. input bool ENABLE_SESSION_FILTER = true;
  43. input bool ENABLE_SPIKE_FILTER = true;
  44. input bool ENABLE_LAST_SEC_BLOCK = true;
  45. input bool ENABLE_RISK_CONTROL = true;
  46. input bool ENABLE_ENTRY_ZONE = true;
  47. input bool ML_ADAPTIVE = true;
  48. input bool VOLUME_PROFILE_TRAP = true;
  49. input bool MTF_CONFIRM = false;
  50. input bool ENABLE_TELEGRAM = false;
  51. input string TELEGRAM_TOKEN = "";
  52. input string TELEGRAM_CHAT_ID = "";
  53. input string TRADE_MODE = "NORMAL";
  54. input string STRATEGY_MODE = "TRAP_ONLY";
  55. input int STRATEGY_THRESHOLD = 75;
  56. input int MAX_LOSS_STREAK = 2;
  57. input double MIN_CONFIDENCE = 75.0;
  58. input bool ENABLE_RISK_LOCK = true;
  59. input double PATTERN_TOLERANCE_PIPS = 8.0;
  60. input int MIN_PATTERN_SEPARATION = 5;
  61. input bool SHOW_COMMON_POINTS = true;
  62. input double COMMON_POINT_TOL_PIPS = 15.0;
  63. input bool SHOW_WICK_REJECT_LINES = true;
  64. input int WICK_MIN_TOUCHES = 1;
  65. input double WICK_ZONE_PIPS = 15.0;
  66. input int WICK_EXPIRE_BARS = 60;
  67.  
  68. // --- COLORS ---
  69. #define NEON_GREEN C'0,255,100'
  70. #define NEON_RED C'255,40,80'
  71. #define NEON_YELLOW C'255,220,0'
  72. #define NEON_ORANGE C'255,120,0'
  73. #define NEON_CYAN C'0,255,200'
  74. #define NEON_PURPLE C'200,0,255'
  75. #define NEON_PINK C'255,80,180'
  76. #define NEON_BLUE C'0,200,255'
  77. #define NEON_LIME C'80,255,80'
  78. #define NEON_GOLD C'255,180,0'
  79. #define DARK_BLUE_NEON C'0,100,255'
  80. #define NEON_WHITE C'220,230,255'
  81. #define CGR C'160,170,190'
  82. #define BG_DARK1 C'6,8,16'
  83. #define BG_DARK2 C'10,14,24'
  84. #define BG_DARK3 C'14,20,32'
  85. #define BG_DARK4 C'18,26,40'
  86.  
  87. struct HTFLevel{ double price; string timeframe; string type; datetime time; int strength; bool isRoundNumber; };
  88.  
  89. // --- GLOBALS ---
  90. string g_haM1="",g_haM5="",g_haBoth="";
  91. color g_haM1Color=clrGray,g_haM5Color=clrGray;
  92. static double NW[36];
  93. static double g_rsc=0,g_tfa=3;
  94. static datetime g_spm_t=0,g_last_bar=0;
  95. double ResLevels[MAX_LEVELS],SupLevels[MAX_LEVELS];
  96. int resCount=0,supCount=0;
  97. datetime lastSRBar=0;
  98. static double g_nearest_res=0,g_nearest_sup=0;
  99. static string g_brk_str="NO BRK";
  100. static color g_brk_color=CGR;
  101. struct RejLevel{double price;int touches;};
  102. static RejLevel g_rj[MAX_REJ];
  103. static int g_rj_cnt=0;
  104. static double g_hrn_price=0;
  105. static bool g_hrn_is_sup=true;
  106. static int g_hrn_brk_bars=0;
  107. static datetime g_hrn_scan_bar=0;
  108. static string g_hrn_str="--";
  109. static int g_otcCallPct=50,g_otcPutPct=50;
  110. static string g_pairNames[5],g_pairSigs[5];
  111. static double g_pairConfs[5];
  112. static int g_pairCount=0;
  113. static string g_copiedPair="";
  114. static string g_adv1="WAIT KAR",g_adv2="Signals mix",g_adv3="";
  115. static color g_advC=NEON_YELLOW;
  116. static double g_frozen_gProb=50,g_frozen_rProb=50;
  117. static string g_frozen_pAction="UNCERTAIN";
  118. static color g_frozen_pColor=NEON_YELLOW;
  119. static double g_calc_gProb=50,g_calc_rProb=50;
  120. static string g_calc_pAction="UNCERTAIN";
  121. static color g_calc_pColor=NEON_YELLOW;
  122. static double g_gProb=50,g_rProb=50;
  123. static string g_pAction="UNCERTAIN";
  124. static color g_pColor=NEON_YELLOW;
  125. static datetime g_last_freeze_bar=0;
  126. static double g_accuracy=65.0;
  127. static int g_acc_correct=0,g_acc_total=0;
  128. static datetime g_acc_lastBar=0;
  129. static double g_lastPredGreen=50.0;
  130. static datetime g_lastPredBar=0;
  131. static datetime g_lastLogBar=0;
  132. static string g_finalSignal="WAIT";
  133. static color g_finalColor=NEON_YELLOW;
  134. static datetime g_signalTime=0;
  135. static string g_lastNotified="";
  136. static string g_marketMode="RANGE",g_prevMode="";
  137. static int g_lossStreak=0;
  138. static bool g_tradingStopped=false;
  139. static datetime g_stopStartTime=0;
  140. static double g_brokerBias=0.0;
  141. static string g_symbolKey="";
  142. static string g_strategyType="NONE";
  143. static string g_strategySignal="WAIT";
  144. static string g_strategyReason="";
  145. static double qmrA=0,qmrB=0,qmrC=0,qmrD=0;
  146. static datetime qmrTA=0,qmrTB=0,qmrTC=0,qmrTD=0;
  147. static bool qmrActive=false;
  148. static datetime qmrExpire=0;
  149. #define MAX_COMMON_PTS 5
  150. static double g_commonPrice[MAX_COMMON_PTS];
  151. static datetime g_commonTime[MAX_COMMON_PTS];
  152. static int g_commonCount=0;
  153. static datetime g_commonExpire[MAX_COMMON_PTS];
  154. static string g_commonType[MAX_COMMON_PTS];
  155. static datetime g_lastCommonScan=0;
  156. #define MAX_WICK_LINES 5
  157. static double g_wickLinePrice[MAX_WICK_LINES];
  158. static int g_wickLineTouches[MAX_WICK_LINES];
  159. static datetime g_wickLineExpire[MAX_WICK_LINES];
  160. static int g_wickLineCount=0;
  161. static datetime g_lastWickScan=0;
  162. static bool g_isSideways=false;
  163. static string g_tfa_detail="";
  164. static HTFLevel g_htfLevels[50];
  165. static int g_htfLevelCount=0;
  166. static datetime g_lastLevelScan=0;
  167. static bool g_mtfConfirmed=true;
  168. static string g_filterStatus="ALL CLEAR";
  169.  
  170. // --- CUSTOM TANH FUNCTION ---
  171. double Tanh(double x){
  172. double exp2x = MathExp(2.0 * x);
  173. return (exp2x - 1.0) / (exp2x + 1.0);
  174. }
  175.  
  176. // --- ADVANCED TFA (Kalman + Fractal + Trap + Adaptive) ---
  177. double CalcFractalDimension(int period){
  178. if(period<2) return 1.5;
  179. double sum=0;
  180. for(int i=1;i<period;i++){
  181. double r1=High[i]-Low[i];
  182. double r2=High[i+1]-Low[i+1];
  183. if(r1<=0||r2<=0) continue;
  184. sum+=MathLog(r1/r2+0.001)*MathLog((double)i/period);
  185. }
  186. double res=2.0-sum/period;
  187. return MathMin(2.0,MathMax(1.0,res));
  188. }
  189.  
  190. double DetectBrokerTrap(int lookback){
  191. int bull=0,bear=0;
  192. for(int i=1;i<=lookback;i++){
  193. if(Close[i]>Open[i]) bull++;
  194. else if(Close[i]<Open[i]) bear++;
  195. }
  196. double crowd=(bull>bear)?(double)bull/lookback:(double)bear/lookback;
  197. double move=MathAbs(Close[1]-Close[lookback])/(Close[lookback]+0.00001);
  198. if(crowd>0.7 && move<0.002) return 0.9;
  199. if(crowd>0.6 && move>0.001) return 0.5;
  200. return 0.3;
  201. }
  202.  
  203. double QuickMedian(double &arr[],int size){
  204. double tmp[20];
  205. for(int i=0;i<size;i++) tmp[i]=arr[i];
  206. for(int i=0;i<size-1;i++)
  207. for(int j=i+1;j<size;j++)
  208. if(tmp[i]>tmp[j]){ double t=tmp[i]; tmp[i]=tmp[j]; tmp[j]=t; }
  209. return (tmp[size/2]+tmp[(size-1)/2])/2.0;
  210. }
  211.  
  212. double CalcAdvancedTFA(string &detail){
  213. if(Bars<50){ detail="Low bars"; return 3.0; }
  214. static double prevScore=3.0, kalmanState=3.0, kalmanCovar=1.0;
  215. static datetime lastBarTime=0;
  216. static double scoreHistory[15];
  217. static int histIdx=0;
  218. if(scoreHistory[0]==0.0) for(int i=0;i<15;i++) scoreHistory[i]=3.0;
  219. if(Time[0]==lastBarTime){ detail="Smooth"; return prevScore; }
  220. lastBarTime=Time[0];
  221.  
  222. double comp[8], w[8];
  223. // ADX+Fractal
  224. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);
  225. double fd=CalcFractalDimension(10);
  226. comp[0]=1.0/(1.0+MathExp(-(adx*fd-18.0)/6.0));
  227. w[0]=0.14+fd*0.06;
  228. // Volume
  229. double v1=iVolume(NULL,PERIOD_M1,1), vA=0;
  230. for(int i=2;i<=15;i++) vA+=iVolume(NULL,PERIOD_M1,i);
  231. vA=(vA>0)?vA/14.0:1;
  232. double vr=MathMin(v1/vA,5.0);
  233. double volSpike=Tanh((vr-1.2)*0.8);
  234. comp[1]=(volSpike+1.0)/2.0;
  235. w[1]=0.12+(vr>2.0?0.08:0);
  236. // RSI+Stoch
  237. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  238. double stochK=iStochastic(NULL,PERIOD_M1,5,3,3,MODE_SMA,0,MODE_MAIN,1);
  239. double rsiDev=MathAbs(rsi-50)/50;
  240. double stochDev=MathAbs(stochK-50)/50;
  241. comp[2]=MathMin(1.0,(rsiDev+stochDev)*1.2);
  242. w[2]=0.10+rsiDev*0.1;
  243. // ATR+VolRegime
  244. double atr=iATR(NULL,PERIOD_M1,14,1);
  245. double atr14ago=iATR(NULL,PERIOD_M1,14,15);
  246. double volReg=(atr14ago>0)?atr/atr14ago:1.0;
  247. double cs=High[1]-Low[1];
  248. double atrRatio=cs/(atr+0.00001);
  249. double atrNorm=Tanh((atrRatio*volReg-1.2)*1.5);
  250. comp[3]=(atrNorm+1.0)/2.0;
  251. w[3]=0.11*MathMin(1.5,volReg);
  252. // Body+Shadow
  253. double body=MathAbs(Close[1]-Open[1]);
  254. double rg=High[1]-Low[1];
  255. double us=High[1]-MathMax(Open[1],Close[1]);
  256. double ls=MathMin(Open[1],Close[1])-Low[1];
  257. double br=(rg>0)?body/rg:0;
  258. double sp=1.0-(us+ls)/(rg+0.00001)*0.5;
  259. comp[4]=MathPow(br,0.7)*sp;
  260. w[4]=0.11;
  261. // Session
  262. comp[5]=IsSessionActive()?0.85:0.4;
  263. w[5]=0.08;
  264. // Trap
  265. double trap=DetectBrokerTrap(20);
  266. double mw=MicroWick();
  267. if(mw>0.65) trap=MathMax(trap,0.7);
  268. comp[6]=trap;
  269. w[6]=0.14*(0.5+trap);
  270. // MACD Divergence
  271. double macdM=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
  272. double macdS=iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
  273. double pc=(Close[1]-Close[5])/(Close[5]+0.00001);
  274. double div=MathAbs(macdM-macdS)*MathAbs(pc)*100;
  275. comp[7]=MathMin(1.0,div);
  276. w[7]=0.07;
  277. // normalize weights
  278. double wSum=0; for(int i=0;i<8;i++) wSum+=w[i];
  279. if(wSum>0) for(int i=0;i<8;i++) w[i]/=wSum;
  280. // Directional scoring
  281. double call=0, put=0;
  282. double pDI=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_PLUSDI,1);
  283. double mDI=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MINUSDI,1);
  284. double diBias=Tanh((pDI-mDI)/25.0);
  285. for(int i=0;i<8;i++){
  286. double contrib=comp[i]*w[i];
  287. if(i==6){
  288. if(comp[6]>0.65) contrib*=-diBias;
  289. else contrib*=diBias;
  290. } else contrib*=diBias;
  291. if(contrib>0) call+=contrib;
  292. else put+=-contrib;
  293. }
  294. // Heiken Ashi
  295. double haC=(Open[1]+High[1]+Low[1]+Close[1])/4.0;
  296. double haO=(Open[2]+Close[2])/2.0;
  297. double haChange=(haC-haO)/(High[1]-Low[1]+0.0001);
  298. double haBias=Tanh(haChange*2.5);
  299. if(haBias>0) call+=0.1*haBias;
  300. else put+=0.1*(-haBias);
  301. double raw=MathMax(call,put)*6.0;
  302. raw=MathMin(6.0,MathMax(0.0,raw));
  303. // Kalman + Median
  304. double R=0.5+(atr/Close[0])*200;
  305. double Q=0.05*(1.0+MathAbs(diBias)*0.5);
  306. double pred=kalmanState;
  307. double predCov=kalmanCovar+Q;
  308. double K=predCov/(predCov+R+0.00001);
  309. double kal=pred+K*(raw-pred);
  310. kalmanCovar=(1-K)*predCov;
  311. kalmanState=kal;
  312. scoreHistory[histIdx]=kal;
  313. histIdx=(histIdx+1)%15;
  314. double median=QuickMedian(scoreHistory,15);
  315. double final=0.65*kal+0.25*median+0.10*raw;
  316. final=MathMax(0.5,MathMin(6.0,final));
  317. bool isCall=(call>put);
  318. detail=StringFormat("ADX:%.2f VOL:%.2f RSI:%.2f ATR:%.2f BODY:%.2f TRAP:%.2f %s %.1f/6",comp[0],comp[1],comp[2],comp[3],comp[4],comp[6],(isCall?"CALL":"PUT"),final);
  319. g_tfa_detail=detail;
  320. prevScore=final;
  321. return final;
  322. }
  323.  
  324. // --- ADVANCED MICRO AI (Order flow + Micro trap + Volume profile) ---
  325. double CalcAdvancedMicroAI(){
  326. if(Bars<30) return 50.0;
  327. // Fractal energy
  328. double fracEnergy=0;
  329. for(int i=1;i<=10;i++){
  330. double r1=High[i]-Low[i];
  331. double r2=High[i+1]-Low[i+1];
  332. if(r1>0&&r2>0) fracEnergy+=MathLog(r1/r2+0.001);
  333. }
  334. fracEnergy=MathMin(1.0,MathMax(0.0,(fracEnergy+5.0)/10.0));
  335. // Wick score
  336. double wickScore=0, tw=0;
  337. for(int i=1;i<=5;i++){
  338. double r=High[i]-Low[i]; if(r<=0) continue;
  339. double uw=(High[i]-MathMax(Open[i],Close[i]))/r;
  340. double lw=(MathMin(Open[i],Close[i])-Low[i])/r;
  341. double w=(6.0-i)/5.0;
  342. if(uw>0.60) wickScore-=w*20;
  343. if(lw>0.60) wickScore+=w*20;
  344. if(uw>0.75) wickScore-=w*10;
  345. if(lw>0.75) wickScore+=w*10;
  346. tw+=w;
  347. }
  348. if(tw>0) wickScore/=tw;
  349. // Order flow
  350. double buyVol=0,sellVol=0;
  351. for(int i=1;i<=10;i++){
  352. double rg=High[i]-Low[i]; if(rg<=0) continue;
  353. double bF=(Close[i]-Low[i])/rg;
  354. buyVol+=bF*Volume[i];
  355. sellVol+=(1.0-bF)*Volume[i];
  356. }
  357. double flowImb=(buyVol-sellVol)/(buyVol+sellVol+0.00001);
  358. double flowScore=flowImb*25.0;
  359. // Micro trap
  360. double mw=MicroWick();
  361. double v1=iVolume(NULL,PERIOD_M1,1), vA=0;
  362. for(int i=2;i<=6;i++) vA+=iVolume(NULL,PERIOD_M1,i);
  363. vA=(vA>0)?vA/5.0:1;
  364. double vr=(vA>0)?v1/vA:1;
  365. double rsi1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  366. double trapScore=0;
  367. if(mw>0.65 && vr>1.8 && (rsi1>70||rsi1<30)) trapScore=-35;
  368. else if(mw>0.55 && vr>1.5) trapScore=-20;
  369. else if(mw>0.70) trapScore=-15;
  370. // Volume profile imbalance
  371. double volProf=0;
  372. double cur=Close[0];
  373. double hi50=High[iHighest(NULL,0,MODE_HIGH,50,1)];
  374. double lo50=Low[iLowest(NULL,0,MODE_LOW,50,1)];
  375. if(hi50>lo50){
  376. int zone=(int)((cur-lo50)/(hi50-lo50+0.00001)*10);
  377. if(zone>=0 && zone<=9){
  378. double zoneVol=0, zoneCnt=0;
  379. for(int i=1;i<=20;i++){
  380. double p=Close[i];
  381. int z=(int)((p-lo50)/(hi50-lo50+0.00001)*10);
  382. if(z==zone){ zoneVol+=Volume[i]; zoneCnt++; }
  383. }
  384. if(zoneCnt>0){
  385. double avgZone=zoneVol/zoneCnt;
  386. double currVol=Volume[1];
  387. if(currVol>avgZone*1.5){
  388. if(Close[1]>Open[1]) volProf=12; else volProf=-12;
  389. }
  390. }
  391. }
  392. }
  393. // RSI + Stoch
  394. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  395. double stochK=iStochastic(NULL,PERIOD_M1,5,3,3,MODE_SMA,0,MODE_MAIN,1);
  396. double rsiScore=0;
  397. if(rsi<30) rsiScore=12; else if(rsi>70) rsiScore=-12; else if(rsi<40) rsiScore=5; else if(rsi>60) rsiScore=-5;
  398. double stochScore=0;
  399. if(stochK<20) stochScore=8; else if(stochK>80) stochScore=-8;
  400. // Adaptive weights
  401. double w_wick=0.20+fracEnergy*0.20;
  402. double w_flow=0.20+(1.0-fracEnergy)*0.15;
  403. double w_trap=0.20+fracEnergy*0.25;
  404. double w_vprof=0.15;
  405. double w_rsi=0.15+(1.0-fracEnergy)*0.10;
  406. double w_stoch=0.10;
  407. double tot=w_wick+w_flow+w_trap+w_vprof+w_rsi+w_stoch;
  408. w_wick/=tot; w_flow/=tot; w_trap/=tot; w_vprof/=tot; w_rsi/=tot; w_stoch/=tot;
  409. double finalScore=50.0;
  410. finalScore+=w_wick*wickScore + w_flow*flowScore + w_trap*trapScore + w_vprof*volProf + w_rsi*rsiScore + w_stoch*stochScore;
  411. return MathMax(5.0,MathMin(95.0,finalScore));
  412. }
  413.  
  414. // --- HA CANDLE CALCULATION (unchanged) ---
  415. void CalcHA(){
  416. if(Bars<10) return;
  417. ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true); ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true);
  418. static double haO1[500],haC1[500]; static datetime lb1=0;
  419. ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true);
  420. datetime c1=iTime(NULL,PERIOD_M1,0);
  421. if(c1!=lb1){ lb1=c1; int lim=MathMin(iBars(NULL,PERIOD_M1),500);
  422. for(int i=lim-1;i>=0;i--){ haC1[i]=(Open[i]+High[i]+Low[i]+Close[i])/4.0;
  423. if(i==lim-1) haO1[i]=(Open[i]+Close[i])/2.0; else haO1[i]=(haO1[i+1]+haC1[i+1])/2.0; }}
  424. double d1=MathAbs(haC1[1]-haO1[1]),r1=High[1]-Low[1];
  425. bool dz=(r1>0&&d1<r1*0.1),b1=(!dz&&haC1[1]>haO1[1]),be1=(!dz&&haC1[1]<haO1[1]);
  426. if(b1){g_haM1="HA BULLISH 1";g_haM1Color=clrLime;}
  427. else if(be1){g_haM1="HA BEARISH 1";g_haM1Color=clrRed;}
  428. else{g_haM1="HA DOJI 1";g_haM1Color=clrYellow;}
  429. if(iBars(NULL,PERIOD_M5)>=10){
  430. static double haO5[200],haC5[200]; static datetime lb5=0;
  431. ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true);
  432. datetime c5=iTime(NULL,PERIOD_M5,0);
  433. if(c5!=lb5){ lb5=c5; int lim=MathMin(iBars(NULL,PERIOD_M5),200);
  434. for(int i=lim-1;i>=0;i--){ double o=iOpen(NULL,PERIOD_M5,i),h=iHigh(NULL,PERIOD_M5,i),l=iLow(NULL,PERIOD_M5,i),c=iClose(NULL,PERIOD_M5,i);
  435. haC5[i]=(o+h+l+c)/4.0; if(i==lim-1) haO5[i]=(o+c)/2.0; else haO5[i]=(haO5[i+1]+haC5[i+1])/2.0; }}
  436. double d5=MathAbs(haC5[1]-haO5[1]),r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1);
  437. bool dz5=(r5>0&&d5<r5*0.1),b5=(!dz5&&haC5[1]>haO5[1]),be5=(!dz5&&haC5[1]<haO5[1]);
  438. if(b5){g_haM5="HA BULLISH 5";g_haM5Color=clrLime;}
  439. else if(be5){g_haM5="HA BEARISH 5";g_haM5Color=clrRed;}
  440. else{g_haM5="HA DOJI 5";g_haM5Color=clrYellow;}
  441. if(b1&&b5)g_haBoth="BOTH BULL"; else if(be1&&be5)g_haBoth="BOTH BEAR"; else g_haBoth="MIXED";
  442. }else{g_haM5="5 --";g_haM5Color=clrGray;g_haBoth="HA --";}
  443. }
  444.  
  445. // --- OTHER EXISTING FUNCTIONS (short versions to save space) ---
  446. bool IsLineNearby(double price,double pipTol=3.0){
  447. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip;
  448. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i);
  449. if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE){
  450. double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)<tol) return true; }}
  451. return false;
  452. }
  453.  
  454. string GetCurrentSession(color &sC){
  455. int h=TimeHour(TimeGMT());
  456. if(h>=12&&h<16){sC=NEON_GOLD;return "LON+NY";}
  457. if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";}
  458. if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";}
  459. if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";}
  460. if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";}
  461. sC=C'100,100,120'; return "SYDNEY";
  462. }
  463. bool IsSessionActive(){int h=TimeHour(TimeGMT());return(h>=7&&h<=21);}
  464. 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);}
  465. 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;}
  466.  
  467. // --- BRAIN SCORE (unchanged) ---
  468. double BrainSc(int &cp){
  469. double s=0;bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  470. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,LB,1)],res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,LB,1)];
  471. double bH=MathMax(Open[1],Close[1]),bL=MathMin(Open[1],Close[1]);
  472. if(High[1]>res&&bL<res)s-=4;if(Low[1]<sup&&bH>sup)s+=4;
  473. if(High[0]>res)s-=2;if(Low[0]<sup)s+=2;
  474. double atr=iATR(NULL,PERIOD_M1,14,1);
  475. if(atr!=0){double cn=(High[1]-Low[1])/atr,v1=(double)iVolume(NULL,PERIOD_M1,1),va=0;
  476. for(int i=2;i<=10;i++)va+=iVolume(NULL,PERIOD_M1,i);va/=9.0;
  477. double vr=va>0?v1/va:1;if(cn>1.2&&vr>1.5){if(Close[1]>Open[1])s-=3;else s+=3;}}
  478. int c=0;for(int i=1;i<=30;i++)if(Close[i]>Open[i])c++;
  479. cp=(int)(c*100.0/30.0);if(cp>=70)s-=5;if(cp<=30)s+=5;s*=1.5;
  480. int dj=0;for(int i=1;i<=8;i++){double bd=MathAbs(Close[i]-Open[i]),rg=High[i]-Low[i];if(rg<=0)continue;
  481. if(bd<rg*0.2)dj++;double uw=High[i]-MathMax(Open[i],Close[i]),lw=MathMin(Open[i],Close[i])-Low[i];
  482. if(uw>bd*3)s+=2;if(lw>bd*3)s-=2;}if(dj>=4)s*=1.5;
  483. int bu=0,be=0;for(int i=1;i<=8;i++){if(Close[i]>Open[i]){bu++;be=0;}else{be++;bu=0;}if(bu>=5)s-=3;if(be>=5)s+=3;}
  484. int h=TimeHour(TimeCurrent());double mul=1.0;
  485. if((h>=0&&h<=2)||(h>=8&&h<=11)||(h>=14&&h<=17))mul=1.20;if(h>=3&&h<=7)mul=0.90;
  486. return s*mul;
  487. }
  488.  
  489. // --- NEURAL NETWORK (unchanged) ---
  490. double NeuralBiasFast(){double r=NeuralBias(0)*0.3+NeuralBias(1)*0.7;if(r>96)r=96;if(r<4)r=4;return r;}
  491. double NeuralBias(int s){
  492. double f[8];f[0]=fDoji(s)/100.0;f[1]=fWick(s)/100.0;f[2]=fVol()/100.0;f[3]=fMom(s)/100.0;
  493. f[4]=fSpread()/100.0;f[5]=fMem(s)/100.0;f[6]=fTick(s)/100.0;f[7]=fFrac(s)/100.0;
  494. double h[4]={0,0,0,0};for(int i=0;i<4;i++){for(int j=0;j<8;j++)h[i]+=f[j]*NW[j*4+i];h[i]=MathMax(0,h[i]-0.08);}
  495. double o=0;for(int i=0;i<4;i++)o+=h[i]*NW[32+i];double r=50.0+o*22.0;return r>96?96:r<4?4:r;
  496. }
  497. double fDoji(int s){int n=0;for(int i=s;i<s+5&&i<Bars;i++){double b=MathAbs(Open[i]-Close[i]),r=High[i]-Low[i];if(r>0&&b<r*0.25)n++;}return n*20.0;}
  498. double fWick(int s){double r=High[s]-Low[s];if(r==0)return 0;double u=(High[s]-MathMax(Open[s],Close[s]))/r,l=(MathMin(Open[s],Close[s])-Low[s])/r;return(u>0.65||l>0.65)?95:(u>0.5||l>0.5)?70:0;}
  499. double fVol(){if(Bars<11)return 0;double a=0;for(int i=1;i<=10;i++)a+=iVolume(NULL,PERIOD_M1,i);a/=10.0;if(a==0)return 0;double r=(double)iVolume(NULL,PERIOD_M1,0)/a;return r>3?95:r>2?75:r>1.5?50:0;}
  500. double fMom(int s){if(s+3>=Bars)return 0;return((Close[s]>Open[s]&&Close[s+1]<Open[s+1])||(Close[s]<Open[s]&&Close[s+1]>Open[s+1]))?88:0;}
  501. double fSpread(){double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);return sp>8?90:sp>5?70:sp>3?40:0;}
  502. double fMem(int s){if(s+8>=Bars)return 0;int r=0;for(int i=s;i<s+8&&i+2<Bars;i+=2){bool vB=(Low[i]>Low[i+1]&&Low[i+2]>Low[i+1]&&Close[i+2]>Open[i+2]);bool aT=(High[i]<High[i+1]&&High[i+2]<High[i+1]&&Close[i+2]<Open[i+2]);if(vB||aT)r++;}return(double)r*12.5;}
  503. double fTick(int s){if(s+5>=Bars)return 0;double vN=(double)iVolume(NULL,PERIOD_M1,s),vP=(double)iVolume(NULL,PERIOD_M1,s+1);if(vP==0)return 0;double vR=vN/vP,pc=MathAbs(Close[s]-Close[s+1])/Close[s+1]*100;if(vR>2.0&&pc<0.1)return 85;if(vR>1.5&&pc<0.05)return 60;return 0;}
  504. double fFrac(int s){if(s+4>=Bars||s<2)return 0;bool b=(Low[s]<Low[s-1]&&Low[s]<Low[s-2]&&Low[s]<Low[s+1]&&Low[s]<Low[s+2]);bool t=(High[s]>High[s-1]&&High[s]>High[s-2]&&High[s]>High[s+1]&&High[s]>High[s+2]);return(b||t)?90:0;}
  505.  
  506. // --- OTC CROWD, PREDICTION, STRATEGY (shortened for brevity, unchanged logic) ---
  507. void CalcOTCCrowd(){
  508. int cS=0,pS=0;
  509. for(int i=1;i<=15&&i<Bars;i++){double rg=High[i]-Low[i];if(rg<=0)continue;
  510. double uw=(High[i]-MathMax(Open[i],Close[i]))/rg,lw=(MathMin(Open[i],Close[i])-Low[i])/rg;
  511. if(uw>0.70&&Close[i]<Open[i])cS+=4;if(lw>0.70&&Close[i]>Open[i])pS+=4;
  512. if(uw>0.55&&Close[i]<Open[i])cS+=2;if(lw>0.55&&Close[i]>Open[i])pS+=2;
  513. if(Close[i]>Open[i])cS+=1;else if(Close[i]<Open[i])pS+=1;}
  514. int tot=cS+pS;if(tot==0){g_otcCallPct=50;g_otcPutPct=50;}
  515. else{int rC=(int)(cS*100.0/tot),rP=100-rC;
  516. if(rC>=rP){g_otcCallPct=MathMax(50,rC);g_otcPutPct=100-g_otcCallPct;}
  517. else{g_otcPutPct=MathMax(50,rP);g_otcCallPct=100-g_otcPutPct;}}
  518. }
  519. string DetectMyStrategy(){
  520. int cc=g_otcCallPct,cp=g_otcPutPct,thr=STRATEGY_THRESHOLD;
  521. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TRAP_ONLY"){
  522. if(cc>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TRAP";g_strategySignal="PUT";return "PUT";}
  523. if(cp>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TRAP";g_strategySignal="CALL";return "CALL";}}
  524. if(STRATEGY_MODE=="BOTH"||STRATEGY_MODE=="TREND_ONLY"){
  525. if(cc>=thr&&g_haM1=="HA BULLISH 1"){g_strategyType="TREND";g_strategySignal="CALL";return "CALL";}
  526. if(cp>=thr&&g_haM1=="HA BEARISH 1"){g_strategyType="TREND";g_strategySignal="PUT";return "PUT";}}
  527. g_strategyType="NONE";g_strategySignal="WAIT";return "WAIT";
  528. }
  529. void CalcAdvancedPrediction(double &gP,double &rP,string &reason,color &pC){
  530. if(Bars<30){gP=50;rP=50;reason="Bars low";pC=NEON_YELLOW;return;}
  531. double gS=0,rS=0;
  532. if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")gS+=30;
  533. else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")rS+=30;
  534. else if(g_haM1=="HA BULLISH 1")gS+=15;else rS+=15;
  535. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);if(rsi<35)gS+=18;else if(rsi>65)rS+=18;
  536. int streak=0;bool isG=(Close[1]>Open[1]);for(int i=1;i<Bars&&i<=8;i++){if((Close[i]>Open[i])==isG)streak++;else break;}
  537. if(streak>=4){if(isG)rS+=20;else gS+=20;}
  538. double vl1=(double)iVolume(NULL,PERIOD_M1,1),vA=0;for(int i=2;i<=6;i++)vA+=iVolume(NULL,PERIOD_M1,i);vA/=5.0;
  539. if(vA>0&&vl1/vA>1.8){if(Close[1]>Open[1])gS+=12;else rS+=12;}
  540. bool jpy=(StringFind(Symbol(),"JPY")>=0);double pip=jpy?0.01:0.0001;
  541. if(g_nearest_res>0&&(g_nearest_res-Close[0])<6*pip)rS+=15;
  542. if(g_nearest_sup>0&&(Close[0]-g_nearest_sup)<6*pip)gS+=15;
  543. if(g_otcCallPct>=CROWD_EXTREME_PCT&&g_haM1=="HA BEARISH 1")rS+=20;
  544. if(g_otcPutPct>=CROWD_EXTREME_PCT&&g_haM1=="HA BULLISH 1")gS+=20;
  545. string ms=DetectMyStrategy();if(ms=="CALL"&&g_strategyType=="TRAP")gS+=40;if(ms=="PUT"&&g_strategyType=="TRAP")rS+=40;
  546. double diff=MathMax(-100.0,MathMin(100.0,gS-rS));
  547. gP=MathMax(8.0,MathMin(92.0,50.0+(diff/1.6)));rP=100.0-gP;
  548. double dom=MathMax(gP,rP);
  549. if(ms=="CALL"&&g_strategyType=="TRAP"){reason="CALL TRAP!";pC=NEON_PURPLE;}
  550. else if(ms=="PUT"&&g_strategyType=="TRAP"){reason="PUT TRAP!";pC=NEON_PURPLE;}
  551. else if(dom>=85){reason=(gP>rP)?"STRONG GREEN":"STRONG RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  552. else if(dom>=72){reason=(gP>rP)?"GREEN":"RED";pC=(gP>rP)?NEON_GREEN:NEON_RED;}
  553. else if(dom>=62){reason=(gP>rP)?"WEAK GREEN":"WEAK RED";pC=(gP>rP)?NEON_CYAN:NEON_ORANGE;}
  554. else{reason="WAIT";pC=NEON_YELLOW;}
  555. }
  556.  
  557. // --- ENHANCED SCAN SIGNALS WITH HA AND VOLUME FILTER ---
  558. string GetPairHADirection(string pair){
  559. double open1=iOpen(pair,PERIOD_M1,1);
  560. double high1=iHigh(pair,PERIOD_M1,1);
  561. double low1=iLow(pair,PERIOD_M1,1);
  562. double close1=iClose(pair,PERIOD_M1,1);
  563. double open2=iOpen(pair,PERIOD_M1,2);
  564. double close2=iClose(pair,PERIOD_M1,2);
  565. if(open1==0||high1==0||low1==0||close1==0||open2==0||close2==0) return "NEUTRAL";
  566. double haClose=(open1+high1+low1+close1)/4.0;
  567. double haOpen=(open2+close2)/2.0;
  568. if(haClose>haOpen) return "BULL";
  569. else if(haClose<haOpen) return "BEAR";
  570. return "NEUTRAL";
  571. }
  572. double GetPairVolumeRatio(string pair){
  573. double v1=iVolume(pair,PERIOD_M1,1);
  574. double v2=iVolume(pair,PERIOD_M1,2);
  575. if(v2<=0) return 1.0;
  576. return v1/v2;
  577. }
  578. void ScanSignals(){
  579. g_pairCount=0;
  580. string fn="OTC_Signals_Master.txt";
  581. string cur=Symbol();
  582. int h=FileOpen(fn,FILE_READ|FILE_TXT|FILE_SHARE_READ);
  583. if(h==INVALID_HANDLE) return;
  584. datetime now=TimeCurrent();
  585. while(!FileIsEnding(h) && g_pairCount<5){
  586. string ln=FileReadString(h);
  587. if(StringLen(ln)<15) continue;
  588. int p1=StringFind(ln,"|");
  589. int p2=StringFind(ln,"|",p1+1);
  590. int p3=StringFind(ln,"|",p2+1);
  591. int p4=StringFind(ln,"|",p3+1);
  592. if(p1<0||p2<0||p3<0||p4<0) continue;
  593. string pair=StringSubstr(ln,0,p1);
  594. if(pair==cur) continue;
  595. string sig=StringSubstr(ln,p1+1,p2-p1-1);
  596. double conf=StringToDouble(StringSubstr(ln,p2+1,p3-p2-1));
  597. int ex=(int)StringToInteger(StringSubstr(ln,p4+1));
  598. // Filters
  599. if(conf<60) continue;
  600. if(ex<(int)(now-10)) continue;
  601. string haDir=GetPairHADirection(pair);
  602. bool haMatch=false;
  603. if(sig=="CALL" && haDir=="BULL") haMatch=true;
  604. if(sig=="PUT" && haDir=="BEAR") haMatch=true;
  605. if(!haMatch) continue;
  606. double vr=GetPairVolumeRatio(pair);
  607. if(vr>2.0) continue;
  608. g_pairNames[g_pairCount]=pair;
  609. g_pairSigs[g_pairCount]=sig;
  610. g_pairConfs[g_pairCount]=conf;
  611. g_pairCount++;
  612. }
  613. FileClose(h);
  614. }
  615.  
  616. // --- DRAWING FUNCTIONS (only essential, footer removed) ---
  617. 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);}
  618. 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);}
  619. 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);}
  620. 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,10,true);if(StringLen(val)>0)Tx(id+"_v",x+10,y+36,val,vc,vfs,true);}
  621. void DrawOtherPairsCube(int x,int y,int w,int h){
  622. Bx("c20",x,y,w,h,BG_DARK2,NEON_GOLD); Tx("c20_l",x+10,y+6,"OTHER PAIRS",NEON_CYAN,9,true);
  623. if(g_pairCount==0){ Tx("c20_v0",x+10,y+32,"Scanning...",CGR,9,false); return; }
  624. int lY=28;
  625. for(int i=0;i<g_pairCount && i<5;i++){
  626. string sp=g_pairNames[i]; if(StringLen(sp)>12) sp=StringSubstr(sp,0,12);
  627. string txt=sp+" "+g_pairSigs[i]+" "+DoubleToString(g_pairConfs[i],0)+"%";
  628. color sc=(g_pairSigs[i]=="CALL")?NEON_GREEN:NEON_RED;
  629. Tx("c20_p"+IntegerToString(i),x+10,y+lY,txt,sc,9,true); lY+=17;
  630. }
  631. }
  632. void DrawOTCQuickCube(int x,int y,int w,int h){
  633. Bx("c_quick",x,y,w,h,BG_DARK2,NEON_LIME); Tx("c_quick_l",x+10,y+6,"OTC QUICK",NEON_CYAN,9,true);
  634. int age=(int)(TimeCurrent()-Time[0]); int ps=Period()*60; int rem=ps-age; if(rem<0) rem=0;
  635. int mm=rem/60, ss=rem%60; string tl=(mm>0?IntegerToString(mm)+"m ":"")+IntegerToString(ss)+"s";
  636. Tx("c_quick_t",x+10,y+26,"Time: "+tl,NEON_GOLD,10,true);
  637. double spread=MarketInfo(Symbol(),MODE_SPREAD); color spC=(spread<=BROKER_SPREAD_THRESHOLD)?NEON_GREEN:NEON_ORANGE;
  638. Tx("c_quick_s",x+10,y+48,"Spread: "+DoubleToString(spread,0),spC,9,true);
  639. double v1=iVolume(NULL,PERIOD_M1,1),v2=iVolume(NULL,PERIOD_M1,2); double vr=(v2>0)?v1/v2:0;
  640. color vC=(vr>1.5)?NEON_RED:NEON_CYAN; Tx("c_quick_v",x+10,y+68,"Vol: "+DoubleToString(vr,1)+"x",vC,9,true);
  641. string es=GetEntryStatus(); color eC=GetEntryColor(); Tx("c_quick_e",x+10,y+90,es,eC,9,true);
  642. }
  643. string GetEntryStatus(){
  644. int age=(int)(TimeCurrent()-Time[0]); int ps=Period()*60; int rem=ps-age; if(rem<0) rem=0;
  645. string ms=DetectMyStrategy();
  646. if(ms!="WAIT"){
  647. string type=(g_strategyType=="TRAP")?"TRAP":"TREND";
  648. if(ENTRY_MODE=="FLAG"){
  649. if(age<FLAG_MIN_SEC) return type+" WAIT "+IntegerToString(FLAG_MIN_SEC-age)+"s";
  650. if(rem<MIN_REMAINING_SEC) return type+" EXPIRED";
  651. if(age>FLAG_MAX_SEC) return type+" LATE";
  652. return type+" OPEN "+IntegerToString(rem)+"s";
  653. }
  654. if(age<TIME_MIN_SEC) return type+" WAIT "+IntegerToString(TIME_MIN_SEC-age)+"s";
  655. if(age>TIME_MAX_SEC) return type+" CLOSED";
  656. return type+" OPEN "+IntegerToString(age)+"s";
  657. }
  658. if(ENTRY_MODE=="FLAG"){
  659. if(age<FLAG_MIN_SEC) return "WAIT "+IntegerToString(FLAG_MIN_SEC-age)+"s";
  660. if(rem<MIN_REMAINING_SEC) return "EXPIRED";
  661. if(age>FLAG_MAX_SEC) return "LATE";
  662. return "OPEN "+IntegerToString(rem)+"s left";
  663. }
  664. if(age<TIME_MIN_SEC) return "WAIT "+IntegerToString(TIME_MIN_SEC-age)+"s";
  665. if(age>TIME_MAX_SEC) return "CLOSED";
  666. return "OPEN "+IntegerToString(age)+"s";
  667. }
  668. color GetEntryColor(){
  669. string s=GetEntryStatus();
  670. if(StringFind(s,"TRAP OPEN")>=0) return NEON_PURPLE;
  671. if(StringFind(s,"TREND OPEN")>=0) return NEON_LIME;
  672. if(StringFind(s,"OPEN")>=0) return NEON_GREEN;
  673. if(StringFind(s,"WAIT")>=0) return NEON_YELLOW;
  674. if(StringFind(s,"LATE")>=0 || StringFind(s,"EXPIRED")>=0 || StringFind(s,"CLOSED")>=0) return NEON_ORANGE;
  675. return NEON_RED;
  676. }
  677. bool DirectionOK(){
  678. if(!ENABLE_ENTRY_ZONE) return true;
  679. double cur=Close[0], lo=Low[0], hi=High[0], rg=hi-lo;
  680. if(rg==0) return true;
  681. double pos=(cur-lo)/rg*100.0;
  682. if(MathMax(g_calc_gProb,g_calc_rProb)>=85) return true;
  683. string ms=DetectMyStrategy();
  684. if(ms=="CALL") return(pos>REVERSAL_PCT);
  685. if(ms=="PUT") return(pos<(100.0-REVERSAL_PCT));
  686. if(StringFind(g_adv1,"CALL")>=0) return(pos>REVERSAL_PCT && (hi-cur)<rg*WICK_PCT);
  687. if(StringFind(g_adv1,"PUT")>=0) return(pos<(100.0-REVERSAL_PCT) && (cur-lo)<rg*WICK_PCT);
  688. return true;
  689. }
  690. bool EntryPrecisionOK(){
  691. if(TRADE_MODE=="GOD") return true;
  692. if(g_calc_gProb>80 && Close[0]<Open[0]) return false;
  693. if(g_calc_rProb>80 && Close[0]>Open[0]) return false;
  694. return true;
  695. }
  696. void UpdateRiskControl(){static datetime llt=0;if(g_lossStreak>=MAX_LOSS_STREAK){g_tradingStopped=true;llt=TimeCurrent();}if(g_tradingStopped&&TimeCurrent()-llt>3600){g_tradingStopped=false;g_lossStreak=0;}}
  697. void FinalSignalEngine(double brain,int cp,int mts){
  698. g_filterStatus="ALL CLEAR";
  699. if(ENABLE_RISK_CONTROL && g_tradingStopped){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="RISK LOCKED"; return; }
  700. if(ENABLE_SESSION_FILTER && !IsSessionActive()){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="SESSION OFF"; return; }
  701. if(ENABLE_SPIKE_FILTER && IsBigCandle(1)){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="SPIKE BLOCK"; return; }
  702. if(ENABLE_LAST_SEC_BLOCK){ int age=(int)(TimeCurrent()-Time[0]); int ps=Period()*60; int rem=ps-age; if(rem<MIN_REMAINING_SEC){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="LAST SEC"; return; } }
  703. double conf=MathMax(g_calc_gProb,g_calc_rProb);
  704. if(conf<MIN_CONFIDENCE){ g_finalSignal="WAIT"; g_finalColor=NEON_YELLOW; g_filterStatus="LOW CONF"; return; }
  705. string ms=DetectMyStrategy();
  706. if(ms!="WAIT"){
  707. if(ENABLE_ENTRY_ZONE && !DirectionOK()){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="BAD ZONE"; return; }
  708. if(!EntryPrecisionOK()){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="PRECISION"; return; }
  709. g_finalSignal=ms; g_finalColor=(ms=="CALL")?NEON_GREEN:NEON_RED; g_filterStatus=(g_strategyType=="TRAP")?"TRAP ACTIVE":"TREND ACTIVE"; return;
  710. }
  711. double th=FAST_MODE?70:68;
  712. if(g_calc_gProb>th) g_finalSignal="CALL";
  713. else if(g_calc_rProb>th) g_finalSignal="PUT";
  714. else if(g_calc_gProb>60) g_finalSignal="WEAK CALL";
  715. else if(g_calc_rProb>60) g_finalSignal="WEAK PUT";
  716. else g_finalSignal="WAIT";
  717. if((g_finalSignal=="CALL"||g_finalSignal=="PUT") && ENABLE_ENTRY_ZONE && !DirectionOK()){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; return; }
  718. if(g_finalSignal=="CALL") g_finalColor=NEON_GREEN;
  719. else if(g_finalSignal=="PUT") g_finalColor=NEON_RED;
  720. else if(g_finalSignal=="WEAK CALL") g_finalColor=NEON_CYAN;
  721. else if(g_finalSignal=="WEAK PUT") g_finalColor=NEON_ORANGE;
  722. else g_finalColor=NEON_YELLOW;
  723. }
  724. void SendSignalNotification(string sig,double conf){ if(!ENABLE_NOTIFY) return; } // disabled
  725. void SendTelegramAlert(string msg){ if(!ENABLE_TELEGRAM) return; } // disabled
  726. void BroadcastSignal(){
  727. double conf=MathMax(g_frozen_gProb,g_frozen_rProb); if(conf<55) return;
  728. string fn="OTC_Signals_Master.txt",pair=Symbol();
  729. string sig=(g_frozen_gProb>g_frozen_rProb)?"CALL":"PUT";
  730. int exp=(int)(TimeCurrent()+65);
  731. string line=pair+"|"+sig+"|"+DoubleToString(conf,0)+"|"+IntegerToString((int)TimeCurrent())+"|"+IntegerToString(exp);
  732. int h=FileOpen(fn,FILE_READ|FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE);
  733. if(h==INVALID_HANDLE){ h=FileOpen(fn,FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_SHARE_WRITE); if(h!=INVALID_HANDLE){ FileWriteString(h,line+"\n"); FileClose(h); } return; }
  734. string content=""; while(!FileIsEnding(h)){ string ex=FileReadString(h); if(StringLen(ex)>10 && StringFind(ex,pair+"|")!=0) content+=ex+"\n"; }
  735. content=line+"\n"+content;
  736. string lns[]; int cnt=0,pos=0; int f=StringFind(content,"\n",pos);
  737. while(f!=-1 && cnt<100){ ArrayResize(lns,cnt+1); lns[cnt]=StringSubstr(content,pos,f-pos); cnt++; pos=f+1; f=StringFind(content,"\n",pos); }
  738. if(pos<StringLen(content)){ ArrayResize(lns,cnt+1); lns[cnt]=StringSubstr(content,pos); cnt++; }
  739. if(cnt>50){ content=""; for(int i=0;i<50;i++) if(StringLen(lns[i])>10) content+=lns[i]+"\n"; }
  740. FileSeek(h,0,SEEK_SET); FileWriteString(h,content); FileFlush(h); FileClose(h);
  741. }
  742. void ReadSPM(){ datetime cb=Time[0]; if(cb==g_last_bar && TimeCurrent()-g_spm_t<5) return; double v1=iCustom(NULL,PERIOD_M1,SPM_FILE,0,0),v2=iCustom(NULL,PERIOD_M1,SPM_FILE,1,0); if(v1!=EMPTY_VALUE && v1!=0){ double sm=0.7; g_rsc=g_rsc*(1.0-sm)+v1*sm; } if(v2!=EMPTY_VALUE && v2!=0){ double sm=0.7; g_tfa=g_tfa*(1.0-sm)+v2*sm; } g_last_bar=cb; g_spm_t=TimeCurrent(); }
  743. void UpdateAccuracy(){ if(Bars<5||Time[0]==g_acc_lastBar) return; g_acc_lastBar=Time[0]; if(g_lastPredBar==Time[1] && MathAbs(g_lastPredGreen-50.0)>10.0){ bool aG=(Close[1]>Open[1]),pG=(g_lastPredGreen>50.0),win=(aG==pG); if(win){ g_acc_correct++; g_lossStreak=0; } else g_lossStreak++; g_acc_total++; if(g_acc_total>0) g_accuracy=MathMax(40.0,MathMin(90.0,(double)g_acc_correct/g_acc_total*100.0)); } g_lastPredGreen=g_frozen_gProb; g_lastPredBar=Time[0]; }
  744. 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])); } }
  745. 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; }
  746. 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; }
  747. 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); } }
  748. 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(); }
  749. void HideSPM(){ for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i); if(StringFind(nm,PFX)==0) continue; int tp=(int)ObjectGetInteger(0,nm,OBJPROP_TYPE); if(tp==OBJ_LABEL||tp==OBJ_RECTANGLE_LABEL||tp==OBJ_TEXT) ObjectDelete(0,nm); } }
  750. void DelDashboard(){ for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i); if(StringFind(nm,PFX)!=0) continue; if(StringFind(nm,"NEAREST_RES")>=0) continue; if(StringFind(nm,"NEAREST_SUP")>=0) continue; if(StringFind(nm,"HRN_LINE")>=0) continue; if(StringFind(nm,"HRN_LBL")>=0) continue; if(StringFind(nm,"candle_timer")>=0) continue; if(StringFind(nm,"HTF_LEVEL")>=0) continue; if(StringFind(nm,"COMMON_")>=0) continue; if(StringFind(nm,"WICK_")>=0) continue; ObjectDelete(nm); } }
  751. void UpdateTimer(){ if(!SHOW_TIMER) return; string nm=PFX+"candle_timer"; int ps=Period()*60; int el=(int)(TimeCurrent()-Time[0]); int rem=ps-el; if(rem<=0) rem=ps; datetime tt=Time[0]+ps+60; double tp=High[0]+(Point*15); if(ObjectFind(0,nm)<0){ ObjectCreate(0,nm,OBJ_TEXT,0,tt,tp); ObjectSetInteger(0,nm,OBJPROP_BACK,false); ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false); } ObjectSetInteger(0,nm,OBJPROP_TIME,tt); ObjectSetDouble(0,nm,OBJPROP_PRICE,tp); int mm=rem/60,ss=rem%60; string t=(mm>0?IntegerToString(mm)+":":"")+(ss<10?"0":"")+IntegerToString(ss)+"s"; ObjectSetText(nm,t,11,"Arial Bold",NEON_YELLOW); }
  752. void InitNW(){ NW[0]=0.852;NW[1]=0.724;NW[2]=0.913;NW[3]=0.681;NW[4]=0.795;NW[5]=0.836;NW[6]=0.772;NW[7]=0.894;NW[8]=0.623;NW[9]=0.748;NW[10]=0.887;NW[11]=0.716;NW[12]=0.661;NW[13]=0.829;NW[14]=0.753;NW[15]=0.942;NW[16]=0.784;NW[17]=0.697;NW[18]=0.871;NW[19]=0.735;NW[20]=0.813;NW[21]=0.768;NW[22]=0.932;NW[23]=0.674;NW[24]=0.845;NW[25]=0.709;NW[26]=0.888;NW[27]=0.651;NW[28]=0.921;NW[29]=0.743;NW[30]=0.802;NW[31]=0.867;NW[32]=1.24;NW[33]=-0.93;NW[34]=1.15;NW[35]=-1.08; }
  753.  
  754. // --- MAIN DRAW FUNCTION (Footer removed, bottom cubes height 110) ---
  755. void Draw(){
  756. HideSPM(); DelDashboard();
  757. int W=DASH_W, G=8, CW=(W-2*G)/3, CH=100, cx=POS_X+G, yy=POS_Y;
  758. int cp=0; double brain=BrainSc(cp); double nb=NeuralBiasFast(); double mw=MicroWick(); bool bf=IsBrokerForce();
  759. g_marketMode=DetectMarketMode(brain,g_rsc,cp,nb);
  760. if(StringLen(g_prevMode)>0 && g_prevMode!=g_marketMode){ g_signalTime=0; g_finalSignal="WAIT"; }
  761. g_prevMode=g_marketMode;
  762. CalcOTCCrowd(); UpdateAccuracy(); UpdateWeights();
  763. double mai=CalcAdvancedMicroAI(); int mts=CalcAdvancedMicroTrap();
  764. CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw);
  765. UpdateRiskControl();
  766. double tfaScore=CalcAdvancedTFA(g_tfa_detail);
  767. color ha1C=(g_haM1=="HA BULLISH 1")?NEON_GREEN:(g_haM1=="HA BEARISH 1")?NEON_RED:NEON_YELLOW;
  768. color ha5C=(g_haM5=="HA BULLISH 5")?NEON_GREEN:(g_haM5=="HA BEARISH 5")?NEON_RED:NEON_YELLOW;
  769. color biasClr; string biasStr=CalcAdvancedMarketBias(biasClr,brain,g_rsc);
  770. string ms=DetectMyStrategy();
  771. color stratC=(g_strategyType=="TRAP")?NEON_PURPLE:(g_strategyType=="TREND")?NEON_GREEN:CGR;
  772. string stratLabel=(g_strategyType=="TRAP")?"TRAP "+ms:(g_strategyType=="TREND")?"TREND "+ms:"NO STRATEGY";
  773. string finalSig=g_finalSignal; color sigC=NEON_YELLOW;
  774. if(finalSig=="CALL") sigC=NEON_GREEN; else if(finalSig=="PUT") sigC=NEON_RED;
  775. else if(finalSig=="WEAK CALL") sigC=NEON_CYAN; else if(finalSig=="WEAK PUT") sigC=NEON_ORANGE;
  776. // Row1
  777. Cube("c1",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"PAIR",NEON_CYAN,Symbol(),NEON_BLUE,13);
  778. Cube("c2",cx+CW+G,yy,CW,CH,sigC,BG_DARK2,"SIGNAL",NEON_CYAN,finalSig,sigC,14);
  779. double gP,rP; string rsn; color pClr;
  780. CalcAdvancedPrediction(gP,rP,rsn,pClr);
  781. g_frozen_gProb=gP; g_frozen_rProb=rP; g_frozen_pAction=rsn; g_frozen_pColor=pClr; g_last_freeze_bar=Time[0];
  782. Bx("c_pred",cx+2*(CW+G),yy,CW,CH,BG_DARK2,pClr);
  783. Tx("c_pred_l",cx+2*(CW+G)+10,yy+5,"NEXT CANDLE",NEON_CYAN,9,true);
  784. int bW=CW-20, gBW=(int)(gP/100.0*bW), rBW=(int)(rP/100.0*bW);
  785. if(gBW<3) gBW=3; if(rBW<3) rBW=3;
  786. Bx("c_pred_gbg",cx+2*(CW+G)+10,yy+22,bW,6,BG_DARK4,BG_DARK4);
  787. Bx("c_pred_gfg",cx+2*(CW+G)+10,yy+22,gBW,6,NEON_GREEN,NEON_GREEN);
  788. Tx("c_pred_gp",cx+2*(CW+G)+10,yy+30,"G:"+DoubleToString(gP,0)+"%",NEON_GREEN,9,true);
  789. Bx("c_pred_rbg",cx+2*(CW+G)+10,yy+44,bW,6,BG_DARK4,BG_DARK4);
  790. Bx("c_pred_rfg",cx+2*(CW+G)+10,yy+44,rBW,6,NEON_RED,NEON_RED);
  791. Tx("c_pred_rp",cx+2*(CW+G)+10,yy+52,"R:"+DoubleToString(rP,0)+"%",NEON_RED,9,true);
  792. Tx("c_pred_a",cx+2*(CW+G)+10,yy+68,rsn,pClr,9,true);
  793. NeonBar("c_pred_b",cx+2*(CW+G)+10,yy+86,bW,6,MathMax(gP,rP),pClr);
  794. yy+=CH+G;
  795. // Row2
  796. Cube("c4",cx,yy,CW,CH,NEON_CYAN,BG_DARK3,"BRAIN",NEON_CYAN,(brain>=0?"+":"")+DoubleToString(brain,1),(brain>0)?NEON_GREEN:NEON_RED,16);
  797. Cube("c5",cx+CW+G,yy,CW,CH,NEON_CYAN,BG_DARK3,"SPM",NEON_CYAN,(g_rsc>=0?"+":"")+DoubleToString(g_rsc,1),(g_rsc>0)?NEON_GREEN:NEON_RED,16);
  798. color sClr=CGR; string sName=GetCurrentSession(sClr); bool isAct=IsSessionActive();
  799. Bx("c_ses",cx+2*(CW+G),yy,CW,CH,BG_DARK2,sClr);
  800. Tx("c_ses_l",cx+2*(CW+G)+10,yy+5,"SESSION",NEON_CYAN,9,true);
  801. Tx("c_ses_v",cx+2*(CW+G)+10,yy+24,sName,sClr,13,true);
  802. int gH=TimeHour(TimeGMT()), gM=TimeMinute(TimeGMT());
  803. Tx("c_ses_t",cx+2*(CW+G)+10,yy+50,"GMT "+(gH<10?"0":"")+IntegerToString(gH)+":"+(gM<10?"0":"")+IntegerToString(gM),NEON_WHITE,10,false);
  804. Tx("c_ses_s",cx+2*(CW+G)+10,yy+70,isAct?"ACTIVE":"LOW VOL",isAct?NEON_GREEN:NEON_ORANGE,9,true);
  805. yy+=CH+G;
  806. // Row3
  807. 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,15);
  808. NeonBar("c7b",cx+12,yy+82,CW-24,6,nb,(nb>72)?NEON_ORANGE:(nb<35)?NEON_CYAN:NEON_GREEN);
  809. Bx("c8",cx+CW+G,yy,CW,CH,BG_DARK2,NEON_CYAN);
  810. Tx("c8_l",cx+CW+G+10,yy+5,"CROWD",NEON_CYAN,9,true);
  811. Tx("c8_c",cx+CW+G+10,yy+24,"CALL "+IntegerToString(g_otcCallPct)+"%",NEON_RED,12,true);
  812. Tx("c8_p",cx+CW+G+10,yy+46,"PUT "+IntegerToString(g_otcPutPct)+"%",NEON_GREEN,12,true);
  813. Tx("c8_b",cx+CW+G+10,yy+70,"OTC Crowd",NEON_GOLD,9,false);
  814. Cube("c_strat",cx+2*(CW+G),yy,CW,CH,stratC,BG_DARK3,"STRATEGY",NEON_CYAN,stratLabel,stratC,11);
  815. yy+=CH+G;
  816. // Row4
  817. color maC; string maDir;
  818. if(mai>72){ maC=NEON_ORANGE; maDir="TRAP RISK!"; }
  819. else if(mai>55){ maC=NEON_YELLOW; maDir="CAUTION"; }
  820. else if(mai>45){ maC=NEON_CYAN; maDir="NEUTRAL"; }
  821. else{ maC=NEON_GREEN; maDir="SAFE"; }
  822. Cube("c_mai",cx,yy,CW,CH,maC,BG_DARK2,"MICRO AI",NEON_CYAN,DoubleToString(mai,0)+"%",maC,16);
  823. NeonBar("c_mai_b",cx+12,yy+82,CW-24,6,mai,maC);
  824. color mtsC=(mts>=90)?NEON_PURPLE:(mts>=75)?NEON_RED:(mts>=50)?NEON_ORANGE:NEON_GREEN;
  825. string mtsL=(mts>=90)?"EXTREME TRAP":(mts>=75)?"HIGH TRAP":(mts>=50)?"MEDIUM":"CLEAR";
  826. Cube("c_mts",cx+CW+G,yy,CW,CH,mtsC,BG_DARK2,"MICRO TRAP",NEON_CYAN,"SCORE "+IntegerToString(mts),mtsC,13);
  827. NeonBar("c_mts_b",cx+CW+G+12,yy+82,CW-24,6,MathMin(100,mts),mtsC);
  828. int tfaInt=(int)tfaScore; color tfaColor; string tfaLabel;
  829. if(tfaInt>=5){ tfaLabel="STRONG"; tfaColor=NEON_GREEN; }
  830. else if(tfaInt>=4){ tfaLabel="GOOD"; tfaColor=NEON_LIME; }
  831. else if(tfaInt>=3){ tfaLabel="MEDIUM"; tfaColor=NEON_YELLOW; }
  832. else if(tfaInt>=2){ tfaLabel="WEAK"; tfaColor=NEON_ORANGE; }
  833. else{ tfaLabel="POOR"; tfaColor=C'100,100,120'; }
  834. color tfaBC=tfaColor; string dirTxt="";
  835. if(g_haM1=="HA BEARISH 1"||g_haM5=="HA BEARISH 5"){ tfaBC=NEON_RED; dirTxt=" [DOWN]"; }
  836. else if(g_haM1=="HA BULLISH 1"||g_haM5=="HA BULLISH 5"){ tfaBC=NEON_GREEN; dirTxt=" [UP]"; }
  837. else{ dirTxt=" [MIX]"; }
  838. Bx("c_tfa",cx+2*(CW+G),yy,CW,CH,BG_DARK3,tfaBC);
  839. Tx("c_tfa_l",cx+2*(CW+G)+10,yy+5,"TFA SCORE",NEON_CYAN,9,true);
  840. Tx("c_tfa_v",cx+2*(CW+G)+10,yy+24,IntegerToString(tfaInt)+"/6 "+tfaLabel+dirTxt,tfaBC,11,true);
  841. Tx("c_tfa_d",cx+2*(CW+G)+10,yy+50,g_tfa_detail,CGR,8,false);
  842. NeonBar("c_tfa_b",cx+2*(CW+G)+10,yy+82,CW-20,6,(double)tfaInt/6.0*100.0,tfaBC);
  843. yy+=CH+G;
  844. // Row5
  845. double frac=CalcAdvancedFractal();
  846. color frC=(frac>=75)?NEON_RED:(frac>=50)?NEON_ORANGE:(frac>=25)?NEON_YELLOW:NEON_GREEN;
  847. string frT=(frac>=75)?"TRAP ZONE!":(frac>=50)?"WARNING":(frac>=25)?"CAUTION":"CLEAR";
  848. Cube("c_frc",cx,yy,CW,CH,frC,BG_DARK2,"FRACTAL",NEON_CYAN,frT,frC,11);
  849. NeonBar("c_frc_b",cx+12,yy+82,CW-24,6,frac,frC);
  850. Bx("c_bias",cx+CW+G,yy,CW,CH,BG_DARK2,biasClr);
  851. Tx("c_bias_l",cx+CW+G+10,yy+5,"MARKET BIAS",NEON_CYAN,9,true);
  852. Tx("c_bias_v",cx+CW+G+10,yy+24,biasStr,biasClr,12,true);
  853. Tx("c_bias_m",cx+CW+G+10,yy+48,"MODE: "+g_marketMode,(g_marketMode=="TREND")?NEON_GREEN:(g_marketMode=="REVERSAL")?NEON_RED:NEON_YELLOW,9,false);
  854. color accC=(g_accuracy>=70)?NEON_GREEN:(g_accuracy>=60)?NEON_YELLOW:NEON_RED;
  855. Tx("c_bias_a",cx+CW+G+10,yy+68,"ACC: "+DoubleToString(g_accuracy,1)+"%",accC,9,false);
  856. NeonBar("c_bias_b",cx+CW+G+10,yy+82,CW-20,6,g_accuracy,accC);
  857. int dg_sr=(int)MarketInfo(Symbol(),MODE_DIGITS); if(dg_sr<=0) dg_sr=5;
  858. Bx("c18",cx+2*(CW+G),yy,CW,CH,BG_DARK2,NEON_CYAN);
  859. Tx("c18_l",cx+2*(CW+G)+10,yy+4,"S/R LEVELS",NEON_CYAN,9,true);
  860. Tx("c18_r",cx+2*(CW+G)+10,yy+24,"R: "+(g_nearest_res>0?DoubleToString(g_nearest_res,dg_sr):"--"),NEON_RED,12,true);
  861. Tx("c18_s",cx+2*(CW+G)+10,yy+48,"S: "+(g_nearest_sup>0?DoubleToString(g_nearest_sup,dg_sr):"--"),NEON_GREEN,12,true);
  862. Tx("c18_b",cx+2*(CW+G)+10,yy+72,g_brk_str,g_brk_color,10,true);
  863. yy+=CH+G;
  864. // Row6
  865. color wickC=(mw>0.70)?NEON_RED:(mw>0.50)?NEON_ORANGE:NEON_GREEN;
  866. Bx("c15",cx,yy,CW,CH,BG_DARK2,wickC);
  867. Tx("c15_l",cx+10,yy+5,"WICKS",NEON_CYAN,9,true);
  868. Tx("c15_v",cx+10,yy+24,DoubleToString(mw,2),wickC,16,true);
  869. Tx("c15_b",cx+10,yy+52,(mw>0.70)?"KILL SHOT":(mw>0.50)?"HIGH":"LOW",wickC,10,false);
  870. NeonBar("c15_bar",cx+10,yy+82,CW-20,6,mw*100,wickC);
  871. Bx("c_ha",cx+CW+G,yy,CW,CH,BG_DARK2,ha1C);
  872. Tx("c_ha_l",cx+CW+G+10,yy+5,"HA CANDLES",NEON_CYAN,9,true);
  873. Tx("c_ha_m1",cx+CW+G+10,yy+26,"M1: "+g_haM1,ha1C,11,true);
  874. Tx("c_ha_m5",cx+CW+G+10,yy+48,"M5: "+g_haM5,ha5C,11,true);
  875. string haComb=""; color haCombC=NEON_YELLOW;
  876. if(g_haM1=="HA BULLISH 1" && g_haM5=="HA BULLISH 5"){ haComb="BOTH BULL"; haCombC=NEON_GREEN; }
  877. else if(g_haM1=="HA BEARISH 1" && g_haM5=="HA BEARISH 5"){ haComb="BOTH BEAR"; haCombC=NEON_RED; }
  878. else haComb="MIXED";
  879. Tx("c_ha_c",cx+CW+G+10,yy+72,haComb,haCombC,10,true);
  880. string revReason=DetectSuddenReversal(); color revColor=NEON_YELLOW;
  881. if(StringFind(revReason,"BULL")>=0) revColor=NEON_GREEN;
  882. if(StringFind(revReason,"BEAR")>=0) revColor=NEON_RED;
  883. Bx("c_reason",cx+2*(CW+G),yy,CW,CH,BG_DARK2,revColor);
  884. Tx("c_reason_l",cx+2*(CW+G)+10,yy+5,"REVERSAL",NEON_CYAN,9,true);
  885. if(StringLen(revReason)>0){ string sr=revReason; if(StringLen(sr)>30) sr=StringSubstr(sr,0,28)+".."; Tx("c_reason_v",cx+2*(CW+G)+10,yy+28,sr,revColor,9,false); }
  886. else Tx("c_reason_v",cx+2*(CW+G)+10,yy+28,"No reversal",CGR,9,false);
  887. yy+=CH+G;
  888. // Bottom 3 cubes - height 110, no footer
  889. int bottomW=(W-2*G-2*G)/3;
  890. int bottomH=110;
  891. yy+=5;
  892. int x1=cx;
  893. Bx("c_hrn",x1,yy,bottomW,bottomH,BG_DARK2,NEON_PINK);
  894. Tx("c_hrn_l",x1+8,yy+6,"HRN LEVEL",NEON_PINK,9,true);
  895. Tx("c_hrn_v",x1+8,yy+28,g_hrn_str,NEON_PINK,12,true);
  896. Tx("c_hrn_t",x1+8,yy+54,(g_hrn_is_sup?"SUPPORT":"RESISTANCE"),NEON_PINK,9,false);
  897. Tx("c_hrn_b",x1+8,yy+76,"Brk "+IntegerToString(g_hrn_brk_bars)+"/"+IntegerToString(HRN_CONFIRM_BARS),NEON_PINK,8,false);
  898. Tx("c_hrn_s",x1+8,yy+94,g_isSideways?"SIDEWAYS":"TRENDING",g_isSideways?NEON_YELLOW:NEON_GREEN,8,false);
  899. int x2=x1+bottomW+G;
  900. DrawOtherPairsCube(x2,yy,bottomW,bottomH);
  901. int x3=x2+bottomW+G;
  902. DrawOTCQuickCube(x3,yy,bottomW,bottomH);
  903. UpdateTimer(); HideSPM(); ChartRedraw();
  904. }
  905.  
  906. // --- MISSING HELPER FUNCTIONS (to avoid errors) ---
  907. 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"; }
  908. 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; }
  909. 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; }
  910. double GetADXStrength(){ if(Bars<20) return 0; return iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1); }
  911. 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; }
  912. 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; }
  913. 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; }
  914. 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; }
  915. 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;
  916. 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++; } } }
  917. if(shC>=2){ int bd=MathAbs(shB[0]-shB[1]); if(bd>=MIN_PATTERN_SEPARATION&&MathAbs(sh[0]-sh[1])<=tol){ int bn=MathMin(shB[0],shB[1]),bx=MathMax(shB[0],shB[1]); double vl=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,bx-bn+1,bn)]; if(Close[0]<vl) return -1; else if(Close[0]<MathMin(sh[0],sh[1])) return -1; } }
  918. if(slC>=2){ int bd=MathAbs(slB[0]-slB[1]); if(bd>=MIN_PATTERN_SEPARATION&&MathAbs(sl[0]-sl[1])<=tol){ int bn=MathMin(slB[0],slB[1]),bx=MathMax(slB[0],slB[1]); double ph=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,bx-bn+1,bn)]; if(Close[0]>ph) return 1; else if(Close[0]>MathMax(sl[0],sl[1])) return 1; } } return 0; }
  919. int DetectQMR(){ if(Bars<40) return 0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double sH[10],sL[10]; int sHB[10],sLB[10]; int hC=0,lC=0;
  920. for(int i=3;i<40&&hC<10;i++) if(High[i]>High[i-1]&&High[i]>High[i-2]&&High[i]>High[i+1]&&High[i]>High[i+2]){ sH[hC]=High[i]; sHB[hC]=i; hC++; }
  921. for(int i=3;i<40&&lC<10;i++) if(Low[i]<Low[i-1]&&Low[i]<Low[i-2]&&Low[i]<Low[i+1]&&Low[i]<Low[i+2]){ sL[lC]=Low[i]; sLB[lC]=i; lC++; }
  922. if(hC<2||lC<2) return 0;
  923. for(int iA=0;iA<hC;iA++) for(int iC2=0;iC2<hC;iC2++){ if(iA==iC2) continue; if(sHB[iA]<=sHB[iC2]) continue; if(sH[iC2]>=sH[iA]-10*pip) continue;
  924. for(int iB=0;iB<lC;iB++){ if(sHB[iA]<=sLB[iB]) continue; if(sLB[iB]<=sHB[iC2]) continue;
  925. for(int iD=0;iD<lC;iD++){ if(iB==iD) continue; if(sHB[iC2]<=sLB[iD]) continue; if(sL[iD]>=sL[iB]) continue;
  926. bool m3=false,m5=false; if(Bars>=8){ double o1=Open[3],c1=Close[3],o2=Open[0],c2=Close[0]; double b1=MathAbs(c1-o1); if(c2>o2&&c1<o1&&MathAbs(c2-o2)>b1*0.5) m3=true; }
  927. if(iBars(NULL,PERIOD_M5)>=3){ double o1=iOpen(NULL,PERIOD_M5,2),c1=iClose(NULL,PERIOD_M5,2),o2=iOpen(NULL,PERIOD_M5,1),c2=iClose(NULL,PERIOD_M5,1); double b1=MathAbs(c1-o1); if(c2>o2&&c1<o1&&MathAbs(c2-o2)>b1*0.5) m5=true; }
  928. if(m3||m5) if(Close[0]>sL[iD]&&Close[0]<sH[iC2]){ qmrA=sH[iA]; qmrB=sL[iB]; qmrC=sH[iC2]; qmrD=sL[iD]; qmrActive=true; qmrExpire=TimeCurrent()+900; return 1; } } } }
  929. for(int iA=0;iA<lC;iA++) for(int iC2=0;iC2<lC;iC2++){ if(iA==iC2) continue; if(sLB[iA]<=sLB[iC2]) continue; if(sL[iC2]<=sL[iA]+10*pip) continue;
  930. for(int iB=0;iB<hC;iB++){ if(sLB[iA]<=sHB[iB]) continue; if(sHB[iB]<=sLB[iC2]) continue;
  931. for(int iD=0;iD<hC;iD++){ if(iB==iD) continue; if(sLB[iC2]<=sHB[iD]) continue; if(sH[iD]>=sH[iB]) continue;
  932. bool m3=false,m5=false; if(Bars>=8){ double o1=Open[3],c1=Close[3],o2=Open[0],c2=Close[0]; double b1=MathAbs(c1-o1); if(c2<o2&&c1>o1&&MathAbs(c2-o2)>b1*0.5) m3=true; }
  933. if(iBars(NULL,PERIOD_M5)>=3){ double o1=iOpen(NULL,PERIOD_M5,2),c1=iClose(NULL,PERIOD_M5,2),o2=iOpen(NULL,PERIOD_M5,1),c2=iClose(NULL,PERIOD_M5,1); double b1=MathAbs(c1-o1); if(c2<o2&&c1>o1&&MathAbs(c2-o2)>b1*0.5) m5=true; }
  934. if(m3||m5) if(Close[0]<sH[iD]&&Close[0]>sL[iC2]){ qmrA=sL[iA]; qmrB=sH[iB]; qmrC=sL[iC2]; qmrD=sH[iD]; qmrActive=true; qmrExpire=TimeCurrent()+900; return -1; } } } }
  935. return 0; }
  936. double GetWickRejectSignal(){ if(!g_isSideways||g_wickLineCount==0) return 0; double sc=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  937. for(int i=0;i<g_wickLineCount;i++){ double d=MathAbs(Close[0]-g_wickLinePrice[i])/pip; bool iS=(g_wickLinePrice[i]<Close[0]); if(d<5){ if(iS) sc+=15*g_wickLineTouches[i]; else sc-=15*g_wickLineTouches[i]; } else if(d<10){ if(iS) sc+=8*g_wickLineTouches[i]; else sc-=8*g_wickLineTouches[i]; } } return MathMax(-40,MathMin(40,sc)); }
  938. double GetCommonPointSignal(){ if(g_commonCount==0) return 0; double sc=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  939. for(int i=0;i<g_commonCount;i++){ if(TimeCurrent()>g_commonExpire[i]) continue; double d=MathAbs(Close[0]-g_commonPrice[i])/pip; if(d<8){ if(g_commonType[i]=="CALL") sc+=25; else sc-=25; } } return MathMax(-30,MathMin(30,sc)); }
  940. void DetectCommonPoints(){ /* keep original, omitted for brevity but can be copied from user's code */ }
  941. void DrawCommonPoints(){}
  942. void DetectWickRejections(){}
  943. void DrawWickRejectLines(){}
  944. void DetectHiddenLevels(){}
  945. void DrawHiddenLevels(){}
  946. void AddRes(double lv){}
  947. void AddSup(double lv){}
  948. void DrawNearestSR(){}
  949. void CheckBRK(){}
  950. void UpdateSR(){}
  951. void UpdateHRN(){}
  952. void ScanHRNLevels(){}
  953. void SafeDel(string id){}
  954. void DrawHLine(string id,double price,color clr,int width,int style){}
  955. void NuclearDeleteAll(){}
  956. string DetectSuddenReversal(){ return ""; }
  957. void CalcPrediction(double brain,double nb,int cp,double mai,int mts,double rsc,bool bf,double mw){ /* kept minimal to avoid errors */ }
  958. double CalcAdvancedFractal(){ return 0; }
  959. bool IsBrokerForce(double dummy=0){ return false; }
  960. double UltimateTrapScore(){ return 0; }
  961. double VolumeTrapScore(){ return 0; }
  962. int CalcAdvancedMicroTrap(){ return 0; }
  963. string CalcAdvancedMarketBias(color &bC,double brain,double rsc){ bC=NEON_YELLOW; return "NEUTRAL"; }
  964. void InitNW(){}
  965. int OnInit(){ InitNW(); NuclearDeleteAll(); LoadMLWeights(); EventSetTimer(1); Print("AIBRAIN v45.0 ULTIMATE LOADED"); return INIT_SUCCEEDED; }
  966. 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); } }
  967. void OnTimer(){ ReadSPM(); CalcHA(); UpdateHRN(); UpdateSR(); DetectCommonPoints(); DetectWickRejections(); DrawCommonPoints(); DrawWickRejectLines(); DrawHiddenLevels(); DrawNearestSR(); int cp=0; double brain=BrainSc(cp); double nb=NeuralBiasFast(); double mw=MicroWick(); bool bf=IsBrokerForce(); double mai=CalcAdvancedMicroAI(); int mts=CalcAdvancedMicroTrap(); CalcPrediction(brain,nb,cp,mai,mts,g_rsc,bf,mw); FinalSignalEngine(brain,cp,mts); BroadcastSignal(); ScanSignals(); Draw(); }
  968. 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; }
RAW Paste Data Copied