How to make a Sleep in a custom indicator ?

 

Dear all,


    The 'Sleep' command doesn't work in indicator.

Is someone has a solution to make a sleep in a custom indicator ?

Thanks in advance for your answer!

 
canarich:

Dear all,

The 'Sleep' command doesn't work in indicator.

Is someone has a solution to make a sleep in a custom indicator ?

Thanks in advance for your answer!

I'm pretty sure you can't . .  unless you want your Indicator to lock up your MT4.
 

You can't. Indicators run in the same thread as the GUI. They can not sleep, they can not wait, they MUST return quickly.

Why do you think you need a delay?

 
WHRoeder:

You can't. Indicators run in the same thread as the GUI. They can not sleep, they can not wait, they MUST return quickly.

Why do you think you need a delay?


I have implemented a "SendMail" in my indicator and it send too much mail and I exceed the quota, so MT4 block my "Sendmail".

I would like to wait 1 minutes before the indicator runs again.

I think i will work on new bars. I will take you informed.

Thanks for your help

 
The SMALLEST chart you can have is 1 minute. Why are you sending messages on the current bar? Only send it on the last completed bar.
int counted = IndicatorCounted();
for(int i=Bars - 1; i>=0; i--){
   buffer[i] = ...;
   if (i = 1 && isSomeCondition) SendMail(...);
}
Alternatively, have it skip sends if too frequent
int counted = IndicatorCounted();
for(int i=Bars - 1; i>=0; i--){
   buffer[i] = ...;
   if (isSomeCondition){
       static datetime lastSend;
       datetime now = TimeCurrent();
       if (now - lastSend > 60){ // 1 minute
           lastSend = now;
           SendMail(...);
       }
   }
}
No sleep required
 
WHRoeder:
The SMALLEST chart you can have is 1 minute. Why are you sending messages on the current bar? Only send it on the last completed bar.Alternatively, have it skip sends if too frequentNo sleep required

Thanks for your answer.

I do this :

//////////////

int my_bars=0;

if(my_bars!=Bars)

{

Sendmail(...);

my_bars=Bars;

}

//////////////////

so i wait for the next Bar :-)

 
canarich:

Thanks for your answer.

I do this :

<SNIP>

so i wait for the next Bar :-)

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 

Don't use Bars . . it s not reliable,   use Time ! !

 
  1. Don't use bars, use time.
  2. I do this :
    int my_bars=0;
    
    if(my_bars!=Bars)
    Won't work unless my_bars is common(global) or static.
 

I return to this thread. I deal the same - "sleep" indicator because is sufficient for me when calculate only once at new bar.

I don´t understand idea use SendMail() ....?

My idea solution is:

start()
{
  if (lastTime>=Time[0]) return();  // will do it until new bar
 /* 
  ...
  mql instructions
  ...
 */
  lastTime=Time[0];
}

pc will be testing over and over again condition lastTime>=Time[0

I don´t like it me. Is exist better solution? I would like relieve procesor...

 
endy5:

I return to this thread. I deal the same - "sleep" indicator because is sufficient for me when calculate only once at new bar.

I don´t understand idea use SendMail() ....?

My idea solution is:

pc will be testing over and over again condition lastTime>=Time[0

I don´t like it me. Is exist better solution? I would like relieve procesor...


Not over and over like a continuous loop,  it only tests lastTime >=Time[0] once for each new tick,  usually less than once per second.
 
yes, Raptor, you have true!... but is "better" solution? I won´t use EA.
Reason: