OrderType not Work why ?

 

hi guy i have a part of my code  that i try to calla OrderType

  void CheckAndCancelOrders()
    {
        // Verifica se il primo ordine è stato eseguito
        if (ticket1 != 0 && OrderSelect(ticket1)) // Selezioniamo l'ordine con il ticket
        {
            ENUM_ORDER_TYPE type1 = OrderType();  // Otteniamo il tipo dell'ordine

            // Controlliamo se il primo ordine è stato eseguito (verifica tramite tipo)
            if (type1 == ORDER_TYPE_BUY || type1 == ORDER_TYPE_SELL)
            {
                // Se il primo ordine è eseguito, cancella il secondo ordine
                if (ticket2 != 0 && OrderSelect(ticket2))
                {
                    MqlTradeRequest cancelRequest = {};
                    MqlTradeResult cancelResult = {};
                    cancelRequest.action = TRADE_ACTION_REMOVE;
                    cancelRequest.order = ticket2;  // Cancella il secondo ordine
                    if (OrderSend(cancelRequest, cancelResult))
                    {
                        Print("Ordine 2 cancellato poiché il primo è stato eseguito.");
                    }
                }
            }
        }

        // Verifica se il secondo ordine è stato eseguito
        if (ticket2 != 0 && OrderSelect(ticket2)) // Selezioniamo il secondo ordine
        {
            ENUM_ORDER_TYPE type2 = OrderType();  // Otteniamo il tipo dell'ordine

            // Controlliamo se il secondo ordine è stato eseguito (verifica tramite tipo)
            if (type2 == ORDER_TYPE_BUY || type2 == ORDER_TYPE_SELL)
            {
                // Se il secondo ordine è eseguito, cancella il primo ordine
                if (ticket1 != 0 && OrderSelect(ticket1))
                {
                    MqlTradeRequest cancelRequest = {};
                    MqlTradeResult cancelResult = {};
                    cancelRequest.action = TRADE_ACTION_REMOVE;
                    cancelRequest.order = ticket1;  // Cancella il primo ordine
                    if (OrderSend(cancelRequest, cancelResult))
                    {
                        Print("Ordine 1 cancellato poiché il secondo è stato eseguito.");
                    }
                }
            }
        }
    }
};

but, 1 OrderType() not highlight and  when i try to run give me error 'OrderType' - undeclared identifier    PanelDialog.mqh    2111    37

but  here exist https://www.mql5.com/en/docs/standardlibrary/tradeclasses/corderinfo/corderinfoordertype  , oprobably because i call it  in file  .mqh ?

Documentation on MQL5: Standard Library / Trade Classes / COrderInfo / OrderType
Documentation on MQL5: Standard Library / Trade Classes / COrderInfo / OrderType
  • www.mql5.com
Gets the order type. Return Value Order type from ENUM_ORDER_TYPE enumeration. Note The order should be selected using the Select (by ticket) or...
 
Stefano Cerbioni:

hi guy i have a part of my code  that i try to calla OrderType

but, 1 OrderType() not highlight and  when i try to run give me error 'OrderType' - undeclared identifier    PanelDialog.mqh    2111    37

but  here exist https://www.mql5.com/en/docs/standardlibrary/tradeclasses/corderinfo/corderinfoordertype  , oprobably because i call it  in file  .mqh ?

Try these , first select with the ticket , call mql4OrderSelect , then call mql4OrderType

//auto selection of pending history or live
ulong SELECTED_TICKET=0;
enum selected_type{
selected_empty=0,//empty
selected_market=1,//live
selected_market_history=2,//history
selected_pending=3,//pending
selected_pending_history=4//pending history
};
selected_type SELECTED_TYPE=selected_empty;
bool mql4OrderSelect(ulong ticket){
  SELECTED_TICKET=0;
  SELECTED_TYPE=selected_empty;
//live 
  if(PositionSelectByTicket(ticket)){SELECTED_TICKET=ticket;SELECTED_TYPE=selected_market;return(true);}
//pending
  if(OrderSelect(ticket)){SELECTED_TICKET=ticket;SELECTED_TYPE=selected_pending;return(true);}
//market history
  if(HistorySelectByPosition(ticket)){SELECTED_TICKET=ticket;SELECTED_TYPE=selected_market_history;return(true);}
//pending history
  if(HistoryOrderSelect(ticket)){SELECTED_TICKET=ticket;SELECTED_TYPE=selected_pending_history;return(true);}

return(false);
}
//order type
int mql4OrderType(){
if(SELECTED_TYPE!=selected_empty)
{
//market + market history
  if(SELECTED_TYPE==selected_market||SELECTED_TYPE==selected_market_history)
    {
    if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){return(OP_BUY);}
    if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){return(OP_SELL);}
    }
//pending
  if(SELECTED_TYPE==selected_pending)
    {
    if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_LIMIT){return(OP_BUYLIMIT);}
    if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP){return(OP_BUYSTOP);}
    if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_LIMIT){return(OP_SELLLIMIT);}
    if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP){return(OP_SELLSTOP);}
    }
//pending history
  if(SELECTED_TYPE==selected_pending_history)
    {
    if(HistoryOrderGetInteger(SELECTED_TICKET,ORDER_TYPE)==ORDER_TYPE_BUY_LIMIT){return(OP_BUYLIMIT);}
    if(HistoryOrderGetInteger(SELECTED_TICKET,ORDER_TYPE)==ORDER_TYPE_BUY_STOP){return(OP_BUYSTOP);}
    if(HistoryOrderGetInteger(SELECTED_TICKET,ORDER_TYPE)==ORDER_TYPE_SELL_LIMIT){return(OP_SELLLIMIT);}
    if(HistoryOrderGetInteger(SELECTED_TICKET,ORDER_TYPE)==ORDER_TYPE_SELL_STOP){return(OP_SELLSTOP);}
    }
}
return(NULL);
}

and also define the mql4 operations somewhere :

#define OP_BUY  1
#define OP_SELL 2
#define OP_BUYLIMIT 3
#define OP_BUYSTOP 4
#define OP_SELLLIMIT 5
#define OP_SELLSTOP 6
 
Lorentzos Roussos #:

Try these , first select with the ticket , call mql4OrderSelect , then call mql4OrderType

and also define the mql4 operations somewhe

thanks  for  solution , but i want  know  why if  exist in manual possibility to call with

OrderType()
in reality  not  work , is  a bug of  MT5 or  is deprecated or  i did do some mistake ?
 
I think you firstly need to understand differences among Orders, Deals and Positions in MT5.

Also, I strongely suggest to use CTrade classes libraries to write easier codes, and have correct errors handling.
 
Stefano Cerbioni #:

thanks  for  solution , but i want  know  why if  exist in manual possibility to call with

in reality  not  work , is  a bug of  MT5 or  is deprecated or  i did do some mistake ?

Meta trader 5 works differently in order to accommodate hedging and netting accounts.

[Deleted]  
Stefano Cerbioni #: thanks  for  solution , but i want  know  why if  exist in manual possibility to call with in reality  not  work , is  a bug of  MT5 or  is deprecated or  i did do some mistake ?
There is no such function in MQL5. OrderType() is a MQL4 function, not MQL5.
[Deleted]  

MetaTrader 5 trade functionality is totally different to that of version 4. Please read the following to better understand it ...

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.