Help!, Command, or commands to detect operation closing automatically.

 

Hello!
              Sorry for my English. I've been looking at the MQL4 .doc and I haven't found any command or command lines to be able to get/detect when a trade is closed. Would someone be so kind and help me. My idea is to incorporate this line/command lines as a void or similar and when an operation is closed I perform a BreakEven that I have already developed.

Thank you so much.

 

Please don't post randomly in any section. MT4/mql4 has it's own section on the forum.

I have moved your topic to the correct section.

 
Manuel De Los Heros Soler: I've been looking at the MQL4 .doc and I haven't found any command or command lines to be able to get/detect when a trade is closed. Would someone be so kind and help me. My idea is to incorporate this line/command lines as a void or similar and when an operation is closed I perform a BreakEven that I have already developed.

In MQL4, to detect when a market order has been closed, you verify that it's "close time" is valid. When it is still open, the close time will be 0.

OrderCloseTime

Returns close time of the currently selected order

OrderCloseTime - Trade Functions - MQL4 Reference
OrderCloseTime - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderCloseTime - Trade Functions - MQL4 Reference
 
  1. Post in the correct place.
  2. Manuel De Los Heros Soler: get/detect when a trade is closed. 
    Select the order by ticket and see if the OrderCloseTime is nonzero. But, EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?

    Use a OrderSelect / Position select loop on the first tick, or persistent storage (GV+flush or files) of ticket numbers required.

    On a network disconnection you might get ERR_NO_RESULT or ERR_TRADE_TIMEOUT. There is nothing to be done, but log the error, return and wait for a reconnection and a new tick. Then reevaluate. Was an order opened or is the condition still valid.

Reason: