Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2013.01.07 15:45

The simplified class of the CArrayRing256 ring buffer - library for MetaTrader 5

| English Русский 中文 Español Deutsch 日本語 Português

votes: 20


The CArrayRing256 class is the simplified version of the CArrayRing ring buffer, but it is faster and allows to organize the mini time series, indicator minibuffers, short sized buffers to store intermediate stream data inside the Expert Advisor or indicator. 

Simplification based on the property of uchar-variable, which is used as the array index. For example, in the code

double array[UCHAR_MAX+1];  // the ring buffer data
uchar  index=0;             // the buffer element index

   array[++index];          // go to the next element of the buffer

the array index always takes the value from 0 to 255 and never go beyond the range of the array dimension. It allows to remove all checking from the methods associated with the possible exit of the index beyond the array exit by simplifying the methods themselves and increasing rate of performance. But the buffer size will be always constant and has the size of 256 elements. For many tasks this is an acceptable alternative to the universal class of CArrayRing in exchange for an increase the rate of the work.


сlass CArrayRing256


#include <IncOnRingBuffer\CArrayRing256.mqh>

The CArrayRing256.mqh class file should be placed in the IncOnRingBuffer folder that need to be established in MQL5\Include\.

Class methods 

//--- buffer initialization method:
void Init(
   double volue=EMPTY_VALUE // value for empty location buffers
//--- addition method of new element into the buffer:
void Add(
   const double element     // added element value
//--- the method rewrites the elements value with the set index:
void Update(                // if error it returns false, if successful - true
   const double element,    // the new value of the element
   const uchar  index=0     // the element index
//--- the method returns the value of the element with the set index:
double At(                  // returns the value of the element
   const uchar index        // the element index
   ) const;
//--- method returns value of the last written in the buffer element:
double Last() const;
//--- method overwrites last element value in the buffer:
void Last(
   const double element     // new value of the element
//--- method returns ring buffer size:
int Size();


  • the size of the ring buffer is always constant and equal to 256 elements
  • in the given realization of the ring buffer the indexing is taken as in a timeseries, i.e. opposite to the usual 


Use of this class is similar to CArrayRing . There are a couple of differences:

  • The Init() method is used for initialization of the buffer by the definite value;
  • The Resize() method is absent as the size of the buffer is always constant.

Translated from Russian by MetaQuotes Software Corp.
Original code:

Breakout Bars Trend v2 Breakout Bars Trend v2

The second (edited and added) version of the alternative indicator for trend definition based on the breakthrough bars and distance from extremums. The breakthrough levels and size of the previous trends are added.

Exp_VininI_Trend_LRMA Exp_VininI_Trend_LRMA

The Exp_VininI_Trend_LRMA trading system is based on changes of the trend direction displayed by the VininI_Trend_LRMA indicator.

The example of the work with the CSV file as with a table The example of the work with the CSV file as with a table

The CSV file was written to write economic news but there was a problem that the Terminal does not distinguish lines, exactly their number when working with the CSV file. That is why I decided to share my solution of this problem.

X-bars Fractals X-bars Fractals

The X-bars Fractals indicator allows setting the number of bars on the left and the right from fractal. It is good as for local, so for global extremums