Download MetaTrader 5

static array in a class -> unresolved static variable

To add comments, please log in or register
Tom Clayson
228
Tom Clayson  

I am trying to create a class to hold variables related to various ongoing potential trade setups. A new Trade_Setup object is created each time a support/resistance level is approached/breached. To avoid adding multiple setups at the same level, I want to save the levels that have ongoing analysis in a static CArrayDouble. However, when I do this, I am shown the compile error of "unresolved static variable". I had read elsewhere on the forum that I apparently have to initialise any static data members of a class. This is not possible however in a dynamic array of unknown size. How can I fix this?


#include <Arrays/ArrayDouble.mqh>

class Trade_Setup
{
   protected:
      string setup_type;
      datetime start_time;
      double level;
      double zone;  
      double swing_momentum;  
      double trend;   
      double proj_1;
      double proj_2; 
      
      virtual bool check_level(double _level);

   public: 
      Trade_Setup(void){};
      Trade_Setup(string setup,datetime time,double _level,double _zone,double _swing_momentum,double _trend): 
                  setup_type(setup),start_time(time),level(_level),zone(_zone),swing_momentum(_swing_momentum),trend(_trend)
                  {}
     ~Trade_Setup(void){};  
     string get_setup_type(){return setup_type;}
     datetime get_start_time(){return start_time;}
     double get_level(){return level;}
     double get_zone(){return zone;}
     double get_swing_momentum(){return swing_momentum;}
     double get_trend(){return trend;}
     double get_proj_1(){return proj_1;}
     double get_proj_2(){return proj_2;}
    
     void set_start_time(datetime _start_time){start_time=_start_time;}
     void set_level(double _level){level=_level;}
     void set_zone(double _zone){zone=_zone;}
     void set_swing_momentum(double _swing_momentum){swing_momentum=_swing_momentum;}
     void set_proj_1(double _proj_1){proj_1=_proj_1;}
     void set_proj_2(double _proj_2){proj_2=_proj_2;}   
};

class ResTST_Setup : public Trade_Setup
{   
   protected:
      static CArrayDouble ResTST_levels;
  
};

class ResBPB_Setup : public Trade_Setup
{
   protected:
      static CArrayDouble ResBPB_levels; 
      bool pause_detected;
      bool level_touched;
      
   public:   
      ResBPB_Setup(void){};
     ~ResBPB_Setup(void){ResBPB_levels.Delete(ResBPB_levels.Search(level));}
      ResBPB_Setup(string setup,datetime time,double _level,double _zone,double _swing_momentum,double _trend):
      Trade_Setup(setup,time,_level,_zone,_swing_momentum,_trend) {pause_detected=NULL; level_touched=NULL;ResBPB_levels.Add(_level);}
      void set_pause_detected(bool _pause_detected){pause_detected=_pause_detected;}
      void set_level_touched(bool _level_touched){level_touched=_level_touched;}
      bool get_pause_detected(){return pause_detected;}
      bool get_level_touched(){return level_touched;}     
      
      virtual bool check_level(double _level)
      {// returns -1 if the level cannot be found
         if(ResBPB_levels.Search(_level)<0) return false;
         else return true;
      }        
};

class ResBOF_Setup : public Trade_Setup
{
   protected:
      static CArrayDouble ResBOF_levels; 
      bool pause_detected;      
   public:   
      ResBOF_Setup(void){};
     ~ResBOF_Setup(void){ResBOF_levels.Delete(ResBOF_levels.Search(level));}
      ResBOF_Setup(string setup,datetime time,double _level,double _zone,double _swing_momentum,double _trend):
      Trade_Setup(setup,time,_level,_zone,_swing_momentum,_trend) {pause_detected=NULL; ResBOF_levels.Add(_level);}
      void set_pause_detected(bool _pause_detected){pause_detected=_pause_detected;}
      bool get_pause_detected(){return pause_detected;}
      
      virtual bool check_level(double _level)
      {// returns -1 if the level cannot be found
         if(ResBOF_levels.Search(_level)<0) return false;
         else return true;
      }                 
};
Jose Francisco Casado Fernandez
3129
Jose Francisco Casado Fernandez  

Static members of a class must be inizialited in the global scope. In your case, you can add this code outside your class:

CArrayDouble ResBPB_Setup::ResBPB_levels = { 0 };
CArrayDouble ResBOF_Setup::ResBOF_levels = { 0 };


Regards.

To add comments, please log in or register