Can Someone Help Me to Fix expression is always 'true' warning in line 285 PLS!!!

 
//+------------------------------------------------------------------+
//|                                                     OxygenAI.mq5 |
//|                             Copyright 2025, Hüseyin Avni Ekmekçi |
//|                                            haekmekci@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Hüseyin Avni Ekmekçi"
#property link      "haekmekci@hotmail.com"
#property version   "1.00"
#property description "OxgenAI EA for daily profit target"

#include <Trade\Trade.mqh>

// Input Parameters
input int fast_ma_period = 10;              // Fast MA Period
input int slow_ma_period = 20;              // Slow MA Period
input double tp_pips = 50;                  // Take Profit in Pips
input double sl_pips = 30;                  // Stop Loss in Pips
input double risk_percent = 1.0;            // Risk Percentage per Trade
input double max_drawdown_percent = 20.0;   // Max Allowed Drawdown Percentage
input int slippage = 3;                      // Max Slippage in Points
input double trailing_stop_pips = 20;       // Trailing Stop in Pips
input ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT; // Trading Timeframe
input bool use_news_filter = false;         // Use News Filter
input string news_start_time = "14:00";     // News Start Time (HH:MM)
input string news_end_time = "15:00";       // News End Time (HH:MM)
input int magic_number = 12345;             // Magic Number for Trades
input int max_spread_points = 30;           // Max Allowed Spread in Points
input double daily_profit_target = 1000.0;  // Daily Profit Target in USD

// Global Variables
int fast_ma_handle, slow_ma_handle;
double daily_profit = 0.0;
datetime last_day;
bool trading_allowed = true;
double pip_size;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   // Initialize Moving Average Handles
   fast_ma_handle = iMA(_Symbol, timeframe, fast_ma_period, 0, MODE_SMA, PRICE_CLOSE);
   slow_ma_handle = iMA(_Symbol, timeframe, slow_ma_period, 0, MODE_SMA, PRICE_CLOSE);
   
   if(fast_ma_handle == INVALID_HANDLE || slow_ma_handle == INVALID_HANDLE)
   {
      Print("Failed to create MA handles");
      return(INIT_FAILED);
   }

   // Calculate Pip Size
   int digits = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS);
   pip_size = MathPow(10, -digits + 1);

   // Create Control Panel Buttons
   ObjectCreate(0, "BuyButton", OBJ_BUTTON, 0, 0, 0);
   ObjectSetInteger(0, "BuyButton", OBJPROP_XDISTANCE, 10);
   ObjectSetInteger(0, "BuyButton", OBJPROP_YDISTANCE, 10);
   ObjectSetString(0, "BuyButton", OBJPROP_TEXT, "Buy");
   ObjectSetInteger(0, "BuyButton", OBJPROP_XSIZE, 60);
   ObjectSetInteger(0, "BuyButton", OBJPROP_YSIZE, 30);

   ObjectCreate(0, "SellButton", OBJ_BUTTON, 0, 0, 0);
   ObjectSetInteger(0, "SellButton", OBJPROP_XDISTANCE, 80);
   ObjectSetInteger(0, "SellButton", OBJPROP_YDISTANCE, 10);
   ObjectSetString(0, "SellButton", OBJPROP_TEXT, "Sell");
   ObjectSetInteger(0, "SellButton", OBJPROP_XSIZE, 60);
   ObjectSetInteger(0, "SellButton", OBJPROP_YSIZE, 30);

   ObjectCreate(0, "CloseAllButton", OBJ_BUTTON, 0, 0, 0);
   ObjectSetInteger(0, "CloseAllButton", OBJPROP_XDISTANCE, 150);
   ObjectSetInteger(0, "CloseAllButton", OBJPROP_YDISTANCE, 10);
   ObjectSetString(0, "CloseAllButton", OBJPROP_TEXT, "Close All");
   ObjectSetInteger(0, "CloseAllButton", OBJPROP_XSIZE, 60);
   ObjectSetInteger(0, "CloseAllButton", OBJPROP_YSIZE, 30);

   // Initialize Day Tracking
   last_day = TimeCurrent() / 86400;

   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   IndicatorRelease(fast_ma_handle);
   IndicatorRelease(slow_ma_handle);
   ObjectDelete(0, "BuyButton");
   ObjectDelete(0, "SellButton");
   ObjectDelete(0, "CloseAllButton");
}

//+------------------------------------------------------------------+
//| Check if there is an open position with the magic number         |
//+------------------------------------------------------------------+
bool HasOpenPosition()
{
   for(int i = 0; i < PositionsTotal(); i++)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC) == magic_number)
         return true;
   }
   return false;
}

//+------------------------------------------------------------------+
//| Check if spread is within acceptable limits                      |
//+------------------------------------------------------------------+
bool IsSpreadAcceptable()
{
   long current_spread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
   if(current_spread > max_spread_points)
   {
      Print("Spread too high: ", current_spread, " points. Max allowed: ", max_spread_points);
      return false;
   }
   return true;
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   // Check for New Day
   datetime current_day = TimeCurrent() / 86400;
   if(current_day != last_day)
   {
      daily_profit = 0.0;
      last_day = current_day;
   }

   // Check Drawdown
   double equity = AccountInfoDouble(ACCOUNT_EQUITY);
   double balance = AccountInfoDouble(ACCOUNT_BALANCE);
   static double highest_equity = balance;
   if(equity > highest_equity) highest_equity = equity;
   double drawdown = (highest_equity - equity) / highest_equity * 100.0;
   trading_allowed = (drawdown <= max_drawdown_percent);

   // Check News Filter
   bool in_news_time = false;
   if(use_news_filter)
   {
      datetime current_time = TimeCurrent();
      datetime start_time = StringToTime(TimeToString(TimeCurrent(), TIME_DATE) + " " + news_start_time);
      datetime end_time = StringToTime(TimeToString(TimeCurrent(), TIME_DATE) + " " + news_end_time);
      if(current_time >= start_time && current_time <= end_time)
         in_news_time = true;
   }

   // Check Spread
   if(!IsSpreadAcceptable())
      return;

   // Get MA Values
   double fast_ma[2], slow_ma[2];
   if(CopyBuffer(fast_ma_handle, 0, 1, 2, fast_ma) < 2 || CopyBuffer(slow_ma_handle, 0, 1, 2, slow_ma) < 2)
   {
      Print("Failed to get MA values");
      return;
   }

   // Check for Crossover
   bool buy_signal = (fast_ma[0] > slow_ma[0]) && (fast_ma[1] <= slow_ma[1]);
   bool sell_signal = (fast_ma[0] < slow_ma[0]) && (fast_ma[1] >= slow_ma[1]);
   bool has_open_position = HasOpenPosition();

   // Auto Open Trades
   if(trading_allowed && !has_open_position && !in_news_time && daily_profit < daily_profit_target)
   {
      if(buy_signal)
         OpenTrade(POSITION_TYPE_BUY);
      else if(sell_signal)
         OpenTrade(POSITION_TYPE_SELL);
   }

   // Trailing Stop
   for(int i = 0; i < PositionsTotal(); i++)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC) == magic_number)
      {
         double open_price = PositionGetDouble(POSITION_PRICE_OPEN);
         double current_sl = PositionGetDouble(POSITION_SL);
         double current_price = (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? 
                               SymbolInfoDouble(_Symbol, SYMBOL_BID) : SymbolInfoDouble(_Symbol, SYMBOL_ASK);
         double profit_pips = (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? 
                             (current_price - open_price) / pip_size : (open_price - current_price) / pip_size;

         if(profit_pips > trailing_stop_pips)
         {
            double new_sl = (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? 
                           current_price - trailing_stop_pips * pip_size : 
                           current_price + trailing_stop_pips * pip_size;
            if((PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && new_sl > current_sl) ||
               (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && new_sl < current_sl))
            {
               CTrade trade;
               trade.PositionModify(ticket, new_sl, PositionGetDouble(POSITION_TP));
            }
         }
      }
   }
}

//+------------------------------------------------------------------+
//| Trade Transaction Handler                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
{
   if(trans.type == TRADE_TRANSACTION_DEAL_ADD)
   {
      ulong deal_ticket = trans.deal;
      if(HistoryDealGetInteger(deal_ticket, DEAL_MAGIC) == magic_number)
      {
         daily_profit += HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);
      }
   }
}

//+------------------------------------------------------------------+
//| Chart Event Handler                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   if(id == CHARTEVENT_OBJECT_CLICK)
   {
      if(sparam == "BuyButton")
         OpenTrade(POSITION_TYPE_BUY);
      else if(sparam == "SellButton")
         OpenTrade(POSITION_TYPE_SELL);
      else if(sparam == "CloseAllButton")
         CloseAllPositions();
   }
}

//+------------------------------------------------------------------+
//| Open Trade Function                                              |
//+------------------------------------------------------------------+
void OpenTrade(ENUM_POSITION_TYPE type)
{
   // Check Spread (redundant but kept for manual button trades)
   if(!IsSpreadAcceptable())
      return;

   CTrade trade;
   trade.SetExpertMagicNumber(magic_number);
   trade.SetDeviationInPoints(slippage);

   double price = (type == POSITION_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double sl_price = (type == POSITION_TYPE_BUY) ? price - sl_pips * pip_size : price + sl_pips * pip_size;
   double tp_price = (type == POSITION_TYPE_BUY) ? price + tp_pips * pip_size : price - tp_pips * pip_size;

   // Calculate Lot Size
   double account_balance = AccountInfoDouble(ACCOUNT_BALANCE);
   double risk_amount = account_balance * (risk_percent / 100.0);
   double tick_size = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   double tick_value = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
   double pip_value_per_lot = (pip_size / tick_size) * tick_value;
   double lot_size = risk_amount / (sl_pips * pip_value_per_lot);

   double min_lot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   double max_lot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
   lot_size = MathMin(MathMax(lot_size, min_lot), max_lot);

   if(type == POSITION_TYPE_BUY)
      trade.Buy(lot_size, _Symbol, price, sl_price, tp_price);
   else
      trade.Sell(lot_size, _Symbol, price, sl_price, tp_price);
}

//+------------------------------------------------------------------+
//| Close All Positions Function                                     |
//+------------------------------------------------------------------+
void CloseAllPositions()
{
   CTrade trade;
   for(int i = PositionsTotal() - 1;! i >= 0; i--)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC) == magic_number)
         trade.PositionClose(ticket);
   }
}
 
Huseyin Avni Ekmekci:
The condition !i >= 0 is logically incorrect.
!i negates the value of i (as a boolean), so the comparison doesn't make sense.
void CloseAllPositions()
{
   CTrade trade;
   for(int i = PositionsTotal() - 1;i >= 0; i--)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC) == magic_number)
         trade.PositionClose(ticket);
   }
}