Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
The file you provided is not your code. It is part of the MQL5 Standard Library and we all have it on our systems.
If you need help with your code, then please show your code, and use the CODE button (Alt-S) when inserting code.
There is no such MQL5 function. Please reference the documentation ...
Returns the symbol corresponding to the open position
Chooses an open position for further working with it
Selects a position to work with by the ticket number specified in it
For selection by an index, use PositionGetSymbol, which selects by the index and returns the symbol of the selected position.

- www.mql5.com
I suggest you read the online book ...
Orders, Positions and Deals in MetaTrader 5
MetaQuotes, 2011.02.01 16:13
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.

- www.mql5.com
There is no such MQL5 function. Please reference the documentation ...
Returns the symbol corresponding to the open position
Chooses an open position for further working with it
Selects a position to work with by the ticket number specified in it
For selection by an index, use PositionGetSymbol, which selects by the index and returns the symbol of the selected position.
Sounds like you're using Gemini to create MQL5, it thinks that is a real function in MQL5, it basically hallunicates it.
When it generates the code with that non-existent function tell it:
There is no such function as PositionSelectByIndex in MQL5. Recreate the code without using this
Which will get a response like:
You are absolutely correct! My apologies for that oversight. PositionSelectByIndex is indeed not a valid function in MQL5.
I have updated the code in the mql5_trading_automation document to correctly select the open position using PositionGetTicket and PositionSelectByTicket , which is the proper way to handle position selection in MQL5. Since the logic specifies only one trade is open at a time, we can reliably get the first (and only) position's ticket.
Here is the updated code:
You still need to learn MQL5 though otherwise you'll never be able to find out why the AI version doesn't work in the event that it fails to compile or produce the results you want.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I just download the official Metatrader 5.
When I coded, I received the error: 'PositionSelectByIndex' - undeclared identifier
In the file Trade.mqh, I don't see any reference to the PositionSelectByIndex.
I'm using a pure MQL5 environment, in windows software. And I don't install MT4 in my PC.
Someone could help me?
Attached the Trade.mqh installed by the MT5 download.
I am using the version 5.00 build 4755 from 13 Dec 2024
Thank you!
Pedro