Download MetaTrader 5

Searching for opened orders my magic number

To add comments, please log in or register
Stan4o1
118
Stan4o1  

Hi, I made some changes to one of my EAs it is about searching for already opened orders by their magic nbr. I have set different magic nbr for the ea, when i attached it to different currencies, but still  order opened stops the other EAs from trading with different currencies. Can you help me ? This is the function i created, and  in the ontick function i have set an if (Arethereorders() ==  1 || AreThereOrders() == 2) then it checks for buy/sell signals

 )

int AreThereOrders ()
{
if (OrdersTotal()<1)
{return 1;}
else
{
int i;
for (i=0;i<OrdersTotal();i++)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
   continue;
   if(OrderMagicNumber() != magic)
   {return 2;}
   break;
   }
   return 0;
   }
   }
Carl Schreiber
7092
Carl Schreiber  

Probably you wanted to write this:

for (i=0;i<OrdersTotal();i++)
   {
   if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false ) 
   continue;
..
Stan4o1
118
Stan4o1  

You were right! Thanks But after opening different orders for different currencies, it opened too many orders on the same currency, How can i fix it?

Carl Schreiber
7092
Carl Schreiber  
Stan4o1:

You were right! Thanks But after opening different orders for different currencies, it opened too many orders on the same currency, How can i fix it?

If it was only a temporary mistake in your code close'em by hand?

Stan4o1
118
Stan4o1  
It is not temporary, as soon as i attach the EA to a second chart it starts opening many many orders, i dont know whats wrong i even added Refreshates but it wouldn`t help.If someone could help me i would be very gratefull
int AreThereOrders ()
{
if (OrdersTotal()<1)
{return 1;}
else
{
int i;
for (i=0;i<OrdersTotal();i++)
   {
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   continue;
   if(OrderMagicNumber() != magic)
   {return 2;}
   break;
   }
   return 0;
   }
   RefreshRates();
   }




And then i use




 if (AreThereOrders() == 1 || AreThereOrders() ==2)
     {    

and there follows the buy or sell condition
 
Carl Schreiber
7092
Carl Schreiber  

You probably wanted to write:

if(OrderMagicNumber() == magic) return 0; // no further order
...
//and at the end
return 2; // no matching open order found 
Stan4o1
118
Stan4o1  
Im sorry i tried it but it still doesnt work - The EA opens many orders
Stan4o1
118
Stan4o1  
int AreThereOrders ()
{
if (OrdersTotal()<1)
{return 1;}
else
{
int i;
for (i=0; i<OrdersTotal() ; i++)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && ( OrderMagicNumber()== magic)) return 0;
   break;
   }
   
   }
   return 2 ;
   }

This is what you meant right?
Keith Watford
Moderator
10569
Keith Watford  
for (i=0; i<OrdersTotal() ; i++)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && ( OrderMagicNumber()== magic)) return 0;
   break;
   }
The break means that only 1 order is checked, remove it.
Stan4o1
118
Stan4o1  

Thanks

Stan4o1
118
Stan4o1  
int AreThereOrders ()
{
if (OrdersTotal()<1)
{
return 1;
}
else if (OrdersTotal()>0)
{

int i;

for (i=OrdersTotal()-1; i>=0; i--)
   {
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   continue;
   if( OrderMagicNumber()!= magic && OrderSymbol()!=Symbol()) 
   {
   return 2;
   }
 
  
  }
  
 
    }
   return 0 ;   
   }
This is what i made but ,i dont know why, it still keeps opening too many orders, not like i wanted just 1 per currency/magic number. I dont` know what to do .
12
To add comments, please log in or register