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

Libraries

Basic List - library for MetaTrader 5

DMITRII PECHERITSA

Views:
717
Rating:
votes: 8
Published:
2020.06.20 06:54
/****************************************************************
BasicList
The List class template provides a basic container for storing an ordered list
 of basic data type objects.
For convenience, List also provides synonyms for stack operations,
 which make code that uses List for stacks more explicit without defining another class.
/**/


template<typename T>class BasicList
  {
public:
   //construction, destruction, initialization, and assignment
                     BasicList() {}
                     BasicList(BasicList&src) {Copy(items,src.items);}
                    ~BasicList() {}
   BasicList         operator=(BasicList&);
   //accessing
   T                 operator[](int i) {return Get(i);}
   T                 Get(int at) {int c=Count(); if(c>0&&at>=0&&at<c) {return items[at];} return NULL;}
   T                 First() {int c=Count(); if(c>0) {return items[0];} return NULL;}
   T                 Last() {int c=Count(); if(c>0) {return items[c-1];} return NULL;}
   //
   int               Count() {return ArraySize(items);}
   int               Find(T item) {int c=Count(); for(int i=0; i<c; i++) {if(item==items[i]) {return i;}} return -1;}
   void              Print() {int c=ArraySize(items); for(int i=0; i<c; i++) {PrintFormat("%d:%s",i,(string)items[i]);}}
   //adding
   void              operator+=(T item) {Append(item);}
   void              operator^=(T item) {Prepend(item);}
   void              Append(T item) {int c=ArraySize(items); IncreaseAt(c); items[c]=item;}
   void              Prepend(T item) {IncreaseAt(0); items[0]=item;}
   //removing
   void              operator-=(T item) {Remove(item);}
   void              operator~() {RemoveAll();}
   void              Remove(T item) {int f=Find(item); if(f>-1) {ReduceAt(f);}}
   void              RemoveLast() {ReduceAt(ArraySize(items)-1);}
   void              RemoveFirst() {ReduceAt(0);}
   void              RemoveAll() {ArrayFree(items);}
   //stack interface
   T                 Top() {return Last();}
   void              Push(T item) {Append(item);}
   T                 Pop() {T top=Top(); RemoveLast(); return top;}
protected:
   T                 items[];
   //service
   void              ReduceAt(int);
   void              IncreaseAt(int);
   void              Copy(T&dst[],T&src[]) {int c=ArraySize(src); ArrayResize(dst,c); for(int i=0; i<c; i++) {dst[i]=src[i];}}
  };


/****************************************************************
Mql does not allow to manipulate pointers and basic types in one template,
 so one generic list with pointer control is impossible for all built-in types and user types.
   This is why I made an independent template List for basic types.
Available operators:
   [index] Get,         eg. T var=list[3];
   += Append,           eg. list+=var;
   ^= Prepend,          eg. list^=var;
   -= Remove,           eg. list-=var;
   ~ RemoveAll,         eg. ~list;
   = Copy list,         eg. T listA=listB; //A-new,B-existing
/**/


/****************************************************************
Example of BasicList usage
/****************************************************************/
void OnStart()
  {
   BasicList<string>list;
   /**/
   list+="worry";                //append
   list+="be happy";             //append
   list.Print();                 //see output
   /**/
     {string s; for(int i=0; i<10; i++) {s+="-";} Print(s);}
   /**/
   list^="don't";                //remove
   BasicList<string>list2=list;  //copy list
   list2.Print();                //see output
   /**/
     {string s; for(int i=0; i<10; i++) {s+="-";} Print(s);}
   /**/
   ~list;                        //clean list
   Print(list2.Pop());           //pop
   /**/
     {string s; for(int i=0; i<10; i++) {s+="-";} Print(s);}
   /**/
   list2.Print();                //see output
  }
/****************************************************************
Output:
/**
   0:worry
   1:be happy
   ----------
   0:don't
   1:worry
   2:be happy
   ----------
   be happy
   ----------
   0:don't
   1:worry
/**/



    Object List Object List

    A basic container for storing an ordered list of objects.

    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).

    custom trail-stop by MA custom trail-stop by MA

    this is my first try at creating an EA from ground up

    Pan PrizMA CD Phase Sin leverage 72 Pan PrizMA CD Phase Sin leverage 72

    Calculates the phase and amplitude of the expected wave