//+------------------------------------------------------------------+ //| REAL MT5 MULTI-MARKET SCANNER | //| MQL5 EA | //+------------------------------------------------------------------+ #property strict #property version "1.00" #property description "Live multi-symbol multi-timeframe MT5 scanner" //================================================================== // SETTINGS //================================================================== input string Symbols = "XAUUSD,EURUSD,GBPUSD,USDJPY,NAS100,BTCUSD"; input ENUM_TIMEFRAMES TrendTF = PERIOD_H4; input ENUM_TIMEFRAMES ConfirmTF = PERIOD_H1; input ENUM_TIMEFRAMES EntryTF = PERIOD_M15; input int EMA_Fast = 50; input int EMA_Slow = 200; input int RSI_Period = 14; input double RSI_Buy_Level = 50.0; input double RSI_Sell_Level = 50.0; input int ATR_Period = 14; input double MinimumScore = 70.0; input int ScanSeconds = 3; //================================================================== // STRUCTURE //================================================================== struct ScanResult { string symbol; string trend; string signal; double score; double price; double entry; double stopLoss; double takeProfit; double rsi; double atr; bool trendOK; bool emaOK; bool structureOK; bool momentumOK; bool entryOK; }; //================================================================== // GLOBAL //================================================================== string SymbolList[]; //================================================================== // INITIALIZATION //================================================================== int OnInit() { Print("=============================================="); Print("REAL MT5 MARKET SCANNER STARTED"); Print("=============================================="); StringSplit(Symbols, ',', SymbolList); for(int i = 0; i < ArraySize(SymbolList); i++) { StringTrimLeft(SymbolList[i]); StringTrimRight(SymbolList[i]); SymbolSelect(SymbolList[i], true); } EventSetTimer(ScanSeconds); return(INIT_SUCCEEDED); } //================================================================== // DEINITIALIZATION //================================================================== void OnDeinit(const int reason) { EventKillTimer(); Comment(""); Print("REAL MT5 MARKET SCANNER STOPPED"); } //================================================================== // TIMER //================================================================== void OnTimer() { ScanMarket(); } //================================================================== // MAIN SCANNER //================================================================== void ScanMarket() { string output = ""; output += "============================================================\n"; output += " REAL MT5 MARKET SCANNER\n"; output += "============================================================\n\n"; int buySignals = 0; int sellSignals = 0; double highestScore = 0; for(int i = 0; i < ArraySize(SymbolList); i++) { ScanResult result; if(!AnalyzeSymbol(SymbolList[i], result)) continue; output += FormatResult(result); output += "------------------------------------------------------------\n"; if(result.signal == "BUY") buySignals++; if(result.signal == "SELL") sellSignals++; if(result.score > highestScore) highestScore = result.score; } output += "\n"; output += "BUY SIGNALS : " + IntegerToString(buySignals) + "\n"; output += "SELL SIGNALS : " + IntegerToString(sellSignals) + "\n"; output += "TOP SCORE : " + DoubleToString(highestScore,0) + "/100\n"; output += "\nLast scan: "; output += TimeToString(TimeCurrent(), TIME_SECONDS); Comment(output); } //================================================================== // ANALYZE SYMBOL //================================================================== bool AnalyzeSymbol(string symbol, ScanResult &r) { r.symbol = symbol; // --------------------------------------------------------------- // Check symbol // --------------------------------------------------------------- if(!SymbolSelect(symbol, true)) return false; MqlTick tick; if(!SymbolInfoTick(symbol, tick)) return false; r.price = tick.bid; if(r.price <= 0) return false; // --------------------------------------------------------------- // GET EMA VALUES // --------------------------------------------------------------- double trendFast; double trendSlow; double confirmFast; double confirmSlow; if(!GetEMA(symbol, TrendTF, EMA_Fast, 1, trendFast)) return false; if(!GetEMA(symbol, TrendTF, EMA_Slow, 1, trendSlow)) return false; if(!GetEMA(symbol, ConfirmTF, EMA_Fast, 1, confirmFast)) return false; if(!GetEMA(symbol, ConfirmTF, EMA_Slow, 1, confirmSlow)) return false; // --------------------------------------------------------------- // TREND // --------------------------------------------------------------- bool bullishTrend = trendFast > trendSlow && confirmFast > confirmSlow; bool bearishTrend = trendFast < trendSlow && confirmFast < confirmSlow; if(bullishTrend) r.trend = "BULLISH"; else if(bearishTrend) r.trend = "BEARISH"; else r.trend = "NEUTRAL"; r.trendOK = bullishTrend || bearishTrend; // --------------------------------------------------------------- // EMA PRICE LOCATION // --------------------------------------------------------------- r.emaOK = (bullishTrend && r.price > trendSlow) || (bearishTrend && r.price < trendSlow); // --------------------------------------------------------------- // RSI // --------------------------------------------------------------- double rsi; if(!GetRSI(symbol, EntryTF, RSI_Period, 1, rsi)) return false; r.rsi = rsi; r.momentumOK = (bullishTrend && rsi > RSI_Buy_Level) || (bearishTrend && rsi < RSI_Sell_Level); // --------------------------------------------------------------- // ATR // --------------------------------------------------------------- double atr; if(!GetATR(symbol, EntryTF, ATR_Period, 1, atr)) return false; r.atr = atr; if(atr <= 0) return false; // --------------------------------------------------------------- // MARKET STRUCTURE // --------------------------------------------------------------- bool bullishStructure = IsBullishStructure(symbol, EntryTF); bool bearishStructure = IsBearishStructure(symbol, EntryTF); r.structureOK = (bullishTrend && bullishStructure) || (bearishTrend && bearishStructure); // --------------------------------------------------------------- // ENTRY CONFIRMATION // --------------------------------------------------------------- bool bullishEntry = bullishTrend && bullishStructure && rsi > RSI_Buy_Level; bool bearishEntry = bearishTrend && bearishStructure && rsi < RSI_Sell_Level; r.entryOK = bullishEntry || bearishEntry; // --------------------------------------------------------------- // SCORE // --------------------------------------------------------------- double score = 0; // Trend = 25 if(r.trendOK) score += 25; // EMA = 20 if(r.emaOK) score += 20; // Structure = 20 if(r.structureOK) score += 20; // Momentum = 15 if(r.momentumOK) score += 15; // Entry = 20 if(r.entryOK) score += 20; r.score = score; // --------------------------------------------------------------- // SIGNAL // --------------------------------------------------------------- if( bullishEntry && score >= MinimumScore ) { r.signal = "BUY"; } else if( bearishEntry && score >= MinimumScore ) { r.signal = "SELL"; } else { r.signal = "WAIT"; } // --------------------------------------------------------------- // TRADE LEVELS // --------------------------------------------------------------- r.entry = r.price; if(r.signal == "BUY") { r.stopLoss = r.entry - (r.atr * 1.5); r.takeProfit = r.entry + (r.atr * 3.0); } else if(r.signal == "SELL") { r.stopLoss = r.entry + (r.atr * 1.5); r.takeProfit = r.entry - (r.atr * 3.0); } else { r.stopLoss = 0; r.takeProfit = 0; } return true; } //================================================================== // EMA //================================================================== bool GetEMA( string symbol, ENUM_TIMEFRAMES timeframe, int period, int shift, double &value ) { int handle = iMA( symbol, timeframe, period, 0, MODE_EMA, PRICE_CLOSE ); if(handle == INVALID_HANDLE) return false; double buffer[]; ArraySetAsSeries(buffer, true); if(CopyBuffer( handle, 0, shift, 1, buffer ) != 1) { IndicatorRelease(handle); return false; } value = buffer[0]; IndicatorRelease(handle); return true; } //================================================================== // RSI //================================================================== bool GetRSI( string symbol, ENUM_TIMEFRAMES timeframe, int period, int shift, double &value ) { int handle = iRSI( symbol, timeframe, period, PRICE_CLOSE ); if(handle == INVALID_HANDLE) return false; double buffer[]; ArraySetAsSeries(buffer, true); if(CopyBuffer( handle, 0, shift, 1, buffer ) != 1) { IndicatorRelease(handle); return false; } value = buffer[0]; IndicatorRelease(handle); return true; } //================================================================== // ATR //================================================================== bool GetATR( string symbol, ENUM_TIMEFRAMES timeframe, int period, int shift, double &value ) { int handle = iATR( symbol, timeframe, period ); if(handle == INVALID_HANDLE) return false; double buffer[]; ArraySetAsSeries(buffer, true); if(CopyBuffer( handle, 0, shift, 1, buffer ) != 1) { IndicatorRelease(handle); return false; } value = buffer[0]; IndicatorRelease(handle); return true; } //================================================================== // GET RATES //================================================================== bool GetRates( string symbol, ENUM_TIMEFRAMES timeframe, int count, MqlRates &rates[] ) { ArraySetAsSeries(rates, true); int copied = CopyRates( symbol, timeframe, 0, count, rates ); return copied >= count; } //================================================================== // BULLISH STRUCTURE //================================================================== bool IsBullishStructure( string symbol, ENUM_TIMEFRAMES timeframe ) { MqlRates rates[]; if(!GetRates( symbol, timeframe, 20, rates )) return false; double recentHigh = rates[2].high; double previousHigh = rates[7].high; double recentLow = rates[2].low; double previousLow = rates[7].low; bool higherHigh = recentHigh > previousHigh; bool higherLow = recentLow > previousLow; return higherHigh && higherLow; } //================================================================== // BEARISH STRUCTURE //================================================================== bool IsBearishStructure( string symbol, ENUM_TIMEFRAMES timeframe ) { MqlRates rates[]; if(!GetRates( symbol, timeframe, 20, rates )) return false; double recentHigh = rates[2].high; double previousHigh = rates[7].high; double recentLow = rates[2].low; double previousLow = rates[7].low; bool lowerHigh = recentHigh < previousHigh; bool lowerLow = recentLow < previousLow; return lowerHigh && lowerLow; } //================================================================== // FORMAT RESULT //================================================================== string FormatResult(ScanResult &r) { string text = ""; text += r.symbol; text += " | TREND: " + r.trend; text += " | SIGNAL: " + r.signal; text += " | SCORE: " + DoubleToString(r.score,0) + "/100\n"; text += "Price: " + DoubleToString( r.price, (int)SymbolInfoInteger( r.symbol, SYMBOL_DIGITS ) ); text += " | RSI: " + DoubleToString(r.rsi,2); text += " | ATR: " + DoubleToString(r.atr,5) + "\n"; text += "Trend: " + BoolText(r.trendOK) + " | EMA: " + BoolText(r.emaOK) + " | Structure: " + BoolText(r.structureOK) + " | Momentum: " + BoolText(r.momentumOK) + " | Entry: " + BoolText(r.entryOK) + "\n"; if(r.signal != "WAIT") { text += "ENTRY: " + DoubleToString( r.entry, (int)SymbolInfoInteger( r.symbol, SYMBOL_DIGITS ) ) + "\n"; text += "STOP: " + DoubleToString( r.stopLoss, (int)SymbolInfoInteger( r.symbol, SYMBOL_DIGITS ) ) + "\n"; text += "TP: " + DoubleToString( r.takeProfit, (int)SymbolInfoInteger( r.symbol, SYMBOL_DIGITS ) ) + "\n"; } return text; } //================================================================== // BOOLEAN TEXT //================================================================== string BoolText(bool value) { if(value) return "PASS"; return "FAIL"; } //+------------------------------------------------------------------+ //| END | //+------------------------------------------------------------------+