Download MetaTrader 5
To add comments, please log in or register
Do you need a programmer? Make an order to let the developer find you!
cryptex23
268
cryptex23 2014.03.06 16:59 

Amongst all the functions listed the OrderSelect is the most confusing. Answers range from time of sending to alphabetical order. I would like to know it from someone who knows it for sure how it works.

Here is the scenario. EA has opened 10 pending orders across 5 charts(2 pending orders per chart). And lets say now i want to modify one my existing orders. The million dollar question what is the most efficient and reliable way of selecting between orders. And what if there are multiple EAs (one EA per chart instead of one EA for 5 charts) running how does one EA differentiate its orders from the others?

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.06 17:02  
cryptex:

Amongst all the functions listed the OrderSelect is the most confusing. Answers range from time of sending to alphabetical order. I would like to know it from someone who knows it for sure how it works.

Here is the scenario. EA has opened 10 pending orders across 5 charts(2 pending orders per chart). And lets say now i want to modify one my existing orders. The million dollar question what is the most efficient and reliable way of selecting between orders. And what if there are multiple EAs (one EA per chart instead of one EA for 5 charts) running how does one EA differentiate its orders from the others?

Select your Orders one at a time using OrderSelect() and then find the one you want by checking for OrderType(), OrderSymbol() and OrderMagicNumber() if you are using one. You can also use OrderLots() and any other Order information that helps you find the correct order . . .
cryptex23
268
cryptex23 2014.03.06 19:30  
RaptorUK:
Select your Orders one at a time using OrderSelect() and then find the one you want by checking for OrderType(), OrderSymbol() and OrderMagicNumber() if you are using one. You can also use OrderLots() and any other Order information that helps you find the correct order . . .


Ok worked with that. Another doubt what does it mean mean i specify my magic number as 0 and expiration as 0 while sending a pending order? it is randomly allot a magic number and no expiration respectively?

And in what format is time stored? i mean if i do TimeCurrent()-OrderCloseTime() what would i get. will it be a value in seconds?

whroeder1
13599
whroeder1 2014.03.06 20:09  
  1. If you specify MN as 0 that is what you get - means your EA is incompatible with manual trading and if you don't check OrderSymbol vs Symbol it is incompatible with itself on other pairs. See order accounting - MQL4 forum
  2. Link "the number of seconds elapsed since January 01, 1970"




cryptex23
268
cryptex23 2014.03.06 20:12  
cryptex:


Ok worked with that. Another doubt what does it mean mean i specify my magic number as 0 and expiration as 0 while sending a pending order? it is randomly allot a magic number and no expiration respectively?

And in what format is time stored? i mean if i do TimeCurrent()-OrderCloseTime() what would i get. will it be a value in seconds?


Ok so after a little more research i think now i understand how the magicnumber() thing works. Basically it is something that will differentiate all orders open by one EA from orders opened by another EA. am i right?
cryptex23
268
cryptex23 2014.03.06 20:20  
WHRoeder:
  1. If you specify MN as 0 that is what you get - means your EA is incompatible with manual trading and if you don't check OrderSymbol vs Symbol it is incompatible with itself on other pairs. See order accounting - MQL4 forum
  2. Link "the number of seconds elapsed since January 01, 1970"





1. Thanks got it. So here is what i am doing. Somebody posted a nice way to assign magic number to an EA. magic = makeMagicNumber(WindowExpertName() + Symbol() + Period());

2. So the difference is indeed in seconds :)

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.06 20:52  
cryptex:


1. Thanks got it. So here is what i am doing. Somebody posted a nice way to assign magic number to an EA. magic = makeMagicNumber(WindowExpertName() + Symbol() + Period());

2. So the difference is indeed in seconds :)

You don't need to use Symbol() in that, you can check OrderSymbol(), and you can assign each EA you write with a unique number . . . so (unique number * 100) + Period() gives you a unique Magic Number for any of your EAs on a specific timeframe.
Daniel Petrovai
440
Daniel Petrovai 2014.03.07 09:32  
cryptex:

Amongst all the functions listed the OrderSelect is the most confusing. Answers range from time of sending to alphabetical order. I would like to know it from someone who knows it for sure how it works.

Here is the scenario. EA has opened 10 pending orders across 5 charts(2 pending orders per chart). And lets say now i want to modify one my existing orders. The million dollar question what is the most efficient and reliable way of selecting between orders. And what if there are multiple EAs (one EA per chart instead of one EA for 5 charts) running how does one EA differentiate its orders from the others?


I believe that the quickest way to access an order if you know which one you want is to store the ticket number in a variable, something like this :

if(ticket=OrderSend(Symbol(),OP_BUYLIMIT,lot,entry,Slip,0,0,0,MagicNumber,0,Red)>=0)
ticketPendingBuyLimit=ticket;
else Print("Error selecting pending BuyLimit"+GetLastError());
// then you can select by ticket number ie. 

if(OrderSelect(ticketPendingBuyLimit,SELECT_BY_TICKET))
   {
   if(OrderStopLoss()==0) // no stop set yet
      {
      OrderModify(...
// the ticket will change if the order is filled and the order will be an OP_BUY then. 

This way you don't need to loop trough all orders to find the one you need (if it is still pending).

And if the order is still pending, you will find it regardless if you have an EA on each symbol or a single EA for 5 symbols.

Not sure if I explained it properly . Just my 2 cents.And for this example you don't need magic number either but you will

end up with 10 variable, one for each order.

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.07 10:05  
thrdel:


I believe that the quickest way to access an order if you know which one you want is to store the ticket number in a variable, something like this :

This way you don't need to loop trough all orders to find the one you need (if it is still pending).

And if the order is still pending, you will find it regardless if you have an EA on each symbol or a single EA for 5 symbols.

Not sure if I explained it properly . Just my 2 cents.And for this example you don't need magic number either but you will

end up with 10 variable, one for each order.

You are right, it is the quickest way, but it isn't fail safe, if your EA has to be shut down or MT4 or your PC closes unexpectedly your code cannot recover from where it left off . . . unless you save the ticket number to a file or maybe Global Variable. If it's possible to do it's always a better solution to find the relevant Order as this can be repeated when an EA starts/restarts.
Daniel Petrovai
440
Daniel Petrovai 2014.03.08 03:46  
RaptorUK:
You are right, it is the quickest way, but it isn't fail safe, if your EA has to be shut down or MT4 or your PC closes unexpectedly your code cannot recover from where it left off . . . unless you save the ticket number to a file or maybe Global Variable. If it's possible to do it's always a better solution to find the relevant Order as this can be repeated when an EA starts/restarts.


True,it is not fail safe. My thoughts were only in regards with the specified context (2 orders per symbol, no manual entries).In this case, in case of unexpected shut down or something, a loop will reassign the ticket numbers to all variables and ea will continue to manage those trades according to specified conditions. Theoretically speaking. Two orders per symbol, different directions.Like on a vps server. No manual entries.
/
To add comments, please log in or register