Please help. While I am compiling following code in EA. I am encountering 2 errors of "unbalanced parenthesis" and "unexpected end of program"

 

Hi Guys, 

Please help in correcting the following code in MQL4. While I am compiling following code in EA. I am encountering 2 errors of "unbalanced parenthesis" (highlited in Bold Red) and "unexpected end of program" (highlited in Bold Yellow)


// declare global variables

double lotSize = 0.01;

double maxRisk = 0.15;  // percentage of account balance for maximum allowed trades

int totalTrades = 0;



// initialization function

int init() {

   return(0);

}



// start function

int start() {

   // get account information

   double accountBalance = AccountBalance();

   double accountEquity = AccountEquity();

   double accountRisk = accountBalance * maxRisk;

   int totalOpenOrders = OrdersTotal();

   

   // check if maximum allowed trades have been reached

   if (totalOpenOrders >= (accountRisk / (lotSize * MarketInfo(Symbol(), MODE_MARGINREQUIRED)))) {

      return(0);

   }

   

   // check if the market is open

   if (!MarketInfo(Symbol(), MODE_TRADEALLOWED)) {

      return(0);

   }

   

   // check if the current time is within trading hours

   if (TimeHour(TimeCurrent()) < 7 || TimeHour(TimeCurrent()) > 20) {

      return(0);

   }

   

   // define trade conditions

   double ma7 = iMA(NULL, 0, 7, 0, MODE_EMA, PRICE_CLOSE, 0);

   double ma21 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 0);

   double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);

   

   // check for buy signal

   if (Close[1] < ma7 && Close[0] > ma7 && ma7 > ma21 && rsi > 50) {

      // calculate lot size based on available margin

      double availableMargin = MarketInfo(Symbol(), MODE_MARGINAVAILABLE);

      double marginRequired = SymbolInfoDouble(Symbol(), SYMBOL_MARGINREQUIRED);

      double calculatedLotSize = NormalizeDouble((availableMargin * 0.01) / marginRequired, 2);

      double lot = MathMin(lotSize, calculatedLotSize);

      

      // open buy order

      int ticket = OrderSend(Symbol(), OP_BUY, lot, Ask, 3, Bid - 10 * Point, Bid + 20 * Point, "Buy order", 0, 0, Green);

      

      if (ticket > 0) {

         totalTrades++;

         Print("Buy order opened: ticket=", ticket, " lot=", lot, " price=", Ask);

      } else {

         Print("Error opening buy order: ", GetLastError());

      }

   }

   

   // check for sell signal

   if (Close[1] > ma7 && Close[0] < ma7 && ma7 < ma21 && rsi < 50) {

      // calculate lot size based on available margin

      double availableMargin = MarketInfo(Symbol(), MODE_MARGINAVAILABLE);

      double marginRequired = SymbolInfoDouble(Symbol(), SYMBOL_MARGINREQUIRED);

      double calculatedLotSize = NormalizeDouble((availableMargin * 0.01) / marginRequired, 2);

      double lot = MathMin(lotSize, calculatedLotSize);

      

      // open sell order

      int ticket = OrderSend(Symbol(), OP_SELL, lot, Bid, 3, Ask + 10 * Point, Ask - 20 * Point, "Sell order", 0, 0, Red);

      

      if (ticket > 0) {

         totalTrades++;

         Print("Sell order opened: ticket=", ticket, " lot=", lot, " price=", Bid);

UNCODE:


I will be gratified if anyone can help in correcting the abovementioned code. Furthermore, any helpful guidence will be most appreciated.


Thanks and regards,

Rizwan

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  3.          Print("Sell order opened: ticket=", ticket, " lot=", lot, " price=", Bid);
    
    UNCODE:
    
    Where is the rest of your code?