Download MetaTrader 5
To add comments, please log in or register
Have you developed a trading robot? Publish it in the Market and make profit!
konradp
18
konradp 2016.04.26 10:14 

Hi,


I have a few orders open for different currencies, how can I find is there an open order for certain Magic Number?

Keith Watford
Moderator
7947
Keith Watford 2016.04.26 10:18  
Loop through the open orders and check OrderMagicNumber()
konradp
18
konradp 2016.04.26 10:27  
yes, but if I setup something like if (OrderMagicNumber() =MagicNUmber){orderopen=1}else{orderopen=0} then it will return 0 every time it scan order different to one i'm looking for, what I need is more like to check is any order open for MagicNumber.
konradp
18
konradp 2016.04.26 10:29  
ok I think i have solution, I will scan orders and add orderopen together for entire scan, at the end if I get value <0 it mean there is some order open
konradp
18
konradp 2016.04.26 10:33  
sugar... but how will I zero it if there is no orders....
Keith Watford
Moderator
7947
Keith Watford 2016.04.26 10:36  
If you want to count the orders, set a counter to zero before the loop then add 1 everytime an order with the magic number is detected
whroeder1
13627
whroeder1 2016.04.26 12:38  
konradp if I setup something like if (OrderMagicNumber() =MagicNUmber){orderopen=1}else{orderopen=0} then it will return 0 every time it scan order different to one i'm looking for, what I need is more like to check is any order open for MagicNumber.
  1. else{orderopen=0} means it's zero if the first order is not the MN (rest of the orders are irrelevant.) Set it zero before the loop, and you'll set it to 1 if any orders exist (in any position.)
  2. Don't use 0 and 1 when you mean boolean.
    This is why I say: You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
  3. OrderSelect loop see. Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
/
To add comments, please log in or register