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
Frequently used and useful functions:
Redesigned GetPositionPrice() function:
This function shows the wrong result, or rather the wrong result. I looked into it and found out that the Position ID does not change at U-turn (i.e. during an in/out trade), as described in documentation:
https://www.mql5.com/ru/docs/constants/tradingconstants/positionproperties
A position reversal changes its ID to the order ticket that resulted in the reversal.
Your GetPositionPrice can pile up 2 or more oppositely directed positions if there is a reversal, and calculates an average price for them. Such an average price of a position is of no practical use.
So, does the Position ID change on reversal or not?
How can you tell from an in/out trade which volume closed a previous position and which opened a new one?
It can be compared with the current open position. But it is better to examine the history of the position by its id, which does not change when the position is reversed... Buy/sell volumes to help.
As of recently, the Position ID CHANGES when you turn around. Documentation on this has already been updated....
POSITION_IDENTIFIER
The Position ID is a unique number, which is assigned to each newly opened position and does not change throughout its lifetime. It corresponds to the ticket of the order with which the position was opened.
The position identifier is specified in each order (ORDER_POSITION_ID) and each trade (DEAL_POSITION_ID) which opened, changed or closed it. Use this property to search for orders and trades related to the position.
A reversal of a position changes its identifier to the order ticket which resulted in the reversal.
long
You could compare it with the current open. But it is better to examine the history of the position by the id, which does not change during a reversal... Buy/sell volumes to help.
This is not an option at all. The previous position could also be open due to a reversal etc. Could be an option, but clearly not an optimal one.
As of recently, the Position ID CHANGES when you turn around. Documentation on this has already been updated....
POSITION_IDENTIFIER
The Position ID is a unique number, which is assigned to each newly opened position and does not change throughout its lifetime. It corresponds to the ticket of the order with which the position was opened.
The position identifier is specified in each order (ORDER_POSITION_ID) and each trade (DEAL_POSITION_ID) which opened, changed or closed it. Use this property to search for orders and trades associated with the position.
A reversal of a position changes its identifier to the order ticket which resulted in the reversal.
long
It's written like this, but in reality nothing changes.
If you like, my code:
Where deal2_ticket is the in/out transaction ticket, deal1_ticket is the ticket preceding the in/out transaction, deal3_ticket is the ticket after the in/out transaction. In all three cases I get the same Position ID.
It says so, but in reality nothing changes.
If you like, my code:
Where deal2_ticket is the in/out transaction ticket, deal1_ticket is the ticket preceding the in/out transaction, deal3_ticket is the ticket after the in/out transaction. In all three cases I get the same Position ID.
And how can we determine from an in/out trade which volume closed the previous position and which opened the new one?
This Expert Advisor is run in "Debugging on History" mode on a netting account. The example is a little rough, because it is calculated that there is only one deal of "IN/OUT" type in the deal history.
At first, after all executed deals and complete closing of a position, the descriptions of all deals are shown(DEAL_POSITION_ID, DEAL_VOLUME, DEAL_ENTRY,DEAL_TYPE), at that DEAL_POSITION_ID for a deal of IN/OUT type is memorized.
Then it goes through the history again and sums all entries for trades with DEAL_POSITION_ID.
This is approximately what we obtain:
It's changing for me. Try it on the latest build 1340.