Unexpected end of program and unbalanced parentheses. Can somone help.

 

I don't understand these errors, I turned on highlighting brackets and I don't understand what is causing the two errors, so close yet so far away. 

*******

 

add a closing bracket at the end.

Also, use code styler, it really helps

 
Andrey Barinov #:

add a closing bracket at the end.

Also, use code styler, it really helps

results after using styler and adding a closing bracket. Errors exploded. Any

//+------------------------------------------------------------------+

//| Global variables                                                 |

//+------------------------------------------------------------------+



// Scalping settings

double ScalpThreshold = 0.0;

double StopLoss = 0.0;

double TakeProfit = 0.0;

double Point = 0.0;



// Trade tracking variables

int buyTicket = 0;

int sellTicket = 0;

double openPrice = 0.0;

double dailyProfit = 0.0;

bool dailyProfitThresholdReached = false;



//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

// Reset the daily profit variable

   dailyProfit = 0.0;



// Reset the daily profit threshold reached flag

   dailyProfitThresholdReached = false;



// Return success

   return (INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

// Reset the daily profit variable

   dailyProfit = 0.0;



// Reset the daily profit threshold reached flag

   dailyProfitThresholdReached = false;

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

int OnTick()

  {

// Check if the daily profit threshold has been reached

   if(dailyProfitThresholdReached)

     {

      // If the daily profit threshold has been reached, close any open trades and return

      if(buyTicket > 0)

        {

         OrderClose(buyTicket, OrderLots(), Bid, 10, Violet);

        }



      if(sellTicket > 0)

        {

         OrderClose(sellTicket, OrderLots(), Ask, 10, Violet);

        }

      return;

     }



// Set the default leverage for the trade

   int leverage = 100;



// Check if the spread is less than the scalp threshold and there are no open orders

   if(SymbolInfoDouble(Symbol(), SYMBOL_SPREAD) <

      ScalpThreshold && buyTicket == 0 && sellTicket == 0)

     {

      // Open a buy order

      buyTicket =

         OrderSend(Symbol(), OP_BUY, 1.0, Ask, 10, 0, 0,

                   "scalp-buy", leverage, 0, Green);



      // Set the stop loss and take profit for the buy order

      OrderModify(buyTicket, Ask - StopLoss * Point,

                  Ask + TakeProfit * Point, 0, Blue);



      // Set the open price for the buy order

      openPrice = Ask;

     }



// Check if there is a buy order open

   if(buyTicket > 0)

     {

      // Check if the order has hit the take profit or the market has moved in favor of the order

      if(OrderProfit() > 0

         || Ask > openPrice + TrailingStop * Point)

        {

         // If either condition is true, close the order and reset the buy ticket variable

         OrderClose(buyTicket, OrderLots(), Bid, 10, Violet);

         buyTicket = 0;



         // Update the daily profit variable

         dailyProfit += OrderProfit();



         // Check if the daily profit has reached or exceeded the threshold

         if(dailyProfit >= 50)

           {

            // If the daily profit has reached or exceeded the threshold, set the daily profit threshold reached flag to true

            // and return

            dailyProfitThresholdReached = true;

            return;

           }

        }

     }



// Check if the spread is less than the scalp threshold and there are no open orders

   if(SymbolInfoDouble(Symbol(), SYMBOL_SPREAD) <

      ScalpThreshold && buyTicket == 0 && sellTicket == 0)

     {

      // Open a sell order

      sellTicket =

         OrderSend(Symbol(), OP_SELL, 1.0, Bid, 10, 0, 0,

                   "scalp-sell", leverage, 0, Green);



      // Set the stop loss and take profit for the sell order

      OrderModify(sellTicket, Bid + StopLoss * Point,

                  Bid - TakeProfit * Point, 0, Blue);





      // Set the open price for the sell order

      openPrice = Bid;



     }





// Check if there is a sell order open

   if(sellTicket > 0)

     {

      // Check if the order has hit the take profit or the market has moved in favor of the order

      if(OrderProfit() > 0

         || Bid < openPrice - TrailingStop * Point)

        {

         // If either condition is true, close the order and reset the sell ticket variable

         OrderClose(sellTicket, OrderLots(), Ask, 10, Violet);

         sellTicket = 0;



         // Update the daily profit variable

         dailyProfit += OrderProfit();



         // Check if the daily profit has reached or exceeded the threshold

         if(dailyProfit >= 50)

           {

            // If the daily profit has reached or exceeded the threshold, set the daily profit threshold reached flag to true

            // and return

            dailyProfitThresholdReached = true;

            return;

           }

        }

     }

//+------------------------------------------------------------------+

 
Compilation Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
Compilation Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Compilation Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
 
  1. 1193ped #: results after usin g styler and adding a closing bracket. Errors exploded. Any

    Please edit your 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

  2. You are missing the closing bracket for OnTick

 
William Roeder #:
  1. Please edit your 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

  2. You are missing the closing bracket for OnTick

apologies danke
 
1193ped #:
apologies danke

i dont understand where t he missing bracket needs to be placed. Can you direct me?

bool dailyProfitThresholdReached = false;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
// Reset the daily profit variable
   dailyProfit = 0.0;

// Reset the daily profit threshold reached flag
   dailyProfitThresholdReached = false;

// Return success
   return (INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
// Reset the daily profit variable
   dailyProfit = 0.0;

// Reset the daily profit threshold reached flag
   dailyProfitThresholdReached = false;
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int OnTick()
  {
// Check if the daily profit threshold has been reached
   if(dailyProfitThresholdReached)
     {
      // If the daily profit threshold has been reached, close any open trades and return
      if(buyTicket > 0)
        {
         OrderClose(buyTicket, OrderLots(), Bid, 10, Violet);
        }

      if(sellTicket > 0)
        {
         OrderClose(sellTicket, OrderLots(), Ask, 10, Violet);
        }
      return;
     }
    }

        }
     }
 
1193ped #: i dont understand where t he missing bracket needs to be placed. Can you direct me?

That is not what you originally posted.

The missing bracket was at the end of your original post.

 
William Roeder #:

That is not what you originally posted.

The missing bracket was at the end of your original post.

srry  you are correct, i deleted lines to fit 64k char limit. danke.

 
William Roeder #:

That is not what you originally posted.

The missing bracket was at the end of your original post.

no luck added it at end, and more error popped up. can you  help me refactor. its my first EA. I am a below avg coding skills

 

Ive attached the text file

these are the errors with the bracket at the end. 78 in total. I am heartbroken, 

without bracket at end , its just 2 errors, once i add bracket it turns into 78 errors. frustrating 

Files:
 
1193ped #: no luck added it at end, and more error popped up. can you  help me refactor. its my first EA. I am a below avg coding skills

without bracket at end , its just 2 errors, once i add bracket it turns into 78 errors. frustrating 

  1. Luck is not involved. Fix the first error, compile, repeat.

  2. int OnTick()

    Read the documentation. OnTick is a void function.

  3.    if(dailyProfitThresholdReached)
         {

    Where is the closing brace?

  4. Don't change the file extension. It is MQ5!