input group "-----BB------"; input int Entry_BB_Len = 20; // Length Bollinger input double Entry_BB_SDs = 2.0; // Number of standard deviations int Entry_BB_Handle; int OnInit() { Entry_BB_Handle = iBands(Symbol(),PERIOD_CURRENT, Entry_BB_Len,0,Entry_BB_SDs,PRICE_CLOSE); ShortName = ChartIndicatorAdd2(0,0,Entry_BB_Handle); return(ShortName == NULL); } void OnDeinit(const int reason) { ChartIndicatorDelete(0,0,ShortName); IndicatorRelease(Entry_BB_Handle); } string ChartIndicatorAdd2( const long chart_id, const int sub_window, const int indicator_handle ) { return(ChartIndicatorAdd(chart_id, sub_window, indicator_handle) ? ChartIndicatorName(chart_id, sub_window, ChartIndicatorsTotal(chart_id, sub_window) - 1) : NULL); } string ShortName;
input group "-----BB------"; input int Entry_BB_Len = 20; // Length Bollinger input double Entry_BB_SDs = 2.0; // Number of standard deviations int Entry_BB_Handle; int OnInit() { Entry_BB_Handle = iBands(Symbol(),PERIOD_CURRENT, Entry_BB_Len,0,Entry_BB_SDs,PRICE_CLOSE); ChartIndicatorAdd(0,0,Entry_BB_Handle); // ChartIndicatorAdd(0,1,Entry_BB_Handle); // ChartIndicatorAdd(0,2,Entry_BB_Handle); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ChartIndicatorDelete(0,Entry_BB_Handle); IndicatorRelease(Entry_BB_Handle); } bool ChartIndicatorDelete( const long chart_id, const int sub_window, const int indicator_handle ) { bool Res = false; for (uint i = ChartIndicatorsTotal(chart_id, sub_window); !Res && (bool)i--;) { const string ShortName = ChartIndicatorName(chart_id, sub_window, i); Res = (ChartIndicatorGet(chart_id, sub_window, ShortName) == indicator_handle) && ChartIndicatorDelete(chart_id, sub_window, ShortName); } return(Res); } bool ChartIndicatorDelete( const long chart_id, const int indicator_handle ) { bool Res = false; for (uint i = (uint)ChartGetInteger(chart_id, CHART_WINDOWS_TOTAL); (bool)i--;) Res |= ChartIndicatorDelete(chart_id, i, indicator_handle); return(Res); }
fxsaber #:
Thank you...
This function works... are the other options you provided better?
bool ChartIndicatorDelete( const long chart_id, const int indicator_handle )
{
bool Res = false;
for (uint i = (uint)ChartGetInteger(chart_id, CHART_WINDOWS_TOTAL); (bool)i--;)
ChartIndicatorDelete(chart_id, i, IntegerToString(indicator_handle));
}
Sorry, it actually does not work...your code dobles the indicaotr plots each time ones changes the parameters in the EA...
That is very nice of you, thank you...indeed second options works...
There is no such function
ChartIndicatorDelete(chart_id, i, indicator_handle)
bool ChartIndicatorDelete( long chart_id, // chart id int sub_window // number of the subwindow const string indicator_shortname // short name of the indicator );

Documentation on MQL5: Chart Operations / ChartIndicatorDelete
- www.mql5.com
Removes an indicator with a specified name from the specified chart window. Parameters chart_id [in] Chart ID. 0 denotes the current chart...

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have an EA that uses an indicator. I would like to see the indicator when running the EA. However, each time I change a parameter in the EA, the indicator is doubled in the chart.
In the example below the Ibands has 3 lines, when I load the EA for the first time...but if I change any parameter in the user interface of the EA, a new set of lines a created for the indicator. Is there a way to delete the prior handle of an indicator?