Platform: MetaTrader5 (Hedge account)
Broker: [redacted]
Issue:
- Using Python module 'MetaTrader5' on Windows.
- When I call positions_get(symbol="NAS100"), it returns empty,
but positions_get(symbol="nas100") returns my open positions.
- Because of that, my auto-trader sometimes thinks it's flat and submits a new opposite market order instead of closing.
- I need a robust way to resolve the "actual symbol name" that has open positions (case-insensitive, partial names like 'nas100.cash').
Questions:
1) Is positions_get case-sensitive on 'symbol' parameter? Any official guidance?
2) Is there a recommended pattern to reliably detect the actual tradable symbol name programmatically?
3) For hedging accounts, is closing by 'position ticket' with TRADE_ACTION_DEAL + 'position' field the correct method?
4) Are there pitfalls with volume_step/volume_min when closing partial positions by ticket we should be careful about?
Environment:
- Windows 11, MetaTrader5 v5.0.45, Python MetaTrader5 module v5.0.45
- Broker server: [redacted]
Thank you for your assistance.
- Instant Execution - Opening and Closing Positions - Trade - MetaTrader 5 for iPhone
- Opening and Closing Positions - Trade - MetaTrader 5 for Android
- Getting the number and list of open positions
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
zhdaos15: Questions:
1) Is positions_get case-sensitive on 'symbol' parameter? Any official guidance?
2) Is there a recommended pattern to reliably detect the actual tradable symbol name programmatically?
3) For hedging accounts, is closing by 'position ticket' with TRADE_ACTION_DEAL + 'position' field the correct method?
4) Are there pitfalls with volume_step/volume_min when closing partial positions by ticket we should be careful about?
- Symbol names are case-sensitive, irrespective of the functions used. You will have to adapt your code to take that into account.
- Symbol naming scheme is defined by the broker and there is no predefined pattern used for symbol names.
- Yes, but your question is somewhat unclear. If you are referring to "close by" with the opposite position, then you would use "TRADE_ACTION_CLOSE_BY".
Either way, you should read the following article for more info ...
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.
-
Not quite sure what you mean by that. You always have to take the volume step into account and I would assume that the remaining position volume cannot be less than the minium, and would need to be closed completely.
On a side note, if you are experiencing some limitations using Python, consider writing your programme in MQL5 to have access to more functionality than what the Python API can offer.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register