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

Automated Trading Language Documentation

Create Your Own Expert Advisor in MQL5 Wizard Create Your Own Expert Advisor in MQL5 Wizard Screenshot
NZDJPY, W1
Real
Subscribe to signal
FxProN
154.87%, 22 854.96 USD
TF PANELTF PANEL Try product
TF PANEL
Author: tol64
EMA Indicator
EMA
Author: GODZILLA

At

Gets the element from the given position in the array.

string  At(
   int  pos      // Position 
   ) const

Parameters

pos

[in] Position of the desired element in the array.

Return Value

The value of the element in case of success, "- if there was an attempt to get an element of not existing positions (the last error ERR_OUT_OF_RANGE).

Note

Of course, "" may be a valid value of an array element, so having a value, always check the last error code.

Example:

//--- example for CArrayString::At(int)
#include <Arrays\ArrayString.mqh>
//---
void OnStart()
  {
   CArrayString *array=new CArrayString;
   //---
   if(array==NULL)
     {
      printf("Object create error");
      return;
     }
   //--- add arrays elements
   //--- . . .
   for(int i=0;i<array.Total();i++)
     {
      string result=array.At(i);
      if(result=="" && GetLastError()==ERR_OUT_OF_RANGE)
        {
         //--- Error reading from array
         printf("Get element error");
         delete array;
         return;
        }
      //--- use element
      //--- . . .
     }
   //--- delete array
   delete array;
  }


Updated: 2010.02.22