Question about OrderSelect()?

Back to topics list To post a new topic, please log in or register
avatar
2
planb- 2016.05.13 22:25
 
Hallo,

could anyone be so kind to help me understand the OrderSelect() function?

When I load this sample EA an order opens and the two Print function start and keep printing. When I then close the trade by hand I thought OrderSelect() by ticket in MODE_TRADES ("order selected from trading pool(opened and pending orders)") should turn false, but it does not. I thought when I close the order it is shifted into history and can then only be accessed by MODE_HISTORY, but it seems not.

I wonder how to tell an EA to stop doing something in the OnTick, if not by OrderSelect.

Thanks you!


//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
    ticket=OrderSend(NULL,OP_BUY,0.01,Ask,1000,0,1000,"test");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true) {
        Print("function " + ticket);
    }
       
    bool dang=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
        if(dang) {
            Print("bool " + ticket);
        }    
  }
//+------------------------------------------------------------------+
Attached files:
  test.mq4  (1.66 KB)
avatar
Moderator
3427
GumRai 2016.05.14 00:05 #
 
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true) {
        Print("function " + ticket);
    }

MODE_TRADES is ignored if you select by ticket.

If you only want to work with the trade when it is open

if(OrderSelect(ticket,SELECT_BY_TICKET) && OrderCloseTime()==0)



avatar
2
planb- 2016.05.14 09:55 #
 
Thank you for your helpful explanation, GumRai! :)
Back to topics list  

To add comments, please log in or register