Compile Errors (Undeclared Identifier)

 

Good morning Forum,

I have an EA that currently has two variables: buyOrders and sellOrders which increase by 1 each time a new trade is made. I have a maximum number limit which is currently set at 10 buys and 10 sells simultaneously. If a trade closes, then I would like these variables to decrease by 1 but I keep getting compile errors (bottom of this message) and I could do with somebody explaining to me why this is and how to fix it, please.

// Loop through all open trades and check for closed trades
    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if (OrderCloseTime() == 0)
            {
                // Order is still open
            }
            else
            {
                // Order is closed
                if (OrderType() == OP_BUY)
                {
                    buyOrders--;
                }
                else if (OrderType() == OP_SELL)
                {
                    sellOrders--;
                }
            }
        }
        else
        {
            // Failed to select the order
            int errorCode = GetLastError();
            // Handle the error here or log it for further analysis
        }
    }
}

Compile Errors:

'OrderCloseTime' - undeclared identifier FTMO Challenge (4 Candles + Closing).mq5 153 17

'OrderType' - undeclared identifier FTMO Challenge (4 Candles + Closing).mq5 160 21

'OrderType' - undeclared identifier FTMO Challenge (4 Candles + Closing).mq5 164 26


Thank you,

CPerry.

 
Post either your complete code, or a simplified version of your code (often you find the mistake yourself when simplifying the code into a presentable version for the forum)

But what you posted won't compile anyways. So how do you expect us to find your mistakes for you? They might not even be in this code snippet you posted...

You see 'undeclared identifier' means that a variable has not been declared before use. In this case you use those identifiers like functions. Have you even declared those functions?
 
Your approach is more complicated than needed.

Reset your variables to 0 on each new tick.

Then cycle all your trades and increase them respectively if buy or sell trade is found.
 
CPerry: but I keep getting compile errors (bottom of this message) and I could do with somebody explaining to me why this is and how to fix it, please.
  1. The code you posted is MT4. You are using MT5. Translate it. MT4 only has orders. On MT5 orders are pending. Open orders are positions. Learn the language.
  2. You are incrementing variables, where do you initialize your counts to zero before entering the loop?
 

Thank you both for your posts! @Tobias Johannes Zimmer @Fabio Cavalloni

I tried opening a thread yesterday with the whole code but because I tried to work this out for myself and the inputs came from ChatGPT, I guess it got flagged by a moderator. I have my TakeProfit, StopLoss, MaximumBuyOrders and MaximumSellOrders inputs first and then my global variables include my buyOrders and sellOrders variables as a way to keep count of how many positions I have open.

Then, because of the compile errors, I tried explicitly defining OrderCloseTime and OrderType in the following code, I even tried explicitly defining the OrderSelect function:

// Declare constants explicitly
#define SELECT_BY_POS             1
#define MODE_TRADES               1
#define OP_BUY                    0
#define OP_SELL                   1
#define OrderCloseTime()          OrderCloseTime
#define OrderType()               OrderType
#define OrderProfit()             OrderProfit

// Function declarations
bool OrderSelect(int index, int select, int pool = MODE_TRADES);
int OrderSend(
   string symbol,
   int cmd,
   double volume,
   double price,
   int slippage,
   double stoploss,
   double takeprofit,
   string comment = "",
   int magic = 0,
   datetime expiration = 0,
   color arrow_color = clrNONE
);

I'm nervous to post the whole code incase it gets flagged up again. I think AI is a fantastic resource to learn from but I am trying to learn this coding language for myself and it's difficult to get help here if posts get taken away. I understand the forum has probably been flooded by mindless AI drivel though.

@Fabio Cavalloni

How do you 'count' the number of long/short trades you currently have open? If I could just reset buyOrders and sellOrders then do a quick 'count' at the start of every new tick then this would make things a lot more efficient; I imagine this should be quite common with risk considerations in EA bots. Could you explain how I would achieve this please? I only want the bot to not place any more buy orders if there are X amount already open and same with sell orders.

Thank you,

CPerry. 

 
William Roeder #:
  1. The code you posted is MT4. You are using MT5. Translate it. MT4 only has orders. On MT5 orders are pending. Open orders are positions. Learn the language.
  2. You are incrementing variables, where do you initialize your counts to zero before entering the loop?

Ahhhhhh I don't know what I don't know clearly. I'll look into translating into MT5. The learning resources I have used previously must have been outdated. Thank you for nudging me in the right direction. 

 
CPerry #: and the inputs came from ChatGPT,

Stop using ChatGPT.
          Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum #2 (2023)

 
How do I trade on Meta5
 
CPerry #:

Thank you both for your posts! @Tobias Johannes Zimmer @Fabio Cavalloni

I tried opening a thread yesterday with the whole code but because I tried to work this out for myself and the inputs came from ChatGPT, I guess it got flagged by a moderator. I have my TakeProfit, StopLoss, MaximumBuyOrders and MaximumSellOrders inputs first and then my global variables include my buyOrders and sellOrders variables as a way to keep count of how many positions I have open.

Then, because of the compile errors, I tried explicitly defining OrderCloseTime and OrderType in the following code, I even tried explicitly defining the OrderSelect function:

I'm nervous to post the whole code incase it gets flagged up again. I think AI is a fantastic resource to learn from but I am trying to learn this coding language for myself and it's difficult to get help here if posts get taken away. I understand the forum has probably been flooded by mindless AI drivel though.

@Fabio Cavalloni

How do you 'count' the number of long/short trades you currently have open? If I could just reset buyOrders and sellOrders then do a quick 'count' at the start of every new tick then this would make things a lot more efficient; I imagine this should be quite common with risk considerations in EA bots. Could you explain how I would achieve this please? I only want the bot to not place any more buy orders if there are X amount already open and same with sell orders.

Thank you,

CPerry. 

Chat GPT wil not code an expert for you. It can be used for small projects like giving you ideas on how to code certain functions. But using it to write you a complete EA will not work. Ai is clever, but not yet clever enough. It will be better to use some EA generator that can be found on google, the chances that you will have code errors are there, but drastically low

Reason: