How to force the current indicator to exit?

 

Hello folks,

I would like to put a conditional forced exit inside the OnInit() method of an indicator,

something like this:

int OnInit() {
   if (<exit_cond>) {
      DeInit();
   }
}

How can I do it?,

Thank you, Cyberglassed!

 
cyberglassed:

Hello folks,

I would like to put a conditional forced exit inside the OnInit() method of an indicator,

something like this:

How can I do it?,

Thank you, Cyberglassed!

Just return(-1) from OnInit. Don't call DeInit() - it will be called automatically.
 
marketeer:
Just return(-1) from OnInit. Don't call DeInit() - it will be called automatically.

Thank you marketeer,

when I call "return(-1);" the OnDeinit() method is called (I know it because I debugged), but for some reason

the indicator subwindow (I used: "#property indicator_separate_window" for the indicator) remains there.

I would like the indicator be completeley deleted, even its containing subwindow.


Thanks, Cyberglassed.

 
Chart Operations - Reference on algorithmic/automated trading language for MetaTrader 5
Documentation on MQL5: Chart Operations
Documentation on MQL5: Chart Operations
  • www.mql5.com
Chart Operations - Reference on algorithmic/automated trading language for MetaTrader 5
 
cyberglassed:

Thank you marketeer,

when I call "return(-1);" the OnDeinit() method is called (I know it because I debugged), but for some reason

the indicator subwindow (I used: "#property indicator_separate_window" for the indicator) remains there.

I would like the indicator be completeley deleted, even its containing subwindow.


Thanks, Cyberglassed.

It should close the sub-window as well, if there is no other bindings to it. Sometimes terminal postpones this operation for a while, I don't know why. If you can catch it, create an issue in the service desk.
Reason: