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

Arrays class - MetaTrader 5용 라이브러리

조회수:
4521
평가:
(7)
게시됨:
2020.06.11 08:45
업데이트됨:
2020.06.13 13:12
Arrays.mq5 (3.16 KB) 조회
Types.mqh (1.46 KB) 조회
Arrays.mqh (8.15 KB) 조회
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Sometimes we need to add an element to array, or insert an element.

Standard Mql Array functions are efficient but do not provide such functionality.

For example, if you need to find an element, you can search only in sorted array with ArrayBsearch.

They also do not support complex data types.

This class fills the gap, and provides some frequent array operation methods:

  •    Add/insert elements to array by value/reference.
  •    Find/ReverseFind an element in unsorted array.
  •    Sum/Average of a numeric array.
  •    Min/Max returns the actual min/max value, not index of the value.
  •    Array copy/insert works with arrays containing complex types.
  •    StringToCodes creates an array of symbol codes from a string.

class Arrays
  {
public:
   template<typename T>int    Add(T src,T &dst[]);
   template<typename T>int    Copy(T &dst[],T &srs[],bool clean=0,int dststart=0,int srcstart=0,int srccount=WHOLE_ARRAY);
   template<typename T>bool   Insert(T src,T &dst[],int pos);
   template<typename T>int    Find(T element,T &array[],int start=0);
   template<typename T>int    FindReverse(T element,T &array[],int start=0);
   template<typename T>double Average(T &src[]);
   template<typename T>double Sum(T &src[]);
   template<typename T>double Max(T& src[]);
   template<typename T>double Min(T& src[]);

   template<typename T>int    Addbyref(T &src,T &dst[]);
   template<typename T>bool   Insertbyref(T &src,T &dst[],int pos);
   template<typename T>bool   Insert(T &dst[],T &src[],int dststart);
   int                        StringToCodes(string src,short &dst[],int startpos=0,int count=-1);
protected:
   Types             types;
  };

Notes:

  • FindReverse searches for the element from array end.
  • Addbyref does the same thing as Add by can work with complex types, which are sent only by reference.
  • Copy has the same signature/behavior as the standard Mql ArrayCopy. Unlike ArrayCopy, it allows complex types in src/dst.
  • StringToCodes is basically the standard StringToShortArray, except that the final 0 is removed from the destination array.

Examples of Arrays class usage.

void OnStart()
  {
   int a[],asrc[]= {1,2,3,4};
   int b[],bsrc[]= {5,6,7};
   ArrayCopy(a,asrc);
   ArrayCopy(b,bsrc);
   /**/
   Arrays arrays;
   arrays.Insert(a,b,0);         //insert array in array
   arrays.Insert(0,a,3);         //insert element in array
   arrays.Add(8,a);              //add element to array
   double sum=arrays.Sum(a);     
   double avg=arrays.Average(a);
   double max=arrays.Max(a);
   int findwhat=2;
   int findindex=arrays.Find(findwhat,a);
   int findrev=arrays.FindReverse(findwhat,a);
   int size=ArraySize(a);
   /**/
   string print=StringFormat("size:%d, sum:%g, avg:%g, max:%g, '%d' found in pos:%d, '%d' found rev in pos:%d",
                             size,sum,avg,max,findwhat,findindex,findwhat,findrev);
   short printcodes[];
   arrays.StringToCodes(print,printcodes); //convert string to array of char codes
   Print(print);
   ArrayPrint(a);
   ArrayPrint(printcodes);
  }

Output:

/**
   size:9, sum:36, avg:4, '2' found in pos:5, '2' found rev in pos:3
   5 6 7 0 1 2 3 4 8
   [ 0] 115 105 122 101  58  57  44  32 115 117 109  58  51  54  44  32  97 118 103  58  52  44  32  39  50  39  32 102 111 117 110 100  32
   [33] 105 110  32 112 111 115  58  53  44  32  39  50  39  32 102 111 117 110 100  32 114 101 118  32 105 110  32 112 111 115  58  51
/**/
    Doubles comparer Doubles comparer

    Class for comparing two floating point variables.

    WaveMTF MT5 WaveMTF MT5

    Indicator WaveMTF Bull and Bear System with Signal and Alert for MetaTrader 5 with options to display signal on the chart.

    Bar Time Count Down Bar Time Count Down

    This MT5 indicator is to count down the remaining time of the current bar as the format HH:MM:SS

    M1MA indicator M1MA indicator

    M1-based Moving Average. It gives more adequate estimation of average price per bar compared to any standard price type (close, open, median, typical, weighted, etc).