Download MetaTrader 5

CIndicator inheritence and casting question and a bug

To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Amir Yacoby
Amir Yacoby 2010.09.02 00:45 


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 

Nikolaos Pantzos
Nikolaos Pantzos 2010.09.02 12:37  


Amir Yacoby
Amir Yacoby 2010.09.02 21:46  

also with casting to CiCustom I couldn't manage:

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


Any comment from the team?



Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Documentation on MQL5
Ilyas 2010.09.03 11:30  
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

Alexey Da
Alexey Da 2010.09.03 13:46  
Please use servicedesk or private messages to send code. - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
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 and take full advantage of its available features.
Amir Yacoby
Amir Yacoby 2010.09.03 20:54  

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

      Print("successful ind creation");
      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.


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 

Amir Yacoby
Amir Yacoby 2010.09.08 18:48  

Anyone? Rosh?

To add comments, please log in or register