Terminate Indicator from inside OnCalculate?

 

Hi there,

I have a password validation class that uses the AccountInfoInteger(ACCOUNT_LOGIN) to compare with an encrypted input parameter (loosely based on https://www.mql5.com/en/code/15534). This call is made in the OnInit function in the Indicator. If it legitimately doesn't validate, I return INIT_FAILED from OnInit and the Indicator doesn't load, as required and expected. This works absolutely fine when you drop the indicator on an already loaded chart in MT4.

However, when starting MT4 for the first time where the Indicator is already on the chart, the call to AccountInfoInteger(ACCOUNT_LOGIN) returns 0 (zero) because at that point, MT4 hasn't connected to the Broker's server (IsConnected() returns false). I've tried a few different approaches to "slow" down this process but nothing works.

In OnCalculate, I am guaranteed the connection has occurred so I could conditionally load the security class in OnCalculate. However, if the validation fails, I have no idea how I could terminate the indicator from inside OnCalculate?

So, if anyone can help with one or both of the above issues, I'd be very grateful indeed. 

Many thanks :)

Adding password protection to your Indicator / Expert Advisor
Adding password protection to your Indicator / Expert Advisor
  • www.mql5.com
Several methods of protecting your code have been proposed over the past, but were either too simple (less secure), required re-compilation of your code for each new customer (ok if you only plan on having a dozen or so customers) or far too complicated involving a remote host to validate the client terminal. Here I propose a simple password...
 

1° There is no need to terminate the indicator, just "return" without doing anything and it will do nothing anyway.

2° To remove an indicator from the chart, use ChartIndicatorDelete().

 
Alain Verleyen:

1° There is no need to terminate the indicator, just "return" without doing anything and it will do nothing anyway.

2° To remove an indicator from the chart, use ChartIndicatorDelete().

Thank you Alain. When you put it in those terms, it makes sense! :) Cheers.

Reason: