Searching for opened orders my magic number

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
Moderator
3406
GumRai 2015.11.30 12:46 #
 
int AreThereOrders ()  //Why use an int, the function is a true false question
{
if (OrdersTotal()<1)
{
return 1;
}
else if (OrdersTotal()>0)  //No need for the else as you have alreaddy returned if OT is less than 1
{

int i;

for (i=OrdersTotal()-1; i>=0; i--)
   {
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   continue;
   if( OrderMagicNumber()!= magic && OrderSymbol()!=Symbol()) //This means that if  any order is open that does not have 
   {                                                          //the magic number or chart symbol, a new order is opened
   return 2;
   }
 
  
  }
  
 
    }
   return 0 ;   
   }

more sensible, in my opinion

bool AreThereOrders()
  {
   if(OrdersTotal()<1)
     {
      return (false);
     }

   int i;
   for(i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
        {
         return (true);
        }
     }
   return (false);
  }

 Then instead of

 if (AreThereOrders() == 1 || AreThereOrders() ==2)
     { 
      //buy or sell condition
     }

 use

 if (!AreThereOrders())
     { 
      //buy or sell condition
     }

 more logical.

 

avatar
34
Stan4o1 2015.11.30 13:01 #
 
What i meant is that i want to open orders in 2 cases - if,  no order is open, and if there is already an open order, but it has to be from another EA, so that my new order will be the only order for the specified currency . My idea is to have only 1 order per EA / currency/, so that why i `ve written if the magic number doesn`t match it can open a new order/ because it will be from another EA/ and i will have only 1 per currency. But the problem is that it doesn`t open only 1 order for the currency. Maybe before i didnt explain it very well.  
avatar
Moderator
3406
GumRai 2015.11.30 13:28 #
 
Stan4o1:
What i meant is that i want to open orders in 2 cases - if,  no order is open, and if there is already an open order, but it has to be from another EA, so that my new order will be the only order for the specified currency . My idea is to have only 1 order per EA / currency/, so that why i `ve written if the magic number doesn`t match it can open a new order/ because it will be from another EA/ and i will have only 1 per currency. But the problem is that it doesn`t open only 1 order for the currency. Maybe before i didnt explain it very well.  

and that is precisely what

      if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
        {
         return (true);
        }

 achieves

avatar
34
Stan4o1 2015.11.30 14:53 #
 

Wow It worked thanks very very much :)))

 

Back to topics list   | 1 2  

To add comments, please log in or register