You can't do that. OnDeinit() needs to be done in less than 2.5 seconds.
Anyway, it's not a good idea even if it was working, OnDeinit() is called in following cases :
- before reinitialization due to the change of a symbol or chart period, to which the mql5 program is attached;
- before reinitialization due to the change of input parameters;
- before unloading the mql5 program.
void OnDeinit(const int reason) { for (int cnt=OrdersTotal()-1; cnt>=0; cnt--) if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) && OrderCloseTime()==0) bool i2= (OrderType()<2) ? OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Red) : OrderDelete(OrderTicket()); }
Taras Slobodyanik: But if you really want it ...
|
|
|
In my experience, if you do all the checks in this place, then the orders will not be closed, the expert will close sooner.
Without these checks, orders are closed, the terminal hangs for this time.
ps. about checking the magic and symbol nothing was said, so the task is to close all.
Yes, all these checks are needed in a normal situation.
In my experience, if you do all the checks in this place, then the orders will not be closed, the expert will close sooner.
Without these checks, orders are closed, the terminal hangs for this time.
ps. about checking the magic and symbol nothing was said, so the task is to close all.
Hi guys,
Thanks for your advices. I dont know why, but my script works now quite fine. Dont know why it seemed to not work at first, but your comments are helping anyway.. Normally I have only one position at time so it should be ok.
Hi guys,
Thanks for your advices. I dont know why, but my script works now quite fine. Dont know why it seemed to not work at first, but your comments are helping anyway.. Normally I have only one position at time so it should be ok.
You can't do that. OnDeinit() needs to be done in less than 2.5 seconds.
Anyway, it's not a good idea even if it was working, OnDeinit() is called in following cases :
Hi Alain, is OnDeinit called when an indicator is manually deleted from the Indicators List? I ask because the follwing code does not delete any onjects or print any messages or return any errors - I just get "Custom indicator XX removed" in the Experts window...
int OnDeinit() { EventKillTimer(); Comment(""); Print("OnDeinit function has run"); int i,ot=ObjectsTotal(); for(i=ot-1;i>=0;i--) { if(StringFind(ObjectName(i),"xx",0)) { ObjectDelete(i); Print("OnDeinit FOR loop has run"); } } return(0); }
I also tried using StringSubstr method but it similarly doesn't work.
if(StringFind(ObjectName(i),"xx",0))
Zero is false, non-zero is true, and StringFind returns -1 if it doesn't find the string. So all strings that have "xx" as the first two characters StringFind returns 0 (false.) and thus the function deletes all objects except for those.
Hi Alain, is OnDeinit called when an indicator is manually deleted from the Indicators List? I ask because the follwing code does not delete any onjects or print any messages or return any errors - I just get "Custom indicator XX removed" in the Experts window...
I also tried using StringSubstr method but it similarly doesn't work.
ObjectDelete(i); will not work either
Check here : https://www.mql5.com/en/docs/objects/objectdelete

- www.mql5.com
Hi Alain, is OnDeinit called when an indicator is manually deleted from the Indicators List? I ask because the follwing code does not delete any onjects or print any messages or return any errors - I just get "Custom indicator XX removed" in the Experts window...
I also tried using StringSubstr method but it similarly doesn't work.
You are off-topic, it's about close orders.
Beside the errors already reported, you could just use :
ObjectsDeleteAll(0,"xx");

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
I am a bit lost with the deinit function (MT4)..
I want to close all opened orders when something happen that stop the EA, but seems to not do anything. Here is what I wrote but no closing action :
void deinit()
{
total=OrdersTotal();
for (cnt = total - 1; cnt >= 0; cnt--)
ok=OrderSelect(cnt,SELECT_BY_POS);
if(OrderType()==OP_SELL)
ok=OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
if(OrderType()==OP_BUY)
ok=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
}
Please help