Question on good programming practices re: PositionSelectByTicket()

 

Hello,

Quick question on good programming practices.

I have a trade entry manager EA which, after the users clicks to buy/sell then tries to immediately select the ticket number (which was captured during the market order entry process).

Sometimes, the EA selects it successfully (open position) with PositionSelectByTicket(), other times, it fails, even thought attempting to use the correct ticket number etc.

I seem to have resolved the problem by putting the PositionSelectByTicket() inside a loop that iterates 5 times with a 500ms Sleep() until it successfully selects the ticket.

Curious if this is the correct approach, or if there is a better approach, or if there is an inherent problem using this approach.

Thanks!

 

Does not sound good, can you show some code?

 
Christian Berrigan:

Hello,

Quick question on good programming practices.

I have a trade entry manager EA which, after the users clicks to buy/sell then tries to immediately select the ticket number (which was captured during the market order entry process).

Sometimes, the EA selects it successfully (open position) with PositionSelectByTicket(), other times, it fails, even thought attempting to use the correct ticket number etc.

I seem to have resolved the problem by putting the PositionSelectByTicket() inside a loop that iterates 5 times with a 500ms Sleep() until it successfully selects the ticket.

Curious if this is the correct approach, or if there is a better approach, or if there is an inherent problem using this approach.

Thanks!

What is the ping time your MT client shows?