pegahcarter / TAcharts

Apply popular TA tools and charts to candlestick data with NumPy.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

atr renko issue on historycal data how can apply on realtime tick ohlc data

gaju432 opened this issue · comments

Respected Sir,

from TAcharts.indicators.renko import Renko
# Renko(df=None, filename=None, interval=None)
r = Renko(df)

	# try:
	r.set_brick_size(auto=True, atr_interval=2)  # errir at this line as shown below
	r.build()
	r.plot()




                  close    high     low    open   volume

2020-08-20 23:29:00 3211.0 3211.0 3211.0 3211.0 69546.0
Index(['date', 'close', 'high', 'low', 'open', 'volume'], dtype='object')
date close high low open volume
0 2020-08-20 23:29:00 3211.0 3211.0 3211.0 3211.0 69546.0
Unhandled Error
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\python\log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\python\log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\python\context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\python\context.py", line 85, in callWithContext
return func(*args,**kw)
--- ---
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
why = getattr(selectable, method)()
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\internet\tcp.py", line 243, in doRead
return self._dataReceived(data)
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\internet\tcp.py", line 249, in _dataReceived
rval = self.protocol.dataReceived(data)
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\protocols\tls.py", line 330, in dataReceived
self._flushReceiveBIO()
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\protocols\tls.py", line 295, in _flushReceiveBIO
ProtocolWrapper.dataReceived(self, bytes)
File "C:\ProgramData\Anaconda3\lib\site-packages\twisted\protocols\policies.py", line 120, in dataReceived
self.wrappedProtocol.dataReceived(data)
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\twisted\websocket.py", line 288, in dataReceived
self._dataReceived(data)
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\websocket\protocol.py", line 1206, in _dataReceived
self.consumeData()
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\websocket\protocol.py", line 1218, in consumeData
while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\websocket\protocol.py", line 1578, in processData
fr = self.onFrameEnd()
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\websocket\protocol.py", line 1700, in onFrameEnd
self._onMessageEnd()
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\twisted\websocket.py", line 316, in _onMessageEnd
self.onMessageEnd()
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\websocket\protocol.py", line 627, in onMessageEnd
self._onMessage(payload, self.message_is_binary)
File "C:\ProgramData\Anaconda3\lib\site-packages\autobahn\twisted\websocket.py", line 319, in _onMessage
self.onMessage(payload, isBinary)
File "C:\ProgramData\Anaconda3\lib\site-packages\kiteconnect\ticker.py", line 71, in onMessage
self.factory.on_message(self, payload, is_binary)
File "C:\ProgramData\Anaconda3\lib\site-packages\kiteconnect\ticker.py", line 670, in _on_message
self.on_ticks(self, self._parse_binary(payload))
File "C:\Users\sc-pc\Downloads\pyrenko1.py", line 355, in on_ticks
r.set_brick_size(auto=True, atr_interval=2)
File "C:\ProgramData\Anaconda3\lib\site-packages\TAcharts\indicators\renko.py", line 46, in set_brick_size
raise ValueError("ATR interval is longer than historical data.")
builtins.ValueError: ATR interval is longer than historical data.

i m solanki from raj.india
8104093607

Hey there! So this error:
ValueError: ATR interval is longer than historical data.

Means that your dataset must have more rows than your ATR interval. You can't form a 20-day moving average on 10 days of data!

I have a feeling the dataset you're inputting doesn't have enough rows. Can you print your df?

Hello, I ran into a similar situation trying to utilize the data and code directly from Github download. Copied my test code below:

from TAcharts.utils.ohlcv import OHLCV
df = OHLCV().btc

from TAcharts.indicators.renko import Renko

r = Renko(df)
r.set_brick_size(auto=True, atr_interval=2)
r.build()

r.plot()

I got a similar ValueError with the data size against the index size.

Traceback (most recent call last): File "test2.py", line 7, in <module> r.set_brick_size(auto=True, atr_interval=2) File "E:\Nemo\Projects\eprojects\TAcharts\TAcharts\TAcharts\indicators\renko.p y", line 46, in set_brick_size self.brick_size = self._optimize_brick_size(auto, brick_size, atr_interval) File "E:\Nemo\Projects\eprojects\TAcharts\TAcharts\TAcharts\indicators\renko.p y", line 54, in _optimize_brick_size self.df["high"], self.df["low"], self.df["close"], n=atr_interval File "E:\Nemo\Projects\eprojects\TAcharts\TAcharts\TAcharts\indicators\atr.py" , line 17, in atr prev_close = np.insert(close[:-1], 0, 0) File "<__array_function__ internals>", line 6, in insert File "E:\Nemo\Projects\eprojects\lab\lib\site-packages\numpy\lib\function_base .py", line 4601, in insert return wrap(new) File "E:\Nemo\Projects\eprojects\lab\lib\site-packages\pandas\core\generic.py" , line 1918, in __array_wrap__ return self._constructor(result, **d).__finalize__(self) File "E:\Nemo\Projects\eprojects\lab\lib\site-packages\pandas\core\series.py", line 292, in __init__ f"Length of passed values is {len(data)}, " ValueError: Length of passed values is 7940, index implies 7939.

I can see the below in the atr.py module. Looks like an off-by-one error? But if we are going to derive the previous close from the data set, the first observation won't able to have a value.

def atr(high, low, close, n=14): """ Returns the average true range from candlestick data """ prev_close = np.insert(close[:-1], 0, 0)

Hello, Thanks for this great project!

I have identical problem as @byteatwork

ValueError: Length of passed values is 196, index implies 195.

This issue is a little bit above my programming skills.
I really appreciate any help

  1. Was anyone able to diagnose why this problem was happening and what is a possible solution? I'm using Python 3.7 under Anaconda.

  2. I am trying to run the following code:

r = Renko(df_sample_1hour)
r.set_brick_size(auto=True, atr_interval=2)
r.build()
r.plot()

  1. I have a DataFrame with 1650 rows, starting with index 0, but I still receive an error:
    ValueError: Length of passed values is 1650, index implies 1649.

  2. Also, after running the statement:
    r = Renko(df_sample_1hour)
    the value of df_sample_1hour[0].date becomes 'NaT'

  3. Even if I specify the brick_size via:
    r.set_brick_size(brick_size=2, atr_interval=2)

On the next statement:
r.build()
it still gives an error:
AttributeError: 'Renko' object has no attribute 'close'
which seems unrelated though.