nardew/talipp

Support old data removal

fadishei opened this issue · 4 comments

Great work! Incremental update is a must for live TA and I've always wondered why none of the existing famous libraries provide that

I think it would be useful to be able to delete old data from indicator buffer. This will make memory usage complexity O(1) just like the computational complexity. I could not find any method in the Indicator class source code for this purpose. There is a remove_input_value() method but it removes the newest sample. Can you add a method for removing the oldest sample?

Hi @fadishei, thanks for the feedback! I was already pondering this feature in the past but was hesitating because was not sure about demand for it.

There are several approaches - remove old values with each addition (once max. limit is reached), remove in bulks (e.g. always remove X oldest values at the same time) or leave it fully up to the user to call the cleanup procedure manually via exposed new API. I tend to opt for 2nd and 3rd option because the 1st one will impose additional performance burden which I would like to avoid.

Do you have a view on it?

I think a simple API method (3rd option) will do it for most users. However, I am not qualified enough to say it is the best approach and the final decision is yours.

@fadishei, I created PR #41 which implements purging of old data via option 3. If you want, you can try it from branch purge.

To remove old data call indicator.purge_oldest(<number_of_values>).

Thank you for the new feature. I have tried it and it works well.