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
No. You can get ResultOrder immediately after send the order. But the fact that you get a success code and the order ticket, doesn't mean that the positions is already available to select. That is why i told to use Sleep.
What he is saying is that you have other ways to handle the opening of positions, like you get the order, then later in OnTradeTransaction you can check if the order was filled, partially filled, canceled, rejected, etc. in the same way you can know the position affected by an order execution handling trade transactions events, especially the TRADE_TRANSACTION_DEAL_ADD.
Good morning,
Firstly, I'd like to thank everyone for their availability.
Returning to the topic at hand, when using the OnTradeTransaction function, is the code below sufficient to retrieve the ticket of the last opened position?
Additionally, with this code, could I eliminate the need for using Sleep?
Thank you in advance for the help.
Good morning,
Firstly, I'd like to thank everyone for their availability.
Returning to the topic at hand, when using the OnTradeTransaction function, is the code below sufficient to retrieve the ticket of the last opened position?
Additionally, with this code, could I eliminate the need for using Sleep?
Thank you in advance for the help.
The position id is the same as the ticket of the order that opened the position. Check documentation. Thanks.
POSITION_IDENTIFIER
Position identifier is a unique number assigned to each re-opened position. It does not change throughout its life cycle and corresponds to the ticket of an order used to open a position.
Position identifier is specified in each order (ORDER_POSITION_ID) and deal (DEAL_POSITION_ID) used to open, modify, or close it. Use this property to search for orders and deals related to the position.
When reversing a position in netting mode (using a single in/out trade), POSITION_IDENTIFIER does not change. However, POSITION_TICKET is replaced with the ticket of the order that led to the reversal. Position reversal is not provided in hedging mode.
Since he is opening a position, not adding or closing partially, the order ticket will work on the same way.
Position identifier corresponds to the ticket of an order used to open a position. It means if he does not have an open position and do send a market order, the ticket of this orders will be used as position identifier once it opens. So there is no point on distinguish between deal, order and position, in this particular case where there is no open position.
Good morning,
Firstly, I'd like to thank everyone for their availability.
Returning to the topic at hand, when using the OnTradeTransaction function, is the code below sufficient to retrieve the ticket of the last opened position?
Additionally, with this code, could I eliminate the need for using Sleep?
Thank you in advance for the help.
don't need check the state, since the deal has been added to history, you can just check if is a buy or sell and any other filter like symbol, magic number, if needed.
Position identifier corresponds to the ticket of an order used to open a position. It means if he does not have an open position and do send a market order, the ticket of this orders will be used as position identifier once it opens. So there is no point on distinguish between deal, order and position, in this particular case where there is no open position.