Incorret handle using CIndicator.Create

 

What is wrong in calling the Empty indicator using CIndicator class:

The output is the following:

handle=-1


The caller:

CIndicator IDiv;
......
int OnInit()
  {
   MqlParam          params[3];

   params[0].type         =TYPE_STRING; 
   params[0].string_value="Empty"; 
   params[1].type         =TYPE_INT; 
   params[1].integer_value=20;   
   params[2].type         =TYPE_BOOL; 
   params[2].integer_value=false; 
   bool res =IDiv.Create(Symbol(),PERIOD_M5,IND_CUSTOM,3,params);
   h_Div = IDiv.Handle();
   Print("handle =",h_Div);


The called:

//+------------------------------------------------------------------+
//|                                                        Empty.mq5 |
//|                                                         Gioooooo |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Gioooooo"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=10;
input bool  aaaa = false;
//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   
//---
   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
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+



Thank in advance

 

Giovanni
:

What is wrong in calling the Empty indicator using CIndicator class:

The output is the following:

handle=-1


The caller:


The called:



Thank in advance

The problem is in the class:

protected:
   //--- methods of tuning
   bool              CreateBuffers(const string symbol,const ENUM_TIMEFRAMES period,const int buffers);
   virtual bool      Initialize(const string symbol,const ENUM_TIMEFRAMES period,
                                const int num_params,const MqlParam &params[]) {return(false);}

Rather call the CiCustom class.

CiCustom IDiv;
//---
int h_Div;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   MqlParam          params[3];

   params[0].type         =TYPE_STRING; 
   params[0].string_value="Empty"; 
   params[1].type         =TYPE_INT; 
   params[1].integer_value=20;   
   params[2].type         =TYPE_BOOL; 
   params[2].integer_value=false; 
   bool res =IDiv.Create(Symbol(),PERIOD_M5,IND_CUSTOM,3,params);
   h_Div = IDiv.Handle();

   Print("handle =",h_Div);
 
Ernst Van Der Merwe:

The problem is in the class:

Rather call the CiCustom class.

Thanks :)

Reason: