Migrating From MQL4 To MQL5 - MQL5 Articles
Migrating From MQL4 To MQL5 - MQL5 Articles
Articles CodeBase Documentation AlgoBook NeuroBook Calendar WebTerminal Algo Trading Channel
Examples
Add a new article
Indicators
Integration
Indicators
Sergey Pavlov
Expert Advisors
Introduction
Statistics and analysis
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,
Machine learning 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.
Interviews
1. Chart Periods
My own
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:
Do you like the article?
ENUM_TIMEFRAMES TFMigrate(int tf)
Share it with others — {
post a link to it! switch(tf)
{
Find us on Facebook! case 0: return(PERIOD_CURRENT);
Join our fan page case 1: return(PERIOD_M1);
case 5: return(PERIOD_M5);
case 15: return(PERIOD_M15);
Use new possibilities of
case 30: return(PERIOD_M30);
MetaTrader 5 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.
Similar articles To determine the number of minutes of the specified time period of the chart, divide the value, returned by function PeriodSeconds by 60.
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
double Close[];
Close
int count; // number of elements to copy
double Close[]
ArraySetAsSeries(Close,true); Series array that contains close prices for each bar of the current chart.
CopyClose(_Symbol,_Period,0,count,Close); CopyClose, ArraySetAsSeries
Digits
Number of digits after the decimal point for the current symbol prices.
int Digits int Digits=_Digits;
_Digits
double High[];
High
int count; // number of elements to copy
double High[]
ArraySetAsSeries(High,true); Series array that contains the highest prices of each bar of the current chart.
CopyHigh(_Symbol,_Period,0,count,High); CopyHigh, ArraySetAsSeries
double Low[];
Low
int count; // number of elements to copy
double Low[]
ArraySetAsSeries(Low,true); Series array that contains the lowest prices of each bar of the current chart.
CopyLow(_Symbol,_Period,0,count,Low); CopyLow, ArraySetAsSeries
double Open[];
Open
int count; // number of elements to copy
double Open[]
ArraySetAsSeries(Open,true); Series array that contains open prices of each bar of the current chart.
CopyOpen(_Symbol,_Period,0,count,Open); CopyOpen, ArraySetAsSeries
Point
double Point double Point=_Point; The current symbol point value in the quote currency.
_Point
datetime Time[]; Time
int count; // number of elements to copy 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
datetime Time[]
ArraySetAsSeries(Time,true); January, 1970.
CopyTime(_Symbol,_Period,0,count,Time); CopyTime, ArraySetAsSeries
long Volume[];
Volume
int count; // number of elements to copy
double Volume[]
ArraySetAsSeries(Volume,true); Series array that contains tick volumes of each bar of the current chart.
CopyTickVolume(_Symbol,_Period,0,count,Volume); CopyTickVolume, ArraySetAsSeries
4. Account Information
AccountFreeMarginMode
double AccountFreeMarginMode() -
Calculation mode of free margin allowed to open positions on the current account.
AccountLeverage
int AccountLeverage() int AccountInfoInteger(ACCOUNT_LEVERAGE) Returns leverage of the current account.
AccountInfoInteger
AccountMargin
double AccountMargin() double AccountInfoDouble(ACCOUNT_MARGIN) Returns margin value of the current account.
AccountInfoDouble
AccountName
string AccountName() string AccountInfoString(ACCOUNT_NAME) Returns the current account name.
AccountInfoString
AccountNumber
int AccountNumber() int AccountInfoInteger(ACCOUNT_LOGIN) Returns the number of the current account.
AccountInfoInteger
AccountProfit
double AccountProfit() double AccountInfoDouble(ACCOUNT_PROFIT) Returns profit value of the current account.
AccountInfoDouble
AccountServer
string AccountServer() string AccountInfoString(ACCOUNT_SERVER) Returns the connected server name.
AccountInfoString
AccountStopoutLevel
int AccountStopoutLevel() double AccountInfoDouble(ACCOUNT_MARGIN_SO_SO) Returns the value of the Stop Out level.
AccountInfoDouble
AccountStopoutMode
int AccountStopoutMode() int AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE) Returns the calculation mode for the Stop Out level.
AccountInfoInteger
5. Array Functions
default: return(0);
}
return(0);
}
ArrayDimension
int ArrayDimension( object array[]) -
Returns the multidimensional array rank.
ArrayGetAsSeries
Returns TRUE if an array is organized as a timeseries array (array elements are indexed from the last to the first
bool ArrayGetAsSeries( object array[]) bool ArrayGetAsSeries(void array)
one), otherwise returns FALSE.
ArrayGetAsSeries
int ArrayInitializeMQL4(double &array[],
double value)
ArrayInitialize
int ArrayInitialize(double &array[], {
double value) ArrayInitialize(array,value); Sets all elements of a numeric array to the same value. Returns the count of initialized elements.
return(ArraySize(array)); ArrayInitialize, ArraySize
}
ArrayIsSeries
Returns TRUE if the array under check is a timeseries array (Time[],Open[],Close[],High[],Low[], or Volume[]),
bool ArrayIsSeries( object array[]) bool ArrayIsSeries(void array[])
otherwise returns FALSE.
ArrayIsSeries
int ArrayMaximumMQL4(double &array[],
int count=WHOLE_ARRAY, ArrayMaximum
int ArrayMaximum(double array[],
int start=0) Searches for the element with the maximal value. The function returns position of this maximal element in the
int count=WHOLE_ARRAY,
int start=0)
{ array.
return(ArrayMaximum(array,start,count)); ArrayMaximum
}
ArraySetAsSeries
bool ArraySetAsSeries(void array[],
bool ArraySetAsSeries(double &array[], Returns the count of elements in the given dimension of the array. Since indexes are zero-based, the size of
bool set
bool set)
) dimension is 1 greater than the largest index.
ArraySetAsSeries
ArraySize
int ArraySize( object array[]) int ArraySize(void array[]) Returns the count of elements contained in the array.
ArraySize
int ArraySortMQL4(double &array[],
int count=WHOLE_ARRAY,
int start=0,
int sort_dir=MODE_ASCEND)
{
switch(sort_dir)
{
int ArraySort(double &array[],
case MODE_ASCEND: ArraySort
int count=WHOLE_ARRAY,
int start=0,
ArraySetAsSeries(array,true); Sorts numeric arrays by first dimension. Series arrays cannot be sorted by ArraySort().
case MODE_DESCEND: ArraySort, ArraySetAsSeries
int sort_dir=MODE_ASCEND)
ArraySetAsSeries(array,false);
default: ArraySetAsSeries(array,true);
}
ArraySort(array);
return(0);
}
6. Checkup
IsDllsAllowed
bool IsDllsAllowed() bool TerminalInfoInteger(TERMINAL_DLLS_ALLOWED) Returns TRUE if the function DLL call is allowed for the Expert Advisor, otherwise returns FALSE.
TerminalInfoInteger
IsExpertEnabled
bool IsExpertEnabled() bool AccountInfoInteger(ACCOUNT_TRADE_EXPERT) Returns TRUE if use of Expert Advisors is enabled in the client terminal, otherwise returns FALSE.
AccountInfoInteger
IsLibrariesAllowed
bool IsLibrariesAllowed() bool MQLInfoInteger(MQL5_DLLS_ALLOWED) Returns TRUE if an Expert Advisor can call library function, otherwise returns FALSE.
MQLInfoInteger
IsOptimization
bool IsOptimization() bool MQLInfoInteger(MQL5_OPTIMIZATION) Returns TRUE if an Expert Advisor is running in the strategy tester optimization mode, otherwise returns FALSE.
MQLInfoInteger
IsStopped
Returns TRUE if the program (an Expert Advisor or a script) has been commanded to stop its operation, otherwise
bool IsStopped() bool IsStopped()
returns FALSE.
IsStopped
IsTesting
bool IsTesting() bool MQLInfoInteger(MQL5_TESTING) Returns TRUE if an Expert Advisor is running in the testing mode, otherwise returns FALSE.
MQLInfoInteger
IsTradeAllowed
bool IsTradeAllowed() bool MQLInfoInteger(MQL5_TRADE_ALLOWED) Returns TRUE if trading by Expert Advisors is allowed and a thread for trading is not occupied, otherwise returns FALSE.
MQLInfoInteger
IsTradeContextBusy
bool IsTradeContextBusy() -
Returns TRUE if a thread for trading is occupied by another Expert Advisor, otherwise returns FALSE.
IsVisualMode
bool IsVisualMode() bool MQLInfoInteger(MQL5_VISUAL_MODE) Returns TRUE if the Expert Advisor is tested with checked "Visual Mode" button, otherwise returns FALSE.
MQLInfoInteger
UninitializeReason
int UninitializeReason() int UninitializeReason() Returns the code of the uninitialization reason for Expert Advisors, custom indicators, and scripts.
UninitializeReason
7. Client Terminal
8. Common Functions
default: return(0);
}
return(0);
}
9. Conversion Functions
IndicatorDigits
void IndicatorDigits(int digits) bool IndicatorSetInteger(INDICATOR_DIGITS,digits) Sets precision format (the count of digits after decimal point) to visualize indicator values.
IndicatorSetInteger
IndicatorShortName
void IndicatorShortName(string name) bool IndicatorSetString(INDICATOR_SHORTNAME,name) Sets the "short" name of a custom indicator to be shown in the DataWindow and in the chart subwindow.
IndicatorSetString
SetIndexArrow
void SetIndexArrow(int index,
int code)
bool PlotIndexSetInteger(index,PLOT_ARROW,code) Sets an arrow symbol for indicators line of the DRAW_ARROW type.
PlotIndexSetInteger
SetIndexBuffer
bool SetIndexBuffer(int index,
double array[])
bool SetIndexBuffer(index,array,INDICATOR_DATA) Binds the array variable declared at a global level to the custom indicator pre-defined buffer.
SetIndexBuffer
SetIndexDrawBegin
void SetIndexDrawBegin(int index, Sets the bar number (from the data beginning) from which the drawing of the given indicator line must
bool PlotIndexSetInteger(index,PLOT_DRAW_BEGIN,begin)
int begin) start.
PlotIndexSetInteger
SetIndexEmptyValue
void SetIndexEmptyValue(int index,
double value)
bool PlotIndexSetDouble(index,PLOT_EMPTY_VALUE,value) Sets drawing line empty value.
PlotIndexSetDouble
SetIndexLabel
void SetIndexLabel(int index,
string text)
bool PlotIndexSetString(index,PLOT_LABEL,text) Sets drawing line description for showing in the DataWindow and in the tooltip.
PlotIndexSetString
SetIndexShift
void SetIndexShift(int index,
int shift)
bool PlotIndexSetInteger(index,PLOT_SHIFT,shift) Sets offset for the drawing line.
PlotIndexSetInteger
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:
void SetIndexStyle(int index, PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_ARROW);
int type, case 4: SetIndexStyle
int style=EMPTY, PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_ZIGZAG); Sets the new type, style, width and color for a given indicator line.
int width=EMPTY, case 12: PlotIndexSetInteger
color clr=CLR_NONE) 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;
}
default: return;
}
}
SetLevelValue
void SetLevelValue(int level,
double value)
bool IndicatorSetDouble(INDICATOR_LEVELVALUE,level,value) The function sets a value for a given horizontal level of the indicator to be output in a separate window.
IndicatorSetDouble
int DayOfWeekMQL4()
{
DayOfWeek
MqlDateTime tm;
int DayOfWeek()
TimeCurrent(tm); Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.
return(tm.day_of_week); TimeCurrent, MqlDateTime
}
int DayOfYearMQL4()
{
DayOfYear
MqlDateTime tm;
int DayOfYear()
TimeCurrent(tm); 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.
return(tm.day_of_year); TimeCurrent, MqlDateTime
}
int HourMQL4()
{ Hour
MqlDateTime tm; 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
int Hour()
TimeCurrent(tm); execution).
return(tm.hour); TimeCurrent, MqlDateTime
}
int MinuteMQL4()
{ Minute
MqlDateTime tm; 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
int Minute()
TimeCurrent(tm); the program execution).
return(tm.min); TimeCurrent, MqlDateTime
}
int MonthMQL4()
{
Month
MqlDateTime tm;
int Month()
TimeCurrent(tm); 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.
return(tm.mon); TimeCurrent, MqlDateTime
}
int SecondsMQL4()
{ Seconds
MqlDateTime tm; 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
int Seconds()
TimeCurrent(tm); value will not change within the time of the program execution).
return(tm.sec); TimeCurrent, MqlDateTime
}
TimeCurrent
datetime TimeCurrent() datetime 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 TimeDayMQL4(datetime date)
{
TimeDay
MqlDateTime tm;
int TimeDay(datetime date)
TimeToStruct(date,tm); Returns day of month (1 - 31) for the specified date.
return(tm.day); TimeToStruct, MqlDateTime
}
TimeLocal
datetime TimeLocal() datetime TimeLocal() Returns local computer time as number of seconds elapsed from 00:00 January 1, 1970.
TimeLocal
int TimeMinuteMQL4(datetime date)
{
TimeMinute
MqlDateTime tm;
int TimeMinute(datetime time)
TimeToStruct(date,tm); Returns the minute for the specified time.
return(tm.min); TimeToStruct, MqlDateTime
}
int YearMQL4()
{
Year
MqlDateTime tm;
int Year()
TimeCurrent(tm); Returns the current year, i.e., the year of the last known server time.
return(tm.year); TimeCurrent, MqlDateTime
}
FileReadInteger
int FileReadInteger(int handle, int FileReadInteger(int file_handle,
int size=LONG_VALUE) int size=INT_VALUE) The function reads the integer from the current binary file position.
FileReadInteger
FileReadNumber
double FileReadNumber(int handle) double FileReadNumber(int file_handle) Read the number from the current file position before the delimiter. Only for CSV files.
FileReadNumber
FileReadString
string FileReadString(int handle, string FileReadString(int file_handle,
int length=0) int size=-1) Функция читает строку с текущей позиции файла.
FileReadString
bool FileSeekMQL4(long handle,
int offset,
FileSeek
bool FileSeek(int handle, ENUM_FILE_POSITION origin)
int offset, { The function moves the file pointer to a new position that is an offset, in bytes, from the beginning, the end or the current
int origin) FileSeek(handle,offset,origin); file position.
return(true); FileSeek
}
FileSize
int FileSize(int handle) ulong FileSize(int file_handle) The function returns file size in bytes.
FileSize
FileTell
int FileTell(int handle) ulong FileTell(int file_handle) Returns the current position of the file pointer.
FileTell
FileWrite
int FileWrite(int handle,...) uint FileWrite(int file_handle,...) The function is intended for writing of data into a CSV file, delimiter being inserted automatically.
FileWrite
int FileWriteArray(int handle, int FileWriteArray(int file_handle,
FileWriteArray
object array[], void array[],
int start, int start_item=0, The function writes the array to a binary file.
int count) int items_count=WHOLE_ARRAY) FileWriteArray
default: return(false);
}
return(false);
}
StringFind
int StringFind(string text, int StringFind(string string_value,
Search for a substring. Returns the position in the string from which the searched substring begins, or -1 if the substring has not been
string matched_text, string match_substring,
int start=0) int start_pos=0) found.
StringFind
StringGetChar
int StringGetChar(string text, ushort StringGetCharacter(string string_value,
int pos) int pos) Returns character (code) from the specified position in the string.
StringGetCharacter
StringLen
int StringLen(string text) int StringLen(string string_value) Returns character count in a string.
StringLen
string StringSetChar(string text, bool StringSetCharacter(string &string_var, StringSetChar
int pos, int pos, Returns the string copy with changed character in the specified position.
int value) ushort character) StringSetCharacter
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:
{
if(index < 0) return(-1); High
double iHigh(string symbol,
double Arr[]; Returns High value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function
int timeframe,
int shift)
ENUM_TIMEFRAMES timeframe=TFMigrate(tf); returns 0.
if(CopyHigh(symbol,timeframe, index, 1, Arr)>0) CopyRates, MqlRates
return(Arr[0]);
else return(-1);
}
{
if(index < 0) return(-1); iLow
double iLow(string symbol,
double Arr[]; Returns Low value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function
int timeframe,
int shift)
ENUM_TIMEFRAMES timeframe=TFMigrate(tf); returns 0.
if(CopyLow(symbol,timeframe, index, 1, Arr)>0) CopyRates, MqlRates
return(Arr[0]);
else return(-1);
}
{
if(index < 0) return(-1); iOpen
double iOpen(string symbol,
double Arr[]; Returns Open value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded),
int timeframe,
int shift)
ENUM_TIMEFRAMES timeframe=TFMigrate(tf); function returns 0.
if(CopyOpen(symbol,timeframe, index, 1, Arr)>0) CopyRates, MqlRates
return(Arr[0]);
else return(-1);
}
{
if(index < 0) return(-1); iTime
datetime iTime(string symbol,
ENUM_TIMEFRAMES timeframe=TFMigrate(tf); Returns Time value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded),
int timeframe,
int shift)
datetime Arr[]; function returns 0.
if(CopyTime(symbol, timeframe, index, 1, Arr)>0) CopyRates, MqlRates
return(Arr[0]);
else return(-1);
}
{
if(index < 0) return(-1); iVolume
double iVolume(string symbol,
long Arr[]; Returns Tick Volume value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded),
int timeframe,
int shift)
ENUM_TIMEFRAMES timeframe=TFMigrate(tf); function returns 0.
if(CopyTickVolume(symbol, timeframe, index, 1, Arr)>0) CopyRates, MqlRates
return(Arr[0]);
else return(-1);
}
WindowFirstVisibleBar
int WindowFirstVisibleBar() int ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0) The function returns the first visible bar number in the current chart window.
ChartGetInteger
int WindowHandleMQL4(string symbol,
int tf)
{
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
long currChart,prevChart=ChartFirst();
int i=0,limit=100;
while(i<limit)
{
WindowHandle
int WindowHandle(string symbol, currChart=ChartNext(prevChart);
int timeframe) if(currChart<0) break; Returns the system window handle of the specified chart.
if(ChartSymbol(currChart)==symbol ChartFirst, ChartNext, ChartSymbol, ChartPeriod
&& ChartPeriod(currChart)==timeframe)
return((int)currChart);
prevChart=currChart;
i++;
}
return(0);
}
WindowIsVisible
bool WindowIsVisible(int index) bool ChartGetInteger(0,CHART_WINDOW_IS_VISIBLE,index) Returns TRUE if the chart subwindow is visible, otherwise returns FALSE.
ChartGetInteger
WindowOnDropped
int WindowOnDropped() int ChartWindowOnDropped() Returns window index where expert, custom indicator or script was dropped.
ChartWindowOnDropped
WindowPriceMax
Returns maximal value of the vertical scale of the specified subwindow of the current
double WindowPriceMax(int index=0) double ChartGetDouble(0,CHART_PRICE_MAX,index)
chart (0-main chart window, the indicators' subwindows are numbered starting from 1).
ChartGetDouble
WindowPriceMin
Returns minimal value of the vertical scale of the specified subwindow of the current chart
double WindowPriceMin(int index=0) double ChartGetDouble(0,CHART_PRICE_MIN,index)
(0-main chart window, the indicators' subwindows are numbered starting from 1).
ChartGetDouble
WindowPriceOnDropped
double WindowPriceOnDropped() double ChartPriceOnDropped() Returns the price part of the chart point where expert or script was dropped.
ChartPriceOnDropped
WindowRedraw
void WindowRedraw() void ChartRedraw(0) Redraws the current chart forcedly.
ChartRedraw
bool WindowScreenShotMQL4(string filename,
int size_x,
int size_y,
int start_bar=-1,
int chart_scale=-1,
int chart_mode=-1)
{
bool WindowScreenShot(string filename, if(chart_scale>0 && chart_scale<=5)
int size_x, ChartSetInteger(0,CHART_SCALE,chart_scale);
WindowScreenShot
int size_y, switch(chart_mode)
int start_bar=-1, { Saves current chart screen shot as a GIF file.
int chart_scale=-1, case 0: ChartSetInteger(0,CHART_MODE,CHART_BARS); ChartSetInteger, ChartScreenShot
int chart_mode=-1) 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));
}
WindowTimeOnDropped
datetime WindowTimeOnDropped() datetime ChartTimeOnDropped() Returns the time part of the chart point where expert or script was dropped.
ChartTimeOnDropped
WindowsTotal
int WindowsTotal() int ChartGetInteger(0,CHART_WINDOWS_TOTAL) Returns count of indicator windows on the chart (including main chart).
ChartGetInteger
WindowXOnDropped
Returns the value at X axis in pixels for the chart window client area point at which the
int WindowXOnDropped() int ChartXOnDropped()
expert or script was dropped.
ChartXOnDropped
WindowYOnDropped
Returns the value at Y axis in pixels for the chart window client area point at which the
int WindowYOnDropped() int ChartYOnDropped()
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.
Warning: All rights to these materials are reserved by MetaQuotes Ltd. Copying or reprinting of these materials in whole or in part is prohibited.
Hello,
This old article (may 2010, more than 11 years ago !) was one of the first trying to simplify the process of migrating a script/EA from MQL4 to MQL5. Meantime, the popular mql4compat.mqh has been created, and I just published a
maintained version of mql4compat on github for people interested : https://github.com/eromawyn/mql4compat
Hi I am struggling with these functions (please see below) I keep on getting these errors. Please help resolve it.
A picture is good, but you need an MQL5 code. You need to insert the code using the button
I was having an issue getting fractals to work when converting from MT4 .. this helps by returning 0 instead of EMPTY_VALUE .. hope this is the right place to post thanks
I am benefited a lot from this great guide. Here is my little improvement on function to share.
// optimization
if(pos < (shift+ma_shift))
break;
}
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--;
// optimization
if(pos < (shift+ma_shift))
break;
}
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;
// optimization
if(pos < (shift+ma_shift))
break;
}
return(buf[shift+ma_shift]);
}
default: return(0);
}
return(0);
}
Practical Application Of Databases For Markets Analysis A Virtual Order Manager to track orders within the position-centric MetaTrader 5 environment
Working with data has become the main task for modern software - both for standalone and network applications. To This class library can be added to an MetaTrader 5 Expert Advisor to enable it to be written with an order-centric
solve this problem a specialized software were created. These are Database Management Systems (DBMS), that can approach broadly similar to MetaTrader 4, in comparison to the position-based approach of MetaTrader 5. It does this
structure, systematize and organize data for their computer storage and processing. As for trading, the most of by keeping track of virtual orders at the MetaTrader 5 client terminal, while maintaining a protective broker stop for
analysts don't use databases in their work. But there are tasks, where such a solution would have to be handy. This each position for disaster protection.
article provides an example of indicators, that can save and load data from databases both with client-server and
file-server architectures.
Creating Active Control Panels in MQL5 for Trading Creating an Indicator with Graphical Control Options
The article covers the problem of development of active control panels in MQL5. Interface elements are managed by Those who are familiar with market sentiments, know the MACD indicator (its full name is Moving Average
the event handling mechanism. Besides, the option of a flexible setup of control elements properties is available. The Convergence/Divergence) - the powerful tool for analyzing the price movement, used by traders from the very first
active control panel allows working with positions, as well setting, modifying and deleting market and pending orders. moments of appearance of the computer analysis methods. In this article we'll consider possible modifications of
MACD and implement them in one indicator with the possibility to graphically switch between the modifications.