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...

 

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:

Are you trying to delete objects with it ? 

Can you post the code you have so far ?

Thank you Marco

as explained in previous comment, I want to end the code so I believe deleting the object will not help.

I can post a sample code but I am simply asking how to end my custom indicator code when error is found within OnCalculate.

 

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.

 

Hi Marco,

Can you share the example how you can do that in OnCalculate? not sure what you are referring. I did try return(false) in OnCalculate but that doesn't stop the program to stop. other way i can think of is to purposely do out of array range to force to exit.

 

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...
Reason: