You want to do something like this:
int total=OrdersTotal(); int i = 0; for(i = 0; i < total; i++) { if(OrderSelect(i,SELECT_BY_POS)) { if((OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol() == _Symbol) { if(OrderType()==OP_BUY) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)) Print("OrderClose error ",GetLastError()); } else { if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet)) Print("OrderClose error ",GetLastError()); } Sleep(100); } } }
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
I am new to MT5 and am still trying to figure a few things out!
Can someone please share a function that shows me how you would close all positions as per the subject line above? I will always only have open positions of either type OP_BUY or OP_SELL and never both.
I have an input parameter on my EA called MaxTrades to limit the number of trades with a single currency pair. However, I expect that I will be running my EA on multiple currency pairs and will need to throttle how many open orders each Currency Pair is allowed..
I don't yet understand the structures which I must use in order to successfully run a "for loop".
Any help would be much appreciated.
Thank you in advance,
CipherPips