• 概述
  • 评论
  • 评论 (8)

Range Bars Chart

iRangeBarsChart indicator allows you to create custom Range Bars charts. Open history file format and history quality control are used.

This indicator is based on iCustomChart and represents its particular implementation. The demo version of iCustomChart can be downloaded for free.

Contents:

  1. Advantages and Features
  2. Input Parameters
  3. Indicator Buffer
  4. Data Window
  5. History Files
  6. History Quality Control
  7. Time Scale 
  8. Graphical Objects for Technical Analysis
  9. Indicators and Expert Advisors

1. Advantages and Features

  • works at any open chart window (called "base chart" further on in this document);
  • looks like a common chart after launching (see Screenshots);
  • to get started,previously created history files are not required; 
  • open history file format is used;
  • MetaTrader 4 and MetaTrader 5 data format can be used;
  • history quality control  (see Screenshot 7);
  • full format of history including open time of bars, spread, tick and exchange volume;
  • built-in Data Window (see Screenshot 4);
  • built-in Time Scale (see Screenshot 6);
  • auto scaling of price scale;
  • major part of the objects from the MetaTrader 5 standard set can be used for technical analysis (see Screenshot 2);
  • displaying online and offline charts;
  • controlling bars open time up to milliseconds;
  • custom indicators and Expert Advisors can be created based on the iRangeBarsChart chart using LibCustomChart (seeScreenshots 3, 8).

2. Input Parameters

  • Max bars in chart allows to display a fixed number of bars in a chart window. Zero value of the parameter allows displaying the maximum possible number of bars, but no more than the number specified in the client terminal settings. This parameter acts as the equivalent parameter of the client terminal described in Help. The default value is 1000.
  • Range - the range or a size of bars in points from Low to High. The default value is 200.
  • Update - iRangeBarsChart indicator update method:
                   Disable - update disabled; 
                   Ticks    - update at each base chart tick, set by default; 
                   Bars     - update when a new bar appears on a base chart.
  • Shadows - managing candlestick shadows drawing:
                   Enable  - shadow display enabled, set by default; 
                   Disable - shadow display disabled.
  • Price scale - select price scale:  
                   Standard - standard price scale. Scaling and scale management are performed by means of MetaTrader 5.
                   Custom - scaling is performed by iRangeBarsChart, set by default.
  • Value of zero buffer - zero buffer value calculated according to selected price constant.

3. Indicator Buffer

Indicator
buffer
number
Content
0  Contains selected price constant. The buffer is basically created for the indicators that use the first call form to get data. 
1  Bar open time 
2  Bar open price 
3  Bar high price 
4  Bar low price 
5  Bar closing price 
6  Bar color 
7  Exchange volume 
8  Tick volume 
9  Spread 

4. Data Window 

Built-in data window looks similar to the standard MetaTrader 5 data window, but has some additional features (Screenshot 4). Data fields displayed in the window:

  • Upper field - symbol name and parameter. Parameter is a size of bar in points (Range), specified in the indicator input parameters. The window containing data on a history file will be opened once you click on this field (Screenshot 5).
  • Date            - bar open date.
  • Time            - bar open time.
  • Open           - bar open price.
  • High            - bar high price.
  • Low             - bar low price.
  • Close           - bar close price.
  • Volume        - exchange volume.
  • Tick Volume - tick volume.
  • Spread        - bar spread.
  • Bar              - bar index, zero bar - last unfinished bar.
5. History Files (HST Files)
Open history files format described in the MetaTrader 4 user guide is used to draw charts. A user can take a ready-made Range Bars history file or create one of their own. Then the iRangeBarsChart indicator can be used to display a chart.
History file format is as following. History file header goes first:
struct HistoryHeader
{
  int		version		// base version
  char		copyright[64];	// copyright
  char		symbol[12];	// symbol
  int		parameter;      // symbol period or parameter, for iRangeBarsChart it is "Range" input parameter value
  int		digits;         // number of digits after the decimal point in a symbol
  time_t	timesign;       // base creation timestamp
  time_t        last_sync;      // last synchronization time
  int		unused[13];	// for future use
};
The version of the base for MetaTrader 4 history files is displayed as "400", while for MetaTrader 5 it is "500". This is important, as each version has its own bar data structure.
The standard representation of the bars array following the header for the version "400" history file looks as follows:
#pragma pack(push,1)
struct RateInfo
{
 time_t   ctm;	  // time in seconds
 double	  open;	  // bar open price
 double	  low;	  // bar low price
 double   high;	  // bar high price
 double   close;  // bar close price
 double   vol;	  // volume
};
#pragma pack(pop)
The standard representation of the bars array for the version "500" history file looks as follows:
#pragma pack(push,1)
struct MqlRates
{
 datetime time;         // bar time in seconds or milliseconds
 double   open;         // open price
 double   high;         // high price for the period
 double   low;          // low price for the period
 double   close;        // close price
 long     tick_volume;  // tick volume
 int      spread;       // spread
 long     real_volume;  // market volume 
};
#pragma pack(pop)

Note that bar time can be set either in seconds or in milliseconds for version "500". iRangeBarsChart  defines both time formats correctly.

Note: users bear responsibility for a history file correctness.

To make iRangeBarsChart recognize a history file, it must be located in the "terminal_data_folder\MQL5\Files\iRangeBarsChart\History". The history file name

  1. must start with "Range" prefix;
  2. Then it must contain the symbol name on the base chart of which the indicator will be loaded (for example, "EURUSD");
  3. Then it must contain the value of the "Range" input parameter;
  4. Finally it must have ".hst" extension.
An example of the file name: RangeEURUSD200.hst

If the history file doesn't exist, so it will be automatically created from the minute history available in the terminal. If it exists, it will be updated in accordance with the "Update" input parameter of the indicator. 

6. History Quality Control

For history files created by iRangeBarsChart, history quality control is available.

Any new history file is created from the minute history available in the terminal. Accordingly, there can be situations when the simulated bars can differ from bars created online. Each doubtful simulated bar on the chart is displayed in lighter color than the concrete bars (Screenshot 7). It allows estimating history quality visually.

When initializing the indicator, a message about its quality will appear in the log (Screenshot 7). It can be estimated in the percentage of good and bad bars. Please note that history quality calculation is performed only for bars displayed on charts, not for the whole history file. 

Using the indicator buffer "Bar color" you can programmatically estimate the history quality in your own indicators and the Expert Advisors. It allows making adequate solutions when implementing a trading strategy.

You can improve the history quality using iRangeBarsChart in the online mode only. At coming of tick data iRangeBarsChart correctly calculates all parameters of bars and saves them in the history file. For example, bar open time will be calculated to milliseconds and saved. If there is no tick data to build history for a period of time (connection failure, terminal is turned off or any other nonstandard situation), so the missing Range history will be formed on the basis of a minute history. 

7. Time Scale

Time scale of charts created using iRangeBarsChart, does not usually coincide with a base chart time scale and it is non-linear. Therefore, the indicator automatically rebinds applied graphical objects to its time scale (Screenshot 6). Built-in scale features:

  • looks similar to the standard time scale;
  • easy to move vertically;
  • semi-transparent background, always visible chart objects and price chart behind the scale.

8. Graphical Objects for Technical Analysis

Standard graphical objects of the terminal are bound to a base chart time scale when placed in a chart window. Therefore, iRangeBarsChart automatically rebinds applied graphical objects to its time scale. It allows using the standard graphical objects for technical analysis of Range Bars charts. Synchronization with iRangeBarsChart is supported for the following conventional MetaTrader 5 graphical objects:
  • lines: horizontal, vertical, trend, trend by angle, cycle, arrowed;
  • channels: equidistant, Andrews Pitchfork;
  • Fibonacci: retracement, time zones, fan, arcs, channel, expansion;
  • Elliott instruments: motive wave, corrective wave;
  • figures: triangle, rectangle, ellipse;
  • arrows: thumbs up, thumbs down, arrow down, arrow up, stop sign, check sign, left and right price labels, Buy and Sell signs, arrow.
In some cases, for example when closing the terminal, iRangeBarsChart saves the objects data to a temporary file located in the "terminal_data_folder\MQL5\Files\iRangeBarsChart\Objects" directory. The system deletes all temporary files when iRangeBarsChart is being removed from a chart window.
9. Indicators and Expert Advisors
Standard indicators follow the time scale of a base chart, as well as the objects. Free LibCustomChart library should be used for binding the indicators to the iRangeBarsChart time scale. 
The library functions allow writing the indicators that are automatically connected to iRangeBarsChart (Screenshort 3), in case it is uploaded to a chart window. In case iRangeBarsChart is not uploaded, these indicators will work in a common chart window. Besides, the library provides simplified access to iRangeBarsChart time series.
In case the library functions are used in an Expert Advisor, then it will also automatically use iRangeBarsChart, in case the latter has already been run on a chart window. In case iRangeBarsChart is not run, the Expert Advisor will work on a common chart window and use its data.
Examples of the library use in indicators and Expert Advisors can be found in Code Base.

This indicator is based on iCustomChart and represents its particular implementation. The demo version of iCustomChart can be downloaded for free.

无评论