compilation issue MT5

 

Hello,

I'm having trouble solving a problem.

A source code that initially didn't present any errors is now showing 102 errors during compilation !!

Unable to find the source of the problem.

I consulted ChatGPT4, and it provided the following response below.

In your opinion, since I'm not a coder, should I ask a developer to make these modifications?

ChatGPT4, response:


The errors you are encountering seem to be related to differences between MQL4 and MQL5, as well as improper declarations of certain functions and variables specific to MQL5. Here’s a list of the main issues and solutions to fix them:

  1. SELECT_BY_POS and OrderSelect In MQL5, SELECT_BY_POS and OrderSelect() are not used in the same way as in MQL4. In MQL5, you need to use HistoryOrderSelect() or PositionSelect() to select an order or a position. Solution: Replace OrderSelect(k, SELECT_BY_POS) with PositionSelect() to select open positions and HistoryOrderSelect() for closed orders.

  2. OrderMagicNumber, OrderSymbol, OrderType, etc. In MQL5, these functions do not exist in their MQL4 form. You need to use structures like MqlTradeResult, MqlTradeRequest, or PositionGetInteger(), PositionGetDouble(), etc. Solution: Replace calls to OrderMagicNumber() , OrderSymbol() , OrderType() , OrderProfit() , etc., with their MQL5 equivalents, like PositionGetInteger(POSITION_MAGIC) , PositionGetString(POSITION_SYMBOL) , and PositionGetDouble(POSITION_PROFIT) .

  3. OP_BUY, OP_SELL, OP_BUYSTOP, OP_SELLSTOP In MQL5, these constants no longer exist in this form. You need to use order types in enum form, such as ORDER_TYPE_BUY, ORDER_TYPE_SELL, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP. Solution: Replace OP_BUY , OP_SELL , OP_BUYSTOP , OP_SELLSTOP with their MQL5 equivalents (ORDER_TYPE_BUY, ORDER_TYPE_SELL, etc.).

  4. OrderSend() In MQL5, the OrderSend() function takes structures of type MqlTradeRequest and MqlTradeResult. The syntax has changed. Solution: You need to prepare an MqlTradeRequest structure and an MqlTradeResult structure, then use OrderSend() in MQL5 to send the order."

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be...
 
Jean Christophe Paput:

Hello,

I'm having trouble solving a problem.

A source code that initially didn't present any errors is now showing 102 errors during compilation !!

Unable to find the source of the problem.

I consulted ChatGPT4, and it provided the following response below.

In your opinion, since I'm not a coder, should I ask a developer to make these modifications?

ChatGPT4, response:



@page { size: 21cm 29.7cm; margin: 2cm } p { line-height: 115%; margin-bottom: 0.25cm; background: transparent } code { font-family: "Liberation Mono", monospace } strong { font-weight: bold }

The errors you are encountering seem to be related to differences between MQL4 and MQL5, as well as improper declarations of certain functions and variables specific to MQL5. Here’s a list of the main issues and solutions to fix them:

  1. SELECT_BY_POS and OrderSelect In MQL5, SELECT_BY_POS and OrderSelect() are not used in the same way as in MQL4. In MQL5, you need to use HistoryOrderSelect() or PositionSelect() to select an order or a position. Solution: Replace OrderSelect(k, SELECT_BY_POS) with PositionSelect() to select open positions and HistoryOrderSelect() for closed orders.

  2. OrderMagicNumber, OrderSymbol, OrderType, etc. In MQL5, these functions do not exist in their MQL4 form. You need to use structures like MqlTradeResult, MqlTradeRequest, or PositionGetInteger(), PositionGetDouble(), etc. Solution: Replace calls to OrderMagicNumber() , OrderSymbol() , OrderType() , OrderProfit() , etc., with their MQL5 equivalents, like PositionGetInteger(POSITION_MAGIC) , PositionGetString(POSITION_SYMBOL) , and PositionGetDouble(POSITION_PROFIT) .

  3. OP_BUY, OP_SELL, OP_BUYSTOP, OP_SELLSTOP In MQL5, these constants no longer exist in this form. You need to use order types in enum form, such as ORDER_TYPE_BUY, ORDER_TYPE_SELL, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP. Solution: Replace OP_BUY , OP_SELL , OP_BUYSTOP , OP_SELLSTOP with their MQL5 equivalents (ORDER_TYPE_BUY, ORDER_TYPE_SELL, etc.).

  4. OrderSend() In MQL5, the OrderSend() function takes structures of type MqlTradeRequest and MqlTradeResult. The syntax has changed. Solution: You need to prepare an MqlTradeRequest structure and an MqlTradeResult structure, then use OrderSend() in MQL5 to send the order."

The modifications seem extensive - it might be best to consult a developer to handle these changes.

 
Thank you for your answer.
 
Jean Christophe Paput:

Hello,

I'm having trouble solving a problem.

A source code that initially didn't present any errors is now showing 102 errors during compilation !!

Unable to find the source of the problem.

I consulted ChatGPT4, and it provided the following response below.

In your opinion, since I'm not a coder, should I ask a developer to make these modifications?

ChatGPT4, response:


The errors you are encountering seem to be related to differences between MQL4 and MQL5, as well as improper declarations of certain functions and variables specific to MQL5. Here’s a list of the main issues and solutions to fix them:

  1. SELECT_BY_POS and OrderSelect In MQL5, SELECT_BY_POS and OrderSelect() are not used in the same way as in MQL4. In MQL5, you need to use HistoryOrderSelect() or PositionSelect() to select an order or a position. Solution: Replace OrderSelect(k, SELECT_BY_POS) with PositionSelect() to select open positions and HistoryOrderSelect() for closed orders.

  2. OrderMagicNumber, OrderSymbol, OrderType, etc. In MQL5, these functions do not exist in their MQL4 form. You need to use structures like MqlTradeResult, MqlTradeRequest, or PositionGetInteger(), PositionGetDouble(), etc. Solution: Replace calls to OrderMagicNumber() , OrderSymbol() , OrderType() , OrderProfit() , etc., with their MQL5 equivalents, like PositionGetInteger(POSITION_MAGIC) , PositionGetString(POSITION_SYMBOL) , and PositionGetDouble(POSITION_PROFIT) .

  3. OP_BUY, OP_SELL, OP_BUYSTOP, OP_SELLSTOP In MQL5, these constants no longer exist in this form. You need to use order types in enum form, such as ORDER_TYPE_BUY, ORDER_TYPE_SELL, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP. Solution: Replace OP_BUY , OP_SELL , OP_BUYSTOP , OP_SELLSTOP with their MQL5 equivalents (ORDER_TYPE_BUY, ORDER_TYPE_SELL, etc.).

  4. OrderSend() In MQL5, the OrderSend() function takes structures of type MqlTradeRequest and MqlTradeResult. The syntax has changed. Solution: You need to prepare an MqlTradeRequest structure and an MqlTradeResult structure, then use OrderSend() in MQL5 to send the order."

Don’t trust ChatGPT with coding. It is unreliable 
 
Paul Anscombe #:
Don’t trust ChatGPT with coding. It is unreliable 

Yes you're right !

That's why I don't want ChatGPT to correct the errors.