Receiving 1 Error: '{' - function definition unexpected - NEWBIE Here - Please Help

 
 
//+------------------------------------------------------------------+
   //|                                                   GoldPro_v1.mq5 |
   //|                                  Copyright 2023, MetaQuotes Ltd. |
   //+------------------------------------------------------------------+
   //+------------------------------------------------------------------+
   //| Expert initialization function                                   |
   //+------------------------------------------------------------------+  
   // include the Trade library
   #include <Trade/Trade.mqh>;
  
   void OnStart()
{
   // Set the symbol and time frame for the chart
   
   SymbolSet("XAUUSD",PERIOD_M5);
   
   // Set the trade parameters
   double volume = 0.02; // trade volume in lots
   double sl = 120; // stop-loss in points
   double tp = 100; // take-profit in points
   
   // Open a buy order
   int order = OrderSend(_Symbol, OP_BUY, volume, Ask, 3, sl,
   tp, "My gold trade", 12345, 0, Green);
   
   
   // Check if the order was successfully placed
   if (order > 0)
   
   Print("Buy order placed successfully, ID: ", order);
   else
   
   Print("Error placing buy order:"),
   ErrorDescription(GetLastError()));
   }
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

You should remove the extra semicolon ...

void OnStart() // <- remove the ";"
{
Also, please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

 
Fernando Carreiro #:

You should remove the extra semicolon ...

Also, please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

Thankyou! I removed it and now have 10 errors instead of the one.

 
MickDar #: Thankyou! I removed it and now have 10 errors instead of the one.

 😅 That is to be expected of a newbie coder that still does not know their way around the language and the platform. It's part of the learning experience.

Also, please fix your post as I demonstrated in the animation. Copy the code from your original code file and not from the post itself.

 
MickDar #:

Is this supposed to be MQL4 or MQL5?

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

 
Fernando Carreiro #:

 😅 That is to be expected of a newbie coder that still does not know their way around the language and the platform. It's part of the learning experience.

Also, please fix your post as I demonstrated in the animation. Copy the code from your original code file and not from the post itself.

Done!

 
Keith Watford #:

Is this supposed to be MQL4 or MQL5?

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

MQL5

(Alt+S) did not work with my Mac. Hope that works and I appreciate the help.

 
MickDar #:

MQL5

Well this appears to be MQL4

 // Open a buy order
   int order = OrderSend(_Symbol, OP_BUY, volume, Ask, 3, sl,
   tp, "My gold trade", 12345, 0, Green);
   
   
   // Check if the order was successfully placed
   if (order > 0)
   
   Print("Buy order placed successfully, ID: ", order);
   else
   
   Print("Error placing buy order:"),
   ErrorDescription(GetLastError()));
 
Keith Watford #:

Well this appears to be MQL4

I'm sure that must be the problem Keith. Thanks! Is there an easier way to convert it to MQL5?

 
MickDar #:I'm sure that must be the problem Keith. Thanks! Is there an easier way to convert it to MQL5?

Yes, in the short-term, but in the long-term you will end up not learning MQL5 properly, making it much more difficult to progress.

Code Base

MT4Orders

fxsaber, 2016.10.10 15:31

Parallel use of the MetaTrader 4 and MetaTrader 5 order systems.
Reason: