unbalanced parenthesis ERROR

 

hi everyone, 

I've been trying to solve this problem for days now. 

but it keep give me the same error  "'unexpected end of program" and "'unbalanced parentheses"

hope that you will spot the error and solve it

thank you in advance

below the code 


void OnTick() 



         {



               // Calculate the opening range for the specified period

               double opening_range_high = High[iHighest(NULL, 0, MODE_HIGH, ORB_Period, 0)];

               double opening_range_low = Low[iLowest(NULL, 0, MODE_LOW, ORB_Period, 0)];

               double opening_range = opening_range_high - opening_range_low;



               // Calculate the breakout level

               double breakout_level = opening_range * ORB_Breakout / 100 + opening_range_low;



               // Calculate the stop-loss and take-profit levels

               double stop_loss = opening_range * ORB_SL / 100;

               double take_profit = opening_range * ORB_TP / 100;



               // Place a buy order if the price breaks above the breakout level

               if (Close[0] > breakout_level)

                     {

                           // Set the stop-loss and take-profit levels for the trade

                           double sl = NormalizeDouble(Close[0] - stop_loss, MarketInfo(Symbol(), MODE_DIGITS));

                           double tp = NormalizeDouble(Close[0] + take_profit, MarketInfo(Symbol(), MODE_DIGITS));



                           // Place the buy order

                           if (OrderSend(Symbol(), OP_BUY, 1, Ask, 3, sl, tp, "ORB Buy", 12345, 0, Green))

                                    {

                                       // Set the trailing stop for the trade

                                       OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Close[0] - opening_range * ORB_Trailing / 100, MarketInfo(Symbol(), MODE_DIGITS)), tp, 0, Blue);

                                    }

                     }





                // Place a sell order if the price breaks below the breakout level

                if (Close[0] < breakout_level)

                     {     

                           // Set the stop-loss and take-profit levels for the trade

                           double sl = NormalizeDouble(Close[0] + stop_loss, MarketInfo(Symbol(), MODE_DIGITS));

                           double tp = NormalizeDouble(Close[0] - take_profit, MarketInfo(Symbol(), MODE_DIGITS));



                           // Place the sell order

                           if (OrderSend(Symbol(), OP_SELL, 1, Bid, 3, sl, tp, "ORB Sell", 12345, 0, Red))

                                    {

                                       // Set the trailing stop for the trade

                                       OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Close[0] + opening_range * ORB_Trailing / 100, MarketInfo(Symbol(), MODE_DIGITS)), tp, 0, Blue);

                                    }



             }

               
 
elyatim: hi everyone, I've been trying to solve this problem for days now. but it keep give me the same error  "'unexpected end of program" and "'unbalanced parentheses" hope that you will spot the error and solve it. thank you in advance below the code

It is important that you learn to style your code properly and not have so much empty space. Use the built-in code styler in MetaEditor to help you with this.

Pride in making your code look "beautiful" helps to be able to read it more easily and find errors in your code and logic ...

void OnTick()
{
   // Calculate the opening range for the specified period
   double opening_range_high = High[iHighest(NULL, 0, MODE_HIGH, ORB_Period, 0)];
   double opening_range_low = Low[iLowest(NULL, 0, MODE_LOW, ORB_Period, 0)];
   double opening_range = opening_range_high - opening_range_low;

   // Calculate the breakout level
   double breakout_level = opening_range * ORB_Breakout / 100 + opening_range_low;

   // Calculate the stop-loss and take-profit levels
   double stop_loss = opening_range * ORB_SL / 100;
   double take_profit = opening_range * ORB_TP / 100;

   // Place a buy order if the price breaks above the breakout level
   if (Close[0] > breakout_level)
   {
      // Set the stop-loss and take-profit levels for the trade
      double sl = NormalizeDouble(Close[0] - stop_loss, MarketInfo(Symbol(), MODE_DIGITS));
      double tp = NormalizeDouble(Close[0] + take_profit, MarketInfo(Symbol(), MODE_DIGITS));

      // Place the buy order
      if (OrderSend(Symbol(), OP_BUY, 1, Ask, 3, sl, tp, "ORB Buy", 12345, 0, Green))
      {
         // Set the trailing stop for the trade
         OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Close[0] - opening_range * ORB_Trailing / 100, MarketInfo(Symbol(), MODE_DIGITS)), tp, 0, Blue);
      }
   }

   // Place a sell order if the price breaks below the breakout level
   if (Close[0] < breakout_level)
   {
      // Set the stop-loss and take-profit levels for the trade
      double sl = NormalizeDouble(Close[0] + stop_loss, MarketInfo(Symbol(), MODE_DIGITS));
      double tp = NormalizeDouble(Close[0] - take_profit, MarketInfo(Symbol(), MODE_DIGITS));

      // Place the sell order
      if (OrderSend(Symbol(), OP_SELL, 1, Bid, 3, sl, tp, "ORB Sell", 12345, 0, Red))
      {
         // Set the trailing stop for the trade
         OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Close[0] + opening_range * ORB_Trailing / 100, MarketInfo(Symbol(), MODE_DIGITS)), tp, 0, Blue);
      }
   }  // <-- Missing closing brace for if statement
}

However, now that the missing brace has been fixed, you now have to fix all the other errors ...


 

Why did you post your MT4 question in the MT5 EA 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.

 
elyatim: hi everyone, I've been trying to solve this problem for days now.  but it keep give me the same error  "'unexpected end of program" and "'unbalanced parentheses" hope that you will spot the error and solve it

thank you in advance. below the code

If I have incorrectly assumed your code to be MQL4 when in fact your are trying to code in MQL5, then please be aware that you have even more bugs in your code as many of the trade functions you are trying to use are for MQL4 only.

 
Moving topic to MQL4 section.
 
Fernando Carreiro #:

It is important that you learn to style your code properly and not have so much empty space. Use the built-in code styler in MetaEditor to help you with this.

Good tips - also enable these options


 
      if (OrderSend(Symbol(), OP_BUY, 1, Ask, 3, sl, tp, "ORB Buy", 12345, 0, Green))
OrderSend does not return a boolean; invalid condition.