When a position hits the Stop Loss, why is the magic number removed in MT5?

 
Hello everyone!
I'm using MT5 and facing an issue where, when a position with a set Stop Loss is closed, the magic number gets removed. I've used the following code to print the magic number in the history.
for(int i=0;i<HistoryDealsTotal()-1;i++){
      ulong dealticket=HistoryDealGetTicket(i);
         Print(HistoryDealGetInteger(dealticket,DEAL_MAGIC));
         if( HistoryDealGetString(dealticket,DEAL_SYMBOL)==_Symbol &&
             HistoryDealGetInteger(dealticket,DEAL_MAGIC)==INMAGIC ){
             profit += ( HistoryDealGetDouble(dealticket,DEAL_PROFIT)+
                         HistoryDealGetDouble(dealticket,DEAL_SWAP)+
                         HistoryDealGetDouble(dealticket,DEAL_COMMISSION) );
         }
   }


Stop Loss positions are marked as shown in the image.


Checking the history, those positions have had their magic number removed.

Positions closed by the EA still retain their magic number. I calculate the total profit using a filter for the magic number, but this issue causes positions without a magic number to be excluded from the calculation.

Please help me.  Thank you for reading.

 
Au Phuong Tan: I'm using MT5 and facing an issue where, when a position with a set Stop Loss is closed, the magic number gets removed. I've used the following code to print the magic number in the history. Stop Loss positions are marked as shown in the image. Checking the history, those positions have had their magic number removed. Positions closed by the EA still retain their magic number. I calculate the total profit using a filter for the magic number, but this issue causes positions without a magic number to be excluded from the calculation.

Please note that a similar issue has been reported for traders using Exness (see below). Is this your case? If so please discuss the issue with your broker.

No magic no. associated post pending order gets filled
No magic no. associated post pending order gets filled
  • 2024.10.28
  • Utkarsh Katiyar
  • www.mql5.com
Hi All, I have run into this weird problem from 24th October, the pending orders when placed show a magic number associated with them but when the...
 
Fernando Carreiro #:

Please note that a similar issue has been reported for traders using Exness (see below). Is this your case? If so please discuss the issue with your broker.

Thank you for your suggestion! I’ll reach out to my broker regarding this issue and see how they respond.