Close All Trades In All Charts Simultaneously Immediately
I've searched around and I've not found
because there isn't
never was and never will
Hello
I've searched around and I've not found a script for MT4 specifically which closes all trades on all charts immediately at whatever price. Has anyone got one?
This will help with testing EAs which work in strategies which work across multiple charts per terminal.
Thanks
Are you looking to close all orders placed by the EA on all symbols or do you want to close all orders regardless of who opened them ?
If you're looking to close one symbol regardless of who opened the order :
If you want to close all symbols, same function without the symbol condition :
void CloseAll() { int trade=0; closed=false; double price=0.0; for(trade=OrdersTotal()-1;trade>=0;trade--) { if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))//if order select fails { Print("Order select failed in CloseAll() with error : "+(string)GetLastError());//tell me the error break; } // else if order select didn't fail else { price=0.0; if(OrderType()==OP_BUY) { price=Bid; } else if(OrderType()==OP_SELL) { price=Ask; } else { continue; } closed=OrderClose(OrderTicket(),OrderLots(),price,slip,Blue); if(!closed) { Print("Close order failed with error : "+(string)GetLastError());//tell me the error } } } }
I believe you get the idea.
Note that pending orders have to be deleted not closed (Use OrderDelete() instead of OrderClose() ) .
@ thrdel your code doesn't do what strontiumDog wants
he want to close all the orders "Simultaneously Immediately"
so with your code ("or any code") it's not gonna happen
B.T.W
you don't need to write:
else { price=0.0; if(OrderType()==OP_BUY) { price=Bid; } else if(OrderType()==OP_SELL) { price=Ask; } else { continue; } closed=OrderClose(OrderTicket(),OrderLots(),price,slip,Blue);
you can simple write
else { closed=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slip,Blue);
@ thrdel your code doesn't do what strontiumDog wants
he want to close all the orders "Simultaneously Immediately"
so with your code ("or any code") it's not gonna happen
Hi qjol:,
Long time, how are we ?
Sure one cannot close " all orders simultaneously immediately " but hey, one can only assume he meant ASAP.
In regards to using OrderClosePrice(), I will test it to see if it works. So far I only used OrderClosePrice() after selecting the order from history .
If it works , it's new for me.
thrdel: If it works , it's new for me.
| OCP() works fine, has for years. It's value is set at the OrderSelect, and doesn't update, just like Bid/Ask is without a RefreshRates. |
Hi,
How can I close all open orders in all chart by simbols?
Asked and answered. You have only four choices:
- Search for it,
- Beg at
- learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- or pay (Freelance) someone to code it.
No free help
urgent help.
Hello
I've searched around and I've not found a script for MT4 specifically which closes all trades on all charts immediately at whatever price. Has anyone got one?
This will help with testing EAs which work in strategies which work across multiple charts per terminal.
Thanks
This my emergency close function(not a script) I have used this for years without fail in the tester and demo trading. Since I don't use MT4 for my live trading I can't attest to how it will work there.
Good Luck.
void Close_AllOrders() { /*-----------------------------------------------------------------------------------------------*/ //Close Orders according to FIFO Rule for(i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { Close_Result=OrderClose(OrderTicket(),OrderLots(),Bid,0,clrNONE); if(Close_Result) i--; } if(OrderType()==OP_SELL) { Close_Result=OrderClose(OrderTicket(),OrderLots(),Ask,0,clrNONE); if(Close_Result) i--; } if(OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP) { Close_Result=OrderDelete(OrderTicket(),clrNONE); if(Close_Result) i--; } } } /*-----------------------------------------------------------------------------------------------*/ return; }
There is a way to close all trades asynchronously for up to eight symbols at once. Here are steps.
- Make EA to apply a custom template to all charts upon init. This will remove any existing EAs that could interfere and replace it with an instance of itself to act as a worker bot.
- Create a collection of symbols to be managed from the order pool.
- Iterate over the symbols, sending them asynchronously to the worker EAs as strings via EventChartCustom
- Each worker EA then calculates the net position of its symbol and sends the appropriate hedge order to flatten the position.
- Since all workers can compute values and send hedge orders async -- all positions regardless of the quantity of orders will be netted to 0 lots at the same time provided the number of workers is greater than or equal to the number symbols and the number of symbols to close is less than or equal to eight.
- All risk is eliminated instantly but there will be offset orders on the books to be dealt with. The manager EA will need to loop through all offsetting orders using closeby to reconcile the transactions as "closed by hedge" with the broker server. There is no rush to do so since all risk has been eliminated by step 5.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
I've searched around and I've not found a script for MT4 specifically which closes all trades on all charts immediately at whatever price. Has anyone got one?
This will help with testing EAs which work in strategies which work across multiple charts per terminal.
Thanks