nardew / talipp

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

SOBV uses SMA but any smoother from MAFactory could probably be used #146

Open femtotrader opened 2 months ago

femtotrader commented 2 months ago

https://github.com/nardew/talipp/blob/ed5e0e10c986121b5762d4538649212ec05a9847/talipp/indicators/SOBV.py#L44

femtotrader commented 2 months ago

Maybe we could even have something more general (let's call this a smoother) which could take the following parameters:

whom role is to "smooth" values of an indicator

SOBV will be defined like so (for example)

SOBV = Smoother(OBV, 20, ma_type=MAType.SMA)

and could be used like so

ind = SOBV()  # or SOBV(*obv_args, **obv_kwargs)

Smoothing indicators which have several values will need to pass a value extractor

femtotrader commented 2 months ago

https://github.com/nardew/talipp/pull/147

implements such an idea... but with a slightly different API idea

We have now in this PR

SOBV = IndicatorFactory.get_smoother(OBV, MAType.SMA)
indicator = SOBV(20)

Smoother and MAFactory seems to be very close concepts but Smoother contains an internal indicator whom output values are smoothed while MAFactory just return a moving average indicator set for a given period.

nardew commented 2 months ago

Hi @femtotrader , first, sorry for not following up on all the discussions you opened. It's very appreciated but currently I cannot allocate time for this project. I will return to them as soon as possible.

Regarding a generic smoother, we can instantiate any MA object directly and pass another indicator into it via indicator chaining like bellow:

sma1 = SMA(3)
sma2 = SMA(3, input_indicator = sma1)

This way you can smooth anything via any MA without need for any new object. Does it fit what you are proposing?

femtotrader commented 2 months ago

Hi @nardew ,

We all have life outside GH! no problem.

My idea was to create SOBV class from OBV class and a moving average class... without setting period neither instantiating the classes. So we can create appropriate classes and only instantiate them as needed.

Kind regards