Detect order close manually

bodojan468
58
bodojan468  

Hi everyone,

I'm trying  to detect an order opened by my EA and closed manually.

I tried with magic number but, unfortunately,  get only 0 for manually closed orders.

Anyone know how to reliable detect an order opened by an EA and closed manually ?

Thank you 

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Deal Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Marco vd Heijden
Moderator
13431
Marco vd Heijden  

Magic number 0 means that the order was closed manually.

You can monitor OrdersTotal() for increase and decrease in orders.

fxsaber
19885
fxsaber  

ORDER_REASON_CLIENT

ORDER_REASON_EXPERT

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
bodojan468
58
bodojan468  

Thank @marco @fxsaber

What i'm trying to do is to count the monthly/weekly profit for a given pair. Sometimes when price goes against trend I close my position manually and I realized  that my code doesnt manage orders closed manually.

After trying many things I think I have to loop on positions and not on deals because positions keeps the magic number info like MT4.

So my next steps are:

  • loop on deals (HistoryDealsTotal)
  • select a deal y its index (HistoryDealGetTicket)
  • add deal's position to an array
  • loop through this array and get the information I need

Do you think it's the good way to achieve it ?


I ask because it's what I tried but I think I do something wrong when handle the array 

bodojan468
58
bodojan468  

@fxsaber

Finally I did it and after I successeded I found your library https://www.mql5.com/en/code/16006

You did a great job

MT4Orders
MT4Orders
  • www.mql5.com
Parallel use of the MetaTrader 4 and MetaTrader 5 order systems.