IndicatorRemove

 

Is there a way that an indicator can remove itself?

I tried ExpertRemove() which worked as far as I remember for mql4 - but mql5 it does not - do I have to force a division by zero or an invalid array access?

 
The pirate way - induce some fatal error. Works with experts, might crash the terminal though.
 
Carl Schreiber:

Is there a way that an indicator can remove itself?

I tried ExpertRemove() which worked as far as I remember for mql4 - but mql5 it does not - do I have to force a division by zero or an invalid array access?

Maybe you can apply a template with ChartApplyTemplate function and you will not have any indicator on the chart...

 

There is also a proper way:

https://www.mql5.com/en/docs/standardlibrary/technicalindicators/cindicators/cindicator/cindicatordeletefromchart

Or just ChartIndicatorDelete();

Documentation on MQL5: Standard Library / Indicators / Base classes / CIndicator / DeleteFromChart
Documentation on MQL5: Standard Library / Indicators / Base classes / CIndicator / DeleteFromChart
  • www.mql5.com
Standard Library / Indicators / Base classes / CIndicator / DeleteFromChart - Reference on algorithmic/automated trading language for MetaTrader 5
 

My indicator doesn't use this library.

So far I use: Print(1.0/(sqrt(1)-1));

 

This is the built-in function that the function from the library calls:

https://www.mql5.com/en/docs/chart_operations/chartindicatordelete

Documentation on MQL5: Chart Operations / ChartIndicatorDelete
Documentation on MQL5: Chart Operations / ChartIndicatorDelete
  • www.mql5.com
//|                                    Demo_ChartIndicatorDelete.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | //| Custom indicator initialization function                         |                           ...
 

Yep, I just found it.

hmm - similar things should have similar names that would make live easier!

Reason: