Skip to main content

Transform Tick Data into OHLCV Renko Dataframe!

Project description

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, add_columns)
    To create Renko OHLCV dataframe with existing Ticks data.
  • RenkoWS(timestamp, price, brick_size, external_df, external_mode)
    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(3)
df_ticks.tail(3)
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
ask close spread
datetime
2023-06-27 23:59:56.612 0.85976 0.85969 0.00007
2023-06-27 23:59:57.175 0.85975 0.85969 0.00006
2023-06-27 23:59:59.053 0.85974 0.85969 0.00005

Only two columns are required:

  • close: Mandatory.
  • datetime: If is not present, the index will be used.
    You can add other columns if you want, just put a list with their names in the add_columns parameter.

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 renkodf import Renko
r = Renko(df_ticks, brick_size=0.0003)
df = r.renko_df('normal') # 'wicks' = default 
df.head(3)
df.tail(3)
 100.0%
open high low close volume
datetime
2023-06-23 01:21:58.333 0.8595 0.8598 0.8595 0.8598 3458.0
2023-06-23 01:33:24.996 0.8598 0.8601 0.8598 0.8601 571.0
2023-06-23 03:18:30.345 0.8601 0.8604 0.8601 0.8604 4993.0
open high low close volume
datetime
2023-06-27 17:29:15.119 0.8595 0.8598 0.8595 0.8598 2889.0
2023-06-27 21:01:00.071 0.8595 0.8595 0.8592 0.8592 7779.0
2023-06-27 21:31:48.569 0.8595 0.8598 0.8595 0.8598 359.0

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

Following the steps of the mplfinance documentation, it can be tricky to display animations properly in jupyter notebooks, therefore, to keep things simple, the animation examples are scripts.

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 the above example files, talking about situations or recommendations to be applied in real cases.

Is the Renko chart calculated correctly?

I also 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 as a 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.

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.



          

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

renkodf-1.1.tar.gz (13.7 kB view hashes)

Uploaded Source

Built Distribution

renkodf-1.1-py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page