This won't work:
bool ExistPositions() {
for (int i=100; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol()) {
return(True);
}
}
}
return(false);
}
replace with:
bool ExistPositions() {
for (int i=OrdersTotal()-1; i>=0; i-) if (
OrderSelect(i, SELECT_BY_POS, MODE_TRADES)
&& OrderSymbol()==Symbol()) {
return(True);
}
return(false);
}