Closed Khanhlinhdang closed 6 months ago
Why do you think update does not work? Can you show a full example?
Regarding the update
function, it accepts float
/OHLCV
based on the indicator type. If indicator works with floats, then supply float to the update function. Accordingly for OHLCV.
this is my example code: import random
from talipp.indicators import AccuDist, ADX, ALMA, AO, Aroon, ATR, BB, BOP, CCI, ChaikinOsc, ChandeKrollStop, CHOP, \ CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, Ichimoku, KAMA, KeltnerChannels, KST, KVO, \ MACD, MassIndex, MeanDev, OBV, PivotsHL, ROC, RSI, ParabolicSAR, SFX, SMA, SMMA, SOBV, STC, StdDev, Stoch, StochRSI, \ SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, WMA, ZLEMA from talipp.ohlcv import OHLCVFactory,OHLCV import time
if name == "main": close = random.sample(range(1, 10000), 1000) ohlcv = OHLCVFactory.from_matrix2([ random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000)] ) ohlcv_update = OHLCVFactory.from_matrix2([ random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000), random.sample(range(1, 10000), 1000)] ) spt = SuperTrend(10, 3, ohlcv) for i in range(100):
if isinstance(ohlcv_update[-i], OHLCV):
spt.update(ohlcv_update[-i]) # example for update last candle as a sigle candle
#spt.update([ohlcv[-i]]) # example for update last candle as a list of candles
print(f'last output value: {spt.output_values[-1]}, update value: {spt.input_values[-1]}')
time.sleep(1)
and this is results: So, we can see that, with every diffirent input single candle we got the same output result. Or I had a misstake in my code?
I looked into it and it seems due to the nature of your data you are generating. The generated input data often do not make sense, e.g. your low
is greater than high
etc. I recommend to run it on real-life data and it should be fine.
Oh my god! thank you bro! I did not pay attention to this cause. but I used your generate function OHLCVFactory, may be you need to fix this function.
Not sure what you mean, OHLCVFactory
just produces OHLCV
objects based on the values you feed it. You are feeding it with randomly generated numbers outside the factory.
update function of supertrend is not work right. Can you check and add some example for update function. And add more option arg fot update function, like OHLCV: example: def update(self, new_candle: OHLCV) -> None: self.remove() self.add(new_candle) or something else. And update heikinashi candle please, I am use this lib for my project, it is very cool lib. Thank you.