Restrictions on the use of indicator by time frame

 
Hi experts,

I am creating an indicator.
I would like to display the indicator only in some time frames such as 5m, 30m, 1h and so on.
For example, if the indicator is selected in a daily chart, it displays nothing or alerts a user.

I don't know how to do this, so I have coded as follows:

bool IsInvalid = false;

int init() {

  if(Period() > PERIOD_H4) {

    IsInvalid = true;

    return(0);

  }

  ...


int start() {

  if(IsInvalid) return(0);

  ...


But it displays an empty sub window and keeps running start() function..

Is there any smart way?

Thanks,


 
gotts:
But it displays an empty sub window and keeps running start() function..
Is there any smart way?
  1. Displays the sub window because that is what the indiator is. It runs start which does nothing because that is what you coded.
  2. Don't attach the indicator on those time frames.
 
WHRoeder:
  1. Displays the sub window because that is what the indiator is. It runs start which does nothing because that is what you coded.
  2. Don't attach the indicator on those time frames.

Hi,

Thank you for the reply.
You are right:-) That's what I coded.
My intention was if my indicator is used by someone and is attached to invalid time frames,
I would like it to alert and detach automatically.

If it is impossible, I will write README or somewhere.

Thanks a lot,
 
if (Period() < 5 || Period()>60){Comment("Invalid timeframe selected");return(0);}
The above should work. Place in the indicator body before anything else is checked.
 
Paul_B:
The above should work. Place in the indicator body before anything else is checked.

Ah, I didn't know Comment() function. It looks good. Thank you for the great suggestion!
 

Useful code, thank you!

 
You might try How do I close an Expert programmatically? - MQL4 forum to see if it closes the indicator
Reason: