twopirllc / pandas-ta

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
https://twopirllc.github.io/pandas-ta/
MIT License
5.46k stars 1.06k forks source link

New zigzag #790

Closed aligheshlaghi97 closed 5 months ago

aligheshlaghi97 commented 6 months ago

Hello @twopirllc and @KilianB I am making this pr to solve the issue @KilianB reported in #761 some hours ago. The problem happens when there's two extremums in a single candle, e.g. we can see local max and min in 2021-09-07 00:00:00 candle. To handle this, I simply continued the code when this situation happens and as a result, one of the two consecutive swings disappear:

Screenshot from 2024-05-22 02-26-56

@twopirllc kindly find the better solution and if you needed any guidance with the code I wrote, do not hesitate to let me know. I also made another local branch in my fork and then made this pr, so you can consider whether or not close the previous pr #761

To explain more about code components, there are three functions: First I defined a rolling window function np_rolling_hl to find local min/max according to window_size value in input. In second function np_find_zigzags, I do the main job of finding zigzag values based on looking backwards to the candles (from the last candle to the first one). In the third function map_zigzag, I just mapped the index (and value) of zigzag points into the whole data vector.

twopirllc commented 6 months ago

@aligheshlaghi97

Excellent! Thanks for quickly responding and providing a fix. Will review and merge it as soon as I can with other PRs. Wish I had more time! 😅 I appreciate all your help. 😎