:( crashed, help me with windowhandle()

 
void init()
{

while(WindowHandle(Symbol(), 0)==0) Print("wait until chart is fully loaded");
if(WindowHandle(Symbol(), 0)!=0) Print("chart is now fully loaded now indicator can start counting");

return(0);
}

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.

 

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);
  }
 
RaptorUK:

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 ?

nope cannot move them into start() cos that would be modify the whole start() <this what i avoid>

WHRoeder:

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.


19730719:

the function is void while it should be returning an integer.

now this is what i look for thank you very much, you are so smart :D
 
ricx:
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.

Reason: