Compare ENUMs

 
Hi, 

i try to understand why the following if-statement not works.

void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
{
        ENUM_TRADE_TRANSACTION_TYPE type=trans.type;

	//Infoprint
        Print("ticket:"+HistoryDealGetInteger(trans.deal,DEAL_TICKET)+" > Type: TRADE_TRANSACTION_DEAL_ADD > Deal_entry (DEAL_ENTRY_IN ["+DEAL_ENTRY_IN+"]): "+HistoryDealGetInteger(trans.deal,DEAL_ENTRY)+"/"+EnumToString((ENUM_DEAL_ENTRY) HistoryDealGetInteger(trans.deal,DEAL_ENTRY)));


        if(     HistoryDealGetInteger(trans.deal,DEAL_ENTRY)==0  //(DEAL_ENTRY_IN) 
                 && HistoryDealSelect(trans.deal) == true
        )
        {
                Print("do on entry_in");
        }
        else
        {
                Print("do nothing");
        }
}

i wondering, in the journal i see my "infoprint" with "ticket:4 > Type: TRADE_TRANSACTION_DEAL_ADD > Deal_entry (DEAL_ENTRY_IN [0]): 1/DEAL_ENTRY_OUT" and the part "do on entry in" from inside this if-statement.

So normaly the simple statement will compare if(0==0), but if it is the infoprint should not printout because DEAL_ENTRY_OUT ist not 0, it should be 1..!?

Did i have to comare enum-fields in a special way!?
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
 
ReLor2:
Hi, 

i try to understand why the following if-statement not works.


i wondering, in the journal i see my "infoprint" with "ticket:4 > Type: TRADE_TRANSACTION_DEAL_ADD > Deal_entry (DEAL_ENTRY_IN [0]): 1/DEAL_ENTRY_OUT" and the part "do on entry in" from inside this if-statement.

So normaly the simple statement will compare if(0==0), but if it is the infoprint should not printout because DEAL_ENTRY_OUT ist not 0, it should be 1..!?

Did i have to comare enum-fields in a special way!?

You should try it like this

void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
{
   ulong ticket = 0;
        if(!HistoryDealSelect(trans.deal))
         return;
        else
         ticket = trans.deal; 
         if((ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket, DEAL_ENTRY) == DEAL_ENTRY_IN)
           {
            Print(EnumToString(DEAL_ENTRY_IN));
           }
}
 

I would recommend to use the Enums itself instead of their integer value.

if (HistoryDealGetInteger(trans.deal,DEAL_ENTRY) == DEAL_ENTRY_IN
And you also should check if the deal exists, before you check it's entry property.