int countOpenedOrders(int MagicNumber){
int openedOrders=0;
for(int i=0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;
if(OrderMagicNumber() != MagicNumber) continue;
if(OrderSymbol() != Symbol()) continue;
//
//
//
//
//
if(OrderType() == OP_BUY || OrderType() == OP_SELL) openedOrders++;
}
return(openedOrders);
}
If it returns 0, there are no opened positions for that magic number + symbol combination
Hi guys,
I want to check for every position to open if there is a position (magicnumber + symbol) already open.
Who can help?
Best Regards,Hi mladen,
many thanks for your help. I have some problems to put in on the right position of the code. Do I have to put your code after in start()?
Best regards,
Place it at the end of the EA
But since you use 2 magic numbers and 2 symbols that function has to be changed a bit and should be something like this :int countOpenedOrders(int magicNumber, string symbol){
int openedOrders=0;
for(int i=0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;
if(OrderMagicNumber() != magicNumber) continue;
if(OrderSymbol() != symbol) continue;
//
//
//
//
//
if(OrderType() == OP_BUY || OrderType() == OP_SELL) openedOrders++;
}
return(openedOrders);
}
Anyway, changed your code a bit so it allows only one opened order per magic number + symbol opened at a time (if that is what you had in mind)
regards
Hi mladen,
many thanks for your help. I have some problems to put in on the right position of the code. Do I have to put your code after in start()?
Best regards,- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
I want to check for every position to open if there is a position (magicnumber + symbol) already open.
Who can help?
julyhedge.mq4
Best Regards,