kitoboynaya

Renko

kitoboynaya 已更新   
Now you can plot a "Renko" chart on any timeframe for free! As with my previous algorithm, you can plot the "Linear Break" chart on any timeframe for free!

I again decided to help TradingView programmers and wrote code that converts a standard candles / bars to a "Renko" chart. The built-in renko() and security() functions for constructing a "Renko" chart are working wrong. Do not try to write strategies based on the built-in renko() function! The developers write in the manual: "Please note that you cannot plot Renko bricks from Pine script exactly as they look. You can only get a series of numbers similar to OHLC values for Renko bars and use them in your algorithms". However, it is possible to build a "Renko" chart exactly like the "Renko" chart built into TradingView. Personally, I had enough Pine Script functionality.

For a complete understanding of how such a chart is built, you can read to Steve Nison's book "BEYOND JAPANESE CANDLES" and see the instructions for creating a "Renko" chart:
Rule 1: one white brick (or series) is built when the price rises above the base price by a fixed threshold value or more.
Rule 2: one black brick (or series) is built when the price falls below the base price by a fixed threshold or more.
Rule 3: if the rise or fall of the price is less than the minimum fixed value, then new bricks are not drawn.
Rule 4: if today's closing price is higher than the maximum of the last brick (white or black) by a threshold or more, move to the column to the right and build one or more white bricks of equal height. A new brick begins with the maximum of the previous brick.
Rule 5: if today's closing price is below the minimum of the last brick (white or black) by a threshold or more, move to the column to the right and build one or more black bricks of equal height. A new brick begins with the minimum of the previous brick.
Rule 6: if the price is below the maximum or above the minimum, then new bricks are not drawn on the chart.

So my algorithm can to plot Traditional Renko with a fixed box size. I want to note that such a "Renko" chart is slightly different from the "Renko" chart built into TradingView, because as a base price I use (by default) close of first candle. How the developers of TradingView calculate the base price I don’t know. Personally, I do as written in the book of Steve Neeson.

The algorithm is very complicated and I do not want to explain it in detail. I will explain very briefly. The first part of the get_renko () function — // creating lists — creates two lists that record how many green bricks should be and how many red bricks. The second part of the get_renko () function — // creating open and close series — creates open and close series to plot bricks. So, this is a white box - study it!

As you understand, one green candle can create a condition under which it will be necessary to plot, for example, 10 green bricks. So the smaller the box size you make, the smaller the portion of the chart you will see.

I stuffed all the logic into a wrapper in the form of the get_renko() function, which returns a tuple of OHLC values. And these series with the help of the plotcandle() annotation can be converted to the "Renko" chart. I also want to note that with a large number of candles on the chart, outrages about the buffer size uncertainty are heard from the TradingView blackbox. Because of it, in the annotation study() set the value of the max_bars_back parameter.

In general, use this script (for example, to write strategies)!
版本注释:
Now you can definitely build an intraday Renko chart without a paid subscription!

The previous version of get_renko() function did not work with the number of candles more than 5000. I modified the script and solved this problem.
Previously, the script needed to iterate over the entire data array in a loop. It could be more than 5000 candles. Now the variables up_stop_index and down_stop_index narrow the array to search. However, you can still have problems if you set a very small box size and there will be a lot of candles on the chart.
版本注释:
At the request of the users of this script, I have updated the minimum box size.
Now the Renko algorithm can be used in Forex and cryptocurrency with a lot of numbers after point.
版本注释:
Just the jump of the algorithm to 5 Pine Script version.

开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?