- 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
- Why do you think you should be calling it?
Are you trying to delete objects with it ?
Can you post the code you have so far ?
- 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
- 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.
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

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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...