Change
//close all open trade
int CloseAllTrade()
{
int total=OrdersTotal();
int t;
int cnt=0;
for(cnt=0; cnt<=total; cnt++)
{
bool s=OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY)
t=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);
if(OrderType()==OP_SELL)
t=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);
if(OrderType()>OP_SELL) //pending orders
t=OrderDelete(OrderTicket());
}
return(0);
}
to
for(cnt=total-1; cnt>=0; cnt--)
Hello roy,
I think its the same approach,
for(cnt=0; cnt<=total; cnt++), it's select index from 0 - last index. ex: 0,1,2,3,4, until last index
for(cnt=total-1; cnt>=0; cnt--), it's select last index - 0. ex: last index, last index-1, last index-2, until 0
Hello roy,
I think its the same approach,
for(cnt=0; cnt<=total; cnt++), it's select index from 0 - last index. ex: 0,1,2,3,4, until last index
for(cnt=total-1; cnt>=0; cnt--), it's select last index - 0. ex: last index, last index-1, last index-2, until 0
No it is not!!
If you close order with cnt=0 the order with cnt=1 becomes the order with cnt=0.
Therefore you HAVE to count down!!
In addition to that may be a RefreshRates() might be helpful especially if there are a bit exotic Symbols() that do not have so many ticks!!
Carl, you would have been correct if Yogie would have used the index "cnt" in the OrderSelect statement, like this:
bool s=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
but now he wrote
bool s=OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
So the order with index zero is selected every time for closing, so that also works just fine. After first Closing, order with index 1 becomes index 0 and is thus deleted next iteration.
in addition, if your broker has a FIFO rule, then the order with index 0 is the oldest, and must be closed before any other, and in that case it would not work to do it your way and count backwards.
thanks a lot for this EA!! exactly what i need. gave it 5 stars.
would be even better if i could enable push alerts, for example alert 1 2 and 3 with specific amounts.
thanks before anything for your contribution. I just would like to know why I can't make it work with an EA. I would love some step by step instructions on how to make it work. Since I'm missing something. I've made it work on my platform while testing but later, doing the same, in my real account, I couldn't make it work. The result 0 kept coming like it the Auto Trading or the DLL weren't allowed (when they were).
Thanks
How can I use this EA with VPS hosting?
It is removed when I am trying to synchronise MT4 environment with VPS.
Hi there, I have the same problem, did you get to fix it? thanks
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Droneox Equity Guardian:
Expert Advisor that will close all orders and disable another Expert Advisor / AutoTrading at desired level.
Author: Yogie Pratama