//+------------------------------------------------------------------+ //| XAUUSD Ultimate EA | //| Trend + Momentum + News Filter | //+------------------------------------------------------------------+ input string TRADE_SETUP = "--- Trading Settings ---"; input double RiskPerTrade = 1.0; // Risk % per trade input int ATR_Period = 14; // ATR period for SL/TP input bool UseNewsFilter = true; // Enable news filter input int NewsMinBefore = 60; // Minutes before news to avoid trading input int NewsMinAfter = 120; // Minutes after news to avoid trading input string STRATEGY = "--- Strategy Settings ---"; input int IchimokuTenkan = 9; // Tenkan-sen period input int IchimokuKijun = 26; // Kijun-sen period input int RSIPeriod = 14; // RSI period input double RSIOverbought = 70; // RSI sell threshold input double RSIOversold = 30; // RSI buy threshold // Global variables int atrHandle; datetime lastNewsTime; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { atrHandle = iATR(_Symbol, _Period, ATR_Period); if (UseNewsFilter) LoadEconomicCalendar(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if (IsNewBar() && !IsTradeOpen() && !IsNewsTime()) { double atr = GetATR(); double lotSize = CalculateLotSize(RiskPerTrade, atr); // Ichimoku Cloud Conditions double tenkan = iIchimoku(NULL, 0, IchimokuTenkan, IchimokuKijun, 52, MODE_TENKANSEN, 0); double kijun = iIchimoku(NULL, 0, IchimokuTenkan, IchimokuKijun, 52, MODE_KIJUNSEN, 0); bool isBullish = tenkan > kijun && iClose(NULL, 0, 1) > iIchimoku(NULL, 0, IchimokuTenkan, IchimokuKijun, 52, MODE_SENKOUSPANA, 26); bool isBearish = tenkan < kijun && iClose(NULL, 0, 1) < iIchimoku(NULL, 0, IchimokuTenkan, IchimokuKijun, 52, MODE_SENKOUSPANA, 26); // Momentum Confirmation (RSI + MACD) double rsi = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, 0); bool rsiBuy = rsi < RSIOversold; bool rsiSell = rsi > RSIOverbought; if (isBullish && rsiBuy) OpenTrade(ORDER_TYPE_BUY, lotSize, atr); else if (isBearish && rsiSell) OpenTrade(ORDER_TYPE_SELL, lotSize, atr); } } //+------------------------------------------------------------------+ //| Calculate position size based on risk | //+------------------------------------------------------------------+ double CalculateLotSize(double riskPercent, double atr) { double accountBalance = AccountInfoDouble(ACCOUNT_BALANCE); double riskAmount = accountBalance * riskPercent / 100; double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE); double lotSize = NormalizeDouble(riskAmount / (atr * tickValue), 2); return MathMin(lotSize, SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX)); } //+------------------------------------------------------------------+ //| Open a trade with dynamic SL/TP | //+------------------------------------------------------------------+ void OpenTrade(ENUM_ORDER_TYPE orderType, double lotSize, double atr) { MqlTradeRequest request = {0}; MqlTradeResult result = {0}; request.action = TRADE_ACTION_DEAL; request.symbol = _Symbol; request.volume = lotSize; request.type = orderType; request.price = (orderType == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID); request.sl = (orderType == ORDER_TYPE_BUY) ? request.price - atr * 2 : request.price + atr * 2; request.tp = (orderType == ORDER_TYPE_BUY) ? request.price + atr * 3 : request.price - atr * 3; request.deviation= 10; OrderSend(request, result); } //+------------------------------------------------------------------+ //| News Filter (simplified) | //+------------------------------------------------------------------+ bool IsNewsTime() { if (!UseNewsFilter) return false; datetime now = TimeCurrent(); // Check if now is within NewsMinBefore/After a high-impact event // (In practice, integrate with an economic calendar API) return false; // Placeholder } //+------------------------------------------------------------------+ //| Check for new bar | //+------------------------------------------------------------------+ bool IsNewBar() { static datetime lastBarTime; datetime currentBarTime = iTime(_Symbol, _Period, 0); if (lastBarTime != currentBarTime) { lastBarTime = currentBarTime; return true; } return false; } //+------------------------------------------------------------------+ //| Check if trade already open | //+------------------------------------------------------------------+ bool IsTradeOpen() { return PositionSelect(_Symbol); } ``` ---