MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading Language Documentation

Screenshot
EURCAD, H4
Demo
Subscribe to signal
RawInvestments
283.36%, 19 185.97 EUR
DailyPivotPoints Indicator
DailyPivotPoints
Author: GODZILLA
Auto-Generated Documentation for MQL5 Code Auto-Generated Documentation for MQL5 Code PCH AND INCREASE VOLPCH AND INCREASE VOL Try product
PCH AND INCREASE VOL
Author: tol64

CArrayObj

CArrayObj class is a class of dynamic array of pointers to instances of CObject and his heirs.

Description

Class CArrayObj provides the ability to work with a dynamic array of pointers to instances of CObject and his heirs. This gives the possibility to work as a multidimensional dynamic arrays of primitive data types, and the more difficult for organized data structures.

In the class implemented the ability to add / insert / delete elements in an array, sort array, searching in sorted array. In addition, the implemented methods of work with the file.

There are certain subtleties of the class CArrayObj.

Declaration

   class CArrayObj : public CArray

Title

   #include <Arrays\ArrayObj.mqh>

Class Method

Attributes

 

FreeMode

Gets the flag memory management

FreeMode

Sets the flag memory management

Memory control

 

Reserve

Allocates memory to increase the size of the array

Resize

Sets a new (smaller) size of the array

Shutdown

Clears the array with a total exemption memory array (not element).

Add methods

 

Add

Adds an element to the end of the array

AddArray

Adds an element to the end of the array

Insert

Inserts an element in the array to the specified position

InsertArray

Inserts an array of elements from another array with the specified position

AssignArray

Copies the array elements from another array

Update methods

 

Update

Changes the element at the specified position array

Shift

Moves an item from a given position in the array to the specified offset

Delete methods

 

Detach

Gets the element from the specified position and removing it from the array

Delete

Removes the element from the specified position array

DeleteRange

Deletes a group of elements from the specified position array

Clear

Removes all elements of the array without the release of the memory array

Access methods

 

At

Gets the element from the specified position array

Compare methods

 

CompareArray

Compares array with another array

Sorted array operations

 

InsertSort

Inserts element in a sorted array

Search

Searches for an element equal to the model in sorted array

SearchGreat

Searches for an element of more samples in sorted array

SearchLess

Searches for an element less than the sample in the sorted array

SearchGreatOrEqual

Searches for an element greater than or equal to the model in sorted array

SearchLessOrEqual

Searches for an element less than or equal to the model in sorted array

SearchFirst

Finds the first element equal to the model in sorted array

SearchLast

Finds the last element equal to the model in sorted array

Input/output

 

Save

Saves data array in the file

Load

Loads data array from a file

Type

Gets the type identifier of the array

Derived classes:

CIndicator

CIndicators

Practical application of arrays are descendants of class CObject (including all classes of the standard library).

For example, consider the options for two-dimensional array:

#include <Arrays\ArrayDouble.mqh>
#include <Arrays\ArrayObj.mqh>
//---
void OnStart()
  {
   int i,j;
   int first_size=10;
   int second_size=100;
//--- create array
   CArrayObj    *array=new CArrayObj;
   CArrayDouble *sub_array;
//---
   if(array==NULL)
     {
      printf("Object create error");
      return;
     }
//--- create subarrays
   for(i=0;i<first_size;i++)
     {
      sub_array=new CArrayDouble;
      if(sub_array==NULL)
        {
         delete array;
         printf("Object create error");
         return;
        }
      //--- fill array
      for(j=0;j<second_size;j++)
        {
         sub_array.Add(i*j);
        }
      array.Add(sub_array);
     }
//--- create array OK
   for(i=0;i<first_size;i++)
     {
      sub_array=array.At(i);
      for(j=0;j<second_size;j++)
        {
         double element=sub_array.At(j);
         //--- use array element
        }
     }
   delete array;
  }

Subtleties

The class has a mechanism to control dynamic memory, so be careful when working with elements of the array.

Mechanism of memory management can be switched on / off using the method FreeMode (bool). By default, the mechanism is enabled.

Accordingly, there are two options for dealing with the class CArrayObj:

1. Mechanism of memory management is enabled. (default)

In this case, CArrayObj take responsibility for freeing the memory elements after their removal from the array. In this program the user should not free the array elements.

Example:

   int i;
//--- Create an array
   CArrayObj *array=new CArrayObj;
//--- Fill array elements
   for(i=0;i<10;i++) array.Add(new CObject);
//--- Do something
   for(i=0;i<array.Total();i++)
     {
      CObject *object=array.At(i);
      //--- Action with an element
      . . .
     }
//--- Remove the array with the elements
   delete array;

2. Mechanism of memory management is turned off.

In this case, CArrayObj not otvetstvechaet for freeing the memory elements after their removal from the array. In this program the user must free the array elements.

Example:

   int i;
//--- Create an array
   CArrayObj *array=new CArrayObj;
//--- Disable the mechanism of memory management
   array.FreeMode(false);
//--- Fill array elements
   for(i=0;i<10;i++) array.Add(new CObject);
//--- Do something
   for(i=0;i<array.Total();i++)
     {
      CObject *object=array.At(i);
      //--- Action with an element
      . . .
     }
//--- Remove array elements
   while(array.Total()) delete array.Detach();
//--- Remove empty array
   delete array;

 


Updated: 2010.08.05