bool ChartIndicatorDelete( longchart_id, // chart id intsub_window,// number of the subwindow const stringindicator_shortname // short name of the indicator );
//+——————————————————————+ //| Demo_ChartIndicatorDelete.mq5 | //| Copyright 2011, MetaQuotes Software Corp. | //| https://www.mql5.com | //+——————————————————————+ #propertycopyright“Copyright 2011, MetaQuotes Software Corp.” #propertylink“https://www.mql5.com” #propertyversion“1.00” #propertyindicator_separate_window #propertyindicator_buffers 1 //— plot Histogram #property indicator_label1 “Histogram” #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //— input parameters inputintfirst_param=1; inputintsecond_param=2; inputintthird_param=3; inputbool wrong_init=true; //— indicator buffers double HistogramBuffer[]; string shortname; //+——————————————————————+ //| Custom indicator initialization function | //+——————————————————————+ intOnInit() { int res=INIT_SUCCEEDED; //— Link the HistogramBuffer array to the indicator buffer SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA); //— Construct a short indicator name based on input parameters shortname=StringFormat(“Demo_ChartIndicatorDelete(%d,%d,%d)”, first_param,second_param,third_param); IndicatorSetString(INDICATOR_SHORTNAME,shortname); //— If forced completion of an indicator is set, return a non-zero value if(wrong_init) res=INIT_FAILED; return(res); } //+——————————————————————+ //| Custom indicator iteration function | //+——————————————————————+ intOnCalculate(constint rates_total, constint prev_calculated, constdatetime &time[], constdouble &open[], constdouble &high[], constdouble &low[], constdouble &close[], constlong &tick_volume[], constlong &volume[], constint &spread[]) { //— Starting position for working in a loop int start=prev_calculated-1; if(start<0) start=0; //— Fill in the indicator buffer with values for(int i=start;i<rates_total;i++) { HistogramBuffer[i]=close[i]; } //— return value of prev_calculated for next call return(rates_total); } //+——————————————————————+ //| Handler of the Deinit event | //+——————————————————————+ voidOnDeinit(constint reason) { PrintFormat(“%s: Deinitialization reason code=%d”,__FUNCTION__,reason); if(reason==REASON_INITFAILED) { PrintFormat(“An indicator with a short name %s (file %s) deletes itself from the chart”,shortname,__FILE__); int window=ChartWindowFind(); bool res=ChartIndicatorDelete(0,window,shortname); //— Analyse the result of call of ChartIndicatorDelete() if(!res) { PrintFormat(“Failed to delete indicator %s from window #%d. Error code %d”, shortname,window,GetLastError()); } } }