Guest

Untitled 1361

Apr 16th, 2026
17
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
None 130.12 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| AIBRAIN OTC v46.0 FULL - All Features + Fixes |
  3. //| Fixed: Crowd (20 candles, 75% threshold, sum 100) |
  4. //| Fixed: HRN (candle close based) |
  5. //| Fixed: TFA (M1 HA priority) |
  6. //| Added: Next Candle Prediction (4 factors OTC optimized) |
  7. //| Added: Volume spike (avg of last 5 candles) |
  8. //| Kept: All original indicators (Neural, Fractal, QMR, etc.) |
  9. //+------------------------------------------------------------------+
  10. #property copyright "AIBRAIN ULTIMATE - KM RANA"
  11. #property version "46.0 FULL"
  12. #property strict
  13. #property indicator_chart_window
  14.  
  15. // ============================================================
  16. // INPUT PARAMETERS
  17. // ============================================================
  18. input string I1 = "===== CROWD SETTINGS =====";
  19. input int CROWD_LOOKBACK = 20;
  20. input double CROWD_THRESHOLD = 75.0;
  21. input bool CROWD_SIMPLE_METHOD = true;
  22.  
  23. input string I2 = "===== VOLUME SPIKE =====";
  24. input double VOLUME_SPIKE_RATIO = 1.5;
  25.  
  26. input string I3 = "===== NEXT CANDLE PREDICTION =====";
  27. input bool USE_NEW_PREDICTION = true;
  28.  
  29. input string I4 = "===== OTHER PAIRS =====";
  30. input double OTHER_PAIRS_CONF_MIN = 62.0;
  31.  
  32. input string I5 = "===== ENTRY TIMING =====";
  33. input int ENTRY_MIN_SEC = 10;
  34. input int ENTRY_MAX_SEC = 35;
  35. input int LAST_SEC_BLOCK = 15;
  36.  
  37. input string I6 = "===== DISPLAY =====";
  38. input int DASHBOARD_X = 4;
  39. input int DASHBOARD_Y = 20;
  40. input int DASHBOARD_WIDTH = 650;
  41. input bool SHOW_SR_LINES = true;
  42. input bool SHOW_ROUND_NUMBERS = true;
  43. input bool SHOW_COMMON_POINTS = true;
  44. input bool SHOW_WICK_REJECTIONS = true;
  45. input bool SHOW_HTF_LEVELS = true;
  46. input bool SHOW_TIMER = true;
  47.  
  48. input string I7 = "===== RISK & FILTERS =====";
  49. input bool ENABLE_SESSION_FILTER = true;
  50. input bool ENABLE_SPIKE_FILTER = true;
  51. input bool ENABLE_LAST_SEC_BLOCK = true;
  52. input bool ENABLE_RISK_CONTROL = true;
  53. input int MAX_LOSS_STREAK = 2;
  54.  
  55. input string I8 = "===== NOTIFICATIONS =====";
  56. input bool ENABLE_NOTIFY = true;
  57. input bool ENABLE_TELEGRAM = false;
  58. input string TELEGRAM_TOKEN = "";
  59. input string TELEGRAM_CHAT_ID = "";
  60.  
  61. // ============================================================
  62. // CONSTANTS & COLORS
  63. // ============================================================
  64. #define PFX "AIB46_"
  65. #define LB 18
  66. #define MAX_LEVELS 5
  67. #define MAX_REJ 50
  68. #define LOOKBACK 20
  69. #define MAX_COMMON_PTS 5
  70. #define MAX_WICK_LINES 5
  71. #define MAX_HTF_LEVELS 50
  72.  
  73. #define NEON_GREEN C'0,255,100'
  74. #define NEON_RED C'255,40,80'
  75. #define NEON_YELLOW C'255,220,0'
  76. #define NEON_ORANGE C'255,120,0'
  77. #define NEON_CYAN C'0,255,200'
  78. #define NEON_PURPLE C'200,0,255'
  79. #define NEON_PINK C'255,80,180'
  80. #define NEON_BLUE C'0,200,255'
  81. #define NEON_LIME C'80,255,80'
  82. #define NEON_GOLD C'255,180,0'
  83. #define DARK_BLUE_NEON C'0,100,255'
  84. #define NEON_WHITE C'220,230,255'
  85. #define CGR C'160,170,190'
  86. #define BG_DARK1 C'6,8,16'
  87. #define BG_DARK2 C'10,14,24'
  88. #define BG_DARK3 C'14,20,32'
  89. #define BG_DARK4 C'18,26,40'
  90.  
  91. // ============================================================
  92. // STRUCTURES
  93. // ============================================================
  94. struct RejLevel { double price; int touches; };
  95. struct HTFLevel { double price; string timeframe; string type; datetime time; int strength; bool isRound; };
  96.  
  97. // ============================================================
  98. // GLOBAL VARIABLES
  99. // ============================================================
  100. // Core
  101. string g_haM1="", g_haM5="", g_haBoth="";
  102. color g_haM1Color=clrGray, g_haM5Color=clrGray;
  103. double g_brain=0, g_spm=0, g_tfa=3;
  104. double g_neural=50, g_microAI=50, g_microTrap=0, g_fractal=0;
  105. string g_tfaDetail="";
  106. double g_accuracy=65.0;
  107. int g_accCorrect=0, g_accTotal=0;
  108. datetime g_accLastBar=0;
  109. double g_lastPredGreen=50.0;
  110. datetime g_lastPredBar=0;
  111. int g_lossStreak=0;
  112. bool g_tradingStopped=false;
  113.  
  114. // Crowd
  115. int g_otcCallPct=50, g_otcPutPct=50;
  116.  
  117. // Signals
  118. string g_finalSignal="WAIT";
  119. color g_finalColor=NEON_YELLOW;
  120. datetime g_signalTime=0;
  121. string g_lastNotified="";
  122. string g_marketMode="RANGE", g_prevMode="";
  123. string g_strategyType="NONE", g_strategySignal="WAIT", g_strategyReason="";
  124.  
  125. // HRN
  126. double g_hrnPrice=0;
  127. bool g_hrnIsSup=true;
  128. int g_hrnBreakBars=0;
  129. datetime g_hrnScanBar=0;
  130. datetime g_hrnLastCandle=0;
  131. RejLevel g_rej[MAX_REJ];
  132. int g_rejCnt=0;
  133.  
  134. // S/R
  135. double g_resLevels[MAX_LEVELS], g_supLevels[MAX_LEVELS];
  136. int g_resCnt=0, g_supCnt=0;
  137. datetime g_lastSRBar=0;
  138. double g_nearestRes=0, g_nearestSup=0;
  139. string g_brkStr="NO BRK";
  140. color g_brkColor=CGR;
  141.  
  142. // Common points & wick lines
  143. double g_commonPrice[MAX_COMMON_PTS];
  144. datetime g_commonTime[MAX_COMMON_PTS];
  145. string g_commonType[MAX_COMMON_PTS];
  146. datetime g_commonExpire[MAX_COMMON_PTS];
  147. int g_commonCount=0;
  148. datetime g_lastCommonScan=0;
  149.  
  150. double g_wickLinePrice[MAX_WICK_LINES];
  151. int g_wickLineTouches[MAX_WICK_LINES];
  152. datetime g_wickLineExpire[MAX_WICK_LINES];
  153. int g_wickLineCount=0;
  154. datetime g_lastWickScan=0;
  155. bool g_isSideways=false;
  156.  
  157. // HTF levels
  158. HTFLevel g_htfLevels[MAX_HTF_LEVELS];
  159. int g_htfLevelCount=0;
  160. datetime g_lastLevelScan=0;
  161.  
  162. // QMR
  163. double qmrA=0,qmrB=0,qmrC=0,qmrD=0;
  164. datetime qmrTA=0,qmrTB=0,qmrTC=0,qmrTD=0;
  165. bool qmrActive=false;
  166. datetime qmrExpire=0;
  167.  
  168. // Other pairs
  169. string g_pairNames[5], g_pairSigs[5];
  170. double g_pairConfs[5];
  171. int g_pairCount=0;
  172.  
  173. // Neural weights
  174. double NW[36];
  175.  
  176. // Filter status
  177. string g_filterStatus="ALL CLEAR";
  178. bool g_mtfConfirmed=true;
  179.  
  180. //+------------------------------------------------------------------+
  181. //| HELPER FUNCTIONS |
  182. //+------------------------------------------------------------------+
  183. bool IsLineNearby(double price, double pipTol=3.0) {
  184. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip;
  185. for(int i=ObjectsTotal()-1;i>=0;i--) { string nm=ObjectName(i);
  186. if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE) {
  187. double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)<tol) return true; } }
  188. return false;
  189. }
  190.  
  191. string GetCurrentSession(color &sC) {
  192. int h=TimeHour(TimeGMT());
  193. if(h>=12&&h<16){sC=NEON_GOLD;return "LON+NY";}
  194. if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";}
  195. if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";}
  196. if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";}
  197. if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";}
  198. sC=C'100,100,120'; return "SYDNEY";
  199. }
  200.  
  201. bool IsSessionActive() { int h=TimeHour(TimeGMT()); return (h>=7 && h<=21); }
  202.  
  203. bool IsBigCandle(int s) {
  204. if(Bars<20) return false;
  205. double a=iATR(NULL,PERIOD_M1,14,0);
  206. return (a>0 && (High[s]-Low[s]) > a*1.8);
  207. }
  208.  
  209. //+------------------------------------------------------------------+
  210. //| HEIKEN ASHI |
  211. //+------------------------------------------------------------------+
  212. void CalcHA() {
  213. if(Bars<10) return;
  214. ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true); ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true);
  215. static double haO1[500],haC1[500]; static datetime lb1=0;
  216. ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true);
  217. datetime c1=iTime(NULL,PERIOD_M1,0);
  218. if(c1!=lb1) {
  219. lb1=c1; int lim=MathMin(iBars(NULL,PERIOD_M1),500);
  220. for(int i=lim-1;i>=0;i--) {
  221. haC1[i]=(Open[i]+High[i]+Low[i]+Close[i])/4.0;
  222. if(i==lim-1) haO1[i]=(Open[i]+Close[i])/2.0;
  223. else haO1[i]=(haO1[i+1]+haC1[i+1])/2.0;
  224. }
  225. }
  226. double d1=MathAbs(haC1[1]-haO1[1]), r1=High[1]-Low[1];
  227. bool dz=(r1>0 && d1<r1*0.1), b1=(!dz && haC1[1]>haO1[1]), be1=(!dz && haC1[1]<haO1[1]);
  228. if(b1) { g_haM1="HA BULLISH 1"; g_haM1Color=NEON_GREEN; }
  229. else if(be1) { g_haM1="HA BEARISH 1"; g_haM1Color=NEON_RED; }
  230. else { g_haM1="HA DOJI 1"; g_haM1Color=NEON_YELLOW; }
  231.  
  232. if(iBars(NULL,PERIOD_M5)>=10) {
  233. static double haO5[200],haC5[200]; static datetime lb5=0;
  234. ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true);
  235. datetime c5=iTime(NULL,PERIOD_M5,0);
  236. if(c5!=lb5) {
  237. lb5=c5; int lim=MathMin(iBars(NULL,PERIOD_M5),200);
  238. for(int i=lim-1;i>=0;i--) {
  239. 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);
  240. haC5[i]=(o+h+l+c)/4.0;
  241. if(i==lim-1) haO5[i]=(o+c)/2.0;
  242. else haO5[i]=(haO5[i+1]+haC5[i+1])/2.0;
  243. }
  244. }
  245. double d5=MathAbs(haC5[1]-haO5[1]), r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1);
  246. bool dz5=(r5>0 && d5<r5*0.1), b5=(!dz5 && haC5[1]>haO5[1]), be5=(!dz5 && haC5[1]<haO5[1]);
  247. if(b5) { g_haM5="HA BULLISH 5"; g_haM5Color=NEON_GREEN; }
  248. else if(be5) { g_haM5="HA BEARISH 5"; g_haM5Color=NEON_RED; }
  249. else { g_haM5="HA DOJI 5"; g_haM5Color=NEON_YELLOW; }
  250. if(b1&&b5) g_haBoth="BOTH BULL";
  251. else if(be1&&be5) g_haBoth="BOTH BEAR";
  252. else g_haBoth="MIXED";
  253. } else { g_haM5="5 --"; g_haM5Color=clrGray; g_haBoth="HA --"; }
  254. }
  255.  
  256. //+------------------------------------------------------------------+
  257. //| TANH |
  258. //+------------------------------------------------------------------+
  259. double Tanh(double x) {
  260. double exp2x=MathExp(2.0*x);
  261. return (exp2x-1.0)/(exp2x+1.0);
  262. }
  263.  
  264. //+------------------------------------------------------------------+
  265. //| FRACTAL DIMENSION |
  266. //+------------------------------------------------------------------+
  267. double CalcFractalDimension(int period) {
  268. if(period<2) return 1.5;
  269. double sum=0.0;
  270. for(int i=1;i<period;i++) {
  271. double range1=High[i]-Low[i];
  272. double range2=High[i+1]-Low[i+1];
  273. if(range1<=0.0 || range2<=0.0) continue;
  274. sum += MathLog(range1/range2+0.001) * MathLog((double)i/(double)period);
  275. }
  276. double result=2.0 - sum/period;
  277. if(result<1.0) result=1.0;
  278. if(result>2.0) result=2.0;
  279. return result;
  280. }
  281.  
  282. //+------------------------------------------------------------------+
  283. //| VOLUME SPIKE (average of last N candles) |
  284. //+------------------------------------------------------------------+
  285. double GetVolumeSpike() {
  286. if(Bars<6) return 1.0;
  287. double currVol = (double)iVolume(NULL,PERIOD_M1,1);
  288. double avgVol = 0;
  289. for(int i=2; i<=6; i++) avgVol += (double)iVolume(NULL,PERIOD_M1,i);
  290. avgVol /= 5.0;
  291. if(avgVol<=0) return 1.0;
  292. return currVol/avgVol;
  293. }
  294.  
  295. //+------------------------------------------------------------------+
  296. //| CROWD CALCULATION (FIXED: simple buyer/seller count, sum 100) |
  297. //+------------------------------------------------------------------+
  298. void CalcCrowd() {
  299. if(Bars < CROWD_LOOKBACK) return;
  300. if(CROWD_SIMPLE_METHOD) {
  301. int buyerCount=0;
  302. for(int i=1; i<=CROWD_LOOKBACK; i++) if(Close[i] > Open[i]) buyerCount++;
  303. double buyerPct = (double)buyerCount / CROWD_LOOKBACK * 100.0;
  304. g_otcCallPct = (int)MathRound(buyerPct);
  305. g_otcPutPct = 100 - g_otcCallPct;
  306. } else {
  307. // Fallback to old wick-based (but we fix sum)
  308. int cS=0,pS=0;
  309. for(int i=1;i<=CROWD_LOOKBACK&&i<Bars;i++) {
  310. double rg=High[i]-Low[i]; if(rg<=0) continue;
  311. double uw=(High[i]-MathMax(Open[i],Close[i]))/rg;
  312. double lw=(MathMin(Open[i],Close[i])-Low[i])/rg;
  313. if(uw>0.70&&Close[i]<Open[i]) cS+=4;
  314. if(lw>0.70&&Close[i]>Open[i]) pS+=4;
  315. if(uw>0.55&&Close[i]<Open[i]) cS+=2;
  316. if(lw>0.55&&Close[i]>Open[i]) pS+=2;
  317. if(Close[i]>Open[i]) cS+=1; else if(Close[i]<Open[i]) pS+=1;
  318. }
  319. int tot=cS+pS;
  320. if(tot==0) { g_otcCallPct=50; g_otcPutPct=50; }
  321. else {
  322. int rC=(int)(cS*100.0/tot);
  323. g_otcCallPct=MathMax(50,rC);
  324. g_otcPutPct=100-g_otcCallPct;
  325. }
  326. }
  327. }
  328.  
  329. //+------------------------------------------------------------------+
  330. //| BRAIN SCORE |
  331. //+------------------------------------------------------------------+
  332. double BrainSc(int &cp) {
  333. double s=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  334. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,LB,1)], res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,LB,1)];
  335. double bH=MathMax(Open[1],Close[1]), bL=MathMin(Open[1],Close[1]);
  336. if(High[1]>res && bL<res) s-=4; if(Low[1]<sup && bH>sup) s+=4;
  337. if(High[0]>res) s-=2; if(Low[0]<sup) s+=2;
  338. double atr=iATR(NULL,PERIOD_M1,14,1);
  339. if(atr!=0) {
  340. double cn=(High[1]-Low[1])/atr, v1=(double)iVolume(NULL,PERIOD_M1,1), va=0;
  341. for(int i=2;i<=10;i++) va+=iVolume(NULL,PERIOD_M1,i); va/=9.0;
  342. double vr=va>0?v1/va:1; if(cn>1.2 && vr>1.5) { if(Close[1]>Open[1]) s-=3; else s+=3; }
  343. }
  344. int c=0; for(int i=1;i<=30;i++) if(Close[i]>Open[i]) c++;
  345. cp=(int)(c*100.0/30.0); if(cp>=70) s-=5; if(cp<=30) s+=5; s*=1.5;
  346. int dj=0; for(int i=1;i<=8;i++) {
  347. double bd=MathAbs(Close[i]-Open[i]), rg=High[i]-Low[i]; if(rg<=0) continue;
  348. if(bd<rg*0.2) dj++;
  349. double uw=High[i]-MathMax(Open[i],Close[i]), lw=MathMin(Open[i],Close[i])-Low[i];
  350. if(uw>bd*3) s+=2; if(lw>bd*3) s-=2;
  351. }
  352. if(dj>=4) s*=1.5;
  353. int bu=0,be=0; for(int i=1;i<=8;i++) {
  354. if(Close[i]>Open[i]) { bu++; be=0; } else { be++; bu=0; }
  355. if(bu>=5) s-=3; if(be>=5) s+=3;
  356. }
  357. int h=TimeHour(TimeCurrent()); double mul=1.0;
  358. if((h>=0&&h<=2)||(h>=8&&h<=11)||(h>=14&&h<=17)) mul=1.20; if(h>=3&&h<=7) mul=0.90;
  359. return s*mul;
  360. }
  361.  
  362. //+------------------------------------------------------------------+
  363. //| NEURAL NETWORK (Full weights) |
  364. //+------------------------------------------------------------------+
  365. void InitNW() {
  366. 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;
  367. 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;
  368. 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;
  369. 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;
  370. NW[32]=1.24;NW[33]=-0.93;NW[34]=1.15;NW[35]=-1.08;
  371. }
  372.  
  373. 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; }
  374. 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; }
  375. 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; }
  376. 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; }
  377. double fSpread() { double sp=(double)MarketInfo(Symbol(),MODE_SPREAD); return sp>8?90:sp>5?70:sp>3?40:0; }
  378. 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; }
  379. 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; }
  380. 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; }
  381.  
  382. double NeuralBias(int s) {
  383. 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;
  384. f[4]=fSpread()/100.0; f[5]=fMem(s)/100.0; f[6]=fTick(s)/100.0; f[7]=fFrac(s)/100.0;
  385. 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); }
  386. 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;
  387. }
  388. double NeuralBiasFast() { return NeuralBias(0)*0.3 + NeuralBias(1)*0.7; }
  389.  
  390. //+------------------------------------------------------------------+
  391. //| MICRO AI & MICRO TRAP |
  392. //+------------------------------------------------------------------+
  393. double CalcMicroAI() {
  394. if(Bars<20) return 50.0; double score=50.0;
  395. for(int i=1;i<=5;i++) { double r=High[i]-Low[i]; if(r<=0) continue;
  396. double uw=(High[i]-MathMax(Open[i],Close[i]))/r, lw=(MathMin(Open[i],Close[i])-Low[i])/r, w=(6.0-i)/5.0;
  397. if(uw>0.60) score-=w*15; if(lw>0.60) score+=w*15; }
  398. double pos5=0; for(int i=1;i<=5;i++) { double r=High[i]-Low[i]; if(r<=0) continue; pos5+=(Close[i]-Low[i])/r; }
  399. score+=(pos5/5.0-0.5)*20.0;
  400. int gc=0,rc=0; for(int i=1;i<=8;i++) { if(Close[i]>Open[i]) gc++; else if(Close[i]<Open[i]) rc++; } score+=(gc-rc)*2.5;
  401. double v1=(double)iVolume(NULL,PERIOD_M1,1), vA=0; for(int i=2;i<=6;i++) vA+=iVolume(NULL,PERIOD_M1,i); vA/=5.0;
  402. if(vA>0) { double vr=v1/vA; if(vr>1.5 && Close[1]>Open[1]) score+=8; if(vr>1.5 && Close[1]<Open[1]) score-=8; }
  403. double r1=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1), r5=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,5);
  404. if(r1<35) score+=10; if(r1>65) score-=10; if(r1>r5 && Close[1]<Close[5]) score+=6; if(r1<r5 && Close[1]>Close[5]) score-=6;
  405. return MathMax(5.0,MathMin(95.0,score));
  406. }
  407.  
  408. int CalcMicroTrap() {
  409. if(Bars<20) return 0; int score=0; double r=High[1]-Low[1];
  410. if(r>0) {
  411. double uw=(High[1]-MathMax(Open[1],Close[1]))/r, lw=(MathMin(Open[1],Close[1])-Low[1])/r;
  412. if(uw>0.65) score+=30; else if(uw>0.50) score+=15; if(lw>0.65) score+=20; else if(lw>0.50) score+=10;
  413. }
  414. double v1=(double)iVolume(NULL,PERIOD_M1,1), v2=(double)iVolume(NULL,PERIOD_M1,2);
  415. if(v2>0 && v1/v2>2.0) score+=25; else if(v2>0 && v1/v2>1.5) score+=12;
  416. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1);
  417. if(rsi>78 || rsi<22) score+=20; else if(rsi>72 || rsi<28) score+=10;
  418. if((High[1]>g_nearestRes && Close[1]<g_nearestRes) || (Low[1]<g_nearestSup && Close[1]>g_nearestSup)) score+=25;
  419. bool aG=(Close[1]>Open[1] && Close[2]>Open[2] && Close[3]>Open[3]), aR=(Close[1]<Open[1] && Close[2]<Open[2] && Close[3]<Open[3]);
  420. if(aG || aR) score+=15;
  421. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD); if(sp>6*1.5) score+=10;
  422. return MathMin(100,score);
  423. }
  424.  
  425. //+------------------------------------------------------------------+
  426. //| ADVANCED FRACTAL |
  427. //+------------------------------------------------------------------+
  428. double CalcAdvancedFractal() {
  429. if(Bars<15) return 0; double score=0;
  430. for(int i=2;i<=8&&i+2<Bars;i++) {
  431. 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; }
  432. 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; }
  433. }
  434. 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++; }
  435. if(dj>=3) score+=25;
  436. 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; }
  437. return MathMin(100,score);
  438. }
  439.  
  440. //+------------------------------------------------------------------+
  441. //| TFA (FIXED: M1 HA priority) |
  442. //+------------------------------------------------------------------+
  443. double CalcTFA(string &detail) {
  444. if(Bars<30) { detail="Bars low"; return 3.0; }
  445. double score=0; string p="";
  446. double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1);
  447. double adxSc=(adx>=25)?1.0:(adx>=20)?0.6:(adx>=15)?0.3:0.1; score+=adxSc; p+="ADX:"+((adxSc>=0.6)?"+":"-")+" ";
  448. double v1=iVolume(NULL,PERIOD_M1,1), vA=0; for(int i=2;i<=6;i++) vA+=iVolume(NULL,PERIOD_M1,i); vA=(vA>0)?vA/5.0:1; double vr=v1/vA; double volSc=(vr>=2.0)?1.0:(vr>=1.5)?0.7:(vr>=1.1)?0.4:0.1; score+=volSc; p+="VOL:"+((volSc>=0.5)?"+":"-")+" ";
  449. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1); double rsiSc=0.2; if(rsi>=60||rsi<=40) rsiSc=1.0; else if(rsi>=55||rsi<=45) rsiSc=0.6; score+=rsiSc; p+="RSI:"+((rsiSc>=0.6)?"+":"-")+" ";
  450. double atr=iATR(NULL,PERIOD_M1,14,1), cs=High[1]-Low[1]; double atrSc=0.2; 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; } score+=atrSc; p+="ATR:"+((atrSc>=0.6)?"+":"-")+" ";
  451. double body=MathAbs(Close[1]-Open[1]), range=High[1]-Low[1]; double bdySc=0.2; 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; } score+=bdySc; p+="BODY:"+((bdySc>=0.6)?"+":"-")+" ";
  452. double sesSc=IsSessionActive()?1.0:0.4; score+=sesSc; p+="SES:"+((sesSc>=0.7)?"+":"-");
  453. double finalScore=MathMin(6.0,score);
  454. int rounded=(int)MathRound(finalScore);
  455. string dir="MIX";
  456. bool m1Bull=(g_haM1=="HA BULLISH 1"), m1Bear=(g_haM1=="HA BEARISH 1");
  457. bool m5Bull=(g_haM5=="HA BULLISH 5"), m5Bear=(g_haM5=="HA BEARISH 5");
  458. if(m1Bull && m5Bull) dir="STRONG UP";
  459. else if(m1Bear && m5Bear) dir="STRONG DOWN";
  460. else if(m1Bull && m5Bear) dir="UP"; // M1 wins
  461. else if(m1Bear && m5Bull) dir="DOWN";
  462. else if(m1Bull) dir="UP";
  463. else if(m1Bear) dir="DOWN";
  464. detail = p + " | " + IntegerToString(rounded)+"/6 "+dir;
  465. g_tfaDetail = detail;
  466. return finalScore;
  467. }
  468.  
  469. //+------------------------------------------------------------------+
  470. //| MARKET BIAS |
  471. //+------------------------------------------------------------------+
  472. string CalcMarketBias(color &bC, double brain, double rsc) {
  473. if(Bars<30){bC=NEON_YELLOW;return "CALCULATING";}
  474. double score=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  475. double pc=Close[0]-Close[10]; 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;
  476. double hh1=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)], hh2=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  477. double ll1=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)], ll2=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  478. 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;
  479. double ema20=0, ema20p=0; for(int i=0;i<20;i++) ema20+=Close[i]; ema20/=20;
  480. for(int i=1;i<=20&&i<Bars;i++) ema20p+=Close[i]; ema20p/=20; if(ema20>ema20p) score+=3; else if(ema20<ema20p) score-=3;
  481. double ema50=0; for(int i=0;i<50&&i<Bars;i++) ema50+=Close[i]; ema50/=MathMin(50,Bars); if(ema20>ema50) score+=3; else score-=3;
  482. 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++;}
  483. if(gC>=7) score+=3; else if(rC>=7) score-=3; else if(gC>=5) score+=1; else if(rC>=5) score-=1;
  484. 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");
  485. if(m1B&&m5B) score+=4; else if(m1Be&&m5Be) score-=4; else if(m1B) score+=2; else if(m1Be) score-=2;
  486. 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);
  487. if(adx>20){if(pDI>mDI+5) score+=4; else if(mDI>pDI+5) score-=4;}
  488. if(brain>3) score-=2; else if(brain<-3) score+=2;
  489. if(Close[1]>Open[1]) score+=1; else if(Close[1]<Open[1]) score-=1;
  490. if(rsc>2) score+=1; else if(rsc<-2) score-=1;
  491. if(score>=12){bC=NEON_GREEN;return "STRONG BULL";}
  492. if(score>=7){bC=NEON_GREEN;return "BULLISH";}
  493. if(score>=3){bC=NEON_CYAN;return "LIGHT BULL";}
  494. if(score<=-12){bC=NEON_RED;return "STRONG BEAR";}
  495. if(score<=-7){bC=NEON_RED;return "BEARISH";}
  496. if(score<=-3){bC=NEON_ORANGE;return "LIGHT BEAR";}
  497. bC=NEON_YELLOW;return "NEUTRAL";
  498. }
  499.  
  500. //+------------------------------------------------------------------+
  501. //| NEXT CANDLE PREDICTION (NEW: weighted 4 factors) |
  502. //+------------------------------------------------------------------+
  503. void CalcNextCandlePrediction(double &greenPct, double &redPct, string &action, color &actColor) {
  504. if(Bars < CROWD_LOOKBACK+5) { greenPct=50; redPct=50; action="WAIT"; actColor=NEON_YELLOW; return; }
  505.  
  506. // 1. Crowd Trap (40%)
  507. int bullCount=0;
  508. for(int i=1;i<=CROWD_LOOKBACK;i++) if(Close[i] > Open[i]) bullCount++;
  509. double crowdPct = (double)bullCount / CROWD_LOOKBACK * 100.0;
  510. double crowdScore = 0;
  511. if(crowdPct >= CROWD_THRESHOLD) crowdScore = 40.0; // Extreme buyer -> RED next
  512. else if(crowdPct <= (100.0 - CROWD_THRESHOLD)) crowdScore = 40.0; // Extreme seller -> GREEN next
  513. else crowdScore = MathAbs(crowdPct - 50.0) / 50.0 * 40.0;
  514.  
  515. // 2. Volume Spike (30%)
  516. double volRatio = GetVolumeSpike();
  517. double volScore = 0;
  518. if(volRatio >= VOLUME_SPIKE_RATIO) volScore = 30.0;
  519. else volScore = (volRatio - 1.0) / (VOLUME_SPIKE_RATIO - 1.0) * 30.0;
  520. if(volScore < 0) volScore = 0;
  521.  
  522. // 3. Wick Rejection (20%)
  523. double range = High[1] - Low[1];
  524. double body = MathAbs(Close[1] - Open[1]);
  525. double wickPct = (range > 0) ? (range - body) / range : 0;
  526. double wickScore = wickPct * 20.0;
  527.  
  528. // 4. Momentum Fade (10%)
  529. double mom = (Close[1] - Close[2]) / Close[2] * 100.0;
  530. double momScore = MathMin(10.0, MathAbs(mom) * 1.0);
  531.  
  532. double greenBase = 0, redBase = 0;
  533. if(crowdPct >= CROWD_THRESHOLD) {
  534. redBase = crowdScore + volScore + wickScore + momScore;
  535. } else if(crowdPct <= (100.0 - CROWD_THRESHOLD)) {
  536. greenBase = crowdScore + volScore + wickScore + momScore;
  537. } else {
  538. greenBase = (crowdScore/2) + (volScore/2) + (wickScore/2) + (momScore/2);
  539. redBase = (crowdScore/2) + (volScore/2) + (wickScore/2) + (momScore/2);
  540. }
  541.  
  542. double total = greenBase + redBase;
  543. if(total <= 0) { greenPct=50; redPct=50; }
  544. else { greenPct = greenBase / total * 100.0; redPct = redBase / total * 100.0; }
  545.  
  546. if(greenPct >= CROWD_THRESHOLD) { action="STRONG GREEN"; actColor=NEON_GREEN; }
  547. else if(redPct >= CROWD_THRESHOLD) { action="STRONG RED"; actColor=NEON_RED; }
  548. else if(greenPct >= 60) { action="WEAK GREEN"; actColor=NEON_CYAN; }
  549. else if(redPct >= 60) { action="WEAK RED"; actColor=NEON_ORANGE; }
  550. else { action="WAIT"; actColor=NEON_YELLOW; }
  551. }
  552.  
  553. //+------------------------------------------------------------------+
  554. //| OLD ADVANCED PREDICTION (kept for fallback) |
  555. //+------------------------------------------------------------------+
  556. void CalcAdvancedPrediction(double &gP, double &rP, string &reason, color &pC) {
  557. if(Bars<50) { gP=50; rP=50; reason="Bars low"; pC=NEON_YELLOW; return; }
  558. double green=0, red=0;
  559. double body1=MathAbs(Close[1]-Open[1]), range1=High[1]-Low[1];
  560. double wick_ratio=(range1>0)?(range1-body1)/range1:0;
  561. if(wick_ratio>0.70 && Close[1]>Open[1]) red+=20;
  562. else if(wick_ratio>0.70 && Close[1]<Open[1]) green+=20;
  563. else if(wick_ratio>0.55){ if(Close[1]>Open[1]) red+=10; else green+=10; }
  564. double rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1), cci=iCCI(NULL,PERIOD_M1,14,PRICE_TYPICAL,1);
  565. if(rsi<30 && cci<-120) green+=15; else if(rsi>70 && cci>120) red+=15;
  566. else if(rsi<40 && cci<-80) green+=8; else if(rsi>60 && cci>80) red+=8;
  567. double v1=iVolume(NULL,PERIOD_M1,1), vAvg=0; for(int i=2;i<=10;i++) vAvg+=iVolume(NULL,PERIOD_M1,i); vAvg/=9.0; double vol_ratio=(vAvg>0)?v1/vAvg:1;
  568. if(vol_ratio>2.0){ if(Close[1]>Open[1]) red+=18; else green+=18; }
  569. else if(vol_ratio>1.5){ if(Close[1]>Open[1]) red+=10; else green+=10; }
  570. bool hammer=(Low[1]==Low[iLowest(NULL,PERIOD_M1,MODE_LOW,3,1)] && Close[1]>Open[1]);
  571. bool shooting_star=(High[1]==High[iHighest(NULL,PERIOD_M1,MODE_HIGH,3,1)] && Close[1]<Open[1]);
  572. if(hammer) green+=12; if(shooting_star) red+=12;
  573. 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);
  574. if(adx>25){ if(plusDI>minusDI+5) green+=12; else if(minusDI>plusDI+5) red+=12; else if(plusDI>minusDI) green+=6; else red+=6; }
  575. else { if(plusDI>minusDI) green+=4; else red+=4; }
  576. // HA M1+M5 (70/30 weight)
  577. 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;
  578. double m1_haO2_apx=(Open[3]+Close[3])/2.0, m1_haO1=(m1_haO2_apx+m1_haC2)/2.0;
  579. bool haBull1=(m1_haC1>m1_haO1);
  580. double m5_o1=iOpen(NULL,PERIOD_M5,1), m5_h1=iHigh(NULL,PERIOD_M5,1), m5_l1=iLow(NULL,PERIOD_M5,1), m5_c1=iClose(NULL,PERIOD_M5,1);
  581. double m5_o2=iOpen(NULL,PERIOD_M5,2), m5_c2=iClose(NULL,PERIOD_M5,2), m5_o3=iOpen(NULL,PERIOD_M5,3), m5_c3=iClose(NULL,PERIOD_M5,3);
  582. double m5_haC1=(m5_o1+m5_h1+m5_l1+m5_c1)/4.0, m5_haC2=(m5_o2+m5_h1+m5_l1+m5_c2)/4.0;
  583. double m5_haO2_apx=(m5_o3+m5_c3)/2.0, m5_haO1=(m5_haO2_apx+m5_haC2)/2.0;
  584. bool haBull5=(m5_haC1>m5_haO1);
  585. if(haBull1 && haBull5) green+=10;
  586. else if(!haBull1 && !haBull5) red+=10;
  587. else if(haBull1 && !haBull5){ green+=7; red+=3; }
  588. else if(!haBull1 && haBull5){ red+=7; green+=3; }
  589. // S/R
  590. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  591. double sup=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,20,2)], res=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,20,2)];
  592. if(Close[1]>res-3*pip) red+=8; if(Close[1]<sup+3*pip) green+=8;
  593. if(g_nearestRes>0 && (g_nearestRes-Close[0])<6*pip) red+=5;
  594. if(g_nearestSup>0 && (Close[0]-g_nearestSup)<6*pip) green+=5;
  595. double diff=MathMax(-100.0, MathMin(100.0, green-red));
  596. gP=MathMax(8.0, MathMin(92.0, 50.0+diff*0.7)); rP=100.0-gP;
  597. double dom=MathMax(gP,rP);
  598. if(dom>=85){ reason=(gP>rP)?"STRONG GREEN":"STRONG RED"; pC=(gP>rP)?NEON_GREEN:NEON_RED; }
  599. else if(dom>=75){ reason=(gP>rP)?"GREEN":"RED"; pC=(gP>rP)?NEON_GREEN:NEON_RED; }
  600. else if(dom>=62){ reason=(gP>rP)?"WEAK GREEN":"WEAK RED"; pC=(gP>rP)?NEON_CYAN:NEON_ORANGE; }
  601. else { reason="WAIT"; pC=NEON_YELLOW; }
  602. }
  603.  
  604. //+------------------------------------------------------------------+
  605. //| VOLUME TRAP, ULTIMATE TRAP, BROKER FORCE |
  606. //+------------------------------------------------------------------+
  607. double VolumeTrapScore() {
  608. if(Bars<50) return 0;
  609. double cur=Close[0], hi=High[iHighest(NULL,0,MODE_HIGH,50,1)], lo=Low[iLowest(NULL,0,MODE_LOW,50,1)];
  610. 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};
  611. 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]++; }
  612. for(int z=0;z<zn;z++) if(zc[z]>0) vz[z]/=zc[z];
  613. int cz=(int)((cur-lo)/zs); if(cz<0) cz=0; if(cz>=zn) cz=zn-1;
  614. double vr=(double)Volume[1]/(vz[cz]+0.001); double wr=(High[1]-MathMax(Open[1],Close[1])+MathMin(Open[1],Close[1])-Low[1])/(High[1]-Low[1]);
  615. if(vr>2.0 && wr>0.65) return 25; if(vr>1.8 && wr>0.55) return 15; return 0;
  616. }
  617.  
  618. double UltimateTrapScore() {
  619. double wr=(High[1]-MathMax(Open[1],Close[1])+MathMin(Open[1],Close[1])-Low[1])/(High[1]-Low[1]);
  620. double v1=(double)iVolume(NULL,PERIOD_M1,1), v2=(double)iVolume(NULL,PERIOD_M1,2);
  621. double avg=v2>0?v2:1.0, vr=v1/avg, rsi=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1), sc=0.0;
  622. if(wr>0.65) sc+=40; if(vr>2.0) sc+=30; if(rsi>75||rsi<25) sc+=20;
  623. if((High[1]>g_nearestRes && Close[1]<g_nearestRes) || (Low[1]<g_nearestSup && Close[1]>g_nearestSup)) sc+=25;
  624. sc+=VolumeTrapScore(); return MathMin(100.0,sc);
  625. }
  626.  
  627. bool IsBrokerForce() {
  628. int sd=0; for(int i=1;i<=3;i++){ if(Close[i]>Open[i]) sd++; else sd--; }
  629. double v1=(double)iVolume(NULL,PERIOD_M1,1), v2=(double)iVolume(NULL,PERIOD_M1,2);
  630. double sp=(double)MarketInfo(Symbol(),MODE_SPREAD);
  631. return (MathAbs(sd)==3 && v1>v2*2.0 && sp>6);
  632. }
  633.  
  634. //+------------------------------------------------------------------+
  635. //| STRATEGY DETECTION (for compatibility) |
  636. //+------------------------------------------------------------------+
  637. string DetectMyStrategy() {
  638. int cc=g_otcCallPct, cp=g_otcPutPct, thr=(int)CROWD_THRESHOLD;
  639. if(cc>=thr && g_haM1=="HA BEARISH 1") { g_strategyType="TRAP"; g_strategySignal="PUT"; g_strategyReason="CALL "+IntegerToString(cc)+"% + HA RED"; return "PUT"; }
  640. if(cp>=thr && g_haM1=="HA BULLISH 1") { g_strategyType="TRAP"; g_strategySignal="CALL"; g_strategyReason="PUT "+IntegerToString(cp)+"% + HA GREEN"; return "CALL"; }
  641. if(cc>=thr && g_haM1=="HA BULLISH 1") { g_strategyType="TREND"; g_strategySignal="CALL"; g_strategyReason="CALL "+IntegerToString(cc)+"% + HA GREEN"; return "CALL"; }
  642. if(cp>=thr && g_haM1=="HA BEARISH 1") { g_strategyType="TREND"; g_strategySignal="PUT"; g_strategyReason="PUT "+IntegerToString(cp)+"% + HA RED"; return "PUT"; }
  643. g_strategyType="NONE"; g_strategySignal="WAIT"; g_strategyReason="Wait "+IntegerToString(thr)+"% + HA"; return "WAIT";
  644. }
  645.  
  646. //+------------------------------------------------------------------+
  647. //| HRN (Hidden Round Number) – Candle close based |
  648. //+------------------------------------------------------------------+
  649. void ScanHRNLevels() {
  650. g_rejCnt=0;
  651. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double cur=Close[0];
  652. for(int i=1;i<=LOOKBACK&&i<Bars;i++) {
  653. double rg=High[i]-Low[i]; if(rg<=0) continue;
  654. double uw=High[i]-MathMax(Open[i],Close[i]), lw=MathMin(Open[i],Close[i])-Low[i];
  655. if(uw>rg*0.35 && MathAbs(High[i]-cur)<=40*pip) {
  656. bool f=false; for(int k=0;k<g_rejCnt;k++) if(MathAbs(g_rej[k].price-High[i])<8*pip){ g_rej[k].touches++; f=true; break; }
  657. if(!f && g_rejCnt<MAX_REJ){ g_rej[g_rejCnt].price=High[i]; g_rej[g_rejCnt].touches=1; g_rejCnt++; }
  658. }
  659. if(lw>rg*0.35 && MathAbs(Low[i]-cur)<=40*pip) {
  660. bool f=false; for(int k=0;k<g_rejCnt;k++) if(MathAbs(g_rej[k].price-Low[i])<8*pip){ g_rej[k].touches++; f=true; break; }
  661. if(!f && g_rejCnt<MAX_REJ){ g_rej[g_rejCnt].price=Low[i]; g_rej[g_rejCnt].touches=1; g_rejCnt++; }
  662. }
  663. }
  664. for(int i=0;i<g_rejCnt-1;i++) for(int j=0;j<g_rejCnt-i-1;j++) if(g_rej[j].touches<g_rej[j+1].touches){ RejLevel tmp=g_rej[j]; g_rej[j]=g_rej[j+1]; g_rej[j+1]=tmp; }
  665. }
  666.  
  667. double FindBestHRN(double curPrice) {
  668. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  669. double step10=10*pip, step50=50*pip, step100=100*pip;
  670. double best=MathRound(curPrice/step10)*step10;
  671. double bestScore=-1;
  672. // Round numbers
  673. double candidates[6];
  674. candidates[0]=MathRound(curPrice/step100)*step100;
  675. candidates[1]=candidates[0]+step100;
  676. candidates[2]=MathRound(curPrice/step50)*step50;
  677. candidates[3]=candidates[2]+step50;
  678. candidates[4]=MathRound(curPrice/step10)*step10;
  679. candidates[5]=candidates[4]+step10;
  680. for(int c=0;c<6;c++) {
  681. double lv=candidates[c]; double dist=MathAbs(curPrice-lv);
  682. if(dist>30*pip) continue;
  683. double score=100.0/(dist/pip+1);
  684. if(c<2) score*=2; else if(c<4) score*=1.5;
  685. if(score>bestScore){ bestScore=score; best=lv; }
  686. }
  687. // Wick rejections
  688. for(int k=0;k<g_rejCnt;k++) {
  689. double lv=g_rej[k].price; double dist=MathAbs(curPrice-lv);
  690. if(dist>30*pip) continue;
  691. double score=g_rej[k].touches*15.0/(dist/pip+1);
  692. if(score>bestScore){ bestScore=score; best=lv; }
  693. }
  694. return best;
  695. }
  696.  
  697. void UpdateHRN() {
  698. if(Time[0]!=g_hrnScanBar){ ScanHRNLevels(); g_hrnScanBar=Time[0]; }
  699. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double cur=Close[0];
  700. if(g_hrnPrice==0){ g_hrnPrice=FindBestHRN(cur); g_hrnIsSup=(cur>g_hrnPrice); g_hrnBreakBars=0; g_hrnLastCandle=Time[1]; return; }
  701. datetime lastClosed=Time[1];
  702. if(lastClosed!=g_hrnLastCandle){
  703. g_hrnLastCandle=lastClosed;
  704. double closedPrice=Close[1];
  705. bool closedAbove=(closedPrice>g_hrnPrice+2*pip);
  706. bool closedBelow=(closedPrice<g_hrnPrice-2*pip);
  707. bool isBreaking=(g_hrnIsSup && closedBelow) || (!g_hrnIsSup && closedAbove);
  708. if(isBreaking){ g_hrnBreakBars++;
  709. if(g_hrnBreakBars>=2){ double newLevel=FindBestHRN(cur); if(MathAbs(newLevel-g_hrnPrice)>3*pip){ g_hrnPrice=newLevel; g_hrnIsSup=(cur>g_hrnPrice); g_hrnBreakBars=0; } }
  710. } else { g_hrnBreakBars=0; }
  711. }
  712. DrawHLine(PFX+"HRN_LINE", g_hrnPrice, NEON_PINK, 2, STYLE_SOLID);
  713. string ln=PFX+"HRN_LBL"; SafeDel(ln);
  714. ObjectCreate(0,ln,OBJ_TEXT,0,Time[0]+Period()*60*2, g_hrnPrice);
  715. string lbl="HRN "+(g_hrnIsSup?"SUP":"RES")+" "+DoubleToString(g_hrnPrice,(int)MarketInfo(Symbol(),MODE_DIGITS));
  716. if(g_hrnBreakBars>0) lbl+=" [BRK "+IntegerToString(g_hrnBreakBars)+"/2]";
  717. ObjectSetText(ln,lbl,9,"Arial Bold",NEON_PINK);
  718. }
  719.  
  720. //+------------------------------------------------------------------+
  721. //| S/R LEVELS |
  722. //+------------------------------------------------------------------+
  723. void AddRes(double lv){ if(lv<=0) return; for(int i=0;i<g_resCnt;i++) if(MathAbs(g_resLevels[i]-lv)<10*Point) return; if(g_resCnt>=MAX_LEVELS){ for(int i=0;i<MAX_LEVELS-1;i++) g_resLevels[i]=g_resLevels[i+1]; g_resCnt=MAX_LEVELS-1; } g_resLevels[g_resCnt++]=lv; }
  724. void AddSup(double lv){ if(lv<=0) return; for(int i=0;i<g_supCnt;i++) if(MathAbs(g_supLevels[i]-lv)<10*Point) return; if(g_supCnt>=MAX_LEVELS){ for(int i=0;i<MAX_LEVELS-1;i++) g_supLevels[i]=g_supLevels[i+1]; g_supCnt=MAX_LEVELS-1; } g_supLevels[g_supCnt++]=lv; }
  725.  
  726. void DrawNearestSR() {
  727. for(int i=0;i<20;i++){ SafeDel(PFX+"RES_"+IntegerToString(i)); SafeDel(PFX+"SUP_"+IntegerToString(i)); } SafeDel(PFX+"NEAREST_RES"); SafeDel(PFX+"NEAREST_SUP");
  728. if(!SHOW_SR_LINES) return;
  729. double cur=Close[0]; g_nearestRes=0; g_nearestSup=0; double mR=999999,mS=999999;
  730. for(int i=0;i<g_resCnt;i++) if(g_resLevels[i]>cur && (g_resLevels[i]-cur)<mR){ mR=g_resLevels[i]-cur; g_nearestRes=g_resLevels[i]; }
  731. for(int i=0;i<g_supCnt;i++) if(g_supLevels[i]<cur && (cur-g_supLevels[i])<mS){ mS=cur-g_supLevels[i]; g_nearestSup=g_supLevels[i]; }
  732. if(g_nearestRes>0 && !IsLineNearby(g_nearestRes,5.0)) DrawHLine(PFX+"NEAREST_RES",g_nearestRes,NEON_RED,2,STYLE_SOLID);
  733. if(g_nearestSup>0 && !IsLineNearby(g_nearestSup,5.0)) DrawHLine(PFX+"NEAREST_SUP",g_nearestSup,NEON_GREEN,2,STYLE_SOLID);
  734. }
  735.  
  736. void CheckBRK() {
  737. double pC=Close[1], pO=Open[1]; g_brkStr="NO BRK"; g_brkColor=CGR;
  738. if(g_nearestRes>0 && pC>g_nearestRes && pO<=g_nearestRes){ g_brkStr="BRK UP!"; g_brkColor=NEON_GREEN; }
  739. else if(g_nearestSup>0 && pC<g_nearestSup && pO>=g_nearestSup){ g_brkStr="BRK DOWN!"; g_brkColor=NEON_RED; }
  740. }
  741.  
  742. void UpdateSR() {
  743. if(Time[0]==g_lastSRBar) return; g_lastSRBar=Time[0];
  744. if(Bars<15) return;
  745. double nR=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,10,1)], nS=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,10,1)], cur=Close[0];
  746. if(nR>0 && cur<nR-5*Point) AddRes(nR); if(nS>0 && cur>nS+5*Point) AddSup(nS);
  747. if(g_resCnt<1) AddRes(High[1]); if(g_supCnt<1) AddSup(Low[1]);
  748. DrawNearestSR(); CheckBRK();
  749. }
  750.  
  751. //+------------------------------------------------------------------+
  752. //| COMMON POINTS & WICK REJECTIONS |
  753. //+------------------------------------------------------------------+
  754. void DetectCommonPoints() {
  755. if(!SHOW_COMMON_POINTS){ g_commonCount=0; return; }
  756. if(Time[0]==g_lastCommonScan) return; g_lastCommonScan=Time[0]; g_commonCount=0;
  757. datetime nowBar=Time[0]; int periodSec=PeriodSeconds(PERIOD_M1);
  758. double m5h=iHigh(NULL,PERIOD_M5,iHighest(NULL,PERIOD_M5,MODE_HIGH,10,1));
  759. double m5l=iLow(NULL,PERIOD_M5,iLowest(NULL,PERIOD_M5,MODE_LOW,10,1));
  760. 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++; }
  761. if(g_hrnPrice>0 && g_hrnIsSup && g_commonCount<MAX_COMMON_PTS){ g_commonPrice[g_commonCount]=g_hrnPrice; g_commonTime[g_commonCount]=nowBar; g_commonType[g_commonCount]="CALL"; g_commonExpire[g_commonCount]=nowBar+periodSec*120; g_commonCount++; }
  762. 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++; }
  763. if(g_hrnPrice>0 && !g_hrnIsSup && g_commonCount<MAX_COMMON_PTS){ g_commonPrice[g_commonCount]=g_hrnPrice; g_commonTime[g_commonCount]=nowBar; g_commonType[g_commonCount]="PUT"; g_commonExpire[g_commonCount]=nowBar+periodSec*120; g_commonCount++; }
  764. 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--; }
  765. }
  766.  
  767. void DrawCommonPoints() {
  768. for(int i=0;i<MAX_COMMON_PTS;i++){ SafeDel(PFX+"COMMON_"+IntegerToString(i)); SafeDel(PFX+"COMMON_L_"+IntegerToString(i)); }
  769. if(!SHOW_COMMON_POINTS||g_commonCount==0) return;
  770. for(int i=0;i<g_commonCount;i++){ if(TimeCurrent()>g_commonExpire[i]) continue; if(IsLineNearby(g_commonPrice[i],8.0)) continue;
  771. string id=PFX+"COMMON_"+IntegerToString(i), idL=PFX+"COMMON_L_"+IntegerToString(i); color zc=DARK_BLUE_NEON;
  772. ObjectCreate(0,id,OBJ_HLINE,0,0,g_commonPrice[i]); ObjectSetInteger(0,id,OBJPROP_COLOR,zc); ObjectSetInteger(0,id,OBJPROP_WIDTH,2); ObjectSetInteger(0,id,OBJPROP_STYLE,STYLE_DOT);
  773. string lbl=(g_commonType[i]=="CALL")?"^ CALL ZONE":"v PUT ZONE";
  774. ObjectCreate(0,idL,OBJ_TEXT,0,Time[0]+PeriodSeconds(PERIOD_M1)*3,g_commonPrice[i]); ObjectSetText(idL,lbl,8,"Arial Bold",zc); }
  775. }
  776.  
  777. void DetectWickRejections() {
  778. g_isSideways = (iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1)<25);
  779. if(!SHOW_WICK_REJECTIONS){ g_wickLineCount=0; return; }
  780. if(Time[0]==g_lastWickScan) return; g_lastWickScan=Time[0];
  781. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double zone=15*pip; double cur=Close[0];
  782. g_wickLineCount=0; datetime now=Time[0], expT=now+PeriodSeconds(PERIOD_M1)*120;
  783. for(int i=1;i<=40&&i<Bars;i++){ double rg=High[i]-Low[i]; if(rg<=0) continue;
  784. double uw=High[i]-MathMax(Open[i],Close[i]), lw=MathMin(Open[i],Close[i])-Low[i];
  785. if(uw>rg*0.30 && MathAbs(High[i]-cur)<zone*3){ bool ex=false; for(int j=0;j<g_wickLineCount;j++) if(MathAbs(g_wickLinePrice[j]-High[i])<zone){ g_wickLineTouches[j]++; ex=true; break; } if(!ex && g_wickLineCount<MAX_WICK_LINES){ g_wickLinePrice[g_wickLineCount]=High[i]; g_wickLineTouches[g_wickLineCount]=1; g_wickLineExpire[g_wickLineCount]=expT; g_wickLineCount++; } }
  786. if(lw>rg*0.30 && MathAbs(Low[i]-cur)<zone*3){ bool ex=false; for(int j=0;j<g_wickLineCount;j++) if(MathAbs(g_wickLinePrice[j]-Low[i])<zone){ g_wickLineTouches[j]++; ex=true; break; } if(!ex && g_wickLineCount<MAX_WICK_LINES){ g_wickLinePrice[g_wickLineCount]=Low[i]; g_wickLineTouches[g_wickLineCount]=1; g_wickLineExpire[g_wickLineCount]=expT; g_wickLineCount++; } }
  787. }
  788. for(int i=g_wickLineCount-1;i>=0;i--) if(TimeCurrent()>g_wickLineExpire[i]){ for(int j=i;j<g_wickLineCount-1;j++){ g_wickLinePrice[j]=g_wickLinePrice[j+1]; g_wickLineTouches[j]=g_wickLineTouches[j+1]; g_wickLineExpire[j]=g_wickLineExpire[j+1]; } g_wickLineCount--; }
  789. }
  790.  
  791. void DrawWickRejectLines() {
  792. for(int i=0;i<MAX_WICK_LINES;i++){ SafeDel(PFX+"WICK_"+IntegerToString(i)); SafeDel(PFX+"WICK_L_"+IntegerToString(i)); }
  793. if(!SHOW_WICK_REJECTIONS||!g_isSideways) return;
  794. for(int i=0;i<g_wickLineCount;i++){ if(TimeCurrent()>g_wickLineExpire[i]) continue;
  795. string id=PFX+"WICK_"+IntegerToString(i), idL=PFX+"WICK_L_"+IntegerToString(i); color lc=C'0,180,255';
  796. ObjectCreate(0,id,OBJ_HLINE,0,0,g_wickLinePrice[i]); ObjectSetInteger(0,id,OBJPROP_COLOR,lc); ObjectSetInteger(0,id,OBJPROP_WIDTH,1); ObjectSetInteger(0,id,OBJPROP_STYLE,STYLE_DOT);
  797. string lbl="W"+IntegerToString(g_wickLineTouches[i])+"x";
  798. ObjectCreate(0,idL,OBJ_TEXT,0,Time[0]+PeriodSeconds(PERIOD_M1)*2,g_wickLinePrice[i]); ObjectSetText(idL,lbl,8,"Arial Bold",lc); }
  799. }
  800.  
  801. //+------------------------------------------------------------------+
  802. //| HTF HIDDEN LEVELS |
  803. //+------------------------------------------------------------------+
  804. bool IsSwingHigh(ENUM_TIMEFRAMES tf, int p, int lb) {
  805. 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;
  806. }
  807. bool IsSwingLow(ENUM_TIMEFRAMES tf, int p, int lb) {
  808. 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;
  809. }
  810.  
  811. void AddHTFLevel(double price, string tf, string type, datetime time, int strength, bool isRound) {
  812. if(g_htfLevelCount>=MAX_HTF_LEVELS) return;
  813. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  814. for(int i=0;i<g_htfLevelCount;i++) if(MathAbs(g_htfLevels[i].price-price)/pip<5) return;
  815. g_htfLevels[g_htfLevelCount].price=price; g_htfLevels[g_htfLevelCount].timeframe=tf; g_htfLevels[g_htfLevelCount].type=type; g_htfLevels[g_htfLevelCount].time=time; g_htfLevels[g_htfLevelCount].strength=strength; g_htfLevels[g_htfLevelCount].isRound=isRound; g_htfLevelCount++;
  816. }
  817.  
  818. void DetectHiddenLevels() {
  819. g_htfLevelCount=0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double curP=Close[0];
  820. double rU=MathCeil(curP/(10*pip))*(10*pip), rD=MathFloor(curP/(10*pip))*(10*pip);
  821. if(MathAbs(curP-rU)/pip<=15) AddHTFLevel(rU,"ROUND","RESISTANCE",TimeCurrent(),8,true);
  822. if(MathAbs(curP-rD)/pip<=15) AddHTFLevel(rD,"ROUND","SUPPORT",TimeCurrent(),8,true);
  823. // M5, M15, M30, H1
  824. if(iBars(NULL,PERIOD_M5)>=30) { for(int i=2;i<30;i++){ if(IsSwingHigh(PERIOD_M5,i,2)) AddHTFLevel(iHigh(NULL,PERIOD_M5,i),"M5","RESISTANCE",iTime(NULL,PERIOD_M5,i),5,false); if(IsSwingLow(PERIOD_M5,i,2)) AddHTFLevel(iLow(NULL,PERIOD_M5,i),"M5","SUPPORT",iTime(NULL,PERIOD_M5,i),5,false); } }
  825. if(iBars(NULL,PERIOD_M15)>=20) { for(int i=2;i<20;i++){ if(IsSwingHigh(PERIOD_M15,i,2)) AddHTFLevel(iHigh(NULL,PERIOD_M15,i),"M15","RESISTANCE",iTime(NULL,PERIOD_M15,i),7,false); if(IsSwingLow(PERIOD_M15,i,2)) AddHTFLevel(iLow(NULL,PERIOD_M15,i),"M15","SUPPORT",iTime(NULL,PERIOD_M15,i),7,false); } }
  826. if(iBars(NULL,PERIOD_M30)>=15) { for(int i=2;i<15;i++){ if(IsSwingHigh(PERIOD_M30,i,2)) AddHTFLevel(iHigh(NULL,PERIOD_M30,i),"M30","RESISTANCE",iTime(NULL,PERIOD_M30,i),9,false); if(IsSwingLow(PERIOD_M30,i,2)) AddHTFLevel(iLow(NULL,PERIOD_M30,i),"M30","SUPPORT",iTime(NULL,PERIOD_M30,i),9,false); } }
  827. if(iBars(NULL,PERIOD_H1)>=10) { for(int i=2;i<10;i++){ if(IsSwingHigh(PERIOD_H1,i,2)) AddHTFLevel(iHigh(NULL,PERIOD_H1,i),"H1","RESISTANCE",iTime(NULL,PERIOD_H1,i),12,false); if(IsSwingLow(PERIOD_H1,i,2)) AddHTFLevel(iLow(NULL,PERIOD_H1,i),"H1","SUPPORT",iTime(NULL,PERIOD_H1,i),12,false); } }
  828. // Sort by strength
  829. 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; }
  830. }
  831.  
  832. void DrawHiddenLevels() {
  833. for(int i=0;i<50;i++){ SafeDel(PFX+"HTF_"+IntegerToString(i)); SafeDel(PFX+"HTF_L_"+IntegerToString(i)); }
  834. if(!SHOW_HTF_LEVELS) return;
  835. int drawn=0;
  836. for(int i=0;i<g_htfLevelCount && drawn<8;i++) {
  837. bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001;
  838. if(MathAbs(Close[0]-g_htfLevels[i].price)/pip>40) continue;
  839. if(IsLineNearby(g_htfLevels[i].price,5.0)) continue;
  840. string nm=PFX+"HTF_"+IntegerToString(drawn); color lc=g_htfLevels[i].isRound?NEON_PURPLE:(g_htfLevels[i].type=="SUPPORT"?NEON_GREEN:NEON_RED);
  841. 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);
  842. string lbl=StringFormat("%s %s",g_htfLevels[i].timeframe,g_htfLevels[i].type);
  843. ObjectCreate(0,nm+"_L",OBJ_TEXT,0,Time[0]+Period()*60*3,g_htfLevels[i].price); ObjectSetText(nm+"_L",lbl,8,"Arial",lc); drawn++;
  844. }
  845. }
  846.  
  847. //+------------------------------------------------------------------+
  848. //| QMR PATTERN |
  849. //+------------------------------------------------------------------+
  850. int DetectQMR() {
  851. 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;
  852. 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++; }
  853. 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++; }
  854. if(hC<2||lC<2) return 0;
  855. 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;
  856. for(int iB=0;iB<lC;iB++){ if(sHB[iA]<=sLB[iB]) continue; if(sLB[iB]<=sHB[iC2]) continue;
  857. for(int iD=0;iD<lC;iD++){ if(iB==iD) continue; if(sHB[iC2]<=sLB[iD]) continue; if(sL[iD]>=sL[iB]) continue;
  858. 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; }
  859. 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; }
  860. 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; }}}}
  861. 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;
  862. for(int iB=0;iB<hC;iB++){ if(sLB[iA]<=sHB[iB]) continue; if(sHB[iB]<=sLB[iC2]) continue;
  863. for(int iD=0;iD<hC;iD++){ if(iB==iD) continue; if(sLB[iC2]<=sHB[iD]) continue; if(sH[iD]>=sH[iB]) continue;
  864. 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; }
  865. 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; }
  866. 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; }}}}
  867. return 0;
  868. }
  869.  
  870. //+------------------------------------------------------------------+
  871. //| OTHER SIGNALS (RSI Divergence, Streak, Classic Patterns) |
  872. //+------------------------------------------------------------------+
  873. int DetectRSIDivergence() {
  874. if(Bars<30) return 0;
  875. double rN=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,1), rP=iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,8);
  876. double lN=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,1)], lPv=Low[iLowest(NULL,PERIOD_M1,MODE_LOW,5,6)];
  877. if(lN<lPv && rN>rP && rN<40) return 1;
  878. double hN=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,1)], hPv=High[iHighest(NULL,PERIOD_M1,MODE_HIGH,5,6)];
  879. if(hN>hPv && rN<rP && rN>60) return -1;
  880. return 0;
  881. }
  882.  
  883. int StreakReversalSignal() {
  884. if(Bars<15) return 0; int g=0,r=0;
  885. 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; }
  886. if(g>=4) return -1; if(r>=4) return 1; return 0;
  887. }
  888.  
  889. int DetectClassicPatterns() {
  890. if(Bars<30) return 0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; double tol=8.0*pip;
  891. double sh[2],sl[2]; int shB[2],slB[2]; int shC=0,slC=0;
  892. 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++; } } }
  893. if(shC>=2){ int bd=MathAbs(shB[0]-shB[1]); if(bd>=5 && 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; } }
  894. if(slC>=2){ int bd=MathAbs(slB[0]-slB[1]); if(bd>=5 && 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; } }
  895. return 0;
  896. }
  897.  
  898. //+------------------------------------------------------------------+
  899. //| ACCURACY TRACKING |
  900. //+------------------------------------------------------------------+
  901. void UpdateAccuracy() {
  902. if(Bars<5||Time[0]==g_accLastBar) return;
  903. g_accLastBar=Time[0];
  904. if(g_lastPredBar==Time[1] && MathAbs(g_lastPredGreen-50.0)>10.0){
  905. bool aG=(Close[1]>Open[1]), pG=(g_lastPredGreen>50.0), win=(aG==pG);
  906. if(win){ g_accCorrect++; g_lossStreak=0; } else g_lossStreak++;
  907. g_accTotal++;
  908. if(g_accTotal>50){ double oldRate=g_accuracy/100.0; g_accCorrect=(int)(oldRate*49); g_accTotal=50; if(win) g_accCorrect++; }
  909. if(g_accTotal>0) g_accuracy=MathMax(40.0,MathMin(90.0,(double)g_accCorrect/g_accTotal*100.0));
  910. }
  911. g_lastPredGreen = (USE_NEW_PREDICTION ? (g_otc_call_pct > 50 ? g_otc_call_pct : 100-g_otc_put_pct) : 50); // placeholder
  912. g_lastPredBar=Time[0];
  913. }
  914.  
  915. //+------------------------------------------------------------------+
  916. //| OTHER PAIRS SCAN |
  917. //+------------------------------------------------------------------+
  918. void ScanOtherPairs() {
  919. g_pairCount=0; string fn="OTC_Signals_Master.txt"; string cur=Symbol();
  920. int h=FileOpen(fn,FILE_READ|FILE_TXT|FILE_SHARE_READ); if(h==INVALID_HANDLE) return;
  921. datetime now=TimeCurrent();
  922. while(!FileIsEnding(h) && g_pairCount<5){
  923. string ln=FileReadString(h); if(StringLen(ln)<15) continue;
  924. int p1=StringFind(ln,"|"), p2=StringFind(ln,"|",p1+1), p3=StringFind(ln,"|",p2+1), p4=StringFind(ln,"|",p3+1);
  925. if(p1<0||p2<0||p3<0||p4<0) continue;
  926. string pair=StringSubstr(ln,0,p1); if(pair==cur) continue;
  927. string sig=StringSubstr(ln,p1+1,p2-p1-1); double conf=StringToDouble(StringSubstr(ln,p2+1,p3-p2-1)); int ex=(int)StringToInteger(StringSubstr(ln,p4+1));
  928. if(conf<OTHER_PAIRS_CONF_MIN) continue; if(ex<(int)(now-10)) continue;
  929. g_pairNames[g_pairCount]=pair; g_pairSigs[g_pairCount]=sig; g_pairConfs[g_pairCount]=conf; g_pairCount++;
  930. }
  931. FileClose(h);
  932. }
  933.  
  934. //+------------------------------------------------------------------+
  935. //| FINAL SIGNAL ENGINE |
  936. //+------------------------------------------------------------------+
  937. void FinalSignalEngine() {
  938. if(ENABLE_RISK_CONTROL && g_tradingStopped){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="RISK LOCKED"; return; }
  939. if(ENABLE_SESSION_FILTER && !IsSessionActive()){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="SESSION OFF"; return; }
  940. int age=(int)(TimeCurrent()-Time[0]); int ps=Period()*60; int rem=ps-age;
  941. if(ENABLE_LAST_SEC_BLOCK && rem<LAST_SEC_BLOCK){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="LAST SEC BLOCK"; return; }
  942. if(age<ENTRY_MIN_SEC || age>ENTRY_MAX_SEC){ g_finalSignal="WAIT"; g_finalColor=NEON_GRAY; return; }
  943. if(ENABLE_SPIKE_FILTER && IsBigCandle(1)){ g_finalSignal="WAIT"; g_finalColor=NEON_ORANGE; g_filterStatus="SPIKE BLOCK"; return; }
  944.  
  945. double volSpike=GetVolumeSpike();
  946. bool crowdCallExtreme=(g_otcCallPct>=CROWD_THRESHOLD);
  947. bool crowdPutExtreme=(g_otcPutPct>=CROWD_THRESHOLD);
  948. bool highVolume=(volSpike>=VOLUME_SPIKE_RATIO);
  949.  
  950. if(crowdCallExtreme && highVolume){ g_finalSignal="PUT"; g_finalColor=NEON_RED; }
  951. else if(crowdPutExtreme && highVolume){ g_finalSignal="CALL"; g_finalColor=NEON_GREEN; }
  952. else if(crowdCallExtreme){ g_finalSignal="WEAK PUT"; g_finalColor=NEON_ORANGE; }
  953. else if(crowdPutExtreme){ g_finalSignal="WEAK CALL"; g_finalColor=NEON_CYAN; }
  954. else { g_finalSignal="WAIT"; g_finalColor=NEON_YELLOW; }
  955.  
  956. static string lastSig="";
  957. if(g_finalSignal!="WAIT" && g_finalSignal!=lastSig){
  958. lastSig=g_finalSignal; g_signalTime=TimeCurrent();
  959. if(ENABLE_NOTIFY) SendNotification(StringFormat("%s %s (Crowd %d%% Vol %.1fx)", Symbol(), g_finalSignal,
  960. (g_finalSignal=="CALL"||g_finalSignal=="WEAK CALL")?g_otc_put_pct:g_otc_call_pct, volSpike));
  961. }
  962. }
  963.  
  964. //+------------------------------------------------------------------+
  965. //| DRAWING HELPERS |
  966. //+------------------------------------------------------------------+
  967. void SafeDel(string id){ if(ObjectFind(0,id)>=0) ObjectDelete(0,id); }
  968. 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); }
  969. void Box(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); }
  970. void Text(string id, int x, int y, string txt, color cl, 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",cl); }
  971. void NeonBar(string id, int x, int y, int w, int h, double pct, color fc){ Box(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; Box(id+"_f",x,y,fw,h,fc,fc); }
  972. 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){ Box(id,x,y,w,h,bg,bc); if(StringLen(lbl)>0) Text(id+"_l",x+10,y+6,lbl,lc,10,true); if(StringLen(val)>0) Text(id+"_v",x+10,y+36,val,vc,vfs,true); }
  973.  
  974. //+------------------------------------------------------------------+
  975. //| DASHBOARD DRAW |
  976. //+------------------------------------------------------------------+
  977. void DrawDashboard() {
  978. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i); if(StringFind(nm,PFX)==0) ObjectDelete(nm); }
  979. int W=DASHBOARD_WIDTH, G=8, CW=(W-2*G)/3, CH=100, cx=DASHBOARD_X+G, yy=DASHBOARD_Y;
  980. // ROW 1
  981. Cube("c1",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"PAIR",NEON_CYAN,Symbol(),NEON_BLUE,13);
  982. Cube("c2",cx+CW+G,yy,CW,CH,g_final_color,BG_DARK2,"SIGNAL",NEON_CYAN,g_finalSignal,g_final_color,14);
  983. double greenPred, redPred; string predAct; color predColor;
  984. if(USE_NEW_PREDICTION) CalcNextCandlePrediction(greenPred, redPred, predAct, predColor);
  985. else CalcAdvancedPrediction(greenPred, redPred, predAct, predColor);
  986. Box("c_pred",cx+2*(CW+G),yy,CW,CH,BG_DARK2,predColor);
  987. Text("c_pred_l",cx+2*(CW+G)+10,yy+5,"NEXT CANDLE",NEON_CYAN,9,true);
  988. int bW=CW-20, gBW=(int)(greenPred/100.0*bW), rBW=(int)(redPred/100.0*bW); if(gBW<3)gBW=3; if(rBW<3)rBW=3;
  989. Box("c_pred_gbg",cx+2*(CW+G)+10,yy+22,bW,6,BG_DARK4,BG_DARK4); Box("c_pred_gfg",cx+2*(CW+G)+10,yy+22,gBW,6,NEON_GREEN,NEON_GREEN);
  990. Text("c_pred_gp",cx+2*(CW+G)+10,yy+30,"G:"+DoubleToString(greenPred,0)+"%",NEON_GREEN,9,true);
  991. Box("c_pred_rbg",cx+2*(CW+G)+10,yy+44,bW,6,BG_DARK4,BG_DARK4); Box("c_pred_rfg",cx+2*(CW+G)+10,yy+44,rBW,6,NEON_RED,NEON_RED);
  992. Text("c_pred_rp",cx+2*(CW+G)+10,yy+52,"R:"+DoubleToString(redPred,0)+"%",NEON_RED,9,true);
  993. Text("c_pred_a",cx+2*(CW+G)+10,yy+68,predAct,predColor,9,true);
  994. NeonBar("c_pred_b",cx+2*(CW+G)+10,yy+86,bW,6,MathMax(greenPred,redPred),predColor);
  995. yy+=CH+G;
  996. // ROW 2
  997. int cp=0; g_brain=BrainSc(cp);
  998. Cube("c4",cx,yy,CW,CH,NEON_CYAN,BG_DARK3,"BRAIN",NEON_CYAN,(g_brain>=0?"+":"")+DoubleToString(g_brain,1),(g_brain>0)?NEON_GREEN:NEON_RED,16);
  999. Cube("c5",cx+CW+G,yy,CW,CH,NEON_CYAN,BG_DARK3,"SPM",NEON_CYAN,(g_spm>=0?"+":"")+DoubleToString(g_spm,1),(g_spm>0)?NEON_GREEN:NEON_RED,16);
  1000. color sClr; string sName=GetCurrentSession(sClr); bool isAct=IsSessionActive();
  1001. Box("c_ses",cx+2*(CW+G),yy,CW,CH,BG_DARK2,sClr);
  1002. Text("c_ses_l",cx+2*(CW+G)+10,yy+5,"SESSION",NEON_CYAN,9,true);
  1003. Text("c_ses_v",cx+2*(CW+G)+10,yy+24,sName,sClr,13,true);
  1004. int gH=TimeHour(TimeGMT()), gM=TimeMinute(TimeGMT());
  1005. Text("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);
  1006. Text("c_ses_s",cx+2*(CW+G)+10,yy+70,isAct?"ACTIVE":"LOW VOL",isAct?NEON_GREEN:NEON_ORANGE,9,true);
  1007. yy+=CH+G;
  1008. // ROW 3
  1009. g_neural=NeuralBiasFast();
  1010. Cube("c7",cx,yy,CW,CH,NEON_CYAN,BG_DARK2,"NEURAL AI",NEON_CYAN,DoubleToString(g_neural,1)+"%",(g_neural>72)?NEON_ORANGE:(g_neural<35)?NEON_CYAN:NEON_GREEN,15);
  1011. NeonBar("c7b",cx+12,yy+82,CW-24,6,g_neural,(g_neural>72)?NEON_ORANGE:(g_neural<35)?NEON_CYAN:NEON_GREEN);
  1012. Box("c8",cx+CW+G,yy,CW,CH,BG_DARK2,NEON_CYAN);
  1013. Text("c8_l",cx+CW+G+10,yy+5,"CROWD",NEON_CYAN,9,true);
  1014. Text("c8_c",cx+CW+G+10,yy+24,"CALL "+IntegerToString(g_otcCallPct)+"%",NEON_RED,12,true);
  1015. Text("c8_p",cx+CW+G+10,yy+46,"PUT "+IntegerToString(g_otcPutPct)+"%",NEON_GREEN,12,true);
  1016. Text("c8_b",cx+CW+G+10,yy+70,"OTC Crowd",NEON_GOLD,9,false);
  1017. string ms=DetectMyStrategy(); color stratC=(g_strategyType=="TRAP")?NEON_PURPLE:(g_strategyType=="TREND")?NEON_GREEN:CGR; string stratLabel=(g_strategyType=="TRAP")?"TRAP "+ms:(g_strategyType=="TREND")?"TREND "+ms:"NO STRATEGY";
  1018. Cube("c_strat",cx+2*(CW+G),yy,CW,CH,stratC,BG_DARK3,"STRATEGY",NEON_CYAN,stratLabel,stratC,11);
  1019. yy+=CH+G;
  1020. // ROW 4
  1021. g_microAI=CalcMicroAI(); color maC; if(g_microAI>72){maC=NEON_ORANGE;} else if(g_microAI>55){maC=NEON_YELLOW;} else if(g_microAI>45){maC=NEON_CYAN;} else{maC=NEON_GREEN;}
  1022. Cube("c_mai",cx,yy,CW,CH,maC,BG_DARK2,"MICRO AI",NEON_CYAN,DoubleToString(g_microAI,0)+"%",maC,16); NeonBar("c_mai_b",cx+12,yy+82,CW-24,6,g_microAI,maC);
  1023. g_microTrap=CalcMicroTrap(); color mtsC=(g_microTrap>=90)?NEON_PURPLE:(g_microTrap>=75)?NEON_RED:(g_microTrap>=50)?NEON_ORANGE:NEON_GREEN;
  1024. Cube("c_mts",cx+CW+G,yy,CW,CH,mtsC,BG_DARK2,"MICRO TRAP",NEON_CYAN,"SCORE "+IntegerToString(g_microTrap),mtsC,13); NeonBar("c_mts_b",cx+CW+G+12,yy+82,CW-24,6,MathMin(100,g_microTrap),mtsC);
  1025. double tfaScore=CalcTFA(g_tfaDetail); int tfaInt=(int)tfaScore; color tfaColor; string tfaLabel;
  1026. if(tfaInt>=5){tfaLabel="STRONG";tfaColor=NEON_GREEN;} else if(tfaInt>=4){tfaLabel="GOOD";tfaColor=NEON_LIME;} else if(tfaInt>=3){tfaLabel="MEDIUM";tfaColor=NEON_YELLOW;} else if(tfaInt>=2){tfaLabel="WEAK";tfaColor=NEON_ORANGE;} else{tfaLabel="POOR";tfaColor=C'100,100,120';}
  1027. 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]";}
  1028. Box("c_tfa",cx+2*(CW+G),yy,CW,CH,BG_DARK3,tfaBC);
  1029. Text("c_tfa_l",cx+2*(CW+G)+10,yy+5,"TFA SCORE",NEON_CYAN,9,true);
  1030. Text("c_tfa_v",cx+2*(CW+G)+10,yy+24,IntegerToString(tfaInt)+"/6 "+tfaLabel+dirTxt,tfaBC,11,true);
  1031. Text("c_tfa_d",cx+2*(CW+G)+10,yy+50,StringSubstr(g_tfaDetail,0,28),CGR,8,false);
  1032. NeonBar("c_tfa_b",cx+2*(CW+G)+10,yy+82,CW-20,6,(double)tfaInt/6.0*100.0,tfaBC);
  1033. yy+=CH+G;
  1034. // ROW 5
  1035. g_fractal=CalcAdvancedFractal(); color frC=(g_fractal>=75)?NEON_RED:(g_fractal>=50)?NEON_ORANGE:(g_fractal>=25)?NEON_YELLOW:NEON_GREEN; string frT=(g_fractal>=75)?"TRAP ZONE!":(g_fractal>=50)?"WARNING":(g_fractal>=25)?"CAUTION":"CLEAR";
  1036. Cube("c_frc",cx,yy,CW,CH,frC,BG_DARK2,"FRACTAL",NEON_CYAN,frT,frC,11); NeonBar("c_frc_b",cx+12,yy+82,CW-24,6,g_fractal,frC);
  1037. color biasClr; string biasStr=CalcMarketBias(biasClr,g_brain,g_spm);
  1038. Box("c_bias",cx+CW+G,yy,CW,CH,BG_DARK2,biasClr);
  1039. Text("c_bias_l",cx+CW+G+10,yy+5,"MARKET BIAS",NEON_CYAN,9,true);
  1040. Text("c_bias_v",cx+CW+G+10,yy+24,biasStr,biasClr,12,true);
  1041. Text("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);
  1042. color accC=(g_accuracy>=70)?NEON_GREEN:(g_accuracy>=60)?NEON_YELLOW:NEON_RED;
  1043. Text("c_bias_a",cx+CW+G+10,yy+68,"ACC: "+DoubleToString(g_accuracy,1)+"%",accC,9,false);
  1044. NeonBar("c_bias_b",cx+CW+G+10,yy+82,CW-20,6,g_accuracy,accC);
  1045. int dg=(int)MarketInfo(Symbol(),MODE_DIGITS); if(dg<=0) dg=5;
  1046. Box("c18",cx+2*(CW+G),yy,CW,CH,BG_DARK2,NEON_CYAN);
  1047. Text("c18_l",cx+2*(CW+G)+10,yy+4,"S/R LEVELS",NEON_CYAN,9,true);
  1048. Text("c18_r",cx+2*(CW+G)+10,yy+24,"R: "+(g_nearestRes>0?DoubleToString(g_nearestRes,dg):"--"),NEON_RED,12,true);
  1049. Text("c18_s",cx+2*(CW+G)+10,yy+48,"S: "+(g_nearestSup>0?DoubleToString(g_nearestSup,dg):"--"),NEON_GREEN,12,true);
  1050. Text("c18_b",cx+2*(CW+G)+10,yy+72,g_brkStr,g_brkColor,10,true);
  1051. yy+=CH+G;
  1052. // ROW 6
  1053. double wick=(High[1]-Low[1])>0?((High[1]-MathMax(Open[1],Close[1]))+(MathMin(Open[1],Close[1])-Low[1]))/(High[1]-Low[1]):0; color wickC=(wick>0.70)?NEON_RED:(wick>0.50)?NEON_ORANGE:NEON_GREEN;
  1054. Box("c15",cx,yy,CW,CH,BG_DARK2,wickC);
  1055. Text("c15_l",cx+10,yy+5,"WICKS",NEON_CYAN,9,true);
  1056. Text("c15_v",cx+10,yy+24,DoubleToString(wick,2),wickC,16,true);
  1057. Text("c15_b",cx+10,yy+52,(wick>0.70)?"KILL SHOT":(wick>0.50)?"HIGH":"LOW",wickC,10,false);
  1058. NeonBar("c15_bar",cx+10,yy+82,CW-20,6,wick*100,wickC);
  1059. Box("c_ha",cx+CW+G,yy,CW,CH,BG_DARK2,g_haM1Color);
  1060. Text("c_ha_l",cx+CW+G+10,yy+5,"HA CANDLES",NEON_CYAN,9,true);
  1061. Text("c_ha_m1",cx+CW+G+10,yy+26,"M1: "+g_haM1,g_haM1Color,11,true);
  1062. Text("c_ha_m5",cx+CW+G+10,yy+48,"M5: "+g_haM5,g_haM5Color,11,true);
  1063. string haComb=""; color haCombC=NEON_YELLOW;
  1064. if(g_haM1=="HA BULLISH 1" && g_haM5=="HA BULLISH 5"){ haComb="BOTH BULL"; haCombC=NEON_GREEN; }
  1065. else if(g_haM1=="HA BEARISH 1" && g_haM5=="HA BEARISH 5"){ haComb="BOTH BEAR"; haCombC=NEON_RED; }
  1066. else haComb="MIXED";
  1067. Text("c_ha_c",cx+CW+G+10,yy+72,haComb,haCombC,10,true);
  1068. string revReason=""; if(g_otcCallPct>=CROWD_THRESHOLD) revReason="BUYER TRAP"; else if(g_otcPutPct>=CROWD_THRESHOLD) revReason="SELLER TRAP"; else revReason="No reversal"; color revColor=(g_otcCallPct>=CROWD_THRESHOLD)?NEON_RED:(g_otcPutPct>=CROWD_THRESHOLD)?NEON_GREEN:NEON_YELLOW;
  1069. Box("c_reason",cx+2*(CW+G),yy,CW,CH,BG_DARK2,revColor);
  1070. Text("c_reason_l",cx+2*(CW+G)+10,yy+5,"REVERSAL",NEON_CYAN,9,true);
  1071. Text("c_reason_v",cx+2*(CW+G)+10,yy+28,revReason,revColor,9,false);
  1072. yy+=CH+G;
  1073. // ROW 7
  1074. int bottomW=(W-2*G-2*G)/3, bottomH=110; yy+=5; int x1=cx;
  1075. Box("c_hrn",x1,yy,bottomW,bottomH,BG_DARK2,NEON_PINK);
  1076. Text("c_hrn_l",x1+8,yy+6,"HRN LEVEL",NEON_PINK,9,true);
  1077. Text("c_hrn_v",x1+8,yy+28,DoubleToString(g_hrnPrice,dg),NEON_PINK,12,true);
  1078. Text("c_hrn_t",x1+8,yy+54,g_hrnIsSup?"SUPPORT":"RESISTANCE",NEON_PINK,9,false);
  1079. Text("c_hrn_b",x1+8,yy+76,"Brk "+IntegerToString(g_hrnBreakBars)+"/2",(g_hrnBreakBars>0)?NEON_ORANGE:NEON_PINK,8,false);
  1080. Text("c_hrn_s",x1+8,yy+94,g_isSideways?"SIDEWAYS":"TRENDING",g_isSideways?NEON_YELLOW:NEON_GREEN,8,false);
  1081. // Other pairs cube
  1082. ScanOtherPairs();
  1083. int x2=x1+bottomW+G;
  1084. Box("c_other",x2,yy,bottomW,bottomH,BG_DARK2,NEON_GOLD);
  1085. Text("c_other_l",x2+10,yy+6,"OTHER PAIRS",NEON_CYAN,9,true);
  1086. if(g_pairCount==0) Text("c_other_n",x2+10,yy+35,"No signals",CGR,9,false);
  1087. else { int ly=30; for(int i=0;i<g_pairCount && i<4;i++){ string txt=g_pairNames[i]+" "+g_pairSigs[i]+" "+DoubleToString(g_pairConfs[i],0)+"%"; color cl=(g_pairSigs[i]=="CALL")?NEON_GREEN:NEON_RED; Text("c_other_p"+IntegerToString(i),x2+10,yy+ly,txt,cl,9,false); ly+=18; } }
  1088. // OTC Quick cube
  1089. int age=(int)(TimeCurrent()-Time[0]); int rem=Period()*60-age; int mm=rem/60, ss=rem%60;
  1090. double volRatio=GetVolumeSpike(); string volStatus=(volRatio>=1.5)?"SPIKE":(volRatio<=0.7)?"FADE":"NORMAL"; color volColor=(volRatio>=1.5)?NEON_RED:(volRatio<=0.7)?CGR:NEON_CYAN;
  1091. Box("c_quick",x2+bottomW+G,yy,bottomW,bottomH,BG_DARK2,NEON_LIME);
  1092. Text("c_quick_l",x2+bottomW+G+10,yy+6,"OTC QUICK",NEON_CYAN,9,true);
  1093. Text("c_quick_t",x2+bottomW+G+10,yy+28,"Time: "+IntegerToString(mm)+":"+(ss<10?"0":"")+IntegerToString(ss)+"s",NEON_GOLD,10,true);
  1094. double spread=MarketInfo(Symbol(),MODE_SPREAD); color spC=(spread<=6)?NEON_GREEN:NEON_ORANGE;
  1095. Text("c_quick_s",x2+bottomW+G+10,yy+48,"Spread: "+DoubleToString(spread,0),spC,9,true);
  1096. Text("c_quick_v",x2+bottomW+G+10,yy+68,"Vol: "+DoubleToString(volRatio,1)+"x "+volStatus,volColor,10,true);
  1097. string entryStatus = (age>=ENTRY_MIN_SEC && age<=ENTRY_MAX_SEC && rem>=LAST_SEC_BLOCK) ? "OPEN" : "CLOSED";
  1098. Text("c_quick_e",x2+bottomW+G+10,yy+88,entryStatus,entryStatus=="OPEN"?NEON_GREEN:NEON_RED,9,true);
  1099. // Timer
  1100. if(SHOW_TIMER){ string nm=PFX+"timer"; int ps=Period()*60; int el=(int)(TimeCurrent()-Time[0]); int remT=ps-el; if(remT<=0) remT=ps; datetime tt=Time[0]+ps+60; double tp=High[0]+(Point*15); ObjectDelete(0,nm); ObjectCreate(0,nm,OBJ_TEXT,0,tt,tp); ObjectSetText(nm,IntegerToString(remT)+"s",11,"Arial Bold",NEON_YELLOW); }
  1101. }
  1102.  
  1103. //+------------------------------------------------------------------+
  1104. //| ON TIMER |
  1105. //+------------------------------------------------------------------+
  1106. void OnTimer() {
  1107. if(Bars<50) return;
  1108. static datetime last5min=0;
  1109. if(Time[0]/300!=last5min/300){ DetectHiddenLevels(); last5min=Time[0]; }
  1110. CalcHA(); CalcCrowd(); UpdateHRN(); UpdateSR();
  1111. DetectCommonPoints(); DetectWickRejections();
  1112. DrawCommonPoints(); DrawWickRejectLines(); DrawHiddenLevels(); DrawNearestSR();
  1113. UpdateAccuracy(); FinalSignalEngine();
  1114. g_marketMode = (MathAbs(g_brain)>2) ? "TREND" : "RANGE";
  1115. DrawDashboard(); ChartRedraw();
  1116. }
  1117.  
  1118. //+------------------------------------------------------------------+
  1119. //| INIT |
  1120. //+------------------------------------------------------------------+
  1121. int OnInit() {
  1122. InitNW(); EventSetTimer(1);
  1123. g_hrnPrice=0; g_resCnt=0; g_supCnt=0; g_commonCount=0; g_wickLineCount=0; g_htfLevelCount=0;
  1124. Print("AIBRAIN OTC v46.0 FULL Loaded | Crowd ", CROWD_LOOKBACK, "c @ ", CROWD_THRESHOLD, "% | Volume Spike ", VOLUME_SPIKE_RATIO, "x");
  1125. return INIT_SUCCEEDED;
  1126. }
  1127.  
  1128. //+------------------------------------------------------------------+
  1129. //| DEINIT |
  1130. //+------------------------------------------------------------------+
  1131. void OnDeinit(const int reason) {
  1132. EventKillTimer();
  1133. for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i); if(StringFind(nm,PFX)==0) ObjectDelete(nm); }
  1134. }
  1135.  
  1136. //+------------------------------------------------------------------+
  1137. //| ON CALCULATE |
  1138. //+------------------------------------------------------------------+
  1139. int OnCalculate(const int rates_total, const int prev_calculated,
  1140. const datetime &time[], const double &open[],
  1141. const double &high[], const double &low[], const double &close[],
  1142. const long &tick_volume[], const long &volume[], const int &spread[]) {
  1143. return rates_total;
  1144. }
  1145. //+------------------------------------------------------------------+
RAW Paste Data Copied