Arrays resizes itself to 0 elements in method call from Base / Child Class

 

UPDATE NOTE: the issue is resolved ...

Dear Friends

I am trying to develop an EA, based on Strategy BaseClass for MACD and derived class MACD OsMA Cross.

When run VWMACD.Refresh_DataBuffer(); all the data are filled in the array(s).

However, when trying to run the "MACDCrossOOZ.Init_MACDCross_OoZ();" from derived class, array out of range error showed up. Checking with ArraySize() I noticed all my arrays get initialized to Zero Elements.

I have failed to find out why it is happening.

Also guide me, if this approach is reasonable for EA development.

Seeking support from the forum.

NOTE: code have been truncated for non-essential parts due to message size limitation.

//+----------------------------------------------------------------------------------------------------------+
//| EA_MACDCross.mq5
//+----------------------------------------------------------------------------------------------------------+
int OnInit()
  {
    Auxiliary.SetParam_WSTF(WSymbol,WTimeFrame);
    Pivots.Set_WSymbol(WSymbol);
    VWMACD.SetParam_Working(WSymbol,WTimeFrame,appliedPrice);
    VWMACD.SetParam_BollingerBands(BB_Period,BB_Deviation);
    VWMACD.SetParam_NormBMR(BB_Period,BB_Deviation,MFI_Period,MFIonBB_Period,MFIonBB_Deviation,
                                                   RSI_Period,RSIonBB_Period,RSIonBB_Deviation);
    VWMACD.SetParam_SwingHL(SlowLength,FastLength);
    VWMACD.SetParam_VWMACD(MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod);
    VWMACD.SetParam_VW3EMA(MAPeriod_Fastest,MAPeriod_Fast,MAPeriod_Slow);
    VWMACD.Init_Indicators();
    return(INIT_SUCCEEDED);
  }
/---void OnTick()
  {
    if(Auxiliary.IsNewDay())
      {
        VWMACD.Refresh_Pivots();                          // for pivot prices in Class 'MACDBase'
        Pivots.Draw_CamarillaPivots();
      }
    if(Auxiliary.IsNewBar())    // Check every 5 minute ...
      {
        ulong start  = GetMicrosecondCount();  
        VWMACD.Refresh_DataBuffer();                      // Update all data buffers
        ulong finish = GetMicrosecondCount();  
        PrintFormat("Function %s in %s took %.1f ms",__FUNCTION__,__FILE__,(finish-start)/1000);
    //--- Implement trading operations of a strategy
        MACDCrossOOZ.Init_MACDCross_OoZ();
      }
  } // END Of expert advisor
//+----------------------------------------------------------------------------------------------------------+

2021.06.07 15:17:28.441 EA_MACDCross (US30,M5) MACDBase::Refresh_DataBuffer arraysize 11

2021.06.07 15:17:28.441 EA_MACDCross (US30,M5) Function OnTick in EA_MACDCross.mq5 took 101.0 ms

2021.06.07 15:17:28.441 EA_MACDCross (US30,M5) MACDBase::Set_FEPoint_LONG arraysize 0

2021.06.07 15:17:28.441 EA_MACDCross (US30,M5) array out of range in 'MACDBase.mqh' (332,17)

 
    if(Auxiliary.IsNewBar())    // Check every 5 minute ...
      {
        ulong start  = GetMicrosecondCount();  
        VWMACD.Refresh_DataBuffer();                      // Update all data buffers
        ulong finish = GetMicrosecondCount();  
        PrintFormat("Function %s in %s took %.1f ms",__FUNCTION__,__FILE__,(finish-start)/1000);
    //--- Implement trading operations of a strategy
        MACDCrossOOZ.Init_MACDCross_OoZ();
      }

Looks like you never called the Refresh_DataBuffer() of your MACDCrossOOZ instance. VWMACD is an entirely different instance, of course they derive from the same base class, but won't share the data.

So all initializing that's done with VWMACD has also to be done with MACDCrossOOZ.

 
lippmaje:

Looks like you never called the Refresh_DataBuffer() of your MACDCrossOOZ instance. VWMACD is an entirely different instance, of course they derive from the same base class, but won't share the data.

So all initializing that's done with VWMACD has also to be done with MACDCrossOOZ.

Thanks lippmaje :)

yes it worked and I am not getting the error.

Reason: