How to Deinit the indicator from OnCalculate?

............ ............  

I don't think it is possible but wonder if there is a way to Deinit the indicator from OnCalculate?

Tried "return(-1)" but it just get pass to "prev_calculated" so it will not exit the indicator program.

Tried calling OnDeinit() function but once it jump to OnDeinit it will return back where it was called.

Did a bit of search but was not able to find anyway to clean exit it...

Marco vd Heijden  

Are you trying to delete objects with it ? 

Can you post the code you have so far ?

............ ............  
William Roeder:
  1. OnDeinit is called automatically for the reasons given at: Constants, Enumerations and Structures / Named Constants / Uninitialization Reason Codes - Reference on algorithmic/automated trading language for MetaTrader 5

  2. Why do you think you should be calling it?

Thank you William

1. yes, seems like it is the case. if return code is -1 in Onint, it will jump to OnDeint automatically and close the indicator but calling OnDeinit() function in OnCalculate, it will jump to OnDeinit but jump back to OnCalculate where OnDeinit() function was call and continue without closing the indicator.

2. reason i want to call OnDeinit in OnCalculate is when there is error or unexpected calculation was found in my code, I want to exit my code to prevent further error.

Marco vd Heijden  

If you want to end the code then you can put a flag over the code and set it to false whenever your condition has been met and that will disable any further processing.

Marco vd Heijden  

No you can just call

IndicatorDelete();

Function, https://www.mql5.com/en/docs/standardlibrary/cchart/cchartindicatordelete

Documentation on MQL5: Standard Library / Price Charts / IndicatorDelete
Documentation on MQL5: Standard Library / Price Charts / IndicatorDelete
  • www.mql5.com
Do not confuse the indicator short name and the file name that is specified when creating an indicator using functions iCustom() and IndicatorCreate(). If the short name of an indicator is not set explicitly, then the name of the file containing the source code of the indicator will be specified during compilation. Deletion of an indicator...