Download MetaTrader 5

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

To add comments, please log in or register
Do you want to learn MQL5? 300 articles will help you!
qiao_feng
29
qiao_feng 2011.10.06 10:53 

      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
29
qiao_feng 2011.10.06 11:32  
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?
Rashid Umarov
Admin
11815
Rashid Umarov 2011.10.06 11:51  

What sort of orders do you mean - pending or an one which placed in history (triggered, canceled, etc)?
qiao_feng
29
qiao_feng 2011.10.06 12:26  
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

 
qiao_feng
29
qiao_feng 2011.10.06 12:27  

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

qiao_feng
29
qiao_feng 2011.10.06 13:45  

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.

Jimmy
490
Jimmy 2011.10.06 13:47  
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.
qiao_feng
29
qiao_feng 2011.10.06 14:24  
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.
qiao_feng
29
qiao_feng 2011.10.06 15:23  

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
qiao_feng
29
qiao_feng 2011.10.06 15:42  
I ordersend a order!   then orderselect it. always false!
Jimmy
490
Jimmy 2011.10.06 16:21  
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.
12
To add comments, please log in or register