Magic number 0 means that the order was closed manually.
You can monitor OrdersTotal() for increase and decrease in orders.
ORDER_REASON_CLIENT
ORDER_REASON_EXPERT

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
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
Code
***

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
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