Getting last closed order loss

hsharghi  

Hi,

I'm trying to get the loss amount for the last closed order, using this code:


void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- if transaction is result of addition of the transaction in history
   if(trans.type==TRADE_TRANSACTION_DEAL_ADD)
     {
      if(HistoryDealSelect(trans.deal))
        {
         ENUM_DEAL_ENTRY deal_entry=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         if(deal_entry!=DEAL_ENTRY_IN)
           {
            ulong m_last_deal_ticket=trans.deal;
            double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); 
            // I want to make sure this deal is the one opened by this EA
            Print(request.magic);
           }
        }
      }
  }

When I try to compare the magic number with the EA magic number, but it's always 0. I've set the magic number before the trade like this:

int OnInit()
  {
     trade.SetExpertMagicNumber(InpMagicNumber);
     return(INIT_SUCCEEDED);
  }

Any idea why magic number is allways 0?

Documentation on MQL5: Integration / MetaTrader for Python / order_calc_margin
Documentation on MQL5: Integration / MetaTrader for Python / order_calc_margin
  • www.mql5.com
order_calc_margin - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: