거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

The class to create the ring buffer - MetaTrader 5용 라이브러리

조회수:
6355
평가:
(41)
게시됨:
2012.12.27 11:56
\MQL5\Include\IncOnRingBuffer\
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Description

The ring buffer is one of the form of organization to store data. Usually it represents itself finite-length array to the entry where the oldest elements are replaced by the newest data. Thus, there is always access to a certain number of the last data. Mostly used for the asynchronous reading/writing of stream data. For further details look here.

When writing the Expert Advisors and indicators often doesn't need to store the calculated values for all bars. It will be enough to keep handy the last data, for example, for 100 bars. The ring buffer is suitable for this. Obvious advantages:

  • calculations increase
  • memory economy
  • easy to use, no need to worry about the exit beyond the array.
Declaration

сlass CArrayRing

Title

#include <IncOnRingBuffer\CArrayRing.mqh>

File of the CArrayRing.mqh class need to be placed in the IncOnRingBuffer folder which is necessary to create in MQL5\Include\. There are examples to the links below which this class uses.

Class methods 

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

Note:

  • when the buffer size decrease then, as usual, not the last, but the oldest elements are missing
  • in the given realization of the ring buffer the indexing is accepted as in time series, i.e. opposite to the usual 

Examples

There are three examples of using the ring buffer to the moment of publication:

 

MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/1340

Exp_ColorLeManTrend Exp_ColorLeManTrend

The Exp_ColorLeManTrend trading system is based on changes of the trend direction displayed by the ColorLeManTrend indicator

Disparity Index Disparity Index

Disparity Index (difference index) displays the difference between the close price and chosen Moving Averages in percentage. It is recommended to use in combination with the other candlestick models

The class for drawing Moving Average using the ring buffer The class for drawing Moving Average using the ring buffer

The class is designed for calculation of Moving Averages (Moving Average) using the algorithm of the ring buffer.

Combinatorics Combinatorics

Initial library of combinatorics functions.