Download MetaTrader 5

Saving OrderOpenTime() after OrderSend()

To add comments, please log in or register
DeanDeV
330
DeanDeV  

Hey guys,

Is there any simple way to save the open time of an order after the OrderSend() function. Something like...

//global 
datetime buyordertime;

Start()
int BuyOrder=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,StopLoss,TakeProfit,"buy order",MagicNumber,0,clrBlue);
buyordertime=OrderOpenTime();

 Or do I have to write a for() after the OrderSend() selecting the order and then save it? 

Any help is appreciated.  

PomeGranate
589
PomeGranate  

Just add the OrderSelect function at the right place (donno if it is wise to RefreshRates() before that, read here and there it is recommended, but as you want to access a recently opened order, maybe not in this case):

//global 
datetime buyordertime;

Start()
int BuyOrder=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,StopLoss,TakeProfit,"buy order",MagicNumber,0,clrBlue);
//RefreshRates() ??
OrderSelect(Buyorder,SELECT_BY_TICKET,MODE_TRADES);
buyordertime=OrderOpenTime();
DeanDeV
330
DeanDeV  
PomeGranate:

Just add the OrderSelect function at the right place (donno if it is wise to RefreshRates() before that, read here and there it is recommended, but as you want to access a recently opened order, maybe not in this case):

 

 

Fantastic! Thanks! Can I make it this: 
//global 
datetime buyordertime;

Start()
int BuyOrder=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,StopLoss,TakeProfit,"buy order",MagicNumber,0,clrBlue);
//RefreshRates() ??
if(BuyOrder>0) OrderSelect(Buyorder,SELECT_BY_TICKET);
buyordertime=OrderOpenTime();
Also, will saving the OrderOpenPrice() help distinguish between 2 orders of the same OrderType() and MagicNumber? Meaning, if the above order gets sent twice at 2 different times can I use OrderOpenPrice() to help distinguish between the two orders?
PomeGranate
589
PomeGranate  

1. Of course you can, why shouldn't you? ^^ (that probably even saves resources)

2. No, I think you can't. For that, you'll have to build more elaborate order management (looping through orders etc.)

DeanDeV
330
DeanDeV  
PomeGranate:

2. No, I think you can't. For that, you'll have to build more elaborate order management (looping through orders etc.)

Can you suggest any properties of each order to look at in these loops to make the EA distinguish between the two?
honest_knave
Moderator
2318
honest_knave  
DeanDeV:
Can you suggest any properties of each order to look at in these loops to make the EA distinguish between the two?

OrderTicket()

DeanDeV
330
DeanDeV  
honest_knave:

OrderTicket()

 

 

Thanks.
To add comments, please log in or register