Returns the handle of a specified technical indicator, in case of failure returns INVALID_HANDLE. The computer memory can be freed from an indicator that is no more utilized, using the IndicatorRelease() function, to which the indicator handle is passed.

Example:

//+------------------------------------------------------------------+//| Demo_iMFI.mq5 |//| Copyright 2011, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#propertycopyright"Copyright 2011, MetaQuotes Software Corp."#propertylink"https://www.mql5.com"#propertyversion"1.00"#propertydescription"The indicator demonstrates how to obtain data"#propertydescription"of indicator buffers for the iMFI technical indicator."#propertydescription"A symbol and timeframe used for calculation of the indicator,"#propertydescription"are set by the symbol and period parameters."#propertydescription"The method of creation of the handle is set through the 'type' parameter (function type)."#propertydescription"All the other parameters are similar to the standard Money Flow Index."#propertyindicator_separate_window#propertyindicator_buffers 1#propertyindicator_plots 1//--- the iMFI plot#property indicator_label1 "iMFI"#property indicator_type1 DRAW_LINE#property indicator_color1 clrDodgerBlue#property indicator_style1 STYLE_SOLID#property indicator_width1 1//--- horizontal levels in the indicator window#property indicator_level1 20#property indicator_level2 80//+------------------------------------------------------------------+//| Enumeration of the methods of handle creation |//+------------------------------------------------------------------+enum Creation { Call_iMFI, // use iMFI Call_IndicatorCreate // use IndicatorCreate };//--- input parametersinput Creation type=Call_iMFI; // type of the function inputint ma_period=14; // periodinputENUM_APPLIED_VOLUME applied_volume=VOLUME_TICK; // type of volumeinputstringsymbol=" "; // symbol inputENUM_TIMEFRAMESperiod=PERIOD_CURRENT; // timeframe//--- indicator bufferdouble iMFIBuffer[];//--- variable for storing the handle of the iMFI indicatorint handle;//--- variable for storingstring name=symbol;//--- name of the indicator on a chartstring short_name;//--- we will keep the number of values in the Money Flow Index indicatorint bars_calculated=0;//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit() {//--- assignment of array to indicator bufferSetIndexBuffer(0,iMFIBuffer,INDICATOR_DATA);//--- determine the symbol the indicator is drawn for name=symbol;//--- delete spaces to the right and to the leftStringTrimRight(name);StringTrimLeft(name);//--- if it results in zero length of the 'name' stringif(StringLen(name)==0) {//--- take the symbol of the chart the indicator is attached to name=_Symbol; }//--- create handle of the indicatorif(type==Call_iMFI) handle=iMFI(name,period,ma_period,applied_volume);else {//--- fill the structure with parameters of the indicator MqlParam pars[2];//--- period pars[0].type=TYPE_INT; pars[0].integer_value=ma_period;//--- type of volume pars[1].type=TYPE_INT; pars[1].integer_value=applied_volume; handle=IndicatorCreate(name,period,IND_MFI,2,pars); }//--- if the handle is not createdif(handle==INVALID_HANDLE) {//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iMFI indicator for the symbol %s/%s, error code %d", name,EnumToString(period),GetLastError());//--- the indicator is stopped earlyreturn(INIT_FAILED); }//--- show the symbol/timeframe the Money Flow Index indicator is calculated for short_name=StringFormat("iMFI(%s/%s, %d, %s)",name,EnumToString(period), ma_period, EnumToString(applied_volume));IndicatorSetString(INDICATOR_SHORTNAME,short_name);//--- normal initialization of the indicatorreturn(INIT_SUCCEEDED); }//+------------------------------------------------------------------+//| 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[]) {//--- number of values copied from the iMFI indicatorint values_to_copy;//--- determine the number of values calculated in the indicatorint calculated=BarsCalculated(handle);if(calculated<=0) {PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());return(0); }//--- if it is the first start of calculation of the indicator or if the number of values in the iMFI indicator changed//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1) {//--- if the iMFIBuffer array is greater than the number of values in the iMFI indicator for symbol/period, then we don't copy everything //--- otherwise, we copy less than the size of indicator buffersif(calculated>rates_total) values_to_copy=rates_total;else values_to_copy=calculated; }else {//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()//--- for calculation not more than one bar is added values_to_copy=(rates_total-prev_calculated)+1; }//--- fill the iMFIBuffer array with values of the Money Flow Index indicator//--- if FillArrayFromBuffer returns false, it means the information is nor ready yet, quit operationif(!FillArrayFromBuffer(iMFIBuffer,handle,values_to_copy)) return(0);//--- form the messagestring comm=StringFormat("%s ==> Updated value in the indicator %s: %d",TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS), short_name, values_to_copy);//--- display the service message on the chartComment(comm);//--- memorize the number of values in the Money Flow Index indicator bars_calculated=calculated;//--- return the prev_calculated value for the next callreturn(rates_total); }//+------------------------------------------------------------------+//| Filling indicator buffers from the iMFI indicator |//+------------------------------------------------------------------+bool FillArrayFromBuffer(double &values[], // indicator buffer of Money Flow Index valuesint ind_handle, // handle of the iMFI indicatorint amount // number of copied values ) {//--- reset error codeResetLastError();//--- fill a part of the iMFIBuffer array with values from the indicator buffer that has 0 indexif(CopyBuffer(ind_handle,0,0,amount,values)<0) {//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iMFI indicator, error code %d",GetLastError());//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false); }//--- everything is finereturn(true); }//+------------------------------------------------------------------+//| Indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason) {//--- clear the chart after deleting the indicatorComment(""); }