Full-featured Renko Charts in MetaTrader 5 - Technical Preview

22 May 2018, 16:53
Stanislav Korotky
5
13 793

Preamble

Renko charts are very popular among traders, yet neither MetaTrader 4 nor MetaTrader 5 does provide them out of the box. To implement renko charts supporting online trading with EAs and indicators one should use a workaround. In MetaTrader 4, it's possible to generate an offline chart and refresh it with emulated ticks using Windows API. In MetaTrader 5, it's possible to build a so-called custom symbol. This blogpost will describe the latter approach and introduce a ready-made product for building renko charts in MetaTrader 5.

The product is published in the Market. Free demo-product is also available. The product reveals some bugs in MetaTrader 5 itself. The bugs were filed in the service desk back in 2017 but still not fixed, and I did not even receive a feedback. You may find more details below.


User guide

This non-trading expert utilizes so called custom symbols feature (available in MQL as well) to build renko charts based on historical quotes of selected standard symbol and to refresh renko in real-time according to new ticks. Also it translates real ticks to the renko charts, which allows other expert advisers to trade on renko and other indicators to analyze renko.

You should place RenkoCharts on a chart of your preferred work instrument. The lesser timeframe of the source chart is, the more precisely resulting renko chart is, but the lesser number of renkoboxes will be generated. This happens so because available history is limited by a constant specified as "Max bars in chart" in the terminal settings. Hence, the same number of bars covers, for example, on M1 chart 60 times shorter period than on H1 chart. The larger the source timeframe is, the deeper history will be used for renko generation, but the lesser quality it will be. It's important to note, that the reduced accuracy of renko affects only past regions, generated from history, but all live changes of quotes (provided RenkoCharts is running) will generate absolutely accurate renko boxes - potentially even more accurate than generated from M1 history.

The generated renko chart uses M1 timeframe. The start time of a "minute" bar corresponds to the start time of renko box. The end time of a such "minute" bar is dummy (MetaTrader does not allow for bars with different timespan), instead you should look at start time of the next "minute" bar. It makes no sense to switch the renko chart to a timeframe other than M1.

After its placement on a source chart, RenkoCharts starts to generate missing renko bars for custom symbol and shows a comment like this:

Processing bar: i / N

where i - number of a current bar being processed on the source timeframe (the numbering goes from maximum to 0), and N - total number of the bars.

When the process is finished, the comment reads like this:

RenkoChart (100pt): open EURUSD_M1_renko / 10000 bars

where 100pt is the renkobox size in points, EURUSD_M1_renko is the custom symbol name (for both see description below), and 10000 is total number of generated renkoboxes (if the expert is running the very 1-st time, this is actual number of renko bars, but if it continues from some previous results, for example, after the terminal restarts, the number of new renko boxes can be a few, because only most recent, missing boxes are generated).

RenkoCharts opens one renko chart for you, but you can open more.

RenkoCharts generates custom symbol quotes, thus you may open many charts with it and apply different trading EAs and indicators. It makes no sense to run multiple RenkoCharts with the same work symbol/timeframe/renkobox size. It's not allowed to run multiple RenkoCharts with the same custom symbol name.

Here is some screenshots.

MetaTrader 5 Renko Chart with volumes

MetaTrader 5 Renko Chart with MA indicator applied



Parameters

  • RenkoBoxSize - renkobox size in points (NOT pips, bear in mind that number of digits in the symbol specification is important), by default - 100;
  • ShowWicks - enable/disable wicks on renko, by default - true;
  • EmulateOnLineChart - enable/disable ticks emulation on the renko chart, by default - true; it allows other expert adviser to trade online from the renko chart;
  • OutputSymbolName - name of the custom symbol used for renko, by default - empty string - that is the name is formed as "Symbol_Period_Type_Size", where Symbol - current work symbol, Period - current timeframe, Type - "r" (renko) if wicks are enabled or "b" (brick) if disabled, Size - RenkoBoxSize; example: "EURUSD_M15_r100";
  • Reset - an option to enforce complete recalculation of entire renko chart, by default - false; after it's set to true and calculations are completed, it's recommended to reset it back to false, in order to eliminate excessive recalculations on every terminal restart; this mode can be helpful in rare cases, when the generated renko chart contains an error for some reason; normally the option should be disabled, because the expert can continue calculation smartly from most recent existing renkobox.


Known limitations

  • Ticks are not used while generating renko boxes from history (ticks are used online only);
  • On fast movements price can jump for several renko boxes in a minute - hence the boxes can "move" to the future on the time scale, because MetaTrader 5 does not allow seconds in bar time stamps;
  • In order to trade on the custom chart, your EA should be aware of parent work symbol used to generate renko and issue all trading orders to the parent symbol instead of the custom symbol of the renko chart; in current implementation the parent symbol name is included as starting part of the custom symbol name (preceding first underscore) by default; further reading on this is posted in the blog;
  • While testing your EAs in the tester, do not use "Every tick based on real ticks" mode for the custom symbol;


Application

Feel free to try the free demo if you're interested in renko trading AND have some knowledge about MQL development and testing. This is the very first version of the product, you should be prepared for bugs, logs reading, incompatible changes in the future.

The demo product is installed in MetaTrader as usual, but can not run in the tester due to its specifics. Only EURUSD M1 is allowed as hosting chart for the demo.


Bugs description

Most annoying thing with the product is that generated renko charts scroll sporadically back and forth by themselves. There is no a single MQL API call in the source code, which makes such an effect intentionally. The bug is especially visible when EmulateOnLineChart is true. In this case the product additionally calls SymbolInfoTick (for work symbol) and CustomTicksAdd (for custom symbol) functions. Also CustomRatesUpdate is used to update only the very last, current bar. Neither of the functions should, by design, lead to the bars jumping to the left and to the right on the chart. Another effect of the bug is that several trailing bars of the custom symbol vanish from the custom chart from time to time, and then get redrawn again. At last, you will experience Data Window blinking: it's wiped out for a moment and then refilled with current data again.

The animated screenshot below illustrates the effects (the animation does not show up in the blog - you should download the image or click to enlarge).

Renko Chart in MetaTrader 5 with "jump" side effects

To remedy this problem to a certain degree, the product provides special input parameter Throttle, which defines minimal period in seconds between 2 successive ticks to process. When it's 0 (by default), all ticks are processed, but the flickering is more probable. Values in the range 1-10 seem reasonable.

Another issue with the custom charts is that it's supposedly not processed by custom indicators as expected, in efficient manner. When a simple custom indicator is attached to a custom chart (please find an example below), it always receives prev_calculated set to 0 in its OnCalculate event handler, no matter what was returned to the core (normally, rates_total).


Bugs test case

Test EA to reproduce the "jumps and blinks" problem in the custom symbol charts - testbed.mq5. This EA should be attached to EURUSD H1 (or M30, M15, or other, but not M1) chart, which will create a custom symbol EURUSD_H1_TB. It should be analyzed on M1 timeframe (very first launch of EA will open such custom M1 chart for you automatically after the custom symbol generation).

This EA does simply duplicate H1 (or other timeframe's) bars on the custom M1 chart - there is no applied sense in this - this is just a tool for the bug reproduction. Please notice that SymbolInfoTick, CustomTicksAdd, CustomRatesUpdate are used per documentation and change only live data (last bar and its ticks) on the fly.

This EA requires 2 include files, attached as well at the bottom.

Test indicator to reproduce the "calculation" problem in the custom symbol charts - CustomCheck.mq5. This indicator will output prev_calculated and rates_total via Comment function, and always return rates_total from its OnCalculate function. You will see that prev_calculated is always 0.


Appeal

If someone knows how to fix the problems or can help to invent a workaround, please, send your suggestions. Your feedback is greatly appreciated.


Continuation


Files:
testbed.mq5  10 kb
ind4to5.mqh  11 kb
Symbol.mqh  4 kb