gangsta1:
I am looking for a way to close ALL open orders rather than just the current code I have which closes just 1 order:
read Close 2 Trades and follow the advice of RaptorUK and WHRoeder
you do also counting up the loop while you close trades inside your loop that will give errors
This is my script, that works great in my case.
Carefull: this really closes all the open positions, for all the crosses. Not just for the cross in the chart you run the script against.
int start() { //---- for(int i=OrdersTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS)==true) { double ExPrice; int Tck=OrderTicket(); RefreshRates(); if (OrderType()==0) { ExPrice=MarketInfo(OrderSymbol(),MODE_BID); OrderClose(Tck,OrderLots(),ExPrice,3); } else if (OrderType()==1) { ExPrice=MarketInfo(OrderSymbol(),MODE_ASK); OrderClose(Tck,OrderLots(),ExPrice,3); } int Err=GetLastError(); if (Err>0) Print("Error closing position. Ticket: ", Tck, " Err: #",Err); } } //---- return(0); }
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 looking for a way to close ALL open orders rather than just the current code I have which closes just 1 order: