CIndicator inheritence and casting question and a bug

 

Hi

I can't get it right when using the CIndicator and the inherited classes.

If I declare a CIndicator pointer, and then use it as an inherited CiCustom, I can't manage to make it.

CIndicator    *ind;

Ind = new CiCustom; 

and when using a method from CiCustom, NumBuffers, in order to set the number of the buffers I get error message: 'NumBuffers' - wrong parameter count.

Ind.NumBuffers(1)   ==> wrong parameter count

because probably NumBuffers of the CiCustom that sets the buffers is not recognised. What am I doing wrong? 

and also then when I try to inspect the Ind variable in order to see what type of CIndicator inherit is it (CiCustom or others)

how do I do it? Because I can't get it with:

switch (Ind.Type())

   case IND_CUSTOM:

       ....

because Type() is not declared in the CIndicator, only in it's inheritors.

The reason that I need to know at run time the type of the indicator, is that if it is custom indicator I want to be able to get the Indicator parameters thru the methods in CiCustom. 

BUG ** - the initialize method in CiCustom does not initializes m_num_params 

thank you 

 

buitiful!!!

 
 

also with casting to CiCustom I couldn't manage:

(CiCustom)Ind.NumBuffers(1)  ==> wrong parameter count

 

Any comment from the team?

 

Thanks 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Documentation on MQL5
 
It would be better, if you attach the code. It seems, that it contains an error. For more information see Virtual Functions help topic and the MQL for "Dummies": How to Design and Construct Object Classes article

 
Please use servicedesk or private messages to send code.
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 

This is the code inside a script

CIndicator    *ind; 

ind = new CiCustom;

ind.NumBuffers(1);    // <== compiler error: wrong parameter count - I also tried ==> ((CiCustom)ind).NumBuffers(1);         // <=== invalid cust operation

if(ind.Create(NULL,PERIOD_CURRENT,IND_CUSTOM,8,parms)){
      Print("successful ind creation");
      }
   else
      Print("failed ind creation"); 

and then passing the ind pointer on to a different class and in that class:

CIndicator *ind;

switch (ind.Type()){               === > compiler error: type is not declared for CIndicator as virtual

   case IND_CUSTOM: 

         parms = ind.NumParams();      ====> always zero -> m_num_params inside CiCustom is zero, it was not initialized by the Initialize method of CiCustom 

 

the ind.Create in third line, runs the Initialize method of CiCustom in the background but the method does not initializes the m_num_params, so on the other class when I use the method ind.NumParams() and get zero, even though the ind.Create was successful and the Initialize method ran.

P.S: 

Please look inside the code of the CiCustom.mqh and you will notice that there is no initialization of m_num_params anywhere in the code. 

And so, the method NumParams() that is defined:  int               NumParams()  { return(m_num_params); }               // <============= always return zero 

 

Anyone? Rosh?

Reason: