- Questions from a "dummy"
- Difficulty selecting the right history
- How to write EA with hidden takeprofit and stoploss?
If you don't already know the Position ID, then you can scan through the Orders history to get a list of Position ID's.
Then use each position ID with HistorySelectByPosition() to get access to all the deals for that position.
You can then scan through the resulting set with HistoryDealGetTicket(), of the the total number returned by HistoryDealsTotal().
No, on MT5, the position ID does not change after a parcial close.
If you don't already know the Position ID, then you can scan through the Orders history to get a list of Position ID's.
Then use each position ID with HistorySelectByPosition() to get access to all the deals for that position.
You can then scan through the resulting set with HistoryDealGetTicket(), of the the total number returned by HistoryDealsTotal().
I've already answered ... "If you don't already know the Position ID, then you can scan through the Orders history to get a list of Position ID's."
For a better understanding, please read the following ...
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.
I've already answered ... "If you don't already know the Position ID, then you can scan through the Orders history to get a list of Position ID's."
For a better understanding, please read the following ...
Oh, my bad, for some reason I didn't noticed the "don't". So, to summarize:
-Scan the closed orders with HistoryOrdersTotal()
-Iterate through the orders and retrieve the associated ticket with HistoryOrderGetTicket() given that the order was a market order and not a pending order
-Select all related deals with HistorySelectByPosition(<ticket>)
-Iterate on them using HistoryDealsTotal().
Would that be the workflow?
Oh, my bad, for some reason I didn't noticed the "don't". So, to summarize:
-Scan the closed orders with HistoryOrdersTotal()
-Iterate through the orders and retrieve the associated ticket with HistoryOrderGetTicket() given that the order was a market order and not a pending order
-Select all related deals with HistorySelectByPosition(<ticket>)
-Iterate on them using HistoryDealsTotal().
Would that be the workflow?
Almost but not quite ...
First you have to select the total orders to scan:
Retrieves the history of transactions and orders for the specified period of the server time
Then you can retrieve the total Order count and iterate over them using:
Returns the number of deals in the history
Returns a ticket of a corresponding deal in the history
And for each iteration, retrieve the Position ID with:
Returns the requested property of the order (datetime or int)
ORDER_POSITION_ID
Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of exactly this position is set to the executed order at this moment.
You have to collect ALL the Positions IDs first before proceeding. You cannot do the next step on each iteration or else that will mess up the cache.
So, only once you have collected all the position IDs, can you then use:
Requests the history of deals with a specified position identifier.
And proceed with scanning the deals with:
Returns the number of deals in the history
Returns a ticket of a corresponding deal in the history
Almost but not quite ...
First you have to select the total orders to scan:
Retrieves the history of transactions and orders for the specified period of the server time
Then you can retrieve the total Order count and iterate over them using:
Returns the number of deals in the history
Returns a ticket of a corresponding deal in the history
And for each iteration, retrieve the Position ID with:
Returns the requested property of the order (datetime or int)
ORDER_POSITION_ID
Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of exactly this position is set to the executed order at this moment.
You have to collect ALL the Positions IDs first before proceeding. You cannot do the next step on each iteration or else that will mess up the cache.
So, only once you have collected all the position IDs, can you then use:
Requests the history of deals with a specified position identifier.
And proceed with scanning the deals with:
Returns the number of deals in the history
Returns a ticket of a corresponding deal in the history
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use