Download MetaTrader 5

How to check is there any order open with certain Magic Number

To add comments, please log in or register
konradp
18
konradp  

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
9641
Keith Watford  
Loop through the open orders and check OrderMagicNumber()
konradp
18
konradp  
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  
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  
sugar... but how will I zero it if there is no orders....
Keith Watford
Moderator
9641
Keith Watford  
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
14781
whroeder1  
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