Maximum allowed Orders

 

Hello,


have someone an idea or codes snippet for me that an ea only open so much trades that i have define in an input value.


Now i use this

if(OrdersTotal() >= maxOrders) 
{
Print("Maximum Orders");
        return;
}

but it looks like it is not working very well. 

 
No idea it looks like this Code count All open trades instead of only from ea
 
Raphael Schwietering:

Hello,


have someone an idea or codes snippet for me that an ea only open so much trades that i have define in an input value.


Now i use this

but it looks like it is not working very well. 

Find the error with GetLastError()

if(OrdersTotal() >= maxOrders) 
{
Print("Maximum Orders");
        return;
}

BTW, it might need to be <= maxOrders

 
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
          Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
 
I think the EA only counts the orders from the input magic. For example if you run the same EA on another pair or even in the same pair I think it will not count the orders. For that you might have to use a script I think.