Skip to content

Commit

Permalink
Added Renko bricks indicator #61
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkrish-coder committed Jul 9, 2023
1 parent d259502 commit 65149fc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions IntelliTrader/IntelliTrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@
indicator.execute_handler('vwap', datasource)
indicator.execute_handler('adx', datasource)
indicator.execute_handler('stochastic', datasource)
indicator.execute_handler('renko', datasource, 5)


1 change: 1 addition & 0 deletions IntelliTrader/IntelliTrader.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<Compile Include="src\indicators\atr.py" />
<Compile Include="src\indicators\ma.py" />
<Compile Include="src\indicators\macd.py" />
<Compile Include="src\indicators\renko.py" />
<Compile Include="src\indicators\rsi.py" />
<Compile Include="src\indicators\stochastic.py" />
<Compile Include="src\indicators\vwap.py" />
Expand Down
23 changes: 22 additions & 1 deletion IntelliTrader/src/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from src.indicators.vwap import vwap
from src.indicators.adx import adx
from src.indicators.stochastic import stochastic
from src.indicators.renko import renko

class Indicator:
def __init__(self, params):
self.prop = params

def execute_handler(self, indicator_option, dataset):
def execute_handler(self, indicator_option, dataset, period=0):
match indicator_option:
case 'macd':
self.option_macd(dataset)
Expand All @@ -37,6 +38,9 @@ def execute_handler(self, indicator_option, dataset):
self.option_adx(dataset)
case 'stochastic':
self.option_stochastic(dataset)
case 'renko':
self.option_renko(dataset, period)

case _:
self.invalid_option(dataset)

Expand Down Expand Up @@ -205,6 +209,23 @@ def option_stochastic(self, dataset):
except:
self.prop['log'].error("The received object is not a valid DataFrame")

def option_renko(self, dataset, period):
try:
if dataset is not None and not dataset.empty:
# Calculate Renko
pdf = pd.DataFrame(dataset)
renko_bricks = renko(pdf, period)
last_renko_brick = renko_bricks.iloc[-1]

# Print the calculated Renko values
print("\nRenko Bricks:")
print(renko_bricks)
else:
self.prop['log'].error("Failed to calculate Renko")
return False
except:
self.prop['log'].error("The received object is not a valid DataFrame")

def invalid_option(self, dataset):
# Invalid indicator option provided
self.prop['log'].warn("The indicator option provided is not valid")
Expand Down
12 changes: 12 additions & 0 deletions IntelliTrader/src/indicators/renko.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pandas as pd
from stocktrends import Renko

def renko(dataset, size=2):
# Check if dataset contains the required columns
data = dataset if 'open' in dataset and 'high' in dataset and 'low' in dataset and 'close' in dataset else None
data.reset_index(inplace=True)
r = Renko(data)
r.brick_size = size
renko_bricks = r.get_ohlc_data()

return renko_bricks

0 comments on commit 65149fc

Please sign in to comment.