Information of the price change comes with two parameters: new price level and time of the change. There appears to be a lot of historical data and in order to reduce the volume of information used, such combinations as bars, candlesticks or recording format as per closing price are used. All these forms are alike and pursue one objective – to reduce the volume of information being processed while saving maximum useful data.
Most often, bars and Japanese candlesticks charting are used. These elements are equally informative. The difference between them is only in how they are displayed.
For convenience, we will consider only the bars hereafter.
Bars have the following parameters:
- Time interval – time span, within which all the price changes are referred exactly to this bar.
- Opening price – the price as of the moment of bar formation start
- Closing price – the last price within a bar time interval
- Highest level – highest price level during bar formation
- Lowest level – lowest price level during bar formation
Metatrader time intervals:
- 1M – 1 minute;
- 5M – 5 minutes;
- 15M -15 minutes;
- 30M – 30 minutes;
- 1H – 1 hour;
- 4H – 4 hours;
- 1D – 1 day;
- 1W – 1 week;
- 1MN – 1 month.
We looked at the time intervals most frequently used, their denotations and amount of seconds within each interval. Minimal time quantum available in MT4 environment to both the trader and the programmer is a second. The price can change more frequently, but the last change within a second will be saved in the history.
Bar formation.
Initially, data for every currency have the following format:
- Price change date. Date detailing right up to a second
- New price level. Detailing of this parameter depends on the broker configurations
Time line example:
- January 1, 2008 9:00:04 – 1.4001
- January 1, 2008 9:00:05 – 1.4003
- January 1, 2008 9:00:25 – 1.4008
- January 1, 2008 9:00:50 – 1.4005
- January 1, 2008 9:01:15 – 1.4006
- January 1, 2008 9:01:28 – 1.4008
- January 1, 2008 9:01:32 – 1.4001
- January 1, 2008 9:01:33 – 1.4002
- January 1, 2008 9:01:45 – 1.4004
- January 1, 2008 9:01:52 – 1.4009
- January 1, 2008 9:01:55 – 1.4010
- January 1, 2008 9:02:08 – 1.4018
- January 1, 2008 9:02:18 – 1.4019
The first, the second and the third minutes of the time span, that starts with January 1, 2008 9:00:00 appeared in this sequence.
Now, we will try to form bars from these data. We will use the time interval 1M. If the date of January 1, 2008 9:00:00 is used as the beginning of history formation, then we have three bars with the following time spans:
- 1 bar – [January 1, 2008 9:00:04 - January 1, 2008 9:00:50]
- 2 bar – [January 1, 2008 9:01:15 - January 1, 2008 9:01:55]
- 3 bar – [January 1, 2008 9:02:08 - January 1, 2008 9:02:18]
The first price change for bar 1 was the value of 1.4001 which is the bar opening price, the last change at January 1, 2008 9:00:50 with the value of 1.4005 is the bar closing price. Then we find the highest value – 1.4008. The lowest is 1.4001. We obtain the bar parameters:
- Open – 1.4001
- Close – 1.4005
- High – 1.4008
- Low – 1.4001
The values for remaining bars are being found analogously
The formed and the current bars
Two types of bars can be distinguished in the time sequence:
Formed – current time is later than the time of bar formation completion, hence the bar is considered as formed, new data will not affect its form.
Current – current time is earlier than the time of bar formation completion, hence the bar is considered as current or the one that is being formed. The bar remains forming one till the time of its formation end, even if there will be no more price level changes. The new data can change any parameter except for opening price. Bar closing price changes with every price change until the bar becomes formed. In other words, current bar parameters are re-computed every time when the new data related to price change are coming.
You have to be very careful when using current bar because its form can totally change during the time from the start to the end of its formation. Normally, the most recent formed bar of a time sequence is used for conditions computation.
Special features of bar formation.
Bar formation process has its small peculiarities that would be useful to know.
Bar consisting of one tic mark. It might happen that during bar formation the price can change only once. For example, within a span of [January 1, 2008 9:03:00 - January 1, 2008 9:03:59] there was only one change on January 1, 2008 9:03:48 – 1.4022. In this case all parameters of the bar are equal to one value of 1.4022
Bar having no tic marks. Sometimes, no changes are happening during bar formation. E.g., there were no changes during a span of [January 1, 2008 9:04:00 - January 1, 2008 9:04:59]. In such case, this bar will not be reflected on the time sequence because there are simply no data for its formation. The time span will also be left out.
Bars indexation
Bars indexation is quite a specific concept that is mainly used by programmers. However, there are several situations when it would be useful for an MQL program user to know the specific features of bars indexation as well.
So, we have 5 bars of 1M within the time span [January 1, 2008 9:00:00 - January 1, 2008 9:04:59]. The last bar is being formed, the rest have been formed. The indexation starts with the current bar, minimal index is 0. Let’s take a look at the table:
- 4 index – [January 1, 2008 9:00:00 - January 1, 2008 9:00:59]
- 3 index – [January 1, 2008 9:01:00 - January 1, 2008 9:01:59]
- 2 index – [January 1, 2008 9:02:00 - January 1, 2008 9:02:59]
- 1 index – [January 1, 2008 9:03:00 - January 1, 2008 9:03:59]
- 0 index – [January 1, 2008 9:04:00 - January 1, 2008 9:04:59]
As soon as a new bar starts and new time span [January 1, 2008 9:05:00 - January 1, 2008 9:05:59] is opened, then all the bars on the time sequence are being indexed. The situation has the following format:
- 5 index – [January 1, 2008 9:00:00 - January 1, 2008 9:00:59]
- 4 index – [January 1, 2008 9:01:00 - January 1, 2008 9:01:59]
- 3 index – [January 1, 2008 9:02:00 - January 1, 2008 9:02:59]
- 2 index – [January 1, 2008 9:03:00 - January 1, 2008 9:03:59]
- 1 index – [January 1, 2008 9:04:00 - January 1, 2008 9:04:59]
- 0 index – [January 1, 2008 9:05:00 - January 1, 2008 9:05:59]
In this manner, the bar being formed always has 0 index. This knowledge is useful for configuration of condition computation algorithm. With the help of variable, it’s possible to set – from which bar the condition computation should start. From 0 (current), 1 (formed) or any other.
When does the bar start and when does it end?
A bar starts with the first price change within a time interval. If the first time interval of 1 minute starts at 00:00:00, and the first price change occurs at 00:00:24, then it is exactly from this time we can consider that a bar started. If no price change occurred within the set time interval, then the bar is left out.
The bar ends along with the interval within which it is being formed, regardless of the time when the last price change has occured.
Bar formation level.
If the time interval within which a bar is formed is broken into equal parts then we will have several levels of bar formation. E.g., let’s take an interval of 1 minute as one and consider the flow of time in percentage ratio. Thus, 00:00:00 will be considered as 0%, and 00:00:59 will be as 100%.
Sometimes traders use trade method on the current bar, but with formation level which is more than the defined value in percentage ratio.
It’s important to keep in mind that current bar formation level can only be defined in percents during price change. Hence, if you expect bar level of 80% and more, then a situation is possible when the last price change occurred at the level of less than 80% and the next change will occur within another time interval already.
This method should be used with great care and preferably with large time intervals.
