From what I have read . . . init() has to complete within 2 seconds . . .
Can't you move this code into the start of start() and have it run just once ?
init() MUST return withing 2 seconds
when start is called, the chart is already loaded. Your code is unnecessary.
the function is void while it should be returning an integer.
int init() { int handle_Window = WindowHandle(Symbol(),0); if(handle_Window > 0) {Print("chart is now fully loaded now indicator can start counting");} else {return(0); Print("wait until chart is fully loaded");} return(handle_Window); }
From what I have read . . . init() has to complete within 2 seconds . . .
Can't you move this code into the start of start() and have it run just once ?
init() MUST return withing 2 seconds
when start is called, the chart is already loaded. Your code is unnecessary.
thanks i take a note init must return within 2 seconds.
the function is void while it should be returning an integer.
nope cannot move them into start() cos that would be modify the whole start() <this what i avoid>
Why?
int start(){ if (MustWait()) return(0); // from here on all stays // the same as it was before // [...] } bool MustWait(){ // here do a quick check for the conditions // (no while loop, just check and return) // for example the time of the oldest bar, // etc. or whatever it is you are waiting for // and return true if not yet ready // or false if everything is ok. if (whatever){ return(true); }else{ return(false); } }
Also relevant might be the following information because you are mentioning crashes (maybe you meant freezing of the UI?) in conjunction with WindowHandle()
https://forum.mql4.com/32837
(There is a nasty bug in MT4, WindowHandle() might occasionally run into a deadlock when this function is called after the EA is already scheduled for deinitializing (happened to me when switching timeframes while the EA was running). Maybe the buggy implementation of WindowHandle() (or possibly other Window related functions too) can cause even more strange problems that are related to initializing/deinitializing. You should be aware of this when using these functions and strange problems occur).
PS:
If there were a bug tracker for MT4 or if the programmers would read the forums at least occasionally I would have reported it already a year ago but MetaQuotes does not seem to care about ordinary end users or want to have any kind of dialog with them, they only care about their paying customers (the FX Dealers) and so this ugly bug will remain unfixed forever.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i try do that and my mt4 crashed, any one could help what i did wrong ? (the goal is, indicator will never start() until init() have all data from chart first)
btw crash occurs when mt4 haven't get data yet for instance after disconnect internet, or when internet connection really slow.