Download MetaTrader 5

BufferResize and BufferSize for TimeSeries Classes - please help

To add comments, please log in or register
Dr Matthias Hammelsbeck
550
Dr Matthias Hammelsbeck  

Hi alltogether,

I'm grateful that there are people always who are willing to help and are giving competent answers to all my questions.

Following problem: I have an object of class CiHigh and I get unexpected values for BufferSize after having called BufferResize with different values:

 

#property copyright "Bobcat"
#property version   "4.00"
#include <Indicators\TimeSeries.mqh>
int OnInit()
{
  CiHigh high;
  high.Create ("EURUSD", PERIOD_M30);
  //--
  high.Refresh();
  Print ("Init BufferSize = ", high.BufferSize());
  for (int i = 98; i < 101; ++i) {
    printf ("%4d: %0.5f", i, high.GetData(i));
  }
  //--
  high.BufferResize(2000);
  high.Refresh();
  Print ("BufferResize(2000): BufferSize = ", high.BufferSize());
  for (int i = 1998; i < 2001; ++i) {
    printf ("%4d: %0.5f", i, high.GetData(i));
  }
  //--
  high.BufferResize(200);
  high.Refresh();
  Print ("BufferResize(200): BufferSize = ", high.BufferSize());
  for (int i = 198; i < 201; ++i) {
    printf ("%4d: %0.5f", i, high.GetData(i));
  }
  //--
  high.BufferResize(50);
  high.Refresh();
  Print ("BufferResize(50): BufferSize = ", high.BufferSize());
  for (int i = 48; i < 51; ++i) {
    printf ("%4d: %0.5f", i, high.GetData(i));
  }
  return INIT_SUCCEEDED;
}

 

 The output is:

Init BufferSize = 100
  98: 1.37734
  99: 1.37704
 100: 179769313486...
BufferResize(2000): BufferSize = 2000
1998: 1.36281
1999: 1.36232
2000:  179769313486...
BufferResize(200): BufferSize = 2000   (HERE I EXPECTED 200)
 198: 1.36776
 199: 1.36617
 200: 179769313486...
BufferResize(50): BufferSize = 2000    (HERE I EXPECTED 50)
  48: 1.37395
  49: 1.37432
  50: 179769313486...

 

 Notes/Questions:

  • obviously the initial buffersize is 100; this is for sure and reliable?
  • except for 2 lines I get the output I expected
  • the exceptions are marked: why do I get the value 2000 for buffer size although I diminished the size two times?

Many thanks for each answer!

Bobcat

 

Alain Verleyen
Moderator
32814
Alain Verleyen  
Bobcat:

Hi alltogether,

I'm grateful that there are people always who are willing to help and are giving competent answers to all my questions.

Following problem: I have an object of class CiHigh and I get unexpected values for BufferSize after having called BufferResize with different values:

 ...

Bobcat

Interesting question. Not sure if it's a feature or a bug. In all case the statement high.BufferResize(200) doesn't really resize the buffer.

I can only suggest you to write to ServideDesk to report this and ask their enlightenment.

Dr Matthias Hammelsbeck
550
Dr Matthias Hammelsbeck  

Hii,

 

thank you again for your answer!

I will describe the problem to ServiceDesk and I let you know the answer!

 

Bobcat


"Happiness is only real when shared"

Dr Matthias Hammelsbeck
550
Dr Matthias Hammelsbeck  

angevoyageur

 

until now I have no answer from the ServiceDesk. But relax - this is no problem.

 I think I have found the cause for the strange buffer size values. Please see the following code extract from Include/Indicators/TimeSeries.mqh:

//+------------------------------------------------------------------+
//| Set size of buffer                                               |
//+------------------------------------------------------------------+
bool CPriceSeries::BufferResize(const int size)
  {
   if(size>m_buffer_size && !CSeries::BufferResize(size))
      return(false);
//-- history is avalible
   CDoubleBuffer *buff=At(0);
//--- check pointer
   if(buff==NULL)
      return(false);
//--
   buff.Size(size);
//--- ok
   return(true);
  }

 The and-Expression (marked in red letters) is the problem: in case if size <= m_buffer_size the second expression !CSeries::BufferResize(size) is never called (for compiler optimization strategy I guess). But one side-effect of CSeries::BufferResize is the modification/adaptation of the variable m_buffer_size.

Solutions:

a simple solution is to exchange the order of the both expressions:

  if(!CSeries::BufferResize(size) && size>m_buffer_size)
      return(false);

 

 A better solution would be:

  bool bufres = CSeries::BufferResize(size);
  if(size>m_buffer_size && !bufres)
      return(false);

 

 What do you think?

 

A second issue:

I wonder if the initial buffer size of the timeseries buffers is 100. And indeed it is:

 In Include/Indicators/Series.mqh there is the following define statement:

#define DEFAULT_BUFFER_SIZE 100

 This macro is used during creation of CiHigh Object.

 

I hope this will clarify some things....

Bobcat 

Alain Verleyen
Moderator
32814
Alain Verleyen  
Bobcat:

angevoyageur

 

until now I have no answer from the ServiceDesk. But relax - this is no problem.

 I think I have found the cause for the strange buffer size values. Please see the following code extract from Include/Indicators/TimeSeries.mqh:

 The and-Expression (marked in red letters) is the problem: in case if size <= m_buffer_size the second expression !CSeries::BufferResize(size) is never called (for compiler optimization strategy I guess). But one side-effect of CSeries::BufferResize is the modification/adaptation of the variable m_buffer_size.

Solutions:

a simple solution is to exchange the order of the both expressions:

 

 A better solution would be:

 

 What do you think?

 

I already read the code when your reported this problem, so I am aware of what you say now. But it's Metaquotes code for the Standard Library, so it's to them to fix it or say : not it works like intended. This is why I wrote previously : bug or feature ?


If you want to use your correction, don't forget to use a copy of TimeSeries.mqh, as it can be overwritten during MT5 update.

Dr Matthias Hammelsbeck
550
Dr Matthias Hammelsbeck  
angevoyageur:
I already read the code when your reported this problem, so I am aware of what you say now. But it's Metaquotes code for the Standard Library, so it's to them to fix it or say : not it works like intended. This is why I wrote previously : bug or feature ?


If you want to use your correction, don't forget to use a copy of TimeSeries.mqh, as it can be overwritten during MT5 update.

Yes, I see what you mean. Thank you.

 Bobcat

 

----------------------------------------------------------------------------------- 

"Computers are good at following instructions, but not at reading your mind."

To add comments, please log in or register