Questions from Beginners MQL5 MT5 MetaTrader 5 - page 762

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
And it is not positions or deals that need to be checked, but orders, because an order comes first, then a deal, then a position.
Why only orders? Doesn't a deal have a position ID (ticket)?
DEAL_POSITION_ID
Why only orders? Doesn't a deal have a position ID (ticket)?
DEAL_POSITION_ID
Yes, you are right. Both orders and deals have a position identifier. However, in the general case we should know that the position is assigned an identifier of the first order that initiated the deal. Accordingly, the "entity" initiating the position is the order, and not the deal. And it is orders, not deals, that should be searched for.
From the documentation:
The position identifier is a unique number that 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.
Yes, you are right. Both orders and trades have a position identifier. However, in general, you should know that the position is assigned the identifier of the first order that initiated the trade. Accordingly, the "entity" initiating the position is the order, and not the deal. And it is orders, not deals, that should be searched for.
From the documentation:
I'm not going to argue, that's exactly what the documentation says. But elsewhere in the same documentation it says"As a rule..." which means there may be inconsistencies. And this is the "as a rule" I once encountered...
position
The position ticket. It should be filled in when a position is changed and closed, for its unique identification. As a rule, it corresponds to the ticket of the order, as a result of which the position was opened.
Please advise how to retrieve the ticket that was used for the trade. On the screenshot it is "63214735".
Hereyou are looking for the number of the Position, in the list of Deals, or else it's wrong.
Here is a script that demonstrates what HistorySelectByPosition gives
And this is how the result looks like :
0 = Open Position
1 = Close Position
If you don't get it = you didn't enter a Ticket Position
The same result can be obtained if we start with the Deal Ticket:
For the HistoryDealGetInteger() function
ENUM_DEAL_PROPERTY_INTEGER
Identifier
Description
Type
DEAL_TICKET
Deal ticket. Unique number to be assigned to each trade
long
DEAL_ORDER
Order, on the basis of which the trade was executed
long
DEAL_TIME
Deal execution time
datetime
DEAL_TIME_MSC
Deal execution time in milliseconds from 01.01.1970
long
DEAL_TYPE
Deal type
ENUM_DEAL_TYPE
DEAL_ENTRY
Deal direction - market entry, market exit or reversal
ENUM_DEAL_ENTRY
DEAL_MAGIC
Magic number for the deal (see ORDER_MAGIC)
long
DEAL_REASON
Reason or source of the deal
ENUM_DEAL_REASON
DEAL_POSITION_ID
The identifier of theposition in the opening, modification or closing of which this trade was involved. Each position has a unique identifier, which is assigned to all deals made on the instrument during the life time of the position.
long
Thank you!
I needed this:HistoryOrderGetTicket
Thank you!
I needed this:HistoryOrderGetTicket
The order can be 1.0 lot. But it may be partially executed, for example, lot 0.9 - the remainder will be rejected (depends on the mode of execution). Then the trade will be lot 0.9. And when you start searching for lots on the order, there will be inconsistencies.
Please help - I need some sane code to get the OHLC environment value - the existing ones are very slow
Option 1
Option 2
Please help - I need some sane code to get the OHLC environment value - the existing ones are very slow
Option 1
Option 2
Post a piece of code how you apply them
I don't know which piece is slowing down - I apply them in different ways, including in loops...
here is an example
I don't know which piece is slowing down - I apply it in different ways, including in loops...
It seems so in loops, and you can dispense with the function