When I use the OrderSelect() ,it always returns false. why???

 

      ulong t="a ticket of a exist order";
      if (!OrderSelect(t))
      {
         Print("In the RunTrade().There is a error when Select order.",GetLastError());
         return(false);
      }

 

 

Thank you very much!!! 

Documentation on MQL5: Trade Functions / OrderSelect
  • www.mql5.com
Trade Functions / OrderSelect - Documentation on MQL5
 
qiao_feng:

      ulong t="a ticket of a exist order";
      if (!OrderSelect(t))
      {
         Print("In the RunTrade().There is a error when Select order.",GetLastError());
         return(false);
      }

 

 

Thank you very much!!! 

It's a big bug of MQL5?
 

What sort of orders do you mean - pending or an one which placed in history (triggered, canceled, etc)?
 
Rosh:

What sort of orders do you mean - pending or an one which placed in history (triggered, canceled, etc)?

In the strategy tester, the order has been accepted which just been send by EA .

OrderSelect() get the error code is 4754.

I try to test it in MetaQuotes-Demo. The position can't be open. The error code is 4752

ERR_TRADE_DISABLED

4752

Trading by Expert Advisors prohibited

ERR_TRADE_ORDER_NOT_FOUND

4754

Order not found

 
 

I'm not good at English.   I hope I have expressed clearly.

 

I used to develop MT4. The OrderSelect also appear some problems.

bool OrderSelect( int index, int select, void pool)

if the index = 0  ,the orderselect always return true! Obviously wrong!

and 

if select = SELECT_BY_POS  pool = MODE_TRADES  ,the orderselect always return false or not return all right orders.

 
qiao_feng:

      ulong t="a ticket of a exist order";
      if (!OrderSelect(t))
      {
         Print("In the RunTrade().There is a error when Select order.",GetLastError());
         return(false);
      }

 

 

Thank you very much!!! 

Maybe the order is already executed, so you may have to use HistorySelect() instead.
 
fireflies:
Maybe the order is already executed, so you may have to use HistorySelect() instead.
See the image which I Upload.The order just there,not executed.
 

I upload the source files.please help me.

 

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
     
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
     
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   MqlTick           m_tick;
   MqlTradeRequest   m_request;           // request data
   MqlTradeResult    m_result;            // result data
   if(!SymbolInfoTick(Symbol(),m_tick))
      Print("SymbolInfoTick(Symbol(),m_tick)  get error:",GetLastError());
  
   m_request.action      =TRADE_ACTION_DEAL;
   m_request.symbol      =Symbol();
   m_request.magic       =88888888;
   m_request.volume      =0.01;
   m_request.type        =ORDER_TYPE_SELL;
   m_request.price       =m_tick.bid;
   m_request.sl          =0.0;
   m_request.tp          =0.0;
   m_request.deviation   =3;
   m_request.type_filling=ORDER_FILLING_FOK;
   m_request.comment     ="";
   if(OrderSend(m_request,m_result))
   {
      if (!OrderSelect(m_result.order))
      {
         Print("There is a error when Select order:",m_result.order,", error#",GetLastError());
      }
      else
      {
         Print("####################",OrderGetDouble(ORDER_PRICE_OPEN));
      }
   }
   else
   {
      Print("Open position ERROR:",GetLastError());
   }
  }

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Language Basics / Preprocessor / Program Properties (#property) - Documentation on MQL5
 
I ordersend a order!   then orderselect it. always false!
 
qiao_feng:
See the image which I Upload.The order just there,not executed.

It's executed, the order became a deal. If you look at the picture, it has become an open position.

Your code (m_request.action =TRADE_ACTION_DEAL) confirms that.
Reason: