Renko bars can be used as an alternative to the standard fixed-time candles. They smooth out a time-series without introducing lag. Most trading platforms don’t seem to support them natively but can be created using scripting. In this post I used DeepThought to generate the bars and Python’s matplotlib to display.
Generating the Renko Bars
From the commandline, Renko bars can be generated by
DeepThought --generate-bars EURUSDm1 --bar-type const-price-2 --price-movement 0.002 --output-filename renko-type-2.csv
This will generate a CSV file containing the Renko bars. Two types are possible, documented here: Deep Thought Renko Bars.
Alternatively you could write some script in your trading platform to generate the bars.
Python Script
Matplotlib does not have an in-build plot type for Renko bars, however using Rectangle and add_patches we can create a nice-looking Renko plot. Below is the script I used to visualise the bars:
import matplotlib.pyplot as plt import pandas as pd import sys def PlotRenko(filename): # Turn interactive mode off plt.ioff() df = pd.read_csv(filename, parse_dates=[['date','time']]) # number of bars to display in the plot num_bars = 100 # get the last num_bars df = df.tail(num_bars) renkos = zip(df['open'],df['close']) # compute the price movement in the Renko price_move = abs(df.iloc[1]['open'] - df.iloc[1]['close']) # create the figure fig = plt.figure(1) fig.clf() axes = fig.gca() # plot the bars, blue for 'up', red for 'down' index = 1 for open_price, close_price in renkos: if (open_price < close_price): renko = matplotlib.patches.Rectangle((index,open_price), 1, close_price-open_price, edgecolor='darkblue', facecolor='blue', alpha=0.5) axes.add_patch(renko) else: renko = matplotlib.patches.Rectangle((index,open_price), 1, close_price-open_price, edgecolor='darkred', facecolor='red', alpha=0.5) axes.add_patch(renko) index = index + 1 # adjust the axes plt.xlim([0, num_bars]) plt.ylim([min(min(df['open']),min(df['close'])), max(max(df['open']),max(df['close']))]) fig.suptitle('Bars from ' + min(df['date_time']).strftime("%d-%b-%Y %H:%M") + " to " + max(df['date_time']).strftime("%d-%b-%Y %H:%M") \ + '\nPrice movement = ' + str(price_move), fontsize=14) plt.xlabel('Bar Number') plt.ylabel('Price') plt.grid(True) plt.show() # save the figure as a png file fig.savefig("Renko.png") if __name__ == "__main__": if (len(sys.argv) == 1): print "Usage: python analyse_backtest_results.py <configuration file location>" exit() else: filename = sys.argv[1] PlotRenko(filename)
The final output is:
Compare this to H4 candles covering the same period:
If you want to experiment yourself, you can download a CSV file of Renko bars here: DeepThoughtRenkoBars.zip
Hello, i found this intereseting, do you know who I can work with to develop a strategy with renko bars ??
[…] segment, there’s somewhat slightly of code. The credit score for this section is going to the code I found here which I’ve changed somewhat […]