Modify deinit() limit time

 

Hi all,


the deinit() function has a time limit of 2.5 seconds, after which it will be terminated forcedly. Has any of you found a way to modify this time? It'd be a convenient to close all open trades, log everything and do some maintenance, but 2.5 seconds are not enough to do all that.


thanks

 

"but 2.5 seconds are not enough to do all that"

show tests [and of course back it all up with ALL test code and your production code to justify such long time needs :] to prove this statement


"Has any of you found a way to modify this time?"

do you normally knife 'n fork your O/S or Compiler or Assembler or Linker or..,..???


This is the design of the beasty - as they say: Live With It, Adapt to It or indeed, find another platform to suit your needs.

is simple, yes?

 

I can only have open OP_BUY or OP_SELL orders with my EA, and this is supposed to close them:


bool closeAllTrades() {
   int i;
   
   for(i = OrdersTotal()-1; i >= 0; i--) {
      if(OrderSelect(i, SELECT_BY_POS) == False)
         Alert("Couldn\'t select order ", i, ": ", ErrorDescription(GetLastError()));
      if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3) == False)
         Alert("Error: ", ErrorDescription(GetLastError()));
   }
   
   return(OrdersTotal() == 0);
}


But I can only close about 7-8 orders in 2.5 seconds with this, no more. Is there a faster way?

I'm only prototyping in MQL, eventually I'll port everything to C++.

 

Do you REALLY want to exit all your trades if your MT4 platform gets closed accidentally?


CB

 

you should add refreshrates() before ORderclose function, and you can use while embracing for loop until OrdersTotal is 0.

while(OrdersTotal() != 0)

{

for...

...

}

 

7,8 is seriously no big deal.

Ah ok. Well, surely Alert() is slow?

I mean, basically you just wanna log that some unexpected event has happened, yes?

Suggest you c/Alert/Print/a and then rerun tests.

sorry - cmd line ed speekez. Please consider changing Alert to Print (formals/actuals are same for both builtins)

why? Print() just effectively dumps to Terminal Experts Tab and even if program finishes, I believe that Print()s are just queued and squirted out asap in background, without interfering with program execution.

Obviously, if I'm correct with that, the overhead is to do with whatever Print() does.

Surely, Alert() by comparison, is massive overhead, ya know? Message pane etc... AND of course, the Alert() o/p also gets shoved onto Experts Tab... so, way slower.

Not happy with Print()? Have a file preOpened file all set to rumble should you need to log something. File ops are very fast indeed. Also they are I believe in memory until FileFlush() or program exit...

just ideas - have a go, ok?

 

Alert() is not the issue, the big OH are network times and they can't be avoided unless I use multiple threads, because OrderClose() has to wait for the server response and therefore takes time to return its value. The 7-8 trades closed were in case of no Alert()s. No I don't just want to log, I'd like to close the open trades too. And I'm already optimizing the I/O.


baris: if some of the parameters are wrong, a loop like that would just block everything.


CB: I know it may not sound like the best idea, but I never close a program by accident, and I want a quick mechanism to reduce the damage manually should something go wrong.

 

This is not what deinit() was designed for.

I suggest you'd be better writing a simple script that you can invoke quickly to close all trades in an emergency.


CB

 

"I suggest you'd be better writing a simple script that you can invoke quickly to close all trades in an emergency."

Well, you can close about 4 positions per second even in the best of conditions from home.

 
Alright, I guess I can use a script that waits until a global variable is set to a certain value by my EA's deinit() and closes all trades.
 

Is there any flexibility to set the 2.5 sec execution time limit for deinit()? Is it different time in MT5?

Reason: