How can I Restrict the number of open position par pair
extern int LimitPerPair=5; int NumberOfTrades=0; for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders { if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available { if(OrderSymbol()==Symbol()) { NumberOfTrades++; } } } if(NumberOfTrades>=LimitPerPair) bool DontTrade=true; if(...&&DontTrade!=true) { // trade }Untested but it should give you an idea
Usually I do something to the effect of:
int _countOpenOrders(int countOpen = 0) { for(int x=0; x<=OrdersTotal(); x++) if( OrderSelect(x, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == Magic.Number && OrderSymbol() == Symbol() && OrderType() == OP_SELL || OP_BUY) // Whatever orders you use countOpen++; return(countOpen); }
thank you very much. you have answered me. I will try it to see if it works.
No problem, glad we could help.
How Can one restrict a number of open position par pair?