Download MetaTrader 5

Check if there is already an open position of a specific pair

To add comments, please log in or register
Deklin
26
Deklin  

What is the simplest and most efficient way to  test if there is already an open position of a specific pair?

This works but is there a simpler way?



    string Pair = "EURUSD";
    if (OrdersTotal() > 0) {
        for (int iii = OrdersTotal() - 1; iii >= 0; iii--) {
            if (OrderSelect(iii, SELECT_BY_POS, MODE_TRADES)) {
                if (OrderSymbol() == Pair) {
                        Alert("There is already an open position of " + Pair);
                }
            }
        }
     }

To add comments, please log in or register