Skip to main content

renkodf

Transform Tick Data into OHLCV Renko Dataframe!


Installation

   pip install renkodf

or just copy renkodf.py file to your project!


Content


Usage

There are two classes available:

  • Renko(df, brick_size)
    To create Renko OHLCV dataframe with existing Ticks data.
  • RenkoWS(timestamp, price, brick_size, external_df, ts_unit)
    To create real-time Renko charts, usually over a WebSocket connection.

Let's start with the first class, load a Pandas DataFrame containing Ticks Data, for example:

import pandas as pd
df_ticks = pd.read_parquet('examples/data/EURGBP_T1_cT.parquet')
df_ticks.rename(columns={'bid': 'close'}, inplace=True)
df_ticks.head(5)
ask close spread
datetime
2023-06-23 00:00:00.335 0.85950 0.85945 0.00005
2023-06-23 00:00:00.541 0.85951 0.85944 0.00007
2023-06-23 00:00:02.106 0.85950 0.85944 0.00006
2023-06-23 00:00:02.487 0.85950 0.85945 0.00005
2023-06-23 00:00:04.359 0.85951 0.85945 0.00006

Only two columns are required:

  • close: Mandatory.
  • datetime: If is not present, the index will be used.

After importing renkodf and setting brick_size, just call renko_df() with the chosen mode name.
See all available modes in renkodf_modes.ipynb

from src.renkodf.renkodf import Renko
r = Renko(df_ticks, brick_size=0.0003)
df = r.renko_df('normal', utils_columns=False) # 'wicks' = default
# utils-columns => [direction, is_reversal, tick_index_open, tick_index_close]
df.head(5)
open high low close volume
datetime
2023-06-23 01:21:58.333 0.8595 0.8598 0.8595 0.8598 3458
2023-06-23 01:33:24.996 0.8598 0.8601 0.8598 0.8601 571
2023-06-23 03:18:30.345 0.8601 0.8604 0.8601 0.8604 4993
2023-06-23 04:40:26.851 0.8604 0.8607 0.8604 0.8607 3358
2023-06-23 05:15:54.438 0.8604 0.8604 0.8601 0.8601 1669

You can use mpf.plot() or r.plot(), as in the example below.

import mplfinance as mpf
mpf.plot(df, type='candle', volume=True, style="charles",
         title=f"renko: normal\nbrick size: 0.0003")
mpf.show()
# same as:
# r.plot('normal')

png

As described in renkodf_modes.ipynb, we can have multiple dataframes of different modes from the same instance.

df_wicks = r.renko_df('wicks')
df_nongap = r.renko_df('nongap')

fig = mpf.figure(style='charles', figsize=(12.5,9))
fig.subplots_adjust(hspace=0.1, wspace=0.01)
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)

mpf.plot(df_wicks,type='candle',ax=ax1,axtitle='wicks', )
mpf.plot(df_nongap,type='candle',ax=ax2,axtitle='nongap')
mpf.show()

png

Animation/Real-time Renko Chart

To run the animation examples, clone this repository, then into the renkodf/examples folder, run:

  • python ws_animchart_demo.py
  • python ws_multichart_demo.py
  • python ws_externaldf_demo.py

NOTE: There are comments, in each of above example files, talking about situations or recommendations to be applied in real cases.

Performance-wise

From v2.0, the Renko calculation is powered by numpy arrays instead of python dicts/list as before, the OHLC variations (modes) are also calculated all at once, leading to a massive speed-up in Renko Charts creation.

Regarding "backtest vs real-time" charts, there are 2 tests about the OHLCV reliability between them.
The tests includes creating charts from scratch or using external data (Renko.to_rws())

Is the Renko chart calculated correctly?

I asked myself the same question, how about we see for ourselves?
We are going to do this based on Spotware's FX/CFD Trading Platform called cTrader,
using IC Markets/Trading as Price Provider.

Let's go!

RESUME: Despite the possible occurrence of more/less bricks, the renko calculation used is practically the same, or very approximate.

References:

The main logical structure seen in 'Renko._add_prices()' method (versions 1.0/1.1) is a REFORMULATION of the code concepts seen in Sergey Malchevskiy's pyrenko, which in fact, was the first more functional Renko calculation available in python.

Non-Affiliation Disclaimer

I'm not endorsed by, directly affiliated with, maintained, authorized, or sponsored by any company previously mentioned. All product and company names are the registered trademarks of their original owners. The use of any trade name or trademark is for identification and reference purposes only and does not imply any association with the trademark holder of their product brand.

Metadata

Release files for renkodf 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for renkodf 2.0
File Size Uploaded
renkodf-2.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for renkodf 2.0
File Interpreter ABI Platform
renkodf-2.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.2 kB

Release files / renkodf-2.0.tar.gz

Download URL renkodf-2.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8963b76e95c2d916c08af1fd0710752a1cafb3826928f996f11bdd2a227beec8
BLAKE2b-256 checksum
How to use checksums
51b9cd439598a3ec3299532268d633d390fcf9d6b5c4530008096641a29a115a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release files / renkodf-2.0-py3-none-any.whl

Download URL renkodf-2.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92e22a76277cec7b3059359fa059a035fc0a8267827f4999cd37fb8be3dc07e6
BLAKE2b-256 checksum
How to use checksums
c5b56d586f5a32e15ce6e2e2914517ed23fef1955cb7ac1da32b15178cbb9b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files

1.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page