//+------------------------------------------------------------------+ //| AIBRAIN OTC v45.4 - OVERLAP + TIMER + SR + POPUP FIXED | //| Fixed: Other pairs no overlap, text size 11, timer screen pos | //| Fixed: SR lines stable (no shift), popup notification removed | //+------------------------------------------------------------------+ #property copyright "AIBRAIN ULTIMATE - KM RANA" #property version "46.2" #property strict #property indicator_chart_window #define PFX "AIB9_" #define VER "v46.2" #define LB 18 #define MAX_LEVELS 5 #define MAX_REJ 50 #define LOOKBACK 50 input string SPM_FILE = "KM RANA"; input int HOLD_SEC = 60; input int POS_X = 4; input int POS_Y = 20; input int DASH_W = 660; input bool SHOW_TIMER = true; input bool SHOW_SR_LINES = true; input string ENTRY_MODE = "TIME"; input int FLAG_MIN_SEC = 10; input int FLAG_MAX_SEC = 35; input int TIME_MIN_SEC = 10; input int TIME_MAX_SEC = 35; input int MIN_REMAINING_SEC = 15; input double REVERSAL_PCT = 30.0; input double WICK_PCT = 0.65; input int HRN_CONFIRM_BARS = 2; input bool HA_ALIGN_FILTER = false; input bool CONSENSUS_FILTER = false; input bool ENABLE_NOTIFY = true; input bool FAST_MODE = false; input int BROKER_SPREAD_THRESHOLD= 6; input double OTC_TRAP_WEIGHT = 15.0; input int CROWD_EXTREME_PCT = 70; input bool ENABLE_BROKER_KILLER = true; input bool ENABLE_SESSION_FILTER = true; input bool ENABLE_SPIKE_FILTER = true; input bool ENABLE_LAST_SEC_BLOCK = true; input bool ENABLE_RISK_CONTROL = true; input bool ENABLE_ENTRY_ZONE = true; input bool ML_ADAPTIVE = true; input bool VOLUME_PROFILE_TRAP = true; input bool MTF_CONFIRM = false; input bool ENABLE_TELEGRAM = false; input string TELEGRAM_TOKEN = ""; input string TELEGRAM_CHAT_ID = ""; input string TRADE_MODE = "NORMAL"; input string STRATEGY_MODE = "TRAP_ONLY"; input int STRATEGY_THRESHOLD = 75; input int MAX_LOSS_STREAK = 2; input double MIN_CONFIDENCE = 75.0; input bool ENABLE_RISK_LOCK = true; input double PATTERN_TOLERANCE_PIPS = 8.0; input int MIN_PATTERN_SEPARATION = 5; input bool SHOW_COMMON_POINTS = true; input double COMMON_POINT_TOL_PIPS = 15.0; input bool SHOW_WICK_REJECT_LINES = true; input int WICK_MIN_TOUCHES = 1; input double WICK_ZONE_PIPS = 15.0; input int WICK_EXPIRE_BARS = 60; // ============================================================ // BB PULLBACK SETTINGS // ============================================================ input bool ENABLE_BB_PULLBACK = true; input int BB_PERIOD = 20; input double BB_DEVIATION = 2.0; input int BB_SIGNAL_EXPIRE_BARS = 5; // ============================================================ // NCP PRO v7.3 SETTINGS // ============================================================ input bool ENABLE_MTG = true; input int NCP_OpenNoiseSeconds = 3; input int NCP_KillZoneSeconds = 55; input double NCP_MaxSpreadPips = 4.0; input int NCP_ATRPeriod = 14; input double NCP_MinATRPips = 0.4; input int NCP_FastEMA = 3; input int NCP_MidEMA = 7; input int NCP_SlowEMA = 15; input bool NCP_UseM5Confirm = true; input bool NCP_UseVolume = true; input double NCP_RoundStepPips = 10.0; input double NCP_RoundTolPips = 4.0; input int NCP_MinProbMedium = 57; input int NCP_MinProbStrong = 63; input int NCP_MinProbExtreme = 70; input bool NCP_UseRSINorm = true; input int NCP_RSIPeriod = 10; input double NCP_RSIBase = 50.0; input double NCP_RSIM5Target = 45.0; input double NCP_RSIM15Target = 40.0; input bool ENABLE_LEARNING = true; input string MEMORY_FILE_NAME = "NCP_Brain_v7.csv"; input int MIN_TRADES_TO_LEARN = 15; input double LEARNING_STEP = 0.025; input bool ENABLE_TRAP_DETECTION = true; input int TRAP_LOOKBACK = 30; #define NEON_GREEN C'0,255,100' #define NEON_RED C'255,40,80' #define NEON_YELLOW C'255,220,0' #define NEON_ORANGE C'255,120,0' #define NEON_CYAN C'0,255,200' #define NEON_PURPLE C'200,0,255' #define NEON_PINK C'255,80,180' #define NEON_BLUE C'0,200,255' #define NEON_LIME C'80,255,80' #define NEON_GOLD C'255,180,0' #define DARK_BLUE_NEON C'0,100,255' #define NEON_WHITE C'220,230,255' #define CGR C'160,170,190' #define BB_GREY C'180,180,190' #define BG_DARK1 C'6,8,16' #define BG_DARK2 C'10,14,24' #define BG_DARK3 C'14,20,32' #define BG_DARK4 C'18,26,40' struct HTFLevel{ double price; string timeframe; string type; datetime time; int strength; bool isRoundNumber; }; //+------------------------------------------------------------------+ // GLOBAL VARIABLES //+------------------------------------------------------------------+ string g_haM1="",g_haM5="",g_haBoth=""; color g_haM1Color=clrGray,g_haM5Color=clrGray; static double NW[36]; static double g_rsc=0,g_tfa=3; static datetime g_spm_t=0,g_last_bar=0; static double g_nearest_res=0,g_nearest_sup=0; static string g_brk_str="NO BRK"; static color g_brk_color=CGR; struct RejLevel{double price;int touches;}; static RejLevel g_rj[MAX_REJ]; static int g_rj_cnt=0; static double g_hrn_price=0; static bool g_hrn_is_sup=true; static int g_hrn_brk_bars=0; static datetime g_hrn_scan_bar=0; static string g_hrn_str="--"; static double g_hrn_score=0; static bool g_hrn_confirmed_break=false; static int g_otcCallPct=50,g_otcPutPct=50; static string g_pairNames[8],g_pairSigs[8]; static double g_pairConfs[8]; static int g_pairCount=0; static double g_frozen_gProb=50,g_frozen_rProb=50; static string g_frozen_pAction="UNCERTAIN"; static color g_frozen_pColor=NEON_YELLOW; static double g_calc_gProb=50,g_calc_rProb=50; static string g_calc_pAction="UNCERTAIN"; static color g_calc_pColor=NEON_YELLOW; static double g_gProb=50,g_rProb=50; static string g_pAction="UNCERTAIN"; static color g_pColor=NEON_YELLOW; static datetime g_last_freeze_bar=0; static double g_accuracy=65.0; static int g_acc_correct=0,g_acc_total=0; static datetime g_acc_lastBar=0; static double g_lastPredGreen=50.0; static datetime g_lastPredBar=0; static string g_finalSignal="WAIT"; static color g_finalColor=NEON_YELLOW; static datetime g_signalTime=0; static string g_lastNotified=""; static string g_marketMode="RANGE",g_prevMode=""; static int g_lossStreak=0; static bool g_tradingStopped=false; static string g_strategyType="NONE"; static string g_strategyReason=""; static double qmrA=0,qmrB=0,qmrC=0,qmrD=0; static bool qmrActive=false; static datetime qmrExpire=0; #define MAX_COMMON_PTS 5 static double g_commonPrice[MAX_COMMON_PTS]; static datetime g_commonTime[MAX_COMMON_PTS]; static int g_commonCount=0; static datetime g_commonExpire[MAX_COMMON_PTS]; static string g_commonType[MAX_COMMON_PTS]; static datetime g_lastCommonScan=0; #define MAX_WICK_LINES 5 static double g_wickLinePrice[MAX_WICK_LINES]; static int g_wickLineTouches[MAX_WICK_LINES]; static datetime g_wickLineExpire[MAX_WICK_LINES]; static int g_wickLineCount=0; static datetime g_lastWickScan=0; static bool g_isSideways=false; static string g_tfa_detail=""; static HTFLevel g_htfLevels[50]; static int g_htfLevelCount=0; static bool g_mtfConfirmed=true; static string g_filterStatus="ALL CLEAR"; static string g_adv1="WAIT KAR"; static string g_symbolKey=""; static double g_brokerBias=0.0; // STABLE S/R GLOBAL VARIABLES double g_stableRes[10]; double g_stableSup[10]; int g_stableResCount = 0; int g_stableSupCount = 0; datetime g_lastSRScan = 0; int g_srScanInterval = 5; // ============================================================ // BB PULLBACK GLOBAL VARIABLES // ============================================================ static string g_bbSignal = "--"; static color g_bbColor = CGR; static double g_bbTouchPrice = 0.0; static datetime g_bbSignalTime = 0; static int g_bbSignalBars = 0; static string g_bbDetail = ""; static double g_ha30_open = 0.0; static double g_ha30_close = 0.0; static double g_ha30_high = 0.0; static double g_ha30_low = 0.0; static datetime g_ha30_bar = 0; #define MAX_BB_LINES 8 static double g_bbLinePrice[MAX_BB_LINES]; static datetime g_bbLineExpire[MAX_BB_LINES]; static string g_bbLineType[MAX_BB_LINES]; static int g_bbLineCount=0; // ============================================================ // NCP PRO GLOBALS // ============================================================ static string g_mtgState = "INIT"; static string g_mtgReason = ""; static string g_mtgAction = ""; static color g_mtgClr = CGR; static double g_mtgHype = 50.0; static double g_mtgBetrayal = 50.0; static string g_mtgPattern = ""; static int g_mtgBullCount = 0; static int g_mtgBearCount = 0; static double g_mtgRecovery = 0.0; static datetime g_mtg_lastBar = 0; static double g_trapScore = 0; static double g_callWeight = 1.0; static double g_putWeight = 1.0; static int g_totalTrades = 0; static int g_callTrades = 0; static int g_putTrades = 0; static int g_callWins = 0; static int g_putWins = 0; static datetime g_ncpLastSignalTime = 0; static string g_ncpLastSignalType = ""; static double g_ncpLastEntryPrice = 0.0; static bool g_ncpSignalProcessed = true; static double g_smoothCallScore = 50.0; static double g_smoothPutScore = 50.0; //+------------------------------------------------------------------+ // 30-SECOND HA CANDLE //+------------------------------------------------------------------+ void Calc30SecHA(){ if(Bars < 5) return; double cur_open = Open[0]; double cur_high = High[0]; double cur_low = Low[0]; double cur_close = Close[0]; double prev_open = Open[1]; double prev_high = High[1]; double prev_low = Low[1]; double prev_close = Close[1]; double haC_prev = (prev_open + prev_high + prev_low + prev_close) / 4.0; double haC_prev2 = (Open[2] + High[2] + Low[2] + Close[2]) / 4.0; double haO_prev2 = (Open[3] + Close[3]) / 2.0; double haO_prev = (haO_prev2 + haC_prev2) / 2.0; double haC_cur = (cur_open + cur_high + cur_low + cur_close) / 4.0; double haO_cur = (haO_prev + haC_prev) / 2.0; g_ha30_open = haO_cur; g_ha30_close = haC_cur; g_ha30_high = cur_high; g_ha30_low = cur_low; g_ha30_bar = Time[0]; } bool Is30SecHABull(){ return (g_ha30_close > g_ha30_open); } bool Is30SecHABear(){ return (g_ha30_close < g_ha30_open); } //+------------------------------------------------------------------+ // BB PULLBACK DETECTION //+------------------------------------------------------------------+ void DetectBBPullback(){ if(!ENABLE_BB_PULLBACK || Bars < BB_PERIOD + 5) return; Calc30SecHA(); double bbUpper1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 1); double bbLower1 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 1); double bbUpper0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_UPPER, 0); double bbLower0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_LOWER, 0); double bbMid0 = iBands(NULL, PERIOD_M1, BB_PERIOD, BB_DEVIATION, 0, PRICE_CLOSE, MODE_MAIN, 0); if(bbUpper1 <= 0 || bbLower1 <= 0) return; bool ha30Bull = Is30SecHABull(); bool ha30Bear = Is30SecHABear(); double adx = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1); double plusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_PLUSDI, 1); double minusDI = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MINUSDI, 1); double rsi = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, 1); bool adxBull = (plusDI > minusDI); bool adxBear = (minusDI > plusDI); bool adxActive = (adx >= 15); bool adxStrong = (adx >= 20); bool rsiOverbought = (rsi >= 60); bool rsiOversold = (rsi <= 40); bool rsiExtremeOB = (rsi >= 70); bool rsiExtremeOS = (rsi <= 30); int putConfirm = 0; if(ha30Bear) putConfirm++; if(adxBear) putConfirm++; if(rsiOverbought) putConfirm++; if(rsiExtremeOB) putConfirm++; int callConfirm = 0; if(ha30Bull) callConfirm++; if(adxBull) callConfirm++; if(rsiOversold) callConfirm++; if(rsiExtremeOS) callConfirm++; string adxStr = "ADX:"+DoubleToString(adx,0)+(adxStrong?"*":""); string rsiStr = "RSI:"+DoubleToString(rsi,0); string diStr = (adxBull?"DI^":adxBear?"DIv":"DI="); if(g_bbSignal != "--" && g_bbSignalTime > 0){ int barsElapsed = (int)((TimeCurrent() - g_bbSignalTime) / (Period() * 60)); if(barsElapsed > BB_SIGNAL_EXPIRE_BARS){ g_bbSignal = "--"; g_bbColor = NEON_YELLOW; g_bbDetail = ""; g_bbTouchPrice = 0.0; } } bool touchedUpper = (High[1] >= bbUpper1 * 0.9998); bool touchedLower = (Low[1] <= bbLower1 * 1.0002); bool wickUpper = (High[1] > bbUpper1 && Close[1] < bbUpper1); bool wickLower = (Low[1] < bbLower1 && Close[1] > bbLower1); string newSignal = "--"; double touchPriceNew = 0.0; string detailNew = ""; color newColor = NEON_YELLOW; if((touchedUpper || wickUpper) && putConfirm >= 2){ newSignal = "PUT"; touchPriceNew = bbUpper1; string conf = (putConfirm>=4)?"STRONG":(putConfirm>=3)?"GOOD":"WEAK"; detailNew = "BB UP|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr; newColor = (putConfirm >= 3) ? NEON_RED : NEON_ORANGE; } else if((touchedLower || wickLower) && callConfirm >= 2){ newSignal = "CALL"; touchPriceNew = bbLower1; string conf = (callConfirm>=4)?"STRONG":(callConfirm>=3)?"GOOD":"WEAK"; detailNew = "BB LO|"+conf+"|"+adxStr+"|"+rsiStr+"|"+diStr; newColor = (callConfirm >= 3) ? NEON_GREEN : NEON_CYAN; } if(newSignal != "--"){ bool isNew = (newSignal != g_bbSignal || touchPriceNew != g_bbTouchPrice); if(isNew){ g_bbSignal = newSignal; g_bbTouchPrice = touchPriceNew; g_bbSignalTime = TimeCurrent(); g_bbDetail = detailNew; g_bbColor = newColor; AddBBLine(touchPriceNew, newSignal); Print("BB PULLBACK: ",newSignal," | ",detailNew," Conf:",(newSignal=="PUT"?putConfirm:callConfirm),"/4"); } } else if(g_bbSignal == "--"){ g_bbColor = NEON_YELLOW; } DrawBBLines(bbUpper0, bbLower0, bbMid0); } //+------------------------------------------------------------------+ // BB LINES DRAW ON CHART //+------------------------------------------------------------------+ void DrawBBLines(double upper, double lower, double mid){ if(!ENABLE_BB_PULLBACK) return; string nmU = PFX+"BB_UPPER"; SafeDel(nmU); if(upper > 0){ ObjectCreate(0, nmU, OBJ_HLINE, 0, 0, upper); ObjectSetInteger(0, nmU, OBJPROP_COLOR, BB_GREY); ObjectSetInteger(0, nmU, OBJPROP_WIDTH, 1); ObjectSetInteger(0, nmU, OBJPROP_STYLE, STYLE_DASH); ObjectSetInteger(0, nmU, OBJPROP_BACK, false); } string nmL = PFX+"BB_LOWER"; SafeDel(nmL); if(lower > 0){ ObjectCreate(0, nmL, OBJ_HLINE, 0, 0, lower); ObjectSetInteger(0, nmL, OBJPROP_COLOR, BB_GREY); ObjectSetInteger(0, nmL, OBJPROP_WIDTH, 1); ObjectSetInteger(0, nmL, OBJPROP_STYLE, STYLE_DASH); ObjectSetInteger(0, nmL, OBJPROP_BACK, false); } string nmM = PFX+"BB_MID"; SafeDel(nmM); if(mid > 0){ ObjectCreate(0, nmM, OBJ_HLINE, 0, 0, mid); ObjectSetInteger(0, nmM, OBJPROP_COLOR, C'100,100,110'); ObjectSetInteger(0, nmM, OBJPROP_WIDTH, 1); ObjectSetInteger(0, nmM, OBJPROP_STYLE, STYLE_DOT); ObjectSetInteger(0, nmM, OBJPROP_BACK, false); } int dg = (int)MarketInfo(Symbol(), MODE_DIGITS); if(dg <= 0) dg = 5; string lblU = PFX+"BB_U_LBL"; SafeDel(lblU); if(upper > 0 && Bars > 2){ ObjectCreate(0, lblU, OBJ_TEXT, 0, Time[2], upper); ObjectSetText(lblU, "BB("+IntegerToString(BB_PERIOD)+")", 8, "Arial", BB_GREY); ObjectSetInteger(0, lblU, OBJPROP_BACK, false); } } void AddBBLine(double price, string sigType){ if(price <= 0) return; for(int i = 0; i < MAX_BB_LINES; i++){ SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i)); SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i)); } g_bbLineCount = 0; g_bbLinePrice[0] = price; g_bbLineExpire[0] = TimeCurrent() + 60 * BB_SIGNAL_EXPIRE_BARS; g_bbLineType[0] = sigType; g_bbLineCount = 1; DrawAllBBTouchLines(); } void DrawAllBBTouchLines(){ for(int i = 0; i < MAX_BB_LINES; i++){ SafeDel(PFX+"BB_TOUCH_"+IntegerToString(i)); SafeDel(PFX+"BB_TOUCH_LBL_"+IntegerToString(i)); } if(g_bbLineCount > 0 && TimeCurrent() > g_bbLineExpire[0]){ g_bbLineCount = 0; return; } if(g_bbLineCount <= 0) return; int dg = (int)MarketInfo(Symbol(), MODE_DIGITS); if(dg <= 0) dg = 5; string nm = PFX+"BB_TOUCH_0"; string lbl = PFX+"BB_TOUCH_LBL_0"; ObjectCreate(0, nm, OBJ_HLINE, 0, 0, g_bbLinePrice[0]); ObjectSetInteger(0, nm, OBJPROP_COLOR, BB_GREY); ObjectSetInteger(0, nm, OBJPROP_WIDTH, 2); ObjectSetInteger(0, nm, OBJPROP_STYLE, STYLE_SOLID); ObjectSetInteger(0, nm, OBJPROP_BACK, false); if(Bars > 3){ string txt = (g_bbLineType[0]=="CALL") ? "BB^ CALL" : "BBv PUT"; color lc = (g_bbLineType[0]=="CALL") ? NEON_GREEN : NEON_RED; ObjectCreate(0, lbl, OBJ_TEXT, 0, Time[3], g_bbLinePrice[0]); ObjectSetText(lbl, txt, 8, "Arial Bold", lc); ObjectSetInteger(0, lbl, OBJPROP_BACK, false); } } // --- LEARNING ENGINE FUNCTIONS --- void LoadBrainMemory(){ if(!ENABLE_LEARNING) return; int h=FileOpen(MEMORY_FILE_NAME,FILE_READ|FILE_CSV|FILE_SHARE_READ); if(h!=INVALID_HANDLE){ if(FileSize(h)>10){ string line=FileReadString(h); string parts[]; int cnt=StringSplit(line,',',parts); if(cnt>=7){ g_totalTrades=(int)StringToInteger(parts[0]); g_callTrades =(int)StringToInteger(parts[1]); g_putTrades =(int)StringToInteger(parts[2]); g_callWins =(int)StringToInteger(parts[3]); g_putWins =(int)StringToInteger(parts[4]); g_callWeight =StringToDouble(parts[5]); g_putWeight =StringToDouble(parts[6]); if(g_callWeight<0.2||g_callWeight>1.8) g_callWeight=1.0; if(g_putWeight <0.2||g_putWeight >1.8) g_putWeight =1.0; Print("NCP Brain loaded: ",g_totalTrades," trades | CW:",DoubleToString(g_callWeight,3)," PW:",DoubleToString(g_putWeight,3)); } } FileClose(h); } } void SaveBrainMemory(){ if(!ENABLE_LEARNING) return; int h=FileOpen(MEMORY_FILE_NAME,FILE_WRITE|FILE_CSV|FILE_SHARE_WRITE); if(h!=INVALID_HANDLE){ string line=IntegerToString(g_totalTrades)+","+IntegerToString(g_callTrades)+","+IntegerToString(g_putTrades)+","+IntegerToString(g_callWins)+","+IntegerToString(g_putWins)+","+DoubleToString(g_callWeight,6)+","+DoubleToString(g_putWeight,6); FileWrite(h,line); FileClose(h); } } void UpdateBrain(string sig,bool win){ if(!ENABLE_LEARNING) return; g_totalTrades++; if(sig=="CALL"){g_callTrades++;if(win)g_callWins++;} else if(sig=="PUT"){g_putTrades++;if(win)g_putWins++;} if(g_totalTrades < MIN_TRADES_TO_LEARN){ SaveBrainMemory(); return; } double adj=LEARNING_STEP; if(sig=="CALL"){ double wr=(g_callTrades>0)?(double)g_callWins/g_callTrades:0.5; double adaptive=adj*(wr-0.5)*2.0; if(win) g_callWeight=MathMin(1.8,g_callWeight+adj+adaptive); else g_callWeight=MathMax(0.3,g_callWeight-adj*1.5+adaptive); if(g_callTrades0)?(double)g_putWins/g_putTrades:0.5; double adaptive=adj*(wr-0.5)*2.0; if(win) g_putWeight=MathMin(1.8,g_putWeight+adj+adaptive); else g_putWeight=MathMax(0.3,g_putWeight-adj*1.5+adaptive); if(g_putTradessigOpen); else if(g_ncpLastSignalType=="PUT") win=(sigClose=0); double pip=jpy?0.01:0.0001; for(int i=1;i<=15&&iOpen[i])&&(Close[i-1]=Open[i-1])&&(Open[i]<=Close[i-1]); bool bearEngulf=(Close[i]Open[i-1])&&(Close[i]<=Open[i-1])&&(Open[i]>=Close[i-1]); if(i>=2){ bool mornStar=(Close[i-2]Open[i]); bool eveStar =(Close[i-2]>Open[i-2])&&(MathAbs(Close[i-1]-Open[i-1])=3){ if(bullEngulf&&Close[i-3]Close[i-2]) trapScore+=3.5; if(mornStar&&Close[i-3]Close[i-2]) trapScore+=3.0; } } double rng=High[i]-Low[i]; if(rng<=0) continue; double uw=(High[i]-MathMax(Open[i],Close[i]))/rng; double lw=(MathMin(Open[i],Close[i])-Low[i])/rng; if(uw>0.55&&Close[i]0.55&&Close[i]>Open[i]) trapScore+=2.0; } double rng0=High[0]-Low[0]; if(rng0>0){ double uw0=(High[0]-MathMax(Open[0],Close[0]))/rng0; double lw0=(MathMin(Open[0],Close[0])-Low[0])/rng0; if(uw0>0.65&&Close[0]0.65&&Close[0]>Open[0]) trapScore+=4.0; if(Close[0]>Open[0]&&Close[1]Open[1]&&Open[0]Open[1]){ if(Close[0]Close[1]) trapScore+=3.0; } } double biasStr=MathMax(callBias,putBias)-50; double biasMul=1.0+biasStr/150.0; if(biasMul>1.5) biasMul=1.5; if(biasMul<0.5) biasMul=0.5; trapScore*=biasMul; return MathMin(100,trapScore); } //+------------------------------------------------------------------+ //| NCP v4.0 - OTC Broker Trap Killer (FIXED) | //+------------------------------------------------------------------+ void CalculateMTG(){ if(!ENABLE_MTG || Bars < 50){ g_mtgState = "OFF"; g_mtgReason = ""; g_mtgClr = CGR; return; } CheckPreviousResult(); bool jpy = (StringFind(Symbol(),"JPY")>=0); double pip = jpy ? 0.01 : 0.0001; int sec = (int)(TimeCurrent() - Time[0]); if(sec < NCP_OpenNoiseSeconds){ g_mtgState = "..."; g_mtgReason = "Bar open"; g_mtgClr = CGR; g_mtgHype = 50; g_mtgBetrayal = 50; return; } if(sec >= NCP_KillZoneSeconds){ g_mtgState = "END"; g_mtgReason = "Late"; g_mtgClr = NEON_ORANGE; g_mtgHype = 50; g_mtgBetrayal = 50; return; } double spPips = MarketInfo(Symbol(),MODE_SPREAD) * Point / pip; if(spPips > NCP_MaxSpreadPips){ g_mtgState = "SPREAD"; g_mtgReason = DoubleToString(spPips,1) + "p"; g_mtgClr = NEON_ORANGE; g_mtgHype = 50; g_mtgBetrayal = 50; return; } double atr = iATR(Symbol(),PERIOD_M1,NCP_ATRPeriod,1); if(atr <= 0) atr = Point * 10; double atrPips = atr / pip; if(atrPips < NCP_MinATRPips){ g_mtgState = "FLAT"; g_mtgReason = "Low ATR"; g_mtgClr = CGR; g_mtgHype = 50; g_mtgBetrayal = 50; return; } // ========== ORIGINAL SCORING CODE (cS, pS) ========== // Aapka purana scoring logic yahan aayega. // Main dummy example de raha hoon - aap ise apne original scoring se replace karna. double cS = 50.0, pS = 50.0; // TODO: Paste your original cS/pS calculation here (EMA, RSI, volume, etc.) // ========== NCP v4.0 SCALING ========== double adx_value = iADX(NULL, PERIOD_M1, 14, PRICE_CLOSE, MODE_MAIN, 1); if(adx_value <= 0) adx_value = 15.0; double adx_strength = MathMax(adx_value, 15.0); double max_conf; if(adx_strength < 20) max_conf = 45.0; else if(adx_strength < 30) max_conf = 65.0; else max_conf = 85.0; double total = cS + pS; double call_percent, put_percent; if(total > 0.01){ call_percent = (cS / total) * max_conf; put_percent = (pS / total) * max_conf; } else { call_percent = 35.0; put_percent = 35.0; } double edge = MathAbs(call_percent - put_percent); double final_ncp; string signal_state; if(edge >= 25.0 && adx_strength >= 22){ if(call_percent > put_percent){ final_ncp = call_percent; signal_state = "CALL_TRAP"; } else { final_ncp = put_percent; signal_state = "PUT_TRAP"; } } else if(edge >= 18.0 && adx_strength >= 20){ final_ncp = MathMax(call_percent, put_percent) * 0.85; signal_state = "WEAK_TRAP"; } else { final_ncp = MathMax(call_percent, put_percent) * 0.6; signal_state = "NEUTRAL"; } if(call_percent > put_percent){ g_mtgState = (signal_state == "NEUTRAL") ? "NEUTRAL" : "CALL"; g_mtgHype = final_ncp; g_mtgBetrayal = 100 - final_ncp; } else { g_mtgState = (signal_state == "NEUTRAL") ? "NEUTRAL" : "PUT"; g_mtgBetrayal = final_ncp; g_mtgHype = 100 - final_ncp; } g_mtgReason = "ADX:" + DoubleToString(adx_strength,0) + " Edge:" + DoubleToString(edge,0); g_mtgAction = g_mtgState + " " + DoubleToString(final_ncp,1) + "%"; if(g_mtgState == "CALL") g_mtgClr = (final_ncp>=70)?NEON_GREEN:NEON_LIME; else if(g_mtgState == "PUT") g_mtgClr = (final_ncp>=70)?NEON_RED:C'255,80,80'; else g_mtgClr = NEON_YELLOW; if(Time[0] != g_ncpLastSignalTime){ g_ncpLastSignalTime = Time[0]; g_ncpSignalProcessed = false; if(g_mtgState == "CALL" || g_mtgState == "PUT"){ g_ncpLastSignalType = g_mtgState; } } } //+------------------------------------------------------------------+ // HA CANDLE CALCULATION (M1 + M5) //+------------------------------------------------------------------+ void CalcHA(){ if(Bars<10) return; ArraySetAsSeries(Open,true); ArraySetAsSeries(High,true); ArraySetAsSeries(Low,true); ArraySetAsSeries(Close,true); static double haO1[500],haC1[500]; static datetime lb1=0; ArraySetAsSeries(haO1,true); ArraySetAsSeries(haC1,true); datetime c1=iTime(NULL,PERIOD_M1,0); if(c1!=lb1){ lb1=c1; int lim=MathMin(iBars(NULL,PERIOD_M1),500); for(int i=lim-1;i>=0;i--){ haC1[i]=(Open[i]+High[i]+Low[i]+Close[i])/4.0; if(i==lim-1) haO1[i]=(Open[i]+Close[i])/2.0; else haO1[i]=(haO1[i+1]+haC1[i+1])/2.0; }} double d1=MathAbs(haC1[1]-haO1[1]),r1=High[1]-Low[1]; bool dz=(r1>0&&d1haO1[1]),be1=(!dz&&haC1[1]=10){ static double haO5[200],haC5[200]; static datetime lb5=0; ArraySetAsSeries(haO5,true); ArraySetAsSeries(haC5,true); datetime c5=iTime(NULL,PERIOD_M5,0); if(c5!=lb5){ lb5=c5; int lim=MathMin(iBars(NULL,PERIOD_M5),200); 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); 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; }} double d5=MathAbs(haC5[1]-haO5[1]),r5=iHigh(NULL,PERIOD_M5,1)-iLow(NULL,PERIOD_M5,1); bool dz5=(r5>0&&d5haO5[1]),be5=(!dz5&&haC5[1]=0); double pip=jpy?0.01:0.0001; double tol=pipTol*pip; for(int i=ObjectsTotal()-1;i>=0;i--){ string nm=ObjectName(i); if((int)ObjectGetInteger(0,nm,OBJPROP_TYPE)==OBJ_HLINE){ double lp=ObjectGetDouble(0,nm,OBJPROP_PRICE); if(MathAbs(lp-price)=12&&h<16){sC=NEON_GOLD;return "LON+NY";} if(h>=7&&h<9){sC=NEON_CYAN;return "ASI+LON";} if(h>=7&&h<16){sC=NEON_GREEN;return "LONDON";} if(h>=12&&h<21){sC=NEON_BLUE;return "NEW YORK";} if(h>=0&&h<9){sC=NEON_ORANGE;return "ASIA";} sC=C'100,100,120'; return "SYDNEY"; } bool IsSessionActive(){int h=TimeHour(TimeGMT());return(h>=7&&h<=21);} 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);} bool CheckMTFConfirmation(){ if(!MTF_CONFIRM) return true; bool m1Bull=(Close[1]>Open[1]); bool m5Bull=false,m15Bull=false; if(iBars(NULL,PERIOD_M5)>=3) m5Bull=(iClose(NULL,PERIOD_M5,1)>iOpen(NULL,PERIOD_M5,1)); if(iBars(NULL,PERIOD_M15)>=3) m15Bull=(iClose(NULL,PERIOD_M15,1)>iOpen(NULL,PERIOD_M15,1)); int bullCount=0,bearCount=0; if(m1Bull) bullCount++; else bearCount++; if(m5Bull) bullCount++; else bearCount++; if(m15Bull) bullCount++; else bearCount++; g_mtfConfirmed=(bullCount>=2 || bearCount>=2); return g_mtfConfirmed; } double Tanh(double x){double e=MathExp(2.0*x);return(e-1.0)/(e+1.0);} double CalcFractalDimension(int period){ if(period<2)return 1.5;double sum=0.0; for(int i=1;i2.0)result=2.0;return result; } double DetectBrokerTrap(int lookback){ int bull=0,bear=0;for(int i=1;i<=lookback;i++){if(Close[i]>Open[i])bull++;else if(Close[i]bear)?(double)bull/lookback:(double)bear/lookback; double priceMove=MathAbs(Close[1]-Close[lookback])/(Close[lookback]+0.00001); if(crowd>0.7&&priceMove<0.002)return 0.9;if(crowd>0.6&&priceMove>0.001)return 0.5;return 0.3; } double QuickMedian(double &arr[],int size){ double sorted[20];for(int i=0;isorted[j]){double tmp=sorted[i];sorted[i]=sorted[j];sorted[j]=tmp;} return(sorted[size/2]+sorted[(size-1)/2])/2.0; } double CalcAdvancedTFA(string &detail){ if(Bars<30){detail="Bars low";return 3.0;} double score=0;string p=""; double adx=iADX(NULL,PERIOD_M1,14,PRICE_CLOSE,MODE_MAIN,1); double adxSc=(adx>=25)?1.0:(adx>=20)?0.6:(adx>=15)?0.3:0.1; score+=adxSc;p+="ADX:"+((adxSc>=0.6)?"+":"-")+" "; 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)?"+":"-")+" "; 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)?"+":"-")+" "; double atr=iATR(NULL,PERIOD_M1,14,1),cs=High[1]-Low[1],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)?"+":"-")+" "; double body=MathAbs(Close[1]-Open[1]),range=High[1]-Low[1],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)?"+":"-")+" "; double sesSc=IsSessionActive()?1.0:0.4; score+=sesSc;p+="SES:"+((sesSc>=0.7)?"+":"-"); double finalScore=MathMin(6.0,score);int rounded=(int)MathRound(finalScore); string dir="MIX"; if(g_haM1=="HA BULLISH 1"&&g_haM5=="HA BULLISH 5")dir="STRONG UP"; else if(g_haM1=="HA BEARISH 1"&&g_haM5=="HA BEARISH 5")dir="STRONG DOWN"; else if(g_haM1=="HA BULLISH 1")dir="UP"; else if(g_haM1=="HA BEARISH 1")dir="DOWN"; detail=p+" | "+IntegerToString(rounded)+"/6 "+dir; g_tfa_detail=detail;return finalScore; } double CalcAdvancedMicroAI(){ if(Bars<20) return 50.0; double score=50.0; bool jpy=(StringFind(Symbol(),"JPY")>=0); double pip=jpy?0.01:0.0001; // 1. Weighted wick analysis — recent bars zyada important for(int i=1;i<=5;i++){ double r=High[i]-Low[i]; if(r<=0) continue; double uw=(High[i]-MathMax(Open[i],Close[i]))/r; double lw=(MathMin(Open[i],Close[i])-Low[i])/r; double w=(6.0-i)/5.0; // Upper wick = price rejected from above = bearish signal if(uw>0.65) score-=w*18; else if(uw>0.50) score-=w*10; // Lower wick = price rejected from below = bullish signal if(lw>0.65) score+=w*18; else if(lw>0.50) score+=w*10; } // 2. Candle body position in range (last 5 bars) 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; } score+=(pos5/5.0-0.5)*25.0; // 3. Green/Red candle count (last 8 bars, weighted) double gc=0,rc=0; for(int i=1;i<=8;i++){ double w=(9.0-i)/8.0; if(Close[i]>Open[i]) gc+=w; else if(Close[i]0){ double vr=vl1/vA; if(vr>2.0&&Close[1]>Open[1]) score+=12; else if(vr>2.0&&Close[1]1.5&&Close[1]>Open[1]) score+=7; else if(vr>1.5&&Close[1]70) score-=15; // Overbought = bearish else if(r1>60) score-=7; // RSI divergence hint if(r1>r5&&Close[1]