Download MetaTrader 5

Migrating from MQL4 to MQL5

17 May 2010, 13:32
Sergey Pavlov
20
34 913

Introduction

Many developers have accumulated a lot of indicators and trading strategies written in MQL4. To use them in Metatrader 5, they should be converted to MQL5. It's not so easy to rewrite all programs in MQL5. It would be much easier to convert them, if there were a translation-reference, and better with examples.

In this article I would like to suggest my version of a guide to migrate from MQL4 to MQL5.

1. Chart Periods

In MQL5 chart period constants changed, and some new time periods (M2, M3, M4, M6, M10, M12, H2, H3, H6, H8, H12) were added. To convert MQL4 time periods you can use the following function:

ENUM_TIMEFRAMES TFMigrate(int tf)
  {
   switch(tf)
     {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      
      default: return(PERIOD_CURRENT);
     }
  }

It should be noted, that in MQL5 the numerical values of chart timeframe constants (from H1) are not equal to the number of minutes of a bar (for example, in MQL5, the numerical value of constant  PERIOD_H1=16385, but in MQL4 PERIOD_H1=60). You should take it into account when converting to MQL5, if numerical values of MQL4 constants are used in MQL4 programs.

To determine the number of minutes of the specified time period of the chart, divide the value, returned by function PeriodSeconds by 60.

2. Declaring Contants

Some of standard MQL4 constants are absent in MQL5, therefore they should be declared:

//+------------------------------------------------------------------+
//|                                                     InitMQL4.mqh |
//|                                                 Copyright DC2008 |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "keiji"
#property copyright "DC2008"
#property link      "http://www.mql5.com"
//--- Declaration of constants
#define OP_BUY 0           //Buy 
#define OP_SELL 1          //Sell 
#define OP_BUYLIMIT 2      //Pending order of BUY LIMIT type 
#define OP_SELLLIMIT 3     //Pending order of SELL LIMIT type 
#define OP_BUYSTOP 4       //Pending order of BUY STOP type 
#define OP_SELLSTOP 5      //Pending order of SELL STOP type 
//---
#define MODE_OPEN 0
#define MODE_CLOSE 3
#define MODE_VOLUME 4 
#define MODE_REAL_VOLUME 5
#define MODE_TRADES 0
#define MODE_HISTORY 1
#define SELECT_BY_POS 0
#define SELECT_BY_TICKET 1
//---
#define DOUBLE_VALUE 0
#define FLOAT_VALUE 1
#define LONG_VALUE INT_VALUE
//---
#define CHART_BAR 0
#define CHART_CANDLE 1
//---
#define MODE_ASCEND 0
#define MODE_DESCEND 1
//---
#define MODE_LOW 1
#define MODE_HIGH 2
#define MODE_TIME 5
#define MODE_BID 9
#define MODE_ASK 10
#define MODE_POINT 11
#define MODE_DIGITS 12
#define MODE_SPREAD 13
#define MODE_STOPLEVEL 14
#define MODE_LOTSIZE 15
#define MODE_TICKVALUE 16
#define MODE_TICKSIZE 17
#define MODE_SWAPLONG 18
#define MODE_SWAPSHORT 19
#define MODE_STARTING 20
#define MODE_EXPIRATION 21
#define MODE_TRADEALLOWED 22
#define MODE_MINLOT 23
#define MODE_LOTSTEP 24
#define MODE_MAXLOT 25
#define MODE_SWAPTYPE 26
#define MODE_PROFITCALCMODE 27
#define MODE_MARGINCALCMODE 28
#define MODE_MARGININIT 29
#define MODE_MARGINMAINTENANCE 30
#define MODE_MARGINHEDGED 31
#define MODE_MARGINREQUIRED 32
#define MODE_FREEZELEVEL 33
//---
#define EMPTY -1
Note: Constants in MQl4 and MQL5 differ, therefore it's better to declare them in a separate file initMQ4.mqh for futher use.

3. Predefined Variables

MQL4
 MQL5Description
double Ask
MqlTick last_tick;
SymbolInfoTick(_Symbol,last_tick);
double Ask=last_tick.ask;
Ask
The latest known ask price for the current symbol.
SymbolInfoTick
int Bars
int Bars=Bars(_Symbol,_Period);
Bars
Number of bars in the current chart.
Bars
double Bid
MqlTick last_tick;
SymbolInfoTick(_Symbol,last_tick);
double Bid=last_tick.bid;
Bid
The latest known bid price of the current symbol.
SymbolInfoTick
double Close[]
double Close[];
int count;   // number of elements to copy
ArraySetAsSeries(Close,true);
CopyClose(_Symbol,_Period,0,count,Close);
Close
Series array that contains close prices for each bar of the current chart.
CopyClose, ArraySetAsSeries
int Digits
int Digits=_Digits;
Digits
Number of digits after the decimal point for the current symbol prices.
_Digits

double High[]
double High[];
int count;   // number of elements to copy
ArraySetAsSeries(High,true);
CopyHigh(_Symbol,_Period,0,count,High);
High
Series array that contains the highest prices of each bar of the current chart.
CopyHigh, ArraySetAsSeries
double Low[]
double Low[];
int count;   // number of elements to copy
ArraySetAsSeries(Low,true);
CopyLow(_Symbol,_Period,0,count,Low);
Low
Series array that contains the lowest prices of each bar of the current chart.
CopyLow, ArraySetAsSeries
double Open[]
double Open[];
int count;   // number of elements to copy
ArraySetAsSeries(Open,true);
CopyOpen(_Symbol,_Period,0,count,Open);
Open
Series array that contains open prices of each bar of the current chart.
CopyOpen, ArraySetAsSeries
double Point
double Point=_Point;
Point
The current symbol point value in the quote currency.
_Point
datetime Time[]
datetime Time[];
int count;   // number of elements to copy
ArraySetAsSeries(Time,true);
CopyTime(_Symbol,_Period,0,count,Time);
Time
Series array that contains open time of each bar of the current chart. Data like datetime represent time, in seconds, that has passed since 00:00 a.m. of 1 January, 1970.
CopyTime, ArraySetAsSeries
double Volume[]
long Volume[];
int count;   // number of elements to copy
ArraySetAsSeries(Volume,true);
CopyTickVolume(_Symbol,_Period,0,count,Volume);
Volume
Series array that contains tick volumes of each bar of the current chart.
CopyTickVolume, ArraySetAsSeries


4. Account Information

MQL4
MQL5
Description
double AccountBalance()
double AccountInfoDouble(ACCOUNT_BALANCE)
AccountBalance
Returns balance value of the current account (the amount of money on the account).
AccountInfoDouble
double AccountCredit()
double AccountInfoDouble(ACCOUNT_CREDIT)
AccountCredit
Returns credit value of the current account.
AccountInfoDouble
string AccountCompany()
string AccountInfoString(ACCOUNT_COMPANY)
AccountCompany
Returns the brokerage company name where the current account was registered.
AccountInfoString
string AccountCurrency()
string AccountInfoString(ACCOUNT_CURRENCY)
AccountCurrency
Returns currency name of the current account.
AccountInfoString
double AccountEquity()
double AccountInfoDouble(ACCOUNT_EQUITY)
AccountEquity
Returns equity value of the current account. Equity calculation depends on trading server settings.
AccountInfoDouble
double AccountFreeMargin()
double AccountInfoDouble(ACCOUNT_FREEMARGIN)
AccountFreeMargin
Returns free margin value of the current account.
AccountInfoDouble
double AccountFreeMarginCheck(string symbol,
                              int cmd,
                              double volume)
-
AccountFreeMarginCheck
Returns free margin that remains after the specified position has been opened at the current price on the current account.
double AccountFreeMarginMode()
-
AccountFreeMarginMode
Calculation mode of free margin allowed to open positions on the current account.
int AccountLeverage()
int AccountInfoInteger(ACCOUNT_LEVERAGE)
AccountLeverage
Returns leverage of the current account.
AccountInfoInteger
double AccountMargin()
double AccountInfoDouble(ACCOUNT_MARGIN)
AccountMargin
Returns margin value of the current account.
AccountInfoDouble
string AccountName()
string AccountInfoString(ACCOUNT_NAME)
AccountName
Returns the current account name.
AccountInfoString
int AccountNumber()
int AccountInfoInteger(ACCOUNT_LOGIN)
AccountNumber
Returns the number of the current account.
AccountInfoInteger
double AccountProfit()
double AccountInfoDouble(ACCOUNT_PROFIT)
AccountProfit
Returns profit value of the current account.
AccountInfoDouble
string AccountServer()
string AccountInfoString(ACCOUNT_SERVER)
AccountServer
Returns the connected server name.
AccountInfoString
int AccountStopoutLevel()
double AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)
AccountStopoutLevel
Returns the value of the Stop Out level.
AccountInfoDouble
int AccountStopoutMode()
int AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE)
AccountStopoutMode
Returns the calculation mode for the Stop Out level.
AccountInfoInteger


5. Array Functions

MQL4
MQL5
 Description
int ArrayBsearch(double array[],
                 double value,
                 int count=WHOLE_ARRAY,
                 int start=0,
                 int direction=MODE_ASCEND)
int ArrayBsearch(double    array[],
                 double    searched_value
                 )
ArrayBsearch
The function searches for a specified value in a one-dimension numeric array.
ArrayBsearch
int ArrayCopy(object&dest[],
              object source[],
              int start_dest=0,
              int start_source=0,
              int count=WHOLE_ARRAY)
int ArrayCopy(void  dst_array[],
              void  src_array[],
              int   dst_start=0,
              int   src_start=0,
              int   cnt=WHOLE_ARRAY
              )
ArrayCopy
Copies an array to another one. Arrays must be of the same type, but arrays with type double[], int[], datetime[], color[], and bool[] can be copied as arrays of the same type. Returns the amount of copied elements.
ArrayCopy
int ArrayCopyRates(double&dest_array[],
                   string symbol=NULL,
                   int timeframe=0)
-ArrayCopyRates
Copies data of the current chart bars to the two-dimensional array of RateInfo[][6] type and returns copied bars amount, or -1 if failed.
int ArrayCopySeries(double&array[],
                    int series_index,
                    string symbol=NULL,
                    int timeframe=0)
int ArrayCopySeriesMQL4(double &array[],
                        int series_index,
                        string symbol=NULL,
                        int tf=0)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int count=Bars(symbol,timeframe);
   switch(series_index)
     {
      case MODE_OPEN:
         return(CopyOpen(symbol,timeframe,0,count,array));
      case MODE_LOW:
         return(CopyLow(symbol,timeframe,0,count,array));
      case MODE_HIGH:
         return(CopyHigh(symbol,timeframe,0,count,array));
      case MODE_CLOSE:
         return(CopyClose(symbol,timeframe,0,count,array));

      default: return(0);
     }
   return(0);
  }
ArrayCopySeries
Copies a timeseries array to a custom array and returns the count of the copied elements.
CopyOpen, CopyLow, CopyHigh, CopyClose, Bars
int ArrayDimension( object array[])
-ArrayDimension
Returns the multidimensional array rank.
bool ArrayGetAsSeries( object array[])
bool ArrayGetAsSeries(void  array)
ArrayGetAsSeries
Returns TRUE if an array is organized as a timeseries array (array elements are indexed from the last to the first one), otherwise returns FALSE.
ArrayGetAsSeries
int ArrayInitialize(double &array[],
                    double value)
int ArrayInitializeMQL4(double &array[],
                        double value)
  {
   ArrayInitialize(array,value);
   return(ArraySize(array));
  }
ArrayInitialize
Sets all elements of a numeric array to the same value. Returns the count of initialized elements.
ArrayInitialize, ArraySize
bool ArrayIsSeries( object array[])
bool ArrayIsSeries(void  array[])
ArrayIsSeries
Returns TRUE if the array under check is a timeseries array (Time[],Open[],Close[],High[],Low[], or Volume[]), otherwise returns FALSE.
ArrayIsSeries
int ArrayMaximum(double array[],
                 int count=WHOLE_ARRAY,
                 int start=0)
int ArrayMaximumMQL4(double &array[],
                     int count=WHOLE_ARRAY,
                     int start=0)
  {
   return(ArrayMaximum(array,start,count));
  }
ArrayMaximum
Searches for the element with the maximal value. The function returns position of this maximal element in the array.
ArrayMaximum
int ArrayMinimum(double array[],
                 int count=WHOLE_ARRAY,
                 int start=0)
int ArrayMinimumMQL4(double &array[],
                     int count=WHOLE_ARRAY,
                     int start=0)
  {
   return(ArrayMinimum(array,start,count));
  }
ArrayMinimum
Searches for the element with the minimal value. The function returns position of this minimal element in the array.
ArrayMinimum
int ArrayRange(object array[],
               int range_index)
int ArrayRange(void  array[],
               int   rank_index
               )
ArrayRange
Returns the count of elements in the given dimension of the array.
ArrayRange
int ArrayResize(object &array[],
                int new_size)
int ArrayResize(void  array[],
                int   new_size,
                int   allocated_size=0
                )
ArrayResize
Sets a new size for the first dimension.
ArrayResize
bool ArraySetAsSeries(double &array[],
                      bool set)
bool ArraySetAsSeries(void  array[],
                      bool  set
                      )
ArraySetAsSeries
Returns the count of elements in the given dimension of the array. Since indexes are zero-based, the size of dimension is 1 greater than the largest index.
ArraySetAsSeries
int ArraySize( object array[])
int ArraySize(void  array[])
ArraySize
Returns the count of elements contained in the array.
ArraySize
int ArraySort(double &array[],
              int count=WHOLE_ARRAY,
              int start=0,
              int sort_dir=MODE_ASCEND)
int ArraySortMQL4(double &array[],
                  int count=WHOLE_ARRAY,
                  int start=0,
                  int sort_dir=MODE_ASCEND)
  {
   switch(sort_dir)
     {
      case MODE_ASCEND:
         ArraySetAsSeries(array,true);
      case MODE_DESCEND:
         ArraySetAsSeries(array,false);

      default: ArraySetAsSeries(array,true);
     }
   ArraySort(array);
   return(0);
  }
ArraySort
Sorts numeric arrays by first dimension. Series arrays cannot be sorted by ArraySort().
ArraySort, ArraySetAsSeries


6. Checkup

MQL4
MQL5
Description
int GetLastError()
int GetLastError()
GetLastError
The function returns the last occurred error, then the value of special last_error variable where the last error code is stored will be zeroized.
GetLastError
bool IsConnected()
bool TerminalInfoInteger(TERMINAL_CONNECTED)
IsConnected
The function returns the status of the main connection between the client terminal and the server that performs data pumping. It returns TRUE if connection to the server was successfully established, otherwise, it returns FALSE.
TerminalInfoInteger
bool IsDemo()
bool IsDemoMQL4()
  {
   if(AccountInfoInteger(ACCOUNT_TRADE_MODE)==ACCOUNT_TRADE_MODE_DEMO)
      return(true);
   else
      return(false);
  }
IsDemo
Returns TRUE if the expert runs on a demo account, otherwise returns FALSE.
AccountInfoInteger
bool IsDllsAllowed()
bool TerminalInfoInteger(TERMINAL_DLLS_ALLOWED)
IsDllsAllowed
Returns TRUE if the function DLL call is allowed for the Expert Advisor, otherwise returns FALSE.
TerminalInfoInteger
bool IsExpertEnabled()
bool AccountInfoInteger(ACCOUNT_TRADE_EXPERT)
IsExpertEnabled
Returns TRUE if use of Expert Advisors is enabled in the client terminal, otherwise returns FALSE.
AccountInfoInteger
bool IsLibrariesAllowed()
bool MQLInfoInteger(MQL5_DLLS_ALLOWED)
IsLibrariesAllowed
Returns TRUE if an Expert Advisor can call library function, otherwise returns FALSE.
MQLInfoInteger
bool IsOptimization()
bool MQLInfoInteger(MQL5_OPTIMIZATION)
IsOptimization
Returns TRUE if an Expert Advisor is running in the strategy tester optimization mode, otherwise returns FALSE.
MQLInfoInteger
bool IsStopped()
bool IsStopped()
IsStopped
Returns TRUE if the program (an Expert Advisor or a script) has been commanded to stop its operation, otherwise returns FALSE.
IsStopped
bool IsTesting()
bool MQLInfoInteger(MQL5_TESTING)
IsTesting
Returns TRUE if an Expert Advisor is running in the testing mode, otherwise returns FALSE.
MQLInfoInteger
bool IsTradeAllowed()
bool MQLInfoInteger(MQL5_TRADE_ALLOWED)
IsTradeAllowed
Returns TRUE if trading by Expert Advisors is allowed and a thread for trading is not occupied, otherwise returns FALSE.
MQLInfoInteger
bool IsTradeContextBusy()
-IsTradeContextBusy
Returns TRUE if a thread for trading is occupied by another Expert Advisor, otherwise returns FALSE.
bool IsVisualMode()
bool MQLInfoInteger(MQL5_VISUAL_MODE)
IsVisualMode
Returns TRUE if the Expert Advisor is tested with checked "Visual Mode" button, otherwise returns FALSE.
MQLInfoInteger
int UninitializeReason()
int UninitializeReason()
UninitializeReason
Returns the code of the uninitialization reason for Expert Advisors, custom indicators, and scripts.
UninitializeReason


7. Client Terminal

MQL4
 MQL5 Description
string TerminalCompany()
string TerminalInfoString(TERMINAL_COMPANY)
TerminalCompany
Returns the name of company owning the client terminal.
TerminalInfoString
string TerminalName()
string TerminalInfoString(TERMINAL_NAME)
TerminalName
Returns client terminal name.
TerminalInfoString
string TerminalPath()
string TerminalInfoString(TERMINAL_PATH)
TerminalPath
Returns the directory, from which the client terminal was launched.
TerminalInfoString


8. Common Functions

MQL4
MQL5
Description
void Alert(...)
void Alert(argument,...)
Alert
Displays a dialog box containing the user-defined data. Parameters can be of any type.
Alert
void Comment(...)
void Comment(argument,...)
Comment
The function outputs the comment defined by the user in the left top corner of the chart.
Comment
int GetTickCount()
uint GetTickCount()
GetTickCount
The GetTickCount() function retrieves the number of milliseconds that have elapsed since the system was started.
GetTickCount
double MarketInfo(string symbol,
                  int type)
double MarketInfoMQL4(string symbol,
                      int type)
  {
   switch(type)
     {
      case MODE_LOW:
         return(SymbolInfoDouble(symbol,SYMBOL_LASTLOW));
      case MODE_HIGH:
         return(SymbolInfoDouble(symbol,SYMBOL_LASTHIGH));
      case MODE_TIME:
         return(SymbolInfoInteger(symbol,SYMBOL_TIME));
      case MODE_BID:
         return(Bid);
      case MODE_ASK:
         return(Ask);
      case MODE_POINT:
         return(SymbolInfoDouble(symbol,SYMBOL_POINT));
      case MODE_DIGITS:
         return(SymbolInfoInteger(symbol,SYMBOL_DIGITS));
      case MODE_SPREAD:
         return(SymbolInfoInteger(symbol,SYMBOL_SPREAD));
      case MODE_STOPLEVEL:
         return(SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL));
      case MODE_LOTSIZE:
         return(SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE));
      case MODE_TICKVALUE:
         return(SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE));
      case MODE_TICKSIZE:
         return(SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE));
      case MODE_SWAPLONG:
         return(SymbolInfoDouble(symbol,SYMBOL_SWAP_LONG));
      case MODE_SWAPSHORT:
         return(SymbolInfoDouble(symbol,SYMBOL_SWAP_SHORT));
      case MODE_STARTING:
         return(0);
      case MODE_EXPIRATION:
         return(0);
      case MODE_TRADEALLOWED:
         return(0);
      case MODE_MINLOT:
         return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN));
      case MODE_LOTSTEP:
         return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP));
      case MODE_MAXLOT:
         return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX));
      case MODE_SWAPTYPE:
         return(SymbolInfoInteger(symbol,SYMBOL_SWAP_MODE));
      case MODE_PROFITCALCMODE:
         return(SymbolInfoInteger(symbol,SYMBOL_TRADE_CALC_MODE));
      case MODE_MARGINCALCMODE:
         return(0);
      case MODE_MARGININIT:
         return(0);
      case MODE_MARGINMAINTENANCE:
         return(0);
      case MODE_MARGINHEDGED:
         return(0);
      case MODE_MARGINREQUIRED:
         return(0);
      case MODE_FREEZELEVEL:
         return(SymbolInfoInteger(symbol,SYMBOL_TRADE_FREEZE_LEVEL));

      default: return(0);
     }
   return(0);
  }
MarketInfo
Returns various data about securities listed in the Market Watch window.
SymbolInfoInteger, SymbolInfoDouble, Bid, Ask
int MessageBox(string text=NULL,
               string caption=NULL,
               int flags=EMPTY)
int MessageBox(string  text,
               string  caption=NULL,
               int     flags=0)
MessageBox
The MessageBox function creates, displays, and operates message box.
MessageBox
void PlaySound(string filename)
bool PlaySound(string filename)
PlaySound
Function plays a sound file.
PlaySound
void Print(...)
void Print(argument,...)
Print
Prints a message to the experts log.
Print
bool SendFTP(string filename,
             string ftp_path=NULL)
bool SendFTP(string filename,
             string ftp_path=NULL)
SendFTP
Sends the file to the FTP server set in the Tools->Options->Publisher tab. If the attempt fails, it retuns FALSE.
SendFTP
void SendMail(string subject,
              string some_text)
bool SendMail(string  subject,
              string  some_text)
SendMail
Sends a message to the e-mail set in the Tools->Options->EMail tab.
SendMail
void Sleep(int milliseconds)
void Sleep(int milliseconds)
Sleep
The Sleep() function suspends execution of the current expert within the specified interval.
Sleep


9. Conversion Functions

MQL4
MQL5
Description
string CharToStr(int char_code)
string CharToString(int char_code)
CharToStr
Conversion of the symbol code into a one-character string.
CharToString
string DoubleToStr(double value,
                   int digits)
string CharDoubleToString(double value,
                      int digits=8)
DoubleToStr
Returns text string with the specified numerical value converted into a specified precision format.
DoubleToString
double NormalizeDouble(double value,
                       int digits)
double NormalizeDouble(double value,
                       int digits)
NormalizeDouble
Rounds the floating point value to the given precision. Returns normalized value of the double type.
NormalizeDouble
double StrToDouble(string value)
double StringToDouble(string value)
StrToDouble
Converts string representation of number to double type (double-precision format with floating point).
StringToDouble
int StrToInteger(string value)
long StringToInteger(string value)
StrToInteger
Converts string containing the value character representation into a value of the int (integer) type.
StringToInteger
datetime StrToTime(string value)
datetime StringToTime(string value)
StrToTime
Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).
StringToTime
string TimeToStr(datetime value,
                 int mode=TIME_DATE|TIME_MINUTES)
string TimeToString(datetime value,
                    int mode=TIME_DATE|TIME_MINUTES)
TimeToStr
Converts value containing time in seconds that has passed since January 1, 1970, into a string of "yyyy.mm.dd hh:mi" format.
TimeToString


10. Custom Indicators

MQL4
MQL5
 Description
void IndicatorBuffers(int count)
-IndicatorBuffers
Allocates memory for buffers used for custom indicator calculations.
int IndicatorCounted()
int IndicatorCountedMQL4()
  {
   if(prev_calculated>0) return(prev_calculated-1);
   if(prev_calculated==0) return(0);
   return(0);
  }
IndicatorCounted
The function returns the amount of bars not changed after the indicator had been launched last.
OnCalculate
void IndicatorDigits(int digits)
bool IndicatorSetInteger(INDICATOR_DIGITS,digits)
IndicatorDigits
Sets precision format (the count of digits after decimal point) to visualize indicator values.
IndicatorSetInteger
void IndicatorShortName(string name)
bool IndicatorSetString(INDICATOR_SHORTNAME,name)
IndicatorShortName
Sets the "short" name of a custom indicator to be shown in the DataWindow and in the chart subwindow.
IndicatorSetString
void SetIndexArrow(int index,
                   int code)
bool PlotIndexSetInteger(index,PLOT_ARROW,code)
SetIndexArrow
Sets an arrow symbol for indicators line of the DRAW_ARROW type.
PlotIndexSetInteger
bool SetIndexBuffer(int index,
                    double array[])
bool SetIndexBuffer(index,array,INDICATOR_DATA)
SetIndexBuffer
Binds the array variable declared at a global level to the custom indicator pre-defined buffer.
SetIndexBuffer
void SetIndexDrawBegin(int index,
                       int begin)
bool PlotIndexSetInteger(index,PLOT_DRAW_BEGIN,begin)
SetIndexDrawBegin
Sets the bar number (from the data beginning) from which the drawing of the given indicator line must start.
PlotIndexSetInteger
void SetIndexEmptyValue(int index,
                        double value)
bool PlotIndexSetDouble(index,PLOT_EMPTY_VALUE,value)
SetIndexEmptyValue
Sets drawing line empty value.
PlotIndexSetDouble
void SetIndexLabel(int index,
                   string text)
bool PlotIndexSetString(index,PLOT_LABEL,text)
SetIndexLabel
Sets drawing line description for showing in the DataWindow and in the tooltip.
PlotIndexSetString
void SetIndexShift(int index,
                   int shift)
bool PlotIndexSetInteger(index,PLOT_SHIFT,shift)
SetIndexShift
Sets offset for the drawing line.
PlotIndexSetInteger
void SetIndexStyle(int index,
                   int type,
                   int style=EMPTY,
                   int width=EMPTY,
                   color clr=CLR_NONE)
void SetIndexStyleMQL4(int index,
                       int type,
                       int style=EMPTY,
                       int width=EMPTY,
                       color clr=CLR_NONE)
  {
   if(width>-1)
      PlotIndexSetInteger(index,PLOT_LINE_WIDTH,width);
   if(clr!=CLR_NONE)
      PlotIndexSetInteger(index,PLOT_LINE_COLOR,clr);
   switch(type)
     {
      case 0:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_LINE);
      case 1:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_SECTION);
      case 2:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);
      case 3:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_ARROW);
      case 4:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_ZIGZAG);
      case 12:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_NONE);

      default:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_LINE);
     }
   switch(style)
     {
      case 0:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_SOLID);
      case 1:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DASH);
      case 2:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DOT);
      case 3:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DASHDOT);
      case 4:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DASHDOTDOT);

      default: return;
     }
SetIndexStyle
Sets the new type, style, width and color for a given indicator line.
PlotIndexSetInteger
void SetLevelStyle(int draw_style,
                   int line_width,
                   color clr=CLR_NONE)
void SetLevelStyleMQL4(int draw_style,
                       int line_width,
                       color clr=CLR_NONE)
  {
   IndicatorSetInteger(INDICATOR_LEVELWIDTH,line_width);
   if(clr!=CLR_NONE)
      IndicatorSetInteger(INDICATOR_LEVELCOLOR,clr);
   switch(draw_style)
     {
      case 0:
         IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_SOLID);
      case 1:
         IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_DASH);
      case 2:
         IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_DOT);
      case 3:
         IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_DASHDOT);
      case 4:
         IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_DASHDOTDOT);

      default: return;
     }
  }
SetLevelStyle
The function sets a new style, width and color of horizontal levels of indicator to be output in a separate window.
IndicatorSetInteger
void SetLevelValue(int level,
                   double value)
bool IndicatorSetDouble(INDICATOR_LEVELVALUE,level,value)
SetLevelValue
The function sets a value for a given horizontal level of the indicator to be output in a separate window.
IndicatorSetDouble


11. Date and Time Functions

MQL4
 MQL5Description
int Day()
int DayMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.day);
  }
Day
Returns the current day of the month, i.e., the day of month of the last known server time.
TimeCurrent, MqlDateTime
int DayOfWeek()
int DayOfWeekMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.day_of_week);
  }
DayOfWeek
Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.
TimeCurrent, MqlDateTime
int DayOfYear()
int DayOfYearMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.day_of_year);
  }
DayOfYear
Returns the current day of the year (1 means 1 January,..,365(6) does 31 December), i.e., the day of year of the last known server time.
TimeCurrent, MqlDateTime
int Hour()
int HourMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.hour);
  }
Hour
Returns the hour (0,1,2,..23) of the last known server time by the moment of the program start (this value will not change within the time of the program execution).
TimeCurrent, MqlDateTime
int Minute()
int MinuteMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.min);
  }
Minute
Returns the current minute (0,1,2,..59) of the last known server time by the moment of the program start (this value will not change within the time of the program execution).
TimeCurrent, MqlDateTime
int Month()
int MonthMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.mon);
  }
Month
Returns the current month as number (1-January,2,3,4,5,6,7,8,9,10,11,12), i.e., the number of month of the last known server time.
TimeCurrent, MqlDateTime
int Seconds()
int SecondsMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.sec);
  }
Seconds
Returns the amount of seconds elapsed from the beginning of the current minute of the last known server time by the moment of the program start (this value will not change within the time of the program execution).
TimeCurrent, MqlDateTime
datetime TimeCurrent()
datetime TimeCurrent()
TimeCurrent
Returns the last known server time (time of incoming of the latest quote) as number of seconds elapsed from 00:00 January 1, 1970.
TimeCurrent
int TimeDay(datetime date)
int TimeDayMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.day);
  }
TimeDay
Returns day of month (1 - 31) for the specified date.
TimeToStruct, MqlDateTime
int TimeDayOfWeek(datetime date)
int TimeDayOfWeekMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.day_of_week);
  }
TimeDayOfWeek
Returns the zero-based day of week (0 means Sunday,1,2,3,4,5,6) for the specified date.
TimeToStruct, MqlDateTime
int TimeDayOfYear(datetime date)
int TimeDayOfYearMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.day_of_year);
  }
TimeDayOfYear
Returns day (1 means 1 January,..,365(6) does 31 December) of year for the specified date.
TimeToStruct, MqlDateTime
int TimeHour(datetime time)
int TimeHourMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.hour);
  }
TimeHour
Returns the hour for the specified time.
TimeToStruct, MqlDateTime
datetime TimeLocal()
datetime TimeLocal()
TimeLocal
Returns local computer time as number of seconds elapsed from 00:00 January 1, 1970.
TimeLocal
int TimeMinute(datetime time)
int TimeMinuteMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.min);
  }
TimeMinute
Returns the minute for the specified time.
TimeToStruct, MqlDateTime
int TimeMonth(datetime time)
int TimeMonthMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.mon);
  }
TimeMonth
Returns the month number for the specified time.
TimeToStruct, MqlDateTime
int TimeSeconds(datetime time)
int TimeSecondsMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.sec);
  }
TimeSeconds
Returns the amount of seconds elapsed from the beginning of the minute for the specified time.
TimeToStruct, MqlDateTime
int TimeYear(datetime time)
int TimeYearMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.year);
  }
TimeYear
Returns year for the specified date. The returned value can be within the range of 1970 to 2037.
TimeToStruct, MqlDateTime
int Year()
int YearMQL4()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.year);
  }
Year
Returns the current year, i.e., the year of the last known server time.
TimeCurrent, MqlDateTime


12. File Functions

MQL4
 MQL5 Description
void FileClose(int handle)
void FileClose(int file_handle)
FileClose
Closes file previously opened by the FileOpen() function.
FileClose
void FileDelete(string filename)
bool FileDelete(string file_name
                int common_flag=0)
FileDelete
Removes specified file name.
FileDelete
void FileFlush(int handle)
void FileFlush(int file_handle)
FileFlush
Flushes all data stored in the file buffer to the disk.
FileFlush
bool FileIsEnding(int handle)
bool FileIsEnding(int file_handle)
FileIsEnding
Returns logical true if file pointer is at the end of the file, otherwise returns false.
FileIsEnding
bool FileIsLineEnding(int handle)
bool FileIsLineEnding(int file_handle)
FileIsLineEnding
For CSV file returns logical true if file pointer is at the end of the line, otherwise returns false.
FileIsLineEnding
int FileOpen(string filename,
             int mode,
             int delimiter=';')
int FileOpen(string ile_name,
             int pen_flags,
             short delimiter='\t'
             uint codepage=CP_ACP)
FileOpen
Opens file for input and/or output. Returns a file handle for the opened file or -1 (if the function fails).
FileOpen
int FileOpenHistory(string filename,
                    int mode,
                    int delimiter=';')
-FileOpenHistory
Opens file in the current history directory (terminal_directory\history\server_name) or in its subfolders. Returns the file handle for the opened file. If the function fails, the returned value is -1.
int FileReadArray(int handle,
                  object &array[],
                  int start,
                  int count)
uint FileReadArray(int file_handle,
                   void array[],
                   int start_item=0,
                   int items_count=WHOLE_ARRAY)
FileReadArray
Reads the specified amount of elements from the binary file into array.
FileReadArray
double FileReadDouble(int handle,
                      int size=DOUBLE_VALUE)
double FileReadDoubleMQL4(int handle,
                          int size=DOUBLE_VALUE)
  {
   return(FileReadDouble(handle));
  }
FileReadDouble
Reads the double-precision number with floating point from the current binary file position.
FileReadDouble
int FileReadInteger(int handle,
                    int size=LONG_VALUE)
int FileReadInteger(int file_handle,
                    int size=INT_VALUE)
FileReadInteger
The function reads the integer from the current binary file position.
FileReadInteger
double FileReadNumber(int handle)
double FileReadNumber(int file_handle)
FileReadNumber
Read the number from the current file position before the delimiter. Only for CSV files.
FileReadNumber
string FileReadString(int handle,
                      int length=0)
string FileReadString(int file_handle,
                      int size=-1)
FileReadString
Функция читает строку с текущей позиции файла.
FileReadString
bool FileSeek(int handle,
              int offset,
              int origin)
bool FileSeekMQL4(long handle,
                  int offset,
                  ENUM_FILE_POSITION origin)
  {
   FileSeek(handle,offset,origin);
   return(true);
  }
FileSeek
The function moves the file pointer to a new position that is an offset, in bytes, from the beginning, the end or the current file position.
FileSeek
int FileSize(int handle)
ulong FileSize(int file_handle)
FileSize
The function returns file size in bytes.
FileSize
int FileTell(int handle)
ulong FileTell(int file_handle)
FileTell
Returns the current position of the file pointer.
FileTell
int FileWrite(int handle,...)
uint FileWrite(int file_handle,...)
FileWrite
The function is intended for writing of data into a CSV file, delimiter being inserted automatically.
FileWrite
int FileWriteArray(int handle,
                   object array[],
                   int start,
                   int count)
int FileWriteArray(int file_handle,
                   void array[],
                   int start_item=0,
                   int items_count=WHOLE_ARRAY)
FileWriteArray
The function writes the array to a binary file.
FileWriteArray
int FileWriteDouble(int handle,
                    double value,
                    int size=DOUBLE_VALUE)
uint FileWriteDouble(int file_handle,
                     double dvalue)
FileWriteDouble
The function writes a double value with floating point to a binary file.
FileWriteDouble
int FileWriteInteger(int handle,
                     int value,
                     int size=LONG_VALUE)
uint FileWriteInteger(int file_handle,
                      int ivalue,
                      int size=INT_VALUE)
FileWriteInteger
The function writes the integer value to a binary file.
FileWriteInteger
int FileWriteString(int handle,
                    string value,
                    int size)
uint FileWriteString(int file_handle,
                     string svalue,
                     int size=-1)
FileWriteString
The function writes the string to a binary file from the current file position.
FileWriteString


13. Global Variables

MQL4
MQL5
 Description
bool GlobalVariableCheck(string name)
bool GlobalVariableCheck(string name)
GlobalVariableCheck
Returns TRUE if the global variable exists, otherwise, returns FALSE.
GlobalVariableCheck
bool GlobalVariableDel(string name)
bool GlobalVariableDel(string name)
GlobalVariableDel
Deletes the global variable.
GlobalVariableDel
double GlobalVariableGet(string name)
double GlobalVariableGet(string name)
GlobalVariableGet
Returns the value of an existing global variable or 0 if an error occurs.
GlobalVariableGet
string GlobalVariableName(int index)
string GlobalVariableName(int index)
GlobalVariableName
The function returns the name of a global variable by its index in the list of global variables.
GlobalVariableName
datetime GlobalVariableSet(string name,
                           double value)
datetime GlobalVariableSet(string name,
                           double value)
GlobalVariableSet
Sets a new value of the global variable. If it does not exist, the system creates a new global variable.
GlobalVariableSet
bool GlobalVariableSetOnCondition(string name,
                                  double value,
                                  double check_value)
bool GlobalVariableSetOnCondition(string name,
                                  double value,
                                  double check_value)
GlobalVariableSetOnCondition
Sets the new value of the existing global variable if the current value equals to the third parameter check_value.
GlobalVariableSetOnCondition
int GlobalVariablesDeleteAll(string prefix_name=NULL)
int GlobalVariablesDeleteAll(string prefix_name=NULL
                             datetime limit_data=0)
GlobalVariablesDeleteAll
Deletes global variables.
GlobalVariablesDeleteAll
int GlobalVariablesTotal()
int GlobalVariablesTotal()
GlobalVariablesTotal
The function returns the total count of global variables.
GlobalVariablesTotal


14. Mathematical Functions

 MQL4MQL5
 Description
double MathAbs(double value)
double MathAbs(double value)
MathAbs
Returns the absolute value (modulus) of the specified numeric value.
MathAbs
double MathArccos(double x)
double MathArccos(double val)
MathArccos
The MathArccos function returns the arccosine of x within the range 0 to Pi (in radians).
MathArccos
double MathArcsin(double x)
double MathArcsin(double val)
MathArcsin
The MathArcsin function returns the arcsine of x in the range -Pi/2 to Pi/2 radians.
MathArcsin
double MathArctan(double x)
double MathArctan(double value)
MathArctan
The MathArctan returns the arctangent of x.
MathArctan
double MathCeil(double x)
double MathCeil(double val)
MathCeil
The MathCeil function returns a numeric value representing the smallest integer that exceeds or equals to x.
MathCeil
double MathCos(double value)
double MathCos(double value)
MathCos
Returns the cosine of the specified angle.
MathCos
double MathExp(double d)
double MathExp(double value)
MathExp
Returns the value of e raised to the power of d.
MathExp
double MathFloor(double x)
double MathFloor(double val)
MathFloor
The MathFloor function returns a numeric value representing the largest integer that is less than or equal to x.
MathFloor
double MathLog(double x)
double MathLog(double val)
MathLog
The MathLog function returns the natural logarithm of x if successful.
MathLog
double MathMax(double value1,
               double value2)
double MathMax(double value1,
               double value2)
MathMax
Returns the maximum value of two numeric values.
MathMax
double MathMin(double value1,
               double value2)
double MathMin(double value1,
               double value2)
MathMin
Returns the minimum value of two numeric values.
MathMin
double MathMod(double value1,
               double value2)
double MathMod(double value1,
               double value2)
MathMod
The function returns the floating-point remainder of division of two numbers.
MathMod
double MathPow(double base,
               double exponent)
double MathPow(double base,
               double exponent)
MathPow
Returns the value of the base expression raised to the specified power (exponent value).
MathPow
int MathRand()
int MathRand()
MathRand
The MathRand function returns a pseudorandom integer within the range of 0 to 32767.
MathRand
double MathRound(double value)
double MathRound(double value)
MathRound
Returns value rounded to the nearest integer of the specified numeric value.
MathRound
double MathSin(double value)
double MathSin(double value)
MathSin
Returns the sine of the specified angle.
MathSin
double MathSqrt(double x)
double MathSqrt(double value)
MathSqrt
The MathSqrt function returns the square root of x.
MathSqrt
void MathSrand(int seed)
void MathSrand(int seed)
MathSrand
The MathSrand() function sets the starting point for generating a series of pseudorandom integers.
MathSrand
double MathTan(double x)
double MathTan(double rad)
MathTan
MathTan returns the tangent of x.
MathTan


15. Object Functions

MQL4
 MQL5Description
bool ObjectCreate(string name,
                  int type,
                  int window,
                  datetime time1,
                  double price1,
                  datetime time2=0,
                  double price2=0,
                  datetime time3=0,
                  double price3=0)
bool ObjectCreateMQL4(string name,
                      ENUM_OBJECT type,
                      int window,
                      datetime time1,
                      double price1,
                      datetime time2=0,
                      double price2=0,
                      datetime time3=0,
                      double price3=0)
  {
   return(ObjectCreate(0,name,type,window,
          time1,price1,time2,price2,time3,price3));
  }
ObjectCreate
Creation of an object with the specified name, type and initial coordinates in the specified window.
ObjectCreate
bool ObjectDelete(string name)
bool ObjectDeleteMQL4(string name)
  {
   return(ObjectDelete(0,name));
  }
ObjectDelete
Deletes object having the specified name.
ObjectDelete
string ObjectDescription(string name)
string ObjectDescriptionMQL4(string name)
  {
   return(ObjectGetString(0,name,OBJPROP_TEXT));
  }
ObjectDescription
Return object description.
ObjectGetString
int ObjectFind(string name)
int ObjectFindMQL4(string name)
  {
   return(ObjectFind(0,name));
  }
ObjectFind
Search for an object having the specified name.
ObjectFind
double ObjectGet(string name,
                 int prop_id)
double ObjectGetMQL4(string name,
                     int index)
  {
   switch(index)
     {
      case OBJPROP_TIME1:
         return(ObjectGetInteger(0,name,OBJPROP_TIME));
      case OBJPROP_PRICE1:
         return(ObjectGetDouble(0,name,OBJPROP_PRICE));
      case OBJPROP_TIME2:
         return(ObjectGetInteger(0,name,OBJPROP_TIME,1));
      case OBJPROP_PRICE2:
         return(ObjectGetDouble(0,name,OBJPROP_PRICE,1));
      case OBJPROP_TIME3:
         return(ObjectGetInteger(0,name,OBJPROP_TIME,2));
      case OBJPROP_PRICE3:
         return(ObjectGetDouble(0,name,OBJPROP_PRICE,2));
      case OBJPROP_COLOR:
         return(ObjectGetInteger(0,name,OBJPROP_COLOR));
      case OBJPROP_STYLE:
         return(ObjectGetInteger(0,name,OBJPROP_STYLE));
      case OBJPROP_WIDTH:
         return(ObjectGetInteger(0,name,OBJPROP_WIDTH));
      case OBJPROP_BACK:
         return(ObjectGetInteger(0,name,OBJPROP_WIDTH));
      case OBJPROP_RAY:
         return(ObjectGetInteger(0,name,OBJPROP_RAY_RIGHT));
      case OBJPROP_ELLIPSE:
         return(ObjectGetInteger(0,name,OBJPROP_ELLIPSE));
      case OBJPROP_SCALE:
         return(ObjectGetDouble(0,name,OBJPROP_SCALE));
      case OBJPROP_ANGLE:
         return(ObjectGetDouble(0,name,OBJPROP_ANGLE));
      case OBJPROP_ARROWCODE:
         return(ObjectGetInteger(0,name,OBJPROP_ARROWCODE));
      case OBJPROP_TIMEFRAMES:
         return(ObjectGetInteger(0,name,OBJPROP_TIMEFRAMES));
      case OBJPROP_DEVIATION:
         return(ObjectGetDouble(0,name,OBJPROP_DEVIATION));
      case OBJPROP_FONTSIZE:
         return(ObjectGetInteger(0,name,OBJPROP_FONTSIZE));
      case OBJPROP_CORNER:
         return(ObjectGetInteger(0,name,OBJPROP_CORNER));
      case OBJPROP_XDISTANCE:
         return(ObjectGetInteger(0,name,OBJPROP_XDISTANCE));
      case OBJPROP_YDISTANCE:
         return(ObjectGetInteger(0,name,OBJPROP_YDISTANCE));
      case OBJPROP_FIBOLEVELS:
         return(ObjectGetInteger(0,name,OBJPROP_LEVELS));
      case OBJPROP_LEVELCOLOR:
         return(ObjectGetInteger(0,name,OBJPROP_LEVELCOLOR));
      case OBJPROP_LEVELSTYLE:
         return(ObjectGetInteger(0,name,OBJPROP_LEVELSTYLE));
      case OBJPROP_LEVELWIDTH:
         return(ObjectGetInteger(0,name,OBJPROP_LEVELWIDTH));
     }
  }
ObjectGet
The function returns the value of the specified object property.
ObjectGetInteger, ObjectGetDouble

string ObjectGetFiboDescription(string name,
                                int index)
string ObjectGetFiboDescriptionMQL4(string name,
                                    int index)
  {
   return(ObjectGetString(0,name,OBJPROP_LEVELTEXT,index));
  }
ObjectGetFiboDescription
The function returns the level description of a Fibonacci object.
ObjectGetString
int ObjectGetShiftByValue(string name,
                          double value)
int ObjectGetShiftByValueMQL4(string name,
                              double value)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
   datetime Arr[];
   int shift;
   MqlRates mql4[];
   if(ObjectGetTimeByValue(0,name,value)<0) return(-1);
   CopyRates(NULL,timeframe,0,1,mql4);
   if(CopyTime(NULL,timeframe,mql4[0].time,
      ObjectGetTimeByValue(0,name,value),Arr)>0)
      return(ArraySize(Arr)-1);
   else return(-1);
  }
ObjectGetShiftByValue
The function calculates and returns bar index (shift related to the current bar) for the given price.
MqlRates, ObjectGetTimeByValue, CopyRates, CopyTime, ArraySize
double ObjectGetValueByShift(string name,
                             int shift)
double ObjectGetValueByShiftMQL4(string name,
                                 int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
   MqlRates mql4[];
   CopyRates(NULL,timeframe,shift,1,mql4);
   return(ObjectGetValueByTime(0,name,mql4[0].time,0));
  }
ObjectGetValueByShift
The function calculates and returns the price value for the specified bar (shift related to the current bar).
MqlRates, CopyRates, ObjectGetValueByTime
bool ObjectMove(string name,
                int point,
                datetime time1,
                double price1)
bool ObjectMoveMQL4(string name,
                    int point,
                    datetime time1,
                    double price1)
  {
   return(ObjectMove(0,name,point,time1,price1));
  }
ObjectMove
The function moves an object coordinate in the chart. Objects can have from one to three coordinates depending on their types.
ObjectMove
string ObjectName(int index)
string ObjectNameMQL4(int index)
  {
   return(ObjectName(0,index));
  }
ObjectName
The function returns the object name by its index in the objects list.
ObjectName
int ObjectsDeleteAll(int window=EMPTY,
                     int type=EMPTY)
int ObjectsDeleteAllMQL4(int window=EMPTY,
                         int type=EMPTY)
  {
   return(ObjectsDeleteAll(0,window,type));
  }
ObjectsDeleteAll
Removes all objects of the specified type and in the specified sub-window of the chart.
ObjectsDeleteAll
bool ObjectSet(string name,
               int prop_id,
               double value)
bool ObjectSetMQL4(string name,
                   int index,
                   double value)
  {
   switch(index)
     {
      case OBJPROP_TIME1:
         ObjectSetInteger(0,name,OBJPROP_TIME,(int)value);return(true);
      case OBJPROP_PRICE1:
         ObjectSetDouble(0,name,OBJPROP_PRICE,value);return(true);
      case OBJPROP_TIME2:
         ObjectSetInteger(0,name,OBJPROP_TIME,1,(int)value);return(true);
      case OBJPROP_PRICE2:
         ObjectSetDouble(0,name,OBJPROP_PRICE,1,value);return(true);
      case OBJPROP_TIME3:
         ObjectSetInteger(0,name,OBJPROP_TIME,2,(int)value);return(true);
      case OBJPROP_PRICE3:
         ObjectSetDouble(0,name,OBJPROP_PRICE,2,value);return(true);
      case OBJPROP_COLOR:
         ObjectSetInteger(0,name,OBJPROP_COLOR,(int)value);return(true);
      case OBJPROP_STYLE:
         ObjectSetInteger(0,name,OBJPROP_STYLE,(int)value);return(true);
      case OBJPROP_WIDTH:
         ObjectSetInteger(0,name,OBJPROP_WIDTH,(int)value);return(true);
      case OBJPROP_BACK:
         ObjectSetInteger(0,name,OBJPROP_BACK,(int)value);return(true);
      case OBJPROP_RAY:
         ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,(int)value);return(true);
      case OBJPROP_ELLIPSE:
         ObjectSetInteger(0,name,OBJPROP_ELLIPSE,(int)value);return(true);
      case OBJPROP_SCALE:
         ObjectSetDouble(0,name,OBJPROP_SCALE,value);return(true);
      case OBJPROP_ANGLE:
         ObjectSetDouble(0,name,OBJPROP_ANGLE,value);return(true);
      case OBJPROP_ARROWCODE:
         ObjectSetInteger(0,name,OBJPROP_ARROWCODE,(int)value);return(true);
      case OBJPROP_TIMEFRAMES:
         ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,(int)value);return(true);
      case OBJPROP_DEVIATION:
         ObjectSetDouble(0,name,OBJPROP_DEVIATION,value);return(true);
      case OBJPROP_FONTSIZE:
         ObjectSetInteger(0,name,OBJPROP_FONTSIZE,(int)value);return(true);
      case OBJPROP_CORNER:
         ObjectSetInteger(0,name,OBJPROP_CORNER,(int)value);return(true);
      case OBJPROP_XDISTANCE:
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,(int)value);return(true);
      case OBJPROP_YDISTANCE:
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,(int)value);return(true);
      case OBJPROP_FIBOLEVELS:
         ObjectSetInteger(0,name,OBJPROP_LEVELS,(int)value);return(true);
      case OBJPROP_LEVELCOLOR:
         ObjectSetInteger(0,name,OBJPROP_LEVELCOLOR,(int)value);return(true);
      case OBJPROP_LEVELSTYLE:
         ObjectSetInteger(0,name,OBJPROP_LEVELSTYLE,(int)value);return(true);
      case OBJPROP_LEVELWIDTH:
         ObjectSetInteger(0,name,OBJPROP_LEVELWIDTH,(int)value);return(true);

      default: return(false);
     }
   return(false);
  }
ObjectSet
Changes the value of the specified object property.
ObjectSetInteger, ObjectSetDouble
bool ObjectSetFiboDescription(string name,
                              int index,
                              string text)
bool ObjectSetFiboDescriptionMQL4(string name,
                                  int index,
                                  string text)
  {
   return(ObjectSetString(0,name,OBJPROP_LEVELTEXT,index,text));
  }
ObjectSetFiboDescription
The function assigns a new description to a level of a Fibonacci object.
ObjectSetString
bool ObjectSetText(string name,
                   string text,
                   int font_size,
                   string font_name=NULL,
                   color text_color=CLR_NONE)
bool ObjectSetTextMQL4(string name,
                       string text,
                       int font_size,
                       string font="",
                       color text_color=CLR_NONE)
  {
   int tmpObjType=(int)ObjectGetInteger(0,name,OBJPROP_TYPE);
   if(tmpObjType!=OBJ_LABEL && tmpObjType!=OBJ_TEXT) return(false);
   if(StringLen(text)>0 && font_size>0)
     {
      if(ObjectSetString(0,name,OBJPROP_TEXT,text)==true
         && ObjectSetInteger(0,name,OBJPROP_FONTSIZE,font_size)==true)
        {
         if((StringLen(font)>0)
            && ObjectSetString(0,name,OBJPROP_FONT,font)==false)
            return(false);
         if(text_color>-1
            && ObjectSetInteger(0,name,OBJPROP_COLOR,text_color)==false)
            return(false);
         return(true);
        }
      return(false);
     }
   return(false);
  }
ObjectSetText
Changes the object description.
ObjectGetInteger, ObjectSetString, ObjectSetInteger StringLen
int ObjectsTotal(int type=EMPTY)
int ObjectsTotalMQL4(int type=EMPTY,
                     int window=-1)
  {
   return(ObjectsTotal(0,window,type));
  }
ObjectsTotal
Returns total amount of objects of the specified type in the chart.
ObjectsTotal
int ObjectType(string name)
int ObjectTypeMQL4(string name)
  {
   return((int)ObjectGetInteger(0,name,OBJPROP_TYPE));
  }
ObjectType
The function returns the object type value.
ObjectGetInteger


16. String Functions

MQL4
MQL5
 Description
string StringConcatenate(...)
int StringConcatenate(string &string_var,
                      void argument1
                      void argument2
                      ...)
StringConcatenate
Forms a string of the data passed and returns it.
StringConcatenate
int StringFind(string text,
               string matched_text,
               int start=0)
int StringFind(string string_value,
               string match_substring,
               int start_pos=0)
StringFind
Search for a substring. Returns the position in the string from which the searched substring begins, or -1 if the substring has not been found.
StringFind
int StringGetChar(string text,
                  int pos)
ushort StringGetCharacter(string string_value,
                          int pos)
StringGetChar
Returns character (code) from the specified position in the string.
StringGetCharacter
int StringLen(string text)
int StringLen(string string_value)
StringLen
Returns character count in a string.
StringLen
string StringSetChar(string text,
                     int pos,
                     int value)
bool StringSetCharacter(string &string_var,
                        int pos,
                        ushort character)
StringSetChar
Returns the string copy with changed character in the specified position.
StringSetCharacter
string StringSubstr(string text,
                    int start,
                    int length=0)
string StringSubstr(string string_value,
                    int start_pos,
                    int length=-1)
StringSubstr
Extracts a substring from text string starting from the given position.
StringSubstr
string StringTrimLeft(string text)
int StringTrimLeft(string& string_var)
StringTrimLeft
The function cuts line feed characters, spaces and tabs in the left part of the string.
StringTrimLeft
string StringTrimRight(string text)
int StringTrimRight(string& string_var)
StringTrimRight
The function cuts line feed characters, spaces and tabs in the right part of the string.
StringTrimRight


17. Technical Indicators

The principles of use of the technical indicators in Expert Advisors are considered in the article MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors. The method, used in this reference is sufficient to get the indicator calculation results for the specified price. To use this method, we need the auxiliary function:

double CopyBufferMQL4(int handle,int index,int shift)
  {
   double buf[];
   switch(index)
     {
      case 0: if(CopyBuffer(handle,0,shift,1,buf)>0)
         return(buf[0]); break;
      case 1: if(CopyBuffer(handle,1,shift,1,buf)>0)
         return(buf[0]); break;
      case 2: if(CopyBuffer(handle,2,shift,1,buf)>0)
         return(buf[0]); break;
      case 3: if(CopyBuffer(handle,3,shift,1,buf)>0)
         return(buf[0]); break;
      case 4: if(CopyBuffer(handle,4,shift,1,buf)>0)
         return(buf[0]); break;
      default: break;
     }
   return(EMPTY_VALUE);
  }
let's declare the following constants:
ENUM_MA_METHOD MethodMigrate(int method)
  {
   switch(method)
     {
      case 0: return(MODE_SMA);
      case 1: return(MODE_EMA);
      case 2: return(MODE_SMMA);
      case 3: return(MODE_LWMA);
      default: return(MODE_SMA);
     }
  }
ENUM_APPLIED_PRICE PriceMigrate(int price)
  {
   switch(price)
     {
      case 1: return(PRICE_CLOSE);
      case 2: return(PRICE_OPEN);
      case 3: return(PRICE_HIGH);
      case 4: return(PRICE_LOW);
      case 5: return(PRICE_MEDIAN);
      case 6: return(PRICE_TYPICAL);
      case 7: return(PRICE_WEIGHTED);
      default: return(PRICE_CLOSE);
     }
  }
ENUM_STO_PRICE StoFieldMigrate(int field)
  {
   switch(field)
     {
      case 0: return(STO_LOWHIGH);
      case 1: return(STO_CLOSECLOSE);
      default: return(STO_LOWHIGH);
     }
  }
//+------------------------------------------------------------------+
enum ALLIGATOR_MODE  { MODE_GATORJAW=1,   MODE_GATORTEETH, MODE_GATORLIPS };
enum ADX_MODE        { MODE_MAIN,         MODE_PLUSDI, MODE_MINUSDI };
enum UP_LOW_MODE     { MODE_BASE,         MODE_UPPER,      MODE_LOWER };
enum ICHIMOKU_MODE   { MODE_TENKANSEN=1,  MODE_KIJUNSEN, MODE_SENKOUSPANA, MODE_SENKOUSPANB, MODE_CHINKOUSPAN };
enum MAIN_SIGNAL_MODE{ MODE_MAIN,         MODE_SIGNAL };
MQL4
 MQL5 Decsription
double iAC(string symbol,
           int timeframe,
           int shift)
double iACMQL4(string symbol,
               int tf,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iAC(symbol,timeframe);
   if(handle<0)
     {
      Print("The iAC object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iAC
Calculates the Bill Williams' Accelerator/Decelerator oscillator.
iAC
double iAD(string symbol,
           int timeframe,
           int shift)
double iADMQL4(string symbol,
               int tf,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=(int)iAD(symbol,timeframe,VOLUME_TICK);
   if(handle<0)
     {
      Print("The iAD object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iAD
Calculates the Accumulation/Distribution indicator and returns its value.
iAD
double iAlligator(string symbol,
                  int timeframe,
                  int jaw_period,
                  int jaw_shift,
                  int teeth_period,
                  int teeth_shift,
                  int lips_period,
                  int lips_shift,
                  int ma_method,
                  int applied_price,
                  int mode,
                  int shift)
double iAlligatorMQL4(string symbol,
                      int tf,
                      int jaw_period,
                      int jaw_shift,
                      int teeth_period,
                      int teeth_shift,
                      int lips_period,
                      int lips_shift,
                      int method,
                      int price,
                      int mode,
                      int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iAlligator(symbol,timeframe,jaw_period,jaw_shift,
                         teeth_period,teeth_shift,
                         lips_period,lips_shift,
                         ma_method,applied_price);
   if(handle<0)
     {
      Print("The iAlligator object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
iAlligator
Calculates the Bill Williams' Alligator and returns its value.
iAlligator
double iADX(string symbol,
            int timeframe,
            int period,
            int applied_price,
            int mode,
            int shift)
double iADXMQL4(string symbol,
                int tf,
                int period,
                int price,
                int mode,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iADX(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iADX object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }
iADX
Calculates the Movement directional index and returns its value.
iADX
double iATR(string symbol,
            int timeframe,
            int period,
            int shift)
double iATRMQL4(string symbol,
                int tf,
                int period,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iATR(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iATR object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iATR
Calculates the Indicator of the average true range and returns its value.
iATR
double iAO(string symbol,
           int timeframe,
           int shift)
double iAOMQL4(string symbol,
               int tf,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iAO(symbol,timeframe);
   if(handle<0)
     {
      Print("The iAO object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iAO
Calculates the Bill Williams' Awesome oscillator and returns its value.
iAO
double iBearsPower(string symbol,
                   int timeframe,
                   int period,
                   int applied_price,
                   int shift)
double iBearsPowerMQL4(string symbol,
                       int tf,
                       int period,
                       int price,
                       int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iBearsPower(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iBearsPower object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iBearsPower
Calculates the Bears Power indicator and returns its value.
iBearsPower
double iBands(string symbol,
              int timeframe,
              int period,
              int deviation,
              int bands_shift,
              int applied_price,
              int mode,
              int shift)
double iBandsMQL4(string symbol,
                  int tf,
                  int period,
                  double deviation,
                  int bands_shift,
                  int method,
                  int mode,
                  int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   int handle=iBands(symbol,timeframe,period,
                     bands_shift,deviation,ma_method);
   if(handle<0)
     {
      Print("The iBands object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }
iBands
Calculates the Bollinger bands indicator and returns its value.
iBands
double iBandsOnArray(double array[],
                     int total,
                     int period,
                     int deviation,
                     int bands_shift,
                     int mode,
                     int shift)
-iBandsOnArray
Calculation of the Bollinger Bands indicator on data stored in a numeric array.
double iBullsPower(string symbol,
                   int timeframe,
                   int period,
                   int applied_price,
                   int shift)
double iBullsPowerMQL4(string symbol,
                       int tf,
                       int period,
                       int price,
                       int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iBullsPower(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iBullsPower object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iBullsPower
Calculates the Bulls Power indicator and returns its value.
iBullsPower
double iCCI(string symbol,
            int timeframe,
            int period,
            int applied_price,
            int shift)
double iCCIMQL4(string symbol,
                int tf,
                int period,
                int price,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iCCI(symbol,timeframe,period,price);
   if(handle<0)
     {
      Print("The iCCI object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iCCI
Calculates the Commodity channel index and returns its value.
iCCI
double iCCIOnArray(double array[],
                   int total,
                   int period,
                   int shift)
-iCCIOnArray
Calculation of the Commodity Channel Index on data stored in a numeric array.
double iCustom(string symbol,
               int timeframe,
               string name,
               ...,
               int mode,
               int shift)
int iCustom(string symbol,
            ENUM_TIMEFRAMES period,
            string name
            ...)
iCustom
Calculates the specified custom indicator and returns its value.
iCustom
double iDeMarker(string symbol,
                 int timeframe,
                 int period,
                 int shift)
double iDeMarkerMQL4(string symbol,
                     int tf,
                     int period,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iDeMarker(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iDeMarker object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iDeMarker
Calculates the DeMarker indicator and returns its value.
iDeMarker
double iEnvelopes(string symbol,
                  int timeframe,
                  int ma_period,
                  int ma_method,
                  int ma_shift,
                  int applied_price,
                  double deviation,
                  int mode,
                  int shift)
double EnvelopesMQL4(string symbol,
                     int tf,
                     int ma_period,
                     int method,
                     int ma_shift,
                     int price,
                     double deviation,
                     int mode,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iEnvelopes(symbol,timeframe,
                         ma_period,ma_shift,ma_method,
                         applied_price,deviation);
   if(handle<0)
     {
      Print("The iEnvelopes object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
iEnvelopes
Calculates the Envelopes indicator and returns its value.
iEnvelopes
double iEnvelopesOnArray(double array[],
                         int total,
                         int ma_period,
                         int ma_method,
                         int ma_shift,
                         double deviation,
                         int mode,
                         int shift)
-iEnvelopesOnArray
Calculation of the Envelopes indicator on data stored in a numeric array.
double iForce(string symbol,
              int timeframe,
              int period,
              int ma_method,
              int applied_price,
              int shift)
double iForceMQL4(string symbol,
                  int tf,
                  int period,
                  int method,
                  int price,
                  int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   int handle=iForce(symbol,timeframe,period,ma_method,VOLUME_TICK);
   if(handle<0)
     {
      Print("The iForce object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iForce
Calculates the Force index and returns its value.
iForce
double iFractals(string symbol,
                 int timeframe,
                 int mode,
                 int shift)
double iFractalsMQL4(string symbol,
                     int tf,
                     int mode,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iFractals(symbol,timeframe);
   if(handle<0)
     {
      Print("The iFractals object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
iFractals
Calculates the Fractals and returns its value.
iFractals
double iGator(string symbol,
              int timeframe,
              int jaw_period,
              int jaw_shift,
              int teeth_period,
              int teeth_shift,
              int lips_period,
              int lips_shift,
              int ma_method,
              int applied_price,
              int mode,
              int shift)
double iGatorMQL4(string symbol,
                  int tf,
                  int jaw_period,
                  int jaw_shift,
                  int teeth_period,
                  int teeth_shift,
                  int lips_period,
                  int lips_shift,
                  int method,
                  int price,
                  int mode,
                  int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iGator(symbol,timeframe,jaw_period,jaw_shift,
                     teeth_period,teeth_shift,
                     lips_period,lips_shift,
                     ma_method,applied_price);
   if(handle<0)
     {
      Print("The iGator object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
iGator
Gator oscillator calculation.
iGator
double iIchimoku(string symbol,
                 int timeframe,
                 int tenkan_sen,
                 int kijun_sen,
                 int senkou_span_b,
                 int mode,
                 int shift)
double iIchimokuMQL4(string symbol,
                     int tf,
                     int tenkan_sen,
                     int kijun_sen,
                     int senkou_span_b,
                     int mode,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iIchimoku(symbol,timeframe,
                        tenkan_sen,kijun_sen,senkou_span_b);
   if(handle<0)
     {
      Print("The iIchimoku object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
iIchimoku
Calculates the Ichimoku Kinko Hyo and returns its value.
iIchimoku
double iBWMFI(string symbol,
              int timeframe,
              int shift)
double iBWMFIMQL4(string symbol,
                  int tf,
                  int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=(int)iBWMFI(symbol,timeframe,VOLUME_TICK);
   if(handle<0)
     {
      Print("The iBWMFI object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iBWMFI
Calculates the Bill Williams Market Facilitation index and returns its value.
iBWMFI
double iMomentum(string symbol,
                 int timeframe,
                 int period,
                 int applied_price,
                 int shift)
double iMomentumMQL4(string symbol,
                     int tf,
                     int period,
                     int price,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iMomentum(symbol,timeframe,period,applied_price);
   if(handle<0)
     {
      Print("The iMomentum object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iMomentum
Calculates the Momentum indicator and returns its value.
iMomentum
double iMomentumOnArray(double array[],
                        int total,
                        int period,
                        int shift)
-iMomentumOnArray
Calculation of the Momentum indicator on data stored in a numeric array.
double iMFI(string symbol,
            int timeframe,
            int period,
            int shift)
double iMFIMQL4(string symbol,
                int tf,
                int period,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=(int)iMFI(symbol,timeframe,period,VOLUME_TICK);
   if(handle<0)
     {
      Print("The iMFI object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iMFI
Calculates the Money flow index and returns its value.
iMFI
double iMA(string symbol,
           int timeframe,
           int period,
           int ma_shift,
           int ma_method,
           int applied_price,
           int shift)
double iMAMQL4(string symbol,
               int tf,
               int period,
               int ma_shift,
               int method,
               int price,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iMA(symbol,timeframe,period,ma_shift,
                  ma_method,applied_price);
   if(handle<0)
     {
      Print("The iMA object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iMA
Calculates the Moving average indicator and returns its value.
iMA
double iMAOnArray(double array[],
                  int total,
                  int period,
                  int ma_shift,
                  int ma_method,
                  int shift)
double iMAOnArrayMQL4(double &array[],
                      int total,
                      int period,
                      int ma_shift,
                      int ma_method,
                      int shift)
  {
   double buf[],arr[];
   if(total==0) total=ArraySize(array);
   if(total>0 && total<=period) return(0);
   if(shift>total-period-ma_shift) return(0);
   switch(ma_method)
     {
      case MODE_SMA :
        {
         total=ArrayCopy(arr,array,0,shift+ma_shift,period);
         if(ArrayResize(buf,total)<0) return(0);
         double sum=0;
         int    i,pos=total-1;
         for(i=1;i<period;i++,pos--)
            sum+=arr[pos];
         while(pos>=0)
           {
            sum+=arr[pos];
            buf[pos]=sum/period;
            sum-=arr[pos+period-1];
            pos--;
           }
         return(buf[0]);
        }
      case MODE_EMA :
        {
         if(ArrayResize(buf,total)<0) return(0);
         double pr=2.0/(period+1);
         int    pos=total-2;
         while(pos>=0)
           {
            if(pos==total-2) buf[pos+1]=array[pos+1];
            buf[pos]=array[pos]*pr+buf[pos+1]*(1-pr);
            pos--;
           }
         return(buf[shift+ma_shift]);
        }
      case MODE_SMMA :
        {
         if(ArrayResize(buf,total)<0) return(0);
         double sum=0;
         int    i,k,pos;
         pos=total-period;
         while(pos>=0)
           {
            if(pos==total-period)
              {
               for(i=0,k=pos;i<period;i++,k++)
                 {
                  sum+=array[k];
                  buf[k]=0;
                 }
              }
            else sum=buf[pos+1]*(period-1)+array[pos];
            buf[pos]=sum/period;
            pos--;
           }
         return(buf[shift+ma_shift]);
        }
      case MODE_LWMA :
        {
         if(ArrayResize(buf,total)<0) return(0);
         double sum=0.0,lsum=0.0;
         double price;
         int    i,weight=0,pos=total-1;
         for(i=1;i<=period;i++,pos--)
           {
            price=array[pos];
            sum+=price*i;
            lsum+=price;
            weight+=i;
           }
         pos++;
         i=pos+period;
         while(pos>=0)
           {
            buf[pos]=sum/weight;
            if(pos==0) break;
            pos--;
            i--;
            price=array[pos];
            sum=sum-lsum+price*period;
            lsum-=array[i];
            lsum+=price;
           }
         return(buf[shift+ma_shift]);
        }
      default: return(0);
     }
   return(0);
  }

double iOsMA(string symbol,
             int timeframe,
             int fast_ema_period,
             int slow_ema_period,
             int signal_period,
             int applied_price,
             int shift)
double iOsMAMQL4(string symbol,
                 int tf,
                 int fast_ema_period,
                 int slow_ema_period,
                 int signal_period,
                 int price,
                 int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iOsMA(symbol,timeframe,
                    fast_ema_period,slow_ema_period,
                    signal_period,applied_price);
   if(handle<0)
     {
      Print("The iOsMA object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iOsMA
Calculates the Moving Average of Oscillator and returns its value.
iOsMA
double iMACD(string symbol,
             int timeframe,
             int fast_ema_period,
             int slow_ema_period,
             int signal_period,
             int applied_price,
             int mode,
             int shift)
double iMACDMQL4(string symbol,
                 int tf,
                 int fast_ema_period,
                 int slow_ema_period,
                 int signal_period,
                 int price,
                 int mode,
                 int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iMACD(symbol,timeframe,
                    fast_ema_period,slow_ema_period,
                    signal_period,applied_price);
   if(handle<0)
     {
      Print("The iMACD object is not created: Error ",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }
iMACD
Calculates the Moving averages convergence/divergence and returns its value.
iMACD
double iOBV(string symbol,
            int timeframe,
            int applied_price,
            int shift)
double iOBVMQL4(string symbol,
                int tf,
                int price,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iOBV(symbol,timeframe,VOLUME_TICK);
   if(handle<0)
     {
      Print("The iOBV object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iOBV
Calculates the On Balance Volume indicator and returns its value.
iOBV
double iSAR(string symbol,
            int timeframe,
            double step,
            double maximum,
            int shift)
double iSARMQL4(string symbol,
                int tf,
                double step,
                double maximum,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iSAR(symbol,timeframe,step,maximum);
   if(handle<0)
     {
      Print("The iSAR object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iSAR
Calculates the Parabolic Stop and Reverse system and returns its value.
iSAR
double iRSI(string symbol,
            int timeframe,
            int period,
            int applied_price,
            int shift)
double iRSIMQL4(string symbol,
                int tf,
                int period,
                int price,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iRSI(symbol,timeframe,period,applied_price);
   if(handle<0)
     {
      Print("The iRSI object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iRSI
Calculates the Relative strength index and returns its value.
iRSI
double iRSIOnArray(double array[],
                   int total,
                   int period,
                   int shift)
-iRSIOnArray
Calculation of the Relative Strength Index on data stored in a numeric array.
double iRVI(string symbol,
            int timeframe,
            int period,
            int mode,
            int shift)
double iRVIMQL4(string symbol,
                int tf,
                int period,
                int mode,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iRVI(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iRVI object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }
iRVI
Calculates the Relative Vigor index and returns its value.
iRVI
double iStdDev(string symbol,
               int timeframe,
               int ma_period,
               int ma_shift,
               int ma_method,
               int applied_price,
               int shift)
double iStdDevMQL4(string symbol,
                   int tf,
                   int ma_period,
                   int ma_shift,
                   int method,
                   int price,
                   int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iStdDev(symbol,timeframe,ma_period,ma_shift,
                      ma_method,applied_price);
   if(handle<0)
     {
      Print("The iStdDev object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iStdDev
Calculates the Standard Deviation indicator and returns its value.
iStdDev
double iStdDevOnArray(double array[],
                      int total,
                      int ma_period,
                      int ma_shift,
                      int ma_method,
                      int shift)
-iStdDevOnArray
Calculation of the Standard Deviation indicator on data stored in a numeric array.
double iStochastic(string symbol,
                   int timeframe,
                   int%Kperiod,
                   int%Dperiod,
                   int slowing,
                   int method,
                   int price_field,
                   int mode,
                   int shift)
double iStochasticMQL4(string symbol,
                       int tf,
                       int Kperiod,
                       int Dperiod,
                       int slowing,
                       int method,
                       int field,
                       int mode,
                       int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_STO_PRICE price_field=StoFieldMigrate(field);
   int handle=iStochastic(symbol,timeframe,Kperiod,Dperiod,
                          slowing,ma_method,price_field);
   if(handle<0)
     {
      Print("The iStochastic object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }
iStochastic
Calculates the Stochastic oscillator and returns its value.
iStochastic
double iWPR(string symbol,
            int timeframe,
            int period,
            int shift)
double iWPRMQL4(string symbol,
                int tf,
                int period,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iWPR(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iWPR object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
iWPR
Calculates the Larry William's percent range indicator and returns its value.
iWPR


18. Timeseries Access

MQL4
 MQL5 Description
int iBars(string symbol,
          int timeframe)
int iBarsMQL4(string symbol,int tf)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   return(Bars(symbol,timeframe));
  }
int iBarsMQL4(string symbol,int tf)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   return(Bars(symbol,timeframe));
  }
Bars

Returns the number of bars on the specified chart.
Bars
int iBarShift(string symbol,
              int timeframe,
              datetime time,
              bool exact=false
int iBarShiftMQL4(string symbol,
                  int tf,
                  datetime time,
                  bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
     {
      if(ArraySize(Arr)>2) return(ArraySize(Arr)-1);
      if(time<time1) return(1);
      else return(0);
     }
   else return(-1);
  }
iBarShift
Search for bar by open time.
CopyTime, ArraySize
double iClose(string symbol,
              int timeframe,
              int shift)
double iCloseMQL4(string symbol,int tf,int index)
{
   if(index < 0) return(-1);
   double Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyClose(symbol,timeframe, index, 1, Arr)>0) 
        return(Arr[0]);
   else return(-1);
}
Close
Returns Close value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.
CopyRates, MqlRates
double iHigh(string symbol,
             int timeframe,
             int shift)
double iHighMQL4(string symbol,int tf,int index)

{
   if(index < 0) return(-1);
   double Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyHigh(symbol,timeframe, index, 1, Arr)>0) 
        return(Arr[0]);
   else return(-1);
}
High
Returns High value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.
CopyRates, MqlRates
int iHighest(string symbol,
             int timeframe,
             int type,
             int count=WHOLE_ARRAY,
             int start=0)
int iHighestMQL4(string symbol,
                 int tf,
                 int type,
                 int count=WHOLE_ARRAY,
                 int start=0)
  {
   if(start<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(count<=0) count=Bars(symbol,timeframe);
   if(type<=MODE_OPEN)
     {
      double Open[];
      ArraySetAsSeries(Open,true);
      CopyOpen(symbol,timeframe,start,count,Open);
      return(ArrayMaximum(Open,0,count)+start);
     }
   if(type==MODE_LOW)
     {
      double Low[];
      ArraySetAsSeries(Low,true);
      CopyLow(symbol,timeframe,start,count,Low);
      return(ArrayMaximum(Low,0,count)+start);
     }
   if(type==MODE_HIGH)
     {
      double High[];
      ArraySetAsSeries(High,true);
      CopyHigh(symbol,timeframe,start,count,High);
      return(ArrayMaximum(High,0,count)+start);
     }
   if(type==MODE_CLOSE)
     {
      double Close[];
      ArraySetAsSeries(Close,true);
      CopyClose(symbol,timeframe,start,count,Close);
      return(ArrayMaximum(Close,0,count)+start);
     }
   if(type==MODE_VOLUME)
     {
      long Volume[];
      ArraySetAsSeries(Volume,true);
      CopyTickVolume(symbol,timeframe,start,count,Volume);
      return(ArrayMaximum(Volume,0,count)+start);
     }
   if(type>=MODE_TIME)
     {
      datetime Time[];
      ArraySetAsSeries(Time,true);
      CopyTime(symbol,timeframe,start,count,Time);
      return(ArrayMaximum(Time,0,count)+start);
      //---
     }
   return(0);
  }

iHighest
Returns the shift of the maximum value over a specific number of periods depending on type.
CopyOpen, CopyLow, CopyHigh, CopyClose, CopyTickVolume, CopyTime, ArrayMaximum
double iLow(string symbol,
            int timeframe,
            int shift)
double iLowMQL4(string symbol,int tf,int index)

{
   if(index < 0) return(-1);
   double Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyLow(symbol,timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}
iLow
Returns Low value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.
CopyRates, MqlRates
int iLowest(string symbol,
            int timeframe,
            int type,
            int count=WHOLE_ARRAY,
            int start=0)
int iLowestMQL4(string symbol,
                int tf,
                int type,
                int count=WHOLE_ARRAY,
                int start=0)
  {
   if(start<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(count<=0) count=Bars(symbol,timeframe);
   if(type<=MODE_OPEN)
     {
      double Open[];
      ArraySetAsSeries(Open,true);
      CopyOpen(symbol,timeframe,start,count,Open);
      return(ArrayMinimum(Open,0,count)+start);
     }
   if(type==MODE_LOW)
     {
      double Low[];
      ArraySetAsSeries(Low,true);
      CopyLow(symbol,timeframe,start,count,Low);
      return(ArrayMinimum(Low,0,count)+start);
     }
   if(type==MODE_HIGH)
     {
      double High[];
      ArraySetAsSeries(High,true);
      CopyHigh(symbol,timeframe,start,count,High);
      return(ArrayMinimum(High,0,count)+start);
     }
   if(type==MODE_CLOSE)
     {
      double Close[];
      ArraySetAsSeries(Close,true);
      CopyClose(symbol,timeframe,start,count,Close);
      return(ArrayMinimum(Close,0,count)+start);
     }
   if(type==MODE_VOLUME)
     {
      long Volume[];
      ArraySetAsSeries(Volume,true);
      CopyTickVolume(symbol,timeframe,start,count,Volume);
      return(ArrayMinimum(Volume,0,count)+start);
     }
   if(type>=MODE_TIME)
     {
      datetime Time[];
      ArraySetAsSeries(Time,true);
      CopyTime(symbol,timeframe,start,count,Time);
      return(ArrayMinimum(Time,0,count)+start);
     }
//---
   return(0);
  }

iLowest
Returns the shift of the lowest value over a specific number of periods depending on type.
CopyOpen, CopyLow, CopyHigh, CopyClose, CopyTickVolume, CopyTimeArrayMinimum
double iOpen(string symbol,
             int timeframe,
             int shift)
double iOpenMQL4(string symbol,int tf,int index)

{   
   if(index < 0) return(-1);
   double Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyOpen(symbol,timeframe, index, 1, Arr)>0) 
        return(Arr[0]);
   else return(-1);
}
iOpen
Returns Open value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.
CopyRates, MqlRates
datetime iTime(string symbol,
               int timeframe,
               int shift)
datetime iTimeMQL4(string symbol,int tf,int index)

{
   if(index < 0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[];
   if(CopyTime(symbol, timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}
iTime
Returns Time value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.
CopyRates, MqlRates
double iVolume(string symbol,
               int timeframe,
               int shift)
int iVolumeMQL4(string symbol,int tf,int index)

{
   if(index < 0) return(-1);
   long Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyTickVolume(symbol, timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}
iVolume
Returns Tick Volume value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.
CopyRates, MqlRates


19. Chart Operations

MQL4
 MQL5Description
void HideTestIndicators(bool hide)
-HideTestIndicators
The function sets a flag hiding indicators called by the Expert Advisor.
int Period()
ENUM_TIMEFRAMES  Period()
Period
Returns the amount of minutes determining the used period (chart timeframe).
Period
bool RefreshRates()
-RefreshRates
Refreshing of data in pre-defined variables and series arrays.
string Symbol()
string Symbol()
Symbol
Returns a text string with the name of the current financial instrument.
Symbol
int WindowBarsPerChart()
int ChartGetInteger(0,CHART_VISIBLE_BARS,0)
WindowBarsPerChart
Function returns the amount of bars visible on the chart.
ChartGetInteger
string WindowExpertName()
string MQLInfoString(MQL5_PROGRAM_NAME)
WindowExpertName
Returns name of the executed expert, script, custom indicator, or library, depending on the MQL4 program, from which this function has been called.
MQLInfoString

int WindowFind(string name)
int WindowFindMQL4(string name)
  {
   int window=-1;
   if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
     }
   else
     {
      window=ChartWindowFind(0,name);
      if(window==-1) Print(__FUNCTION__+"(): Error = ",GetLastError());
     }
   return(window);
  }
WindowFind
If indicator with name was found, the function returns the window index containing this specified indicator, otherwise it returns -1.
ChartWindowFind, MQLInfoInteger
int WindowFirstVisibleBar()
int ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0)
WindowFirstVisibleBar
The function returns the first visible bar number in the current chart window.
ChartGetInteger
int WindowHandle(string symbol,
                 int timeframe)
int WindowHandleMQL4(string symbol,
                     int tf)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   while(i<limit)
     {
      currChart=ChartNext(prevChart);
      if(currChart<0) break;
      if(ChartSymbol(currChart)==symbol
         && ChartPeriod(currChart)==timeframe)
         return((int)currChart);
      prevChart=currChart;
      i++;
     }
   return(0);
  }
WindowHandle
Returns the system window handle of the specified chart.
ChartFirst, ChartNext, ChartSymbol, ChartPeriod
bool WindowIsVisible(int index)
bool ChartGetInteger(0,CHART_WINDOW_IS_VISIBLE,index)
WindowIsVisible
Returns TRUE if the chart subwindow is visible, otherwise returns FALSE.
ChartGetInteger
int WindowOnDropped()
int ChartWindowOnDropped()
WindowOnDropped
Returns window index where expert, custom indicator or script was dropped.
ChartWindowOnDropped
double WindowPriceMax(int index=0)
double ChartGetDouble(0,CHART_PRICE_MAX,index)
WindowPriceMax
Returns maximal value of the vertical scale of the specified subwindow of the current chart (0-main chart window, the indicators' subwindows are numbered starting from 1).
ChartGetDouble
double WindowPriceMin(int index=0)
double ChartGetDouble(0,CHART_PRICE_MIN,index)
WindowPriceMin
Returns minimal value of the vertical scale of the specified subwindow of the current chart (0-main chart window, the indicators' subwindows are numbered starting from 1).
ChartGetDouble
double WindowPriceOnDropped()
double ChartPriceOnDropped()
WindowPriceOnDropped
Returns the price part of the chart point where expert or script was dropped.
ChartPriceOnDropped
void WindowRedraw()
void ChartRedraw(0)
WindowRedraw
Redraws the current chart forcedly.
ChartRedraw
bool WindowScreenShot(string filename,
                      int size_x,
                      int size_y,
                      int start_bar=-1,
                      int chart_scale=-1,
                      int chart_mode=-1)
bool WindowScreenShotMQL4(string filename,
                          int size_x,
                          int size_y,
                          int start_bar=-1,
                          int chart_scale=-1,
                          int chart_mode=-1)
  {
   if(chart_scale>0 && chart_scale<=5)
      ChartSetInteger(0,CHART_SCALE,chart_scale);
   switch(chart_mode)
     {
      case 0: ChartSetInteger(0,CHART_MODE,CHART_BARS);
      case 1: ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
      case 2: ChartSetInteger(0,CHART_MODE,CHART_LINE);
     }
   if(start_bar<0)
      return(ChartScreenShot(0,filename,size_x,size_y,ALIGN_RIGHT));
   else
      return(ChartScreenShot(0,filename,size_x,size_y,ALIGN_LEFT));
  }
WindowScreenShot
Saves current chart screen shot as a GIF file.
ChartSetInteger, ChartScreenShot
datetime WindowTimeOnDropped()
datetime ChartTimeOnDropped()
WindowTimeOnDropped
Returns the time part of the chart point where expert or script was dropped.
ChartTimeOnDropped
int WindowsTotal()
int ChartGetInteger(0,CHART_WINDOWS_TOTAL)
WindowsTotal
Returns count of indicator windows on the chart (including main chart).
ChartGetInteger
int WindowXOnDropped()
int ChartXOnDropped()
WindowXOnDropped
Returns the value at X axis in pixels for the chart window client area point at which the expert or script was dropped.
ChartXOnDropped
int WindowYOnDropped()
int ChartYOnDropped()
WindowYOnDropped
Returns the value at Y axis in pixels for the chart window client area point at which the expert or script was dropped.
ChartYOnDropped

Conclusion

  1. We haven't considered trading functions, because in MQL5 the concept is different, and the original should be used! It's possible to convert them, but the trading logic should be changed. In other words, there is no sense in converting them.
  2. The conversion of programs from one language to another is always associated with the loss of functionality and performance. Therefore, use this guide for the quick search for the functions analogues.
  3. I have plans to develop the MQL4 emulator, which will allow you to run your MQL4 programs in new MetaTrader 5 client terminal.

Credits: keiji, A. Williams.

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/81

Attached files |
initmql4.mqh (7.5 KB)
Last comments | Go to discussion (20)
onewithzachy
onewithzachy | 21 Apr 2012 at 06:36
Trintoro:

i love this article.

your idea for make emulator mt4, very good idea... 

I agree with Trintoro. This article is not about migrating, it's more like emulating. I much concern about speed execution then especially after reading this and Rosh's reply to this topic.  I think what happen to that topic, is the user still think in MQL4 kind a way. Maybe out of habit, so I can't blame him.

Its better to fresh learn and fresh write everything directly into mql5 rather than using commands that this article suggest.

Nevertheless, it's good to know the differences which this article has show.  

BTW. Out of my habit :

1. Pressing F5 (or F7, but rarely use) in MQL4 MetaEditor will compile, in MQL5 MetaEditor is F7 to compile, F5 will start / resume debugging.

2. In MQL4 MetaEditor, pressing Esc, will show/hide Toolbox window, In MQL5 MetaEditor, nothing will ever happen.  

Migrating that are annoying for me :) 

Mohammad Ali
Mohammad Ali | 10 Nov 2013 at 11:57

Dear Guys,

I call a below function into my indicator. But i got 7 warning message. i can i improve below function, so that not to show warning message:

 

double MarketInfoMQL4(string symbol,
                      int type)
  {
   switch(type)
     {
      case MODE_LOW:
         return(SymbolInfoDouble(symbol,SYMBOL_LASTLOW));
      case MODE_HIGH:
         return(SymbolInfoDouble(symbol,SYMBOL_LASTHIGH));
      case MODE_TIME:
         return(SymbolInfoInteger(symbol,SYMBOL_TIME));
      case MODE_BID:
         //return(Bid);
      case MODE_ASK:
         //return(Ask);
      case MODE_POINT:
         return(SymbolInfoDouble(symbol,SYMBOL_POINT));
      case MODE_DIGITS:
         return(SymbolInfoInteger(symbol,SYMBOL_DIGITS));
      case MODE_SPREAD:
         return(SymbolInfoInteger(symbol,SYMBOL_SPREAD));
      case MODE_STOPLEVEL:
         return(SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL));
      case MODE_LOTSIZE:
         return(SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE));
      case MODE_TICKVALUE:
         return(SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE));
      case MODE_TICKSIZE:
         return(SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE));
      case MODE_SWAPLONG:
         return(SymbolInfoDouble(symbol,SYMBOL_SWAP_LONG));
      case MODE_SWAPSHORT:
         return(SymbolInfoDouble(symbol,SYMBOL_SWAP_SHORT));
      case MODE_STARTING:
         return(0);
      case MODE_EXPIRATION:
         return(0);
      case MODE_TRADEALLOWED:
         return(0);
      case MODE_MINLOT:
         return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN));
      case MODE_LOTSTEP:
         return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP));
      case MODE_MAXLOT:
         return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX));
      case MODE_SWAPTYPE:
         return(SymbolInfoInteger(symbol,SYMBOL_SWAP_MODE));
      case MODE_PROFITCALCMODE:
         return(SymbolInfoInteger(symbol,SYMBOL_TRADE_CALC_MODE));
      case MODE_MARGINCALCMODE:
         return(0);
      case MODE_MARGININIT:
         return(0);
      case MODE_MARGINMAINTENANCE:
         return(0);
      case MODE_MARGINHEDGED:
         return(0);
      case MODE_MARGINREQUIRED:
         return(0);
      case MODE_FREEZELEVEL:
         return(SymbolInfoInteger(symbol,SYMBOL_TRADE_FREEZE_LEVEL));

      default: return(0);
     }
   return(0);
  }
Simon Gniadkowski
Simon Gniadkowski | 10 Nov 2013 at 13:18
advali82:

Dear Guys,

I call a below function into my indicator. But i got 7 warning message. i can i improve below function, so that not to show warning message:

 

What are thee warning ?
Mohammad Ali
Mohammad Ali | 10 Nov 2013 at 16:02
RaptorUK:
What are thee warning ?

warning is:

possible loss of data due to type conversion Ciiio.mq5 676 10

Tadas Talaikis
Tadas Talaikis | 15 Apr 2015 at 22:09
iStdOnArray() is missing :) Seems MT5 is the first autotrading platform which doesn't have basic statistic :) Trying to do something with MQL5 for a few days, but until now only various problems like I would be creating entire financial engineering warehouse.
Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

False trigger protection for Trading Robot False trigger protection for Trading Robot

Profitability of trading systems is defined not only by logic and precision of analyzing the financial instrument dynamics, but also by the quality of the performance algorithm of this logic. False trigger is typical for low quality performance of the main logic of a trading robot. Ways of solving the specified problem are considered in this article.

Using text files for storing input parameters of Expert Advisors, indicators and scripts Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.