Bob,
OrdersTotal returns the number of orders that you have open or pending for all currencies. You must iterate through the current orders to determine what trades you have on the current symbol. E.g.
OrdersTotal returns the number of orders that you have open or pending for all currencies. You must iterate through the current orders to determine what trades you have on the current symbol. E.g.
bool HaveBuyOrder = false, HaveSellOrder = false; for (int iter = OrdersTotal(); iter >= 0; iter--) { if (OrderSelect(iter, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)) { HaveBuyOrder = true; } else if (OrderSymbol() == Symbol() && (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP)) { HaveSellOrder = true; } } }
You could write your own functions, HaveBuyOrder and HaveSellOrder, that return a boolean value using the above logic. This helps to simplify the main loop.
HTH,
Aaron.
Corrections have been made to above listing.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Just a quick question, I am in the middle of writting an EA, where it places a buystop and a sellstop at the same.
At the moment, I want the EA to place a maxium of 2 pending orders, (buystop/sellstop) per currency. If I use the following code, will that only place 2 orders all together on all currencys, or place 2 orders per currency, if that makes sence?
For example, I trade gbp/usd and eur/usd. I want to place a buystop order and a sellstop sellstop on each of these currencys.
Thanks
Bob