iCustom not working

 

Hello everyone


I can't get the call to iCustom to work. The called indicator is located in the \Indicators folder. It returns INVALID_HANDLE.

I have also tried the path "\\Indicators\\Bollinger_bands_1b.ex5" and "Indicators\\Bollinger_bands_1b.ex5". The calling indicator program is in the Indicators folder too.

//+------------------------------------------------------------------+
//|                                      CST BB Percent Smoothed.mq5 |
//|                                                              CST |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "CST"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Draw
#property indicator_label1  "Draw"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         DrawBuffer[];
int            hCustom;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,DrawBuffer,INDICATOR_DATA);
   hCustom = iCustom(_Symbol,PERIOD_CURRENT,"Bollinger_bands_1b",20,0,2.0,PRICE_CLOSE);
   if (hCustom==INVALID_HANDLE) Print("Invalid handle");
   
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   CopyBuffer(hCustom,0,0,rates_total,DrawBuffer);
   return(rates_total);
  }
//+------------------------------------------------------------------+

The called indicator's input parameters are:

//---- input parameters
input int    BBPeriod=20;        //Period
input int    BBShift=0;         // Shift
input double StdDeviation=2.0;  //Standard Deviation
input ENUM_APPLIED_PRICE appliedprc=PRICE_CLOSE; //Applied Price


Am I missing something here? Could anyone suggest a fix?

 
CobusSteyn0105:

I can't get the call to iCustom to work. The called indicator is located in the \Indicators folder. It returns INVALID_HANDLE.

I have also tried the path "\\Indicators\\Bollinger_bands_1b.ex5" and "Indicators\\Bollinger_bands_1b.ex5". The calling indicator program is in the Indicators folder too.

The called indicator's input parameters are:


You can use Print() statements or PrintFormat() to output variable values and debug messages. For example, you can print the path you're passing to iCustom() to verify it's correct.

hCustom = iCustom(_Symbol, PERIOD_CURRENT, "Indicators\\Bollinger_bands_1b.ex5", 20, 0, 2.0, PRICE_CLOSE);
if (hCustom == INVALID_HANDLE)
{
    Print("Invalid handle. Error code: ", GetLastError());
    Print("Indicator path: ", TerminalInfoString(TERMINAL_DATA_PATH), "\\MQL5\\Indicators\\Bollinger_bands_1b.ex5");
}
If relative path ( "Indicators\\Bollinger_bands_1b.ex5" ) doesn't work, try using the absolute path to the indicator file.

You are getting the 'invalid handle' error because the iCustom function failed to load the custom indicator. Also make sure the custom indicator you use is compiled.

 
Use the input variable names from the indicator in the call to iCustom. Don't put the values directly as arguments in iCustom
 
Conor Mcnamara #:  Don't put the values directly as arguments in iCustom

Makes no difference. Variables are never passed, only their values. Non-reference arguments are by value.

 
CobusSteyn0105:

Hello everyone


I can't get the call to iCustom to work. The called indicator is located in the \Indicators folder. It returns INVALID_HANDLE.

I have also tried the path "\\Indicators\\Bollinger_bands_1b.ex5" and "Indicators\\Bollinger_bands_1b.ex5". The calling indicator program is in the Indicators folder too.

The called indicator's input parameters are:


Am I missing something here? Could anyone suggest a fix?

The applied price you include is actually an input value to the indicator so you still need to supply an applied price to the call to icustom 

You can you use getlasterror to help debug
 

Thank you to all who responded.

I will try all the advice here and reply if or when I can get this solved. 

Appreciate the help.

 

Nothing works unfortunately.

The called indicator works fine as a standalone indicator, but calling it via iCustom gives the same error.

I've included the full data path - no success. Passed variables, added a PRICE_CLOSE at the end of the parameter list, still nothing.

 
CobusSteyn0105 #:

Nothing works unfortunately.

The called indicator works fine as a standalone indicator, but calling it via iCustom gives the same error.

I've included the full data path - no success. Passed variables, added a PRICE_CLOSE at the end of the parameter list, still nothing.

Post the indicator file. And I’ll have a Quick Look or pm if you prefer
 
You were asked (twice) to post the error code. You didn't. You can't know the problem until you do.
 
Check if there are any errors in the journal when running the indicator. Sometimes an indicator works but is still error prone. If there is any error, iCustom will refuse to work. I have a working example of iCustom in one of my simple code publications..but I don't think it will help. It's likely a problem with the indicator 
 
Paul Anscombe #:
Post the indicator file. And I’ll have a Quick Look or pm if you prefer

Thank you very much!

Here is the indicator file. Can't remember where I got it from.

//+------------------------------------------------------------------+
//|                                           Bollinger bands %b.mq5 |
//|                                   Copyright 2014, mohsen khashei |
//|                                               mkhashei@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, mohsen khashei"
#property link      "mkhashei@gmail.com"
#property version   "1.10"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Bollinger bands %b"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellow
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_level1 0.0
#property indicator_level2 0.5
#property indicator_level3 1.0

//---- input parameters
input int    BBPeriod=20;        //Period
input int    BBShift=0;         // Shift
input double StdDeviation=2.0;  //Standard Deviation
input ENUM_APPLIED_PRICE appliedprc=PRICE_CLOSE; //Applied Price
//--- indicator buffers
double         UpperBuffer[];
double         LowerBuffer[];
double         MiddleBuffer[];
double         BLGBuffer[];
int    bbhandle;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BLGBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,MiddleBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,UpperBuffer ,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,LowerBuffer ,INDICATOR_CALCULATIONS); 
   ArraySetAsSeries(BLGBuffer,true);
   ArraySetAsSeries(MiddleBuffer,true);
   ArraySetAsSeries(UpperBuffer,true);
   ArraySetAsSeries(LowerBuffer,true);
    if(Bars(_Symbol,_Period)<60)
  {
  Alert("We have less than 60 bars for Indicator exited now!!");
  return (-1);
  
  }
   bbhandle=iBands(NULL,0,BBPeriod,BBShift,StdDeviation,appliedprc);
    if(bbhandle<0){
  Alert("Can not create handle ",GetLastError(),"!!");
  return (-1);
  }
 //---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   ArraySetAsSeries(close,true);
   if(BarsCalculated(bbhandle)<rates_total) return(0);
   if(CopyBuffer(bbhandle,0,0,rates_total,MiddleBuffer)<=0) return (0);
   if(CopyBuffer(bbhandle,1,0,rates_total,UpperBuffer)<=0) return (0);
   if(CopyBuffer(bbhandle,2,0,rates_total,LowerBuffer)<=0) return (0); 
   
   int pos=prev_calculated-1;
   if(pos<0) pos=0;
   for(int i=pos; i<rates_total-(BBPeriod+BBShift+1); i++)
     {
    
     BLGBuffer[i]=(close[i]-LowerBuffer[i])/(UpperBuffer[i]-LowerBuffer[i]);

     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: