Issue trying to plot renko chart
gambitov opened this issue · comments
I am getting OHLCV from binance
symbol = 'BTC/USDT'
time_frame = '1h'
candles = exchange.fetch_ohlcv(symbol, time_frame)
df = pd.DataFrame(candles,columns=['date','open','high','low','close','volume'])
df['date'] = df['date'].apply(lambda date: pd.Timestamp(time.ctime(date/1000.)))
#df.set_index('date',inplace=True)
print(df.head())
My data has this form:
date open high low close volume
0 2021-06-07 16:00:00 34440.44 34647.58 33563.40 34113.35 7836.220911
1 2021-06-07 17:00:00 34113.66 34291.54 33905.55 34147.92 3330.645468
2 2021-06-07 18:00:00 34147.92 34182.80 33300.00 33552.79 5918.137625
3 2021-06-07 19:00:00 33556.96 34068.01 33340.00 33670.35 7752.349081
4 2021-06-07 20:00:00 33669.79 33961.90 33553.39 33776.06 3102.174650
I am using renko code:
r = Renko(df)
r.set_brick_size(auto=True, atr_interval=2)
r.build()
r.plot()
But I have this issue:
File "c:/Users/Gabriel/Desktop/Bot/Analizador/test_tacharts.py", line 47, in <module>
r.set_brick_size(auto=True, atr_interval=2)
File "C:\Users\Gabriel\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\TAcharts\indicators\renko.py", line 46, in set_brick_size
self.brick_size = self._optimize_brick_size(auto, brick_size, atr_interval)
File "C:\Users\Gabriel\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\TAcharts\indicators\renko.py", line 53, in _optimize_brick_size
average_true_range = atr(
File "C:\Users\Gabriel\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\TAcharts\indicators\atr.py", line 17, in atr
prev_close = np.insert(close[:-1], 0, 0)
File "<__array_function__ internals>", line 5, in insert
File "C:\Users\Gabriel\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\numpy\lib\function_base.py", line 4601, in insert
return wrap(new)
File "C:\Users\Gabriel\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\generic.py", line 1918, in __array_wrap__
return self._constructor(result, **d).__finalize__(self)
File "C:\Users\Gabriel\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\series.py", line 291, in __init__
raise ValueError(
ValueError: Length of passed values is 500, index implies 499.
Hello!
I have the exact same issue.
i have same issue, can you please check
I have been looking through the source code because I am having the same issue, and I have found some stuff that seem to be erroneous in the renko implementation.
In the source code for building the blocks, I have found that in these two lines:
You are referring to a self.close
class variable that does not exist. I tried to change it to self.df.close
in order to see if that made everything work but another error arises. This one has to do with the atr function, and going through it I saw that in line 23 two true_range
are computed(idk if its a normal thing) but only the last one is used.
I am unsure if the things I said are expected to happen. Anyways, hope this helps. If have some time, I might try to do a PR trying to fix the renko implementation.