nardew / talipp

talipp - incremental technical analysis library for python
https://nardew.github.io/talipp
MIT License
367 stars 59 forks source link

After the upgrade to 2.2.1 I can only initialize indicators RSI and TSI but cannot add a new input using rsi().add() and tsi().add(). #134

Open hysech opened 4 months ago

hysech commented 4 months ago

Hello Nardew, sorry to disturb you. I used your older version of talipp at the same code without any issue. After the upgrade to 2.2.1 I can only initialize indicators RSI and TSI but cannot add a new input using rsi().add() and tsi().add(). Maybe the reason is in my using global variables gl.rsi, gl. tsi or other trik in Python, but I am stalling 2 weeks already. To go on in debugging I have to initialize rsi, tsi repeatedly and after a limit use .purge_oldest which for some reason is working!?!? Of course repeating the initializations is very time consuming and downgrading to older version is the last step? I tried to add type(R/TSI) to the declaration of the global var. but it did not help.

My config file with globals:

from talipp.indicators import TSI, RSI, EMA, SMA, Stoch tsi1l = type(TSI) # TSI(13, 25, input_values = close_1ll)

tsi1l.add() = TSI(13, 25, input_values = close_1ll).add()

rsi1l = type(RSI) # RSI(14, input_values = close_1ll)

rsi1l.add() = RSI(14, input_values = close_1ll).add()

tsi2l = type(TSI) # TSI(13, 25, input_values = close_1ll) rsi2l = type(RSI) # RSI(14, input_values = close_1ll) tsi3l = type(TSI) # TSI(13, 25, input_values = close_1ll) rsi3l = type(RSI) # RSI(14, input_values = close_1ll)

Code using talipp is of this type:

if len(gl.b1ldframe) < 50: gl.close_1ll += [gl.b1l_close]

logger.info(f'gl.close_1ll = {gl.close_1ll}')

        gl.rsi1l = RSI(14, input_values=gl.close_1ll)
        gl.tsi1l = TSI(13, 25, input_values=gl.close_1ll)
        if gl.rsi1l[-1] != gl.rsi1l[-1]:
            xlst = gl.b1l_bar + [0.0]
        else:
            xlst = gl.b1l_bar + [gl.rsi1l[-1]]
        if gl.tsi1l[-1] != gl.tsi1l[-1]:
            xlst = xlst + [0.0]
        else:
            xlst = xlst + [gl.tsi1l[-1]]

        #   lis1.extend([None])

else:

xlst = gl.b1l_bar + [gl.rsi1l.add(gl.b1l_bar[4])[-1]]
xlst += [gl.tsi1l.add(gl.b1l_bar[4])[-1]]
[logger.info](http://logger.info/)(f'xlst = {xlst}')
print('[RSI(14,).add(gl.b1l_bar[4])][-1]:')
print([RSI(14,).add(gl.b1l_bar[4])][-1])
gl.b1ldframe.loc[len(gl.b1ldframe.index)] = xlst
len1 = len(gl.b1ldframe)
[logger.info](http://logger.info/)(f'=3.len(gl.b1ldframe): {len1},')
[logger.info](http://logger.info/)(f'=3gl.b1ldframe.iloc[-1]:')
[logger.info](http://logger.info/)(f'{gl.b1ldframe.iloc[-1].tolist()}')
#################################################

RSI and TSI needs for my data(S&P2000, future) more than 30 bars to calculate a value, NaNs at start. RSI, TSI values for 1st 50 bars. When the second part of code is executed (see gl.rsi1l.add(gl.b1l_bar[4]), error message occurs:

File "name.py", line 394, in genbars xlst = gl.b1l_bar + [gl.rsi1l.add(gl.b1l_bar[4])[-1]]


TypeError: 'NoneType' object is not subscriptable

 #################################################

Thank you very much in advance for your time and help.
With my regards,
                                Hynek Sechovsky 

    Neobsahuje žádné viry.[www.avast.com](https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail)

talipp.pyth@gmail.com. Stisknutím tabulátoru návrh vložíte.
Strana 1 z 2
nardew commented 4 months ago

Hi @hysech , it's difficult to judge what is going wrong in your script. What is in gl.rsi1l and gl.b1l_bar at the line where it fails? Can you print those values in the line right before it?

Also when pasting a code, please enclose it between triple backticks to render it properly, otherwise it is not very readable.

hysech commented 4 months ago

Hi Nardew, sorry for my delay. I am too old and too slow. I tried to prepare testing data in more readable form as far as my not advanced lknowledge of Python allowed, see appended files. At my first glance at the data I thought that the root may be in my using of global variables. So I added testing local variables as well and corrected some mistakes in my source. The local variables now have the same behavior as global ones. From this I assume, the mistake is on my side, I do not understand how to use the RSI, TSI classes in a new version of TALIPP properly. In my case I would like to calculate rsi, tsi values for 3 different lengths of data bars like 10 sec, 1min, 10min at the same program. May I ask you to show me simple example how to use 3 different calls of RSI class that keep relation to their own data source? I tried to use same code which was working for previous talipp version and now for new version I am dependent on "input values" function that I have to repeat for last 200 bars after each new data bar. In fact your library is pretty fast and I am able to reach needed speed of the run. But I feel like a fool to make such technical nonse just for my poor knowledge of the object oriented python. Thank you in advance for your response and help, Hynek https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Neobsahuje žádné viry.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#m_-3670896732873681728_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

st 1. 5. 2024 v 22:28 odesílatel nardew @.***> napsal:

Hi, it's difficult to judge what is going wrong in your script. What is in gl.rsi1l and gl.b1l_bar at the line where it fails? Can you print those values in the line right before it?

Also when pasting a code, please enclose it between triple backticks to render it properly, otherwise it is not very readable.

— Reply to this email directly, view it on GitHub https://github.com/nardew/talipp/issues/134#issuecomment-2089081675, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQITNIOJFFXXMFXF5SZUB3LZAFF73AVCNFSM6AAAAABG662V66VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBZGA4DCNRXGU . You are receiving this because you authored the thread.Message ID: @.***>

hysech commented 4 months ago

---------- Forwarded message --------- Od: Hynek Sechovsky senior @.> Date: út 14. 5. 2024 v 18:34 Subject: Re: [nardew/talipp] Sorry Nardew, my poor knowledge - After the upgrade to 2.2.1 I can only initialize indicators RSI and TSI but cannot add a new input using rsi().add() and tsi().add(). (Issue #134) To: nardew/talipp < @.>

Hi Nardew, sorry for my delay. I am too old and too slow. I tried to prepare testing data in more readable form as far as my not advanced lknowledge of Python allowed, see appended files. At my first glance at the data I thought that the root may be in my using of global variables. So I added testing local variables as well and corrected some mistakes in my source. The local variables now have the same behavior as global ones. From this I assume, the mistake is on my side, I do not understand how to use the RSI, TSI classes in a new version of TALIPP properly. In my case I would like to calculate rsi, tsi values for 3 different lengths of data bars like 10 sec, 1min, 10min at the same program. May I ask you to show me simple example how to use 3 different calls of RSI class that keep relation to their own data source? I tried to use same code which was working for previous talipp version and now for new version I am dependent on "input values" function that I have to repeat for last 200 bars after each new data bar. In fact your library is pretty fast and I am able to reach needed speed of the run. But I feel like a fool to make such technical nonse just for my poor knowledge of the object oriented python. Thank you in advance for your response and help, Hynek https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Neobsahuje žádné viry.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#m_-3019286199351059079m-3670896732873681728_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

st 1. 5. 2024 v 22:28 odesílatel nardew @.***> napsal:

Hi, it's difficult to judge what is going wrong in your script. What is in gl.rsi1l and gl.b1l_bar at the line where it fails? Can you print those values in the line right before it?

Also when pasting a code, please enclose it between triple backticks to render it properly, otherwise it is not very readable.

— Reply to this email directly, view it on GitHub https://github.com/nardew/talipp/issues/134#issuecomment-2089081675, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQITNIOJFFXXMFXF5SZUB3LZAFF73AVCNFSM6AAAAABG662V66VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBZGA4DCNRXGU . You are receiving this because you authored the thread.Message ID: @.***>

nardew commented 3 months ago

Hi @hysech , instantiating three independent RSI indicators should not be problematic in any way:

close = random.sample(range(1, 10000), 1000)

rsi1 = RSI(2, input_values=close)
rsi2 = RSI(3, input_values=close)
rsi3 = RSI(4, input_values=close)

print(rsi1[-1])
print(rsi2[-1])
print(rsi3[-1])

Output:

65.18165798725016
59.795855990107746
56.95817180954775

Some logging output I asked for above could help.