COrderInfo always return 0 for all OrderTypes

 

I just noticed that OrderInfo.Type() always return a 0 for all type of Orders. Why is this so?

OrderInfoType always return 0 mql5

//+------------------------------------------------------------------+
//|                                       Check OrderInfo.Type().mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"


#include <Trade\Trade.mqh>         CTrade          Trade;
#include <Trade\OrderInfo.mqh>     COrderInfo      OrderInfo;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   Place_Pending_Orders();
  }


int execute_once = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Place_Pending_Orders()
  {

   if(execute_once == 0)
     {
      string _symbol = _Symbol;
      Info_Market(_Symbol);


      double Entry_price = PriceAsk+(1.5*Level_Stop*Poin);
      double Lots = NormalizeDouble(MathAbs(0.1),Decimals); if(Lots < MinLot){Lots = MinLot;} if(Lots > MaxLot){Lots = MaxLot;}
      double TP = 0;
      double SL = 0;
      string Your_Comment = "";
      datetime expiration = 0;
      int Magic_Number = 1234;
      ENUM_ORDER_TYPE_TIME type_time = ORDER_TIME_GTC;


      Trade.SetExpertMagicNumber(Magic_Number);

      if(!(Trade.BuyStop(Lots,Entry_price,_symbol,SL,TP,type_time,expiration,Your_Comment) && (Trade.ResultRetcode() == 10008 || Trade.ResultRetcode() == 10009)))
        {Print("Buy Stop Pending Order Failed! Reason: "+Trade.ResultRetcodeDescription()+ "   Error: "+IntegerToString(Trade.ResultRetcode()));}

      if(!(Trade.SellLimit(Lots,Entry_price,_symbol,SL,TP,type_time,expiration,Your_Comment) && (Trade.ResultRetcode() == 10008 || Trade.ResultRetcode() == 10009)))
        {Print("Sell Limit Pending Order Failed! Reason: "+Trade.ResultRetcodeDescription()+ "   Error: "+IntegerToString(Trade.ResultRetcode()));}


      Entry_price = PriceBid-(1.5*Level_Stop*Poin);

      if(!(Trade.BuyLimit(Lots,Entry_price,_symbol,SL,TP,type_time,expiration,Your_Comment) && (Trade.ResultRetcode() == 10008 || Trade.ResultRetcode() == 10009)))
        {Print("Buy Limit Pending Order Failed! Reason: "+Trade.ResultRetcodeDescription()+ "   Error: "+IntegerToString(Trade.ResultRetcode()));}

      if(!(Trade.SellStop(Lots,Entry_price,_symbol,SL,TP,type_time,expiration,Your_Comment) && (Trade.ResultRetcode() == 10008 || Trade.ResultRetcode() == 10009)))
        {Print("Sell Stop Pending Order Failed! Reason: "+Trade.ResultRetcodeDescription()+ "   Error: "+IntegerToString(Trade.ResultRetcode()));}

      show_OrderTypes();

      execute_once = 1;
     }

  }

//+------------------------------------------------------------------+
//| Display Order Types                                              |
//+------------------------------------------------------------------+
void show_OrderTypes()
  {
   for(int c = OrdersTotal()-1; c>=0; c--)
     {
      if(OrderInfo.SelectByIndex(c) == true)
        {
         if(OrderInfo.Symbol() == _Symbol)
           {
            Print("The OrderType is: ",OrderInfo.Type(),"  the Order Type Description is: ",OrderInfo.TypeDescription());
           }
        }
     }

  }




//---- MarketInfo Variabless
double Poin, FreeMargin, PriceAsk, PriceBid, LotStep, MaxLot, MinLot;
int  Decimals;
int Digit;
ulong Level_Stop;
//+------------------------------------------------------------------+
//| Function to Gets Market Information Data                         |
//+------------------------------------------------------------------+
void Info_Market(string _symbol)
  {
   LotStep      = SymbolInfoDouble(_symbol, SYMBOL_VOLUME_STEP);
   MaxLot       = SymbolInfoDouble(_symbol, SYMBOL_VOLUME_MAX);
   MinLot       = SymbolInfoDouble(_symbol, SYMBOL_VOLUME_MIN);
   Digit        = (int) SymbolInfoInteger(_symbol,SYMBOL_DIGITS);
   Poin         = SymbolInfoDouble(_symbol, SYMBOL_POINT);
   PriceAsk     = NormalizeDouble(SymbolInfoDouble(_symbol,SYMBOL_ASK),Digit);
   PriceBid     = NormalizeDouble(SymbolInfoDouble(_symbol,SYMBOL_BID),Digit);
   FreeMargin   = NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_FREE),2);
   Level_Stop   = SymbolInfoInteger(_symbol,SYMBOL_TRADE_STOPS_LEVEL);

   Decimals  = 0;
   Decimals = (int) MathLog10(1/LotStep);
//---
  }
//+------------------------------------------------------------------+
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
You should use
OrderInfo.OrderType()
 

Hi

In the COrderInfo class Type is not defined virtual method. If You want to get the type of the order you have to use OrderType() function which return ORDER_TYPE property of the order.

Have a nice day👍📊

 
Frederic Metraux #:
You should use
That's what I said.

COrderInfo OrderInfo.OrderType() always returns 0 for any Order type.

I had to use the OrderTypeDescription() to identify different Orders type because Order info.OrderType() returns 0 


Is this a bug on Mql5 or it's meant to do this?


 
That's true. I made a mistake, it's OrderInfo.OrderType() not OrderInfo.Type().