admin管理员组

文章数量:1291260

I am trying to develop an Expert Advisor (EA) for MetaTrader 5 using MQL5, but I keep encountering the error '(<) - open parenthesis expected' for the following:

if (Bars < 3)

Here is a snippet of my code where the error occurs:

bool CheckBuyCondition()
{
   if (Bars < 3)
      return false;
   
   double prevClose1 = iClose(Symbol(), PERIOD_M5, 1);
   double prevClose2 = iClose(Symbol(), PERIOD_M5, 2);
   double prevHigh1 = iHigh(Symbol(), PERIOD_M5, 1);
   double prevHigh2 = iHigh(Symbol(), PERIOD_M5, 2);
   double currClose = iClose(Symbol(), PERIOD_M5, 0);
   
   double prevOpen1 = iOpen(Symbol(), PERIOD_M5, 1);
   double prevOpen2 = iOpen(Symbol(), PERIOD_M5, 2);
   
   if ((prevClose1 < prevOpen1) && (prevClose2 < prevOpen2) && (currClose > prevHigh1) && (currClose > prevHigh2) && (currClose > ema10))
      return true;

   return false;
}

bool CheckSellCondition()
{
   if (Bars < 3)
      return false;
   
   double prevClose1 = iClose(Symbol(), PERIOD_M5, 1);
   double prevClose2 = iClose(Symbol(), PERIOD_M5, 2);
   double prevLow1 = iLow(Symbol(), PERIOD_M5, 1);
   double prevLow2 = iLow(Symbol(), PERIOD_M5, 2);
   double currClose = iClose(Symbol(), PERIOD_M5, 0);
   
   double prevOpen1 = iOpen(Symbol(), PERIOD_M5, 1);
   double prevOpen2 = iOpen(Symbol(), PERIOD_M5, 2);
   
   if ((prevClose1 > prevOpen1) && (prevClose2 > prevOpen2) && (currClose < prevLow1) && (currClose < prevLow2) && (currClose < ema10))
      return true;

   return false;
}

I have tried adding parentheses around each comparison, and I have made sure the syntax follows the correct structure for conditional statements in MQL5. Despite these efforts, I still receive the same errors. I expect the code to compile without syntax errors and the EA to work as intended.

本文标签: syntax error39lt39open parenthesis expectedStack Overflow