Download MetaTrader 5

TimeSeries of MqlRates creation and upadating for quantitative analysis.

To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
maximaxx
81
maximaxx 2011.07.07 14:21 

I'm tryng to design an Object Oriented EA for quantitative analysis and I'm in trouble with Timeseries.

I'll try to explain: 

-I want to store in an object the history of a symbol for a timeframe from a certain date in the past (startdate) to date of initialization of object  (initdate) to an MqlRates struct (m_data); object class definition:

//+------------------------------------------------------------------+
//| Struct of instrument parameter                                   |
//+------------------------------------------------------------------+
struct Param_Instrument
  {
   string            symbol;
   ENUM_TIMEFRAMES   timeframe;
  };

//+------------------------------------------------------------------+
//| Class C_Instrument                                               |
//| Description: Class with methods for creating Instrument Object   |
//+------------------------------------------------------------------+

class C_Instrument : public CObject
  {

   Param_Instrument  m_param;                //struct of instrument parameters
   CisNewBar         m_newbar;               //class for detecting new bar
   datetime          m_startdate;            //start date for initialization
   datetime          m_initdate;             //init date for initialization
   MqlRates          m_data[];               //array of data   

public:
                     C_Instrument(void);
                    ~C_Instrument(void);
   bool              Init(Param_Instrument &param, datetime startdate);
   int               Refresh();
  };

code of Init function: 

 

//+------------------------------------------------------------------+
//| C_Instrument Init (Param_Instrument &param,datetime startdate).  |
//|                                                                  |
//| INPUT:  no.                                                      |
//| OUTPUT: no.                                                      |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool C_Instrument::Init(Param_Instrument &param,datetime startdate)
  {
  //--- instrument parameter setting  
  m_param.symbol=param.symbol;
  m_param.timeframe=param.timeframe;
  //--- date initialization
  m_startdate=startdate;
  m_initdate=(datetime)SeriesInfoInteger(m_param.symbol,m_param.timeframe,SERIES_LASTBAR_DATE);
  //--- class newbar initialization 
  m_newbar.SetSymbol(m_param.symbol);
  m_newbar.SetPeriod(m_param.timeframe);
  //--- loading of instrument history into m_data
  int NumBars=Bars(m_param.symbol,m_param.timeframe,m_startdate,m_initdate);
  Print("NumBars from",
         TimeToString(m_startdate,TIME_DATE|TIME_MINUTES),
         TimeToString(m_initdate,TIME_DATE|TIME_MINUTES),
         "=",
         NumBars);
  int chk=CopyRates(m_param.symbol,m_param.timeframe,m_startdate,m_initdate,m_data);
  Print("Copied bars from",
         TimeToString(m_startdate,TIME_DATE|TIME_MINUTES),
         TimeToString(m_initdate,TIME_DATE|TIME_MINUTES),
         "=",
         chk);
  return 1;
  }

 

how can i append new bars to m_data[] in ordered mode so i can get the history of symbol to make my calculation with metod Refresh()? Any idea or suggestion of implemantation? 

I tried to find some example on documentation and forum, but no result...

N.B. I have to admit that MQL5 is a very powerfull language and with OOP is possible to do almost everything, but I found that implementing a quantitative analysis framework it's very hard due to timesaries access and managing. I would suggest to developers and article writers that an article on subject like "Time series accessing and managing" with explanations of use of  price series classes  will be very usefull.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / History Data Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / History Data Structure - Documentation on MQL5
JMRodMartins
238
JMRodMartins 2011.07.07 20:12  
"maximaxx:

I'm tryng to design an Object Oriented EA for quantitative analysis and I'm in trouble with Timeseries.

I'll try to explain: 

-I want to store in an object the history of a symbol for a timeframe from a certain date in the past (startdate) to date of initialization of object  (initdate) to an MqlRates struct (m_data); object class definition:

code of Init function: 

 

 

how can i append new bars to m_data[] in ordered mode so i can get the history of symbol to make my calculation with metod Refresh()? Any idea or suggestion of implemantation? 

I tried to find some example on documentation and forum, but no result...

N.B. I have to admit that MQL5 is a very powerfull language and with OOP is possible to do almost everything, but I found that implementing a quantitative analysis framework it's very hard due to timesaries access and managing. I would suggest to developers and article writers that an article on subject like "Time series accessing and managing" with explanations of use of  price series classes  will be very useful

 

An idea:

On a new bar:

 

MqlRates buf[1]; 

if( CopyRates( m_param.symbol, m_param.timeframe,  0, 1, buf) > 0) {

       int arraySize = ArraySize( m_data);

      ArrayResize( m_data, arraySize + 1);

      ArrayCopy(  (void) m_data, (void) buf, arraySize, 0);

}

It's an idea, i didn't try it.... 

 

 

 

 

maximaxx
81
maximaxx 2011.07.07 21:59  

Thanks, I'm trying your idea.. it seems promising..

 

To add comments, please log in or register