help required to debug why indicator class is calculating only current chart values

 

Hi

I have created a VWMA custom indicator, and using an OOP class to get VWMA_Tx (triple period values) for different timeframes.

The class is however returning _Sybmol + _Period data only, irrespective of initializing class with different time frames.

Please help me out, what is wrong in my code.

Zip file attached for all relevant code files (for one to run it for debug) and OOP class is as below:

#define         iVWMAPath "iVWMA.ex5"
#resource "\\" + iVWMAPath

#include  "CBase.mqh"

#define         _bufferVWMA             0
//+-----------------------------------------------------------------------------------------------------------------------------+
//| CLASS:                              CiVWMATx
//| APPLICATION:        Class for Tripple (Fast,Mid & Slow) Volume Weighted Moving Average Indicator 
//+-----------------------------------------------------------------------------------------------------------------------------+
class CiVWMATx final : public CBase {

public:
          CiVWMATx() : CBase(_Symbol,PERIOD_CURRENT) {  }
          CiVWMATx(string pSymbol,ENUM_TIMEFRAMES pTimeFrame,SParam_iVWMA_TX &pParam_iVWMA);
         ~CiVWMATx();

private:
                int                                                                     mHandleFast;
                int                                                                     mHandleMid;
        int                                                                             mHandleSlow;

public:
        double                                                          getFast(int pIdx);
        double                                                          getMid(int pIdx);
        double                                                          getSlow(int pIdx);

}; // END Of Class Definition
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                             Init()
//| APPLICATION:        METHOD TO INITIALIAZE MEMBER VARIABLES OF THE INDICATOR CLASS
//+-----------------------------------------------------------------------------------------------------------------------------+
CiVWMATx::CiVWMATx(string pSymbol,ENUM_TIMEFRAMES pTimeFrame,SParam_iVWMA_TX &pParam_iVWMA)
                : CBase(pSymbol,mTimeFrame) {

                TesterHideIndicators(true);
                ResetLastError();
                mHandleFast = iCustom(mSymbol,mTimeFrame,"::" + iVWMAPath,pParam_iVWMA.periodFast,
                                                                pParam_iVWMA.appliedPrice,
                                                                pParam_iVWMA.maMethod,
                                                                mAppliedVolume);
                mHandleMid  = iCustom(mSymbol,mTimeFrame,"::" + iVWMAPath,pParam_iVWMA.periodMid,
                                                                pParam_iVWMA.appliedPrice,
                                                                pParam_iVWMA.maMethod,
                                                                mAppliedVolume);
                mHandleSlow = iCustom(mSymbol,mTimeFrame,"::" + iVWMAPath,pParam_iVWMA.periodSlow,
                                                                pParam_iVWMA.appliedPrice,
                                                                pParam_iVWMA.maMethod,
                                                                mAppliedVolume);
          if(mHandleFast == INVALID_HANDLE || mHandleMid == INVALID_HANDLE || mHandleSlow == INVALID_HANDLE) {
                string vMethod = "[" + (string)mSymbol + "," + EnumToString(mTimeFrame) + "] " + (string)__FUNCTION__;
            PrintFormat("%s Error[#%i] Creating handle CiVWMATx Fast or Mid or Slow",vMethod,GetLastError());
          }
                TesterHideIndicators(false);

} // END Of method InitClass()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                             ~CiVWMATx()
//| APPLICATION:        DECONSTRUCTOR METHOD
//+-----------------------------------------------------------------------------------------------------------------------------+
CiVWMATx::~CiVWMATx() {

                IndicatorRelease(mHandleFast);
                IndicatorRelease(mHandleMid);
                IndicatorRelease(mHandleSlow);

} // END Of method ~CiVWMATx()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                     getSlow()
//| APPLICATION:  METHOD TO RETURN VOLUME WEIGHTED MA VALUE ON SPECIFIED INDEX
//+-----------------------------------------------------------------------------------------------------------------------------+
double CiVWMATx::getSlow(int pIdx) {

          double arrayData[1];

                ResetLastError();
          if(CopyBuffer(mHandleSlow,_bufferVWMA,pIdx,1,arrayData) == -1) {
      string vMethod = "[" + (string)mSymbol + "," + EnumToString(mTimeFrame) + "] " + (string)__FUNCTION__;
            PrintFormat("%s Error[#%i] getting iVWMA_PeriodTX Slow at Index[%i]",vMethod,GetLastError(),pIdx);
            return(0.00);
          }

        return(NormalizeDouble(arrayData[0],mDigits));

} // END Of method getSlow()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                     getMid()
//| APPLICATION:  METHOD TO RETURN MA VALUE ON SPECIFIED INDEX
//+-----------------------------------------------------------------------------------------------------------------------------+
double CiVWMATx::getMid(int pIdx) {

        double arrayData[1];

                ResetLastError();
          if(CopyBuffer(mHandleMid,_bufferVWMA,pIdx,1,arrayData) == -1) {
      string vMethod = "[" + (string)mSymbol + "," + EnumToString(mTimeFrame) + "] " + (string)__FUNCTION__;
            PrintFormat("%s Error[#%i] getting iVWMA_PeriodTX Mid at Index[%i]",vMethod,GetLastError(),pIdx);
        return(0.00);
          }

        return(NormalizeDouble(arrayData[0],mDigits));

} // END Of method getMid()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                     getFast()
//| APPLICATION:  METHOD TO RETURN MA VALUE ON SPECIFIED INDEX
//+-----------------------------------------------------------------------------------------------------------------------------+
double CiVWMATx::getFast(int pIdx) {

        double arrayData[1];

                ResetLastError();
          if(CopyBuffer(mHandleFast,_bufferVWMA,pIdx,1,arrayData) == -1) {
      string vMethod = "[" + (string)mSymbol + "," + EnumToString(mTimeFrame) + "] " + (string)__FUNCTION__;
            PrintFormat("%s Error[#%i] getting iVWMA_PeriodTX Fast at Index[%i]",vMethod,GetLastError(),pIdx);
        return(0.00);
          }

        return(NormalizeDouble(arrayData[0],mDigits));

} // END Of method getFast()
//+-----------------------------------------------------------------------------------------------------------------------------+

Thanks in advance.

Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
Files:
MQLForum.zip  69 kb
 

Perhaps the problem is here. Try replacing this with pTimeFrame. I didn't run your code

CiVWMATx::CiVWMATx(string pSymbol,ENUM_TIMEFRAMES pTimeFrame,SParam_iVWMA_TX &pParam_iVWMA)
                : CBase(pSymbol,mTimeFrame) {
 
Vladislav Boyko #:

Perhaps the problem is here. Try replacing this with pTimeFrame. I didn't run your code

@Vladislav Boyko Thanks a lot man, yes that's the exact cause of problem.

I have tried to everywhere else, except this ... what a silly mistake :)