OrderSend return ticket of an order which has not completely - page 2

 
Alain Verleyen:
False.
False. You don't need PostionSelect() if you are using PositionSelectByTicket().

Go read the documentation.

And also try to open a position on ECN in one go with TP and or SL it will reject in many cases.

PositionSelectByTicket

Selects an open position to work with based on the ticket number specified in the position. If successful, returns true. Returns false if the function failed. Call GetLastError() for error details.

bool  PositionSelectByTicket( 
   ulong   ticket     // Position ticket 
   );

Parameters

ticket

[in]  Position ticket.

Return Value

A value of the bool type.

Note

The PositionSelectByTicket() function copies position data to the program environment. Further calls of PositionGetDouble(), PositionGetInteger() and PositionGetString() return the previously copied data. Even if a position does not exist already (or its size, direction etc. has changed), the data may still be received sometimes. To make sure that you receive valid position data, it is recommended to call PositionSelect() before you access the data.

See also

PositionGetSymbol(), PositionsTotal(), Position Properties

I tdoesn't say it is needed but it is recommended.
 
Marco vd Heijden:

Go read the documentation.

And also try to open a position on ECN in one go with TP and or SL it will reject in many cases.

PositionSelectByTicket

Selects an open position to work with based on the ticket number specified in the position. If successful, returns true. Returns false if the function failed. Call GetLastError() for error details.

bool  PositionSelectByTicket( 
   ulong   ticket     // Position ticket 
   );

Parameters

ticket

[in]  Position ticket.

Return Value

A value of the bool type.

Note

The PositionSelectByTicket() function copies position data to the program environment. Further calls of PositionGetDouble(), PositionGetInteger() and PositionGetString() return the previously copied data. Even if a position does not exist already (or its size, direction etc. has changed), the data may still be received sometimes. To make sure that you receive valid position data, it is recommended to call PositionSelect() before you access the data.

See also

PositionGetSymbol(), PositionsTotal(), Position Properties

I tdoesn't say it is needed but it is recommended.


Thank you for the reply!

From what i read in the documentation i don't fully understand the PositionSelect function. This function has as parameter the symbol.So i think it selects the symbol which the order was executed. But what happens if you have an account type hedging and have many others orders(opposites) at the same symbol ? Does this situation affects the result or it doesn't matter? 

An ultimate solution could be the following code :

if(PositionSelect(_Symbol) && PositionSelectByTicket(ticket)){
    ........
}

Thank you for your time!

 
Marco vd Heijden:

Go read the documentation.

And also try to open a position on ECN in one go with TP and or SL it will reject in many cases.

...

Note

The PositionSelectByTicket() function copies position data to the program environment. Further calls of PositionGetDouble(), PositionGetInteger() and PositionGetString() return the previously copied data. Even if a position does not exist already (or its size, direction etc. has changed), the data may still be received sometimes. To make sure that you receive valid position data, it is recommended to call PositionSelect() before you access the data.

See also

PositionGetSymbol(), PositionsTotal(), Position Properties

I tdoesn't say it is needed but it is recommended.

I am talking by experience as I coded a lot of mql5 EA. You are wrong Marco.

I will wait your code and screenshot or log to prove that you can not set an SL/TP with an ECN account. So I repeat there is no problem to set an SL/TP when opening a trade with an ECN account. You still may want to set them separately by it's not mandatory at all.

The part you highlighted contains an error, it says PositionSelect() when it should be PositionSelectByTicket(). The point of this sentence is to say, use the function JUST BEFORE accessing the data with other functions. You can report it to the ServiceDesk if you want.

So I repeat, if you are using PositionSelectByTicket() you don't have to use PositionSelect().

 
Alain Verleyen:

I am talking by experience as I coded a lot of mql5 EA. You are wrong Marco.

I will wait your code and screenshot or log to prove that you can not set an SL/TP with an ECN account. So I repeat there is no problem to set an SL/TP when opening a trade with an ECN account. You still may want to set them separately by it's not mandatory at all.

The part you highlighted contains an error, it says PositionSelect() when it should be PositionSelectByTicket(). The point of this sentence is to say, use the function JUST BEFORE accessing the data with other functions. You can report it to the ServiceDesk if you want.

So I repeat, if you are using PositionSelectByTicket() you don't have to use PositionSelect().

It seems that the documentation has accidentally use wrong word (PositionSelect insteed of PositionSelectByTicket) . Thank you for this clarification!

As for the Account type, i think i was wrong about the type. It is not the ECN the problem but the broker. I used to make trades with a broker's platform (which i can't recall right now) which can not let me to set the stoploss and takeprofit directly. Not only with EA(OrderSend) but on manually. Also this experience shared by other through the internet. For example that post https://www.mql5.com/en/forum/138021 the last comment refer that "On ECN brokers you must open first and THEN set stops".
Here is another post from stackoverflow https://stackoverflow.com/questions/27240934/modifying-order-returns-error-130 which at last comment refers that "Another quite common condition set on STP/ECN systems ( introduced by the Broker's inhouse Risk Management policy ) is that one is not allowed to setup TP/SL right at the OrderSend(), but has to leave these blank and upon a positive confirmation of the OrderSend(), submit a separate OrderModify() instruction for the given OrderTicketNumber to add ex-post the TP and/or SL price-level(s)".

So the problem exists but it is not an ECN but a broker issue. 
At the end, according to this post , in order to cover these brokers maybe you need to complete the order first and then right after to set the stoploss and takeprofit with OrderModify. 
In order to do so, you need to be sure that the ticket exists. The most obvious way is to take the ticket from the function OrderSend immediately. But in that way an unexpected even may occurs when the PositionSelectByTicket failed to select the ticket due to the delay of the server executation time. So the last question is that , is the OrderSend function possible to return a ticket of an order which is NOT executed on the server by the time (the next line of code) where the PositionSelectByTicket try to select that order?

Thank you for your time!

 

I know i am wrong but nevertheless it's in the docs.

I don't think it will help to write to service desk so let's just leave it.

 
Marco vd Heijden:

I know i am wrong but nevertheless it's in the docs.

I don't think it will help to write to service desk so let's just leave it.

Reported nonetheless. Ticket # #1974057.
 
md42:

It seems that the documentation has accidentally use wrong word (PositionSelect insteed of PositionSelectByTicket) . Thank you for this clarification!

As for the Account type, i think i was wrong about the type. It is not the ECN the problem but the broker. I used to make trades with a broker's platform (which i can't recall right now) which can not let me to set the stoploss and takeprofit directly. Not only with EA(OrderSend) but on manually. Also this experience shared by other through the internet. For example that post https://www.mql5.com/en/forum/138021 the last comment refer that "On ECN brokers you must open first and THEN set stops".
Here is another post from stackoverflow https://stackoverflow.com/questions/27240934/modifying-order-returns-error-130 which at last comment refers that "Another quite common condition set on STP/ECN systems ( introduced by the Broker's inhouse Risk Management policy ) is that one is not allowed to setup TP/SL right at the OrderSend(), but has to leave these blank and upon a positive confirmation of the OrderSend(), submit a separate OrderModify() instruction for the given OrderTicketNumber to add ex-post the TP and/or SL price-level(s)".

So the problem exists but it is not an ECN but a broker issue. 

The problem existed. Your references are for mql4, they are old and obsolete.That being said maybe it's possible for a broker to configure that otherwise but I never see it.

For mql5, you can set sl/tp with the order since build 821.


At the end, according to this post , in order to cover these brokers maybe you need to complete the order first and then right after to set the stoploss and takeprofit with OrderModify. 
In order to do so, you need to be sure that the ticket exists. The most obvious way is to take the ticket from the function OrderSend immediately. But in that way an unexpected even may occurs when the PositionSelectByTicket failed to select the ticket due to the delay of the server executation time. So the last question is that , is the OrderSend function possible to return a ticket of an order which is NOT executed on the server by the time (the next line of code) where the PositionSelectByTicket try to select that order?

Thank you for your time!

So the above point being clarified, there is no problem to open an order and set sl/tp after that of course (my point is just to say it's not mandatory). Now, your problem is with mql5, you can sometimes receive the ticket number from the server's answer, BUT the local database (Positions) is not yet updated (it's what is explained in the link I provided you). You need to use OnTrade() or OnTradeTransaction() to detect that the terminal is aware about the new ticket and from there you can set your SL/TP.

 
Alain Verleyen:
Reported nonetheless. Ticket # #1974057.
Fixed.
Reason: