question about CiOpen class

 

hi I wrote this code:


#include <Indicators\TimeSeries.mqh>

void OnStart()
  {

    CiOpen op;
    op.Create(_Symbol,PERIOD_CURRENT);
    op.Refresh();
    
    double value = op.GetData(0);
    
    value = NormalizeDouble(value,5);
    
    Print(DoubleToString(value,5));
    
    Print("buffers total: " + (string)op.BuffersTotal());
   
  }

the output is :

buffers total: 0


my question is , shouldn't it be 1?? because we have at least 1 buffer

 
farhadmax #:
anybody can help me?
There is no buffer for Price series, only for indicators.
 

this is the getData method from this class.

//Gets the element of timeseries by starting position and number.
int  GetData(
   int   start_pos,     // starting position
   int   count,         // number
   double& buffer       // array
   ) const

I want to know how many elements are there already so that I can pass it to the count parameter. what is the best way of doing that? 

I rewrote the code as below:

#include <Indicators\TimeSeries.mqh>

void OnStart()
  {
   
   CiOpen op;
   
   op.Create(_Symbol,PERIOD_CURRENT);
   op.Refresh();
   
   int starPosition = 0;
   int count = 1; //  what is the best way to find out maximum value that can be put inside count variable?
   double openPricesArray[];
   
   //  here is the GetData documentaion:  Gets the element of timeseries by starting position and number.
   int result = op.GetData(starPosition,count,openPricesArray);
  
}
 
farhadmax #:

this is the getData method from this class.

I want to know how many elements are there already so that I can pass it to the count parameter. what is the best way of doing that? 

I rewrote the code as below:

An other time, if you want answer to a second question, please at least acknowledge receipt of the answer to the first one. I am not a robot providing answers at will.
 
ok, my apologize. now could you please help me?
 
farhadmax #:

this is the getData method from this class.

I want to know how many elements are there already so that I can pass it to the count parameter. what is the best way of doing that? 

I rewrote the code as below:

int maxCount = Bars(_Symbol,PERIOD_CURRENT);
 

thanks for reply


I think it would be better to define a member variable in CiOpen class to hold the count of elements. whats your opinion?

 
farhadmax #:

thanks for reply


I think it would be better to define a member variable in CiOpen class to hold the count of elements. whats your opinion?

No because this variable/value is not related (not specific) to CiOpen.
 
Alain Verleyen #:
No because this variable/value is not related (not specific) to CiOpen.
Im not expert in OOP, but I think there should be a variable in CiOpens's super classes that holds this value (if there is already one, please let me know)
 

hi again

I'm not sure whether I should post this question as a new thread or just post it here. I post it here anyway.

I'm really confused with this CiOpen class (and standard library). I can't figure it out what is exactly happening inside these classes. I think MetaQuotes should provide much more documentation for standard library source codes and provide examples of working with these classes. I would really appreciate if anybody can make videos or write articles about MQL5 standard library classes and shed some light on the internals of these classes. I've read a few articles here about standard classes, but they were not that much helpful.


so, lets take a look at the code I've written

#include <Indicators\TimeSeries.mqh>


void OnStart()
  {
      CiOpen op;
      op.Create(_Symbol,PERIOD_CURRENT);
      op.Refresh();

      int index;
      double openPrice_Max_Value = op.MaxValue(0,1024,index);
      double normilized = NormalizeDouble(openPrice_Max_Value,5);

      printf("openPrice Max Value is: %f  which is at bar %d", normilized,index);
      
  }


this code works well when there is only 1024 bars in the chart and gives us correct output. but if the number of bars on the chart exceed 1024,  It returns wrong index.


so for example if there are 1500 bars on the chart, and the bar 1499 has the highest open price, and I put 1500 in the above code( instead of 1024), the index value wont be 1499. (it only finds the index of highest open price index within the range of 0 to 1024)


finally I want to thank Mr Verleyen that answers most of these questions on this forum

 
farhadmax #:

hi again

I'm not sure whether I should post this question as a new thread or just post it here. I post it here anyway.

This thread is fine as it's the same topic.

I'm really confused with this CiOpen class (and standard library). I can't figure it out what is exactly happening inside these classes. I think MetaQuotes should provide much more documentation for standard library source codes and provide examples of working with these classes. I would really appreciate if anybody can make videos or write articles about MQL5 standard library classes and shed some light on the internals of these classes. I've read a few articles here about standard classes, but they were not that much helpful.

The internal work of classes doesn't have to be documented publicly, that's why it's "internal" work. If you want to understand, you can study the code. But the public interface and usage would benefit from a better documentation for sure.

so, lets take a look at the code I've written


this code works well when there is only 1024 bars in the chart and gives us correct output. but if the number of bars on the chart exceed 1024,  It returns wrong index.

You didn't define the size of the collected data, so by default it's 1024.

You can change it with BufferResize().

   op.Create(_Symbol,PERIOD_CURRENT);
   op.BufferResize(2000);
   op.Refresh();

finally I want to thank Mr Verleyen that answers most of these questions on this forum

You are welcome.