Using N timeframes inside class

 

Hi forum,


I'm building a new Indicator that shoud work on different pre-selected timeframes.

What is the best way to manage the selection of the timeframes for the users?

after the selection inside the class I plan to have an array m_tfs[] that stores the selected timeframes to work with


thanks

 
Have you looked at the Series class? (include\indicators\series.mqh)
 
Ernst Van Der Merwe:
Have you looked at the Series class? (include\indicators\series.mqh)

Yess, PeriodToTimeframeFlag is a good starting point but my problem is on first initialization, when the user select the default input params for the indicator.

For example in a web-form I use combo box to let user decide witch options select.

In mql I can't use combo box so I think that would be achieved with some bool flags input. 1 flag * 1 Timeframe = 21 flags  :/

Is there a better solution?

 

Don't know if this example will help.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
enum ENUM_INDICATORS
  {
   INDICATOR_AC,           //Accelerator
   INDICATOR_AO,           //Awesome Oscillator
   INDICATOR_CHO,          //Chaikin Oscillator
   INDICATOR_CCI,          //Commodity Channel Index
   INDICATOR_DEMARKER,     //DeMarker
   INDICATOR_DPO,          //Detrended Price Oscillator
   INDICATOR_FORCE,        //Force
   INDICATOR_MOMENTUM,     //Momentum
   INDICATOR_MFI,          //Money Flow Index
   INDICATOR_MA,           //Moving Average
   INDICATOR_MACD,         //Moving Average Convergence/Divergence
   INDICATOR_OSMA,         //Oscillator of Moving Averages
   INDICATOR_PCI,          //Price Change Index
   INDICATOR_PVT,          //Price and Volume Trend
   INDICATOR_RSI,          //Relative Strength Index
   INDICATOR_RVI,          //Relative Vigour Index
   INDICATOR_STOCHASTIC,   //Stochastic Oscillator
   INDICATOR_TRIX,         //Triple Exponential Average
   INDICATOR_UOS,          //Ultimate Oscillator
   INDICATOR_WPR,          //Williams' Percent Range
  };
//--- indicator to display
input string Symbol="EURUSD";
input ENUM_TIMEFRAMES TimeFrame=PERIOD_CURRENT;
input ENUM_INDICATORS Indicator=INDICATOR_MA;

//+------------------------------------------------------------------+
//| Indicator and index buffers class                                |
//+------------------------------------------------------------------+
class CIndicator
  {
private:
   //---             symbol name
   string            m_symbol;
   //---             time frame
   ENUM_TIMEFRAMES   m_period;
   //---             custom indicator name
   string            m_name;
   //---             indicator type
   ENUM_INDICATORS   m_indicator;
public:
   //---             constructor
                     CIndicator(void);
   //---             destructor
                    ~CIndicator(void);
   //---             initialize indicator parameters
   bool              iCustom(const string symbol,ENUM_TIMEFRAMES timeframe,const string name,ENUM_INDICATORS indicator);
   //---
   //---
   
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CIndicator::CIndicator()   :  m_symbol(NULL),
                                   m_period(0),
                                   m_name(NULL)
  {
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CIndicator::iCustom(const string symbol_name,
                       ENUM_TIMEFRAMES period,
                       const string name,
                       ENUM_INDICATORS indicator)
  {
//--- check name
   if(name==NULL || name=="")
      return(false);
//--- set symbol, time frame and name
   m_symbol=(symbol_name==NULL) ? Symbol() : symbol_name;
   m_period=(period==0) ? (ENUM_TIMEFRAMES)Period() : period;
   m_name=name;
   m_indicator=indicator;
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CIndicator *indicator; 
//---
int OnInit()
  {
//--- declare/check pointers
   if((indicator=new CIndicator)==NULL || 
      !indicator.iCustom(Symbol,TimeFrame,"Oscillators",Indicator))
      return(INIT_FAILED);
//---
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- check and delete object pointer
   if(CheckPointer(indicator))
      delete indicator;
 
 
Hi Ernst and thank you but your example is for a single select only, not multi-select
 

They could probably only be selected individually.

input bool M1=false;
input bool M5=false;
input bool M15=false;
input bool M30=false;
input bool H1=false;
input bool H4=false;
input bool D1=false;
input bool W1=false;
input bool MN1=false;
//+------------------------------------------------------------------+
//| Indicator and index buffers class                                |
//+------------------------------------------------------------------+
class CIndicator
  {
private:
   //---             symbol name
   string            m_symbol;
   //---             time frames
   ENUM_TIMEFRAMES   m_periods[];
   //---             custom indicator name
   string            m_name;
public:
   //---             constructor
                     CIndicator(void);
   //---             destructor
                    ~CIndicator(void);
   //---             initialize indicator parameters
   bool              SetTimeFrames(const bool &tfs[]);
   //---
   //---
  }; 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CIndicator::CIndicator()   :  m_symbol(NULL),
                                   m_name(NULL)
  {
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CIndicator::~CIndicator()
  {
   ArrayFree(m_periods);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CIndicator::SetTimeFrames(const bool &tfs[])
  {
   ENUM_TIMEFRAMES timeFrames[9]={PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,
                                  PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
//--- check time frames
   int j=0;
   for(int i=0;i<9;i++)
     {
      if(tfs[i])
        {
         ArrayResize(m_periods,j+1,9);
         m_periods[j]=timeFrames[i];
         j++;
        }
     }    
   int size=ArraySize(m_periods);
//---
   return(size>0 && size<10);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CIndicator *indicator; 
//---
int OnInit()
  {
   bool TimeFrames[9];
//--- assign time frame flags
   TimeFrames[0]=M1;
   TimeFrames[1]=M5;
   TimeFrames[2]=M15;
   TimeFrames[3]=M30;
   TimeFrames[4]=H1;
   TimeFrames[5]=H4;
   TimeFrames[6]=D1;
   TimeFrames[7]=W1;
   TimeFrames[8]=MN1;
//--- declare/check pointers & set time frames
   if((indicator=new CIndicator)==NULL ||
      !indicator.SetTimeFrames(TimeFrames))
      return(INIT_FAILED);
//---
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- check and delete object pointer
   if(CheckPointer(indicator))
      delete indicator;
//---