|
|
|
|
|
|
|
|
|
Indicators, advisers and scripts are written in order to be attached to the charts. That is why it's better to find out what a chart is at once. Let's consider EURUSD chart, time-frame D1. That is, we have a chart of EURUSD, each bar of which reflects this pair behaviour during a day (D1). You can get the name of the instrument in MQL-4 with the help of function Symbol()), time-frame value with the help of Period ().
|
|
|
|
|
These functions can be used in every file of MQL-4. For help refer to the answer wizard in MetaEditor. Function Period() returns the value of the period in minutes, which can be one of the preset constants: 1 minute, 5 minutes, 15 minutes, 30 minutes etc. This is how it is described in the Help:
Charts periods enumeration
Chart period. May be one of the following values:
Constant Figure Description
PERIOD_M1 1 1 minute.
PERIOD_M5 5 5 minutes.
PERIOD_M15 15 15 minutes.
PERIOD_M30 30 30 minutes.
PERIOD_H1 60 1 hour.
PERIOD_H4 240 4 hours.
PERIOD_D1 1440 Days.
PERIOD_W1 10080 Weeks.
PERIOD_MN1 43200 Months.
|
|
|
|
|
In fact, even if there are no indicators in the chart, we have at least one indicator, as even prices can be shown in a chart window in three different ways, candles, bars and lines.
|
|
|
|
|
Thus, it is not so important how a chart is displayed. On what basis it is done is of much greater importance. In this picture a bar chart is given. Unlike the first picture (candles) there are no white or black bodies with the help of which bullish and bearish candles are distinguished visually. Line charts, built by close prices, give even less visual information. Though this additional information is stored in the terminal, but not shown.
|
|
|
|
|
If in terminal MT4 we press Ctrl+S combination (menu item «Save as»), then a dialogue window of EURUSD D1 history saving in *.csv format (the format with delimiters) will appear.
|
|
|
|
|
Let's save the file with the name, suggested by default, EURUSD1440.csv. As we can guess, the file name by default contains the name of the instrument (which may be got with the help of function Symbol()) and period 1440 minutes (the value of function Period() for the daily time-frame is equal to 1440). Then we open the accepted file with Excel.
The last five lines look like:
2005.12.19,00:00,1.2029,1.2037,1.1973,1.1999,5166
2005.12.20,00:00,1.2002,1.2011,1.1839,1.1861,6679
2005.12.21,00:00,1.1859,1.1910,1.1800,1.1832,6787
2005.12.22,00:00,1.1830,1.1895,1.1808,1.1871,5284
2005.12.23,00:00,1.1870,1.1883,1.1827,1.1864,4686
|
|
|
|
|
Let's consider the last line, the rest of them are similar. At first there is a record 2005.12.23, this is a date, December 23, 2005. Then comma separated 00:00, that is 00 o'clock. All in one they mean the beginning of the day 23.12.2005, the time of the daily candlestick opening (Time). Then figures 1.1870 (opening price – Open), 1.1883 (the highest price within a period - High), 1827 (the lowest price within a period - Low), 1.1864 (close price - Close) and 4686 (volume within a period – Volume). If we point the last candlestick in the chart, a prompt message will pop up. Thus, we can draw a conclusion that a chart of every instrument in any time-frame can be presented in the shape of six arrays: Time[], Open[], Low[], High[], Close[] and Volume[]. Only these data are used by indicators and advisers. The first of them contains datetime-type data, the next four arrays contain double-type data, and the last one contains int-type data. Refer to MetaEditor for help. Access to the elements of the array is done by the index, indices always have integer type. The last bar (candlestick) by time always has a zero index. Open[0] means the price of the zero bar opening (the last bar), Time[1] means the date and time of the last but one bar opening, Low[3] is the lowest price within a period for three periods back and so on. It is important to remember that increasing the index we move further into the history up to the earliest bar. To find out the number of bars, given in the chart of an instrument, parameter Bars is necessary. This parameter always contains that number of bars, which can be seen in the chart and it updates automatically while the terminal is working on-line. It should be taken into account that the very first bar in the chart (the most remote one from us by time) will have index Bars-1, as indexation begins from zero.
|
|
|
|
|
And the last thing I want to say is that predefined variable Bars is connected with setup «The maximum number of bars in the window» (that is usually not more than this figure) and does not mean «The maximum number of bars in history» (in the picture 250000). The more the value of the parameter «The maximum number of bars in the window» (in the picture 15000) is, the more memory is consumed by the terminal. This parameter change comes into effect only once MT4 is restarted.
|
|
|
|
Go to article «Script writing».
|
|
|
|
|
|