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.37k stars 1.05k forks source link

Dev Branch: Chandelier Exit offset direction #820

Open severin-meng opened 2 months ago

severin-meng commented 2 months ago

Which version are you running? The lastest version is on Github. Pip is for major releases. I am using python 3.9 and pandas_ta 0.4.19b0 (dev branch).

Do you have TA Lib also installed in your environment? no

There is a bug in the development branch of the volatility indicator "Chandelier Exit", see here: https://github.com/twopirllc/pandas-ta/blob/438f3a97b71b26bc17efb1a204fb0e0fdc48e0aa/pandas_ta/volatility/chandelier_exit.py#L108

    direction = uptrend + downtrend
    if direction.iloc[0] == 0:
        direction.iloc[0] = 1
    direction = direction.replace(0, nan).ffill()

    # Offset
    if offset != 0:
        long = long.shift(offset)
        short = short.shift(offset)
        direction = short.shift(offset)

If you add a nonzero offset, the direction column is replaced with the shifted short column. In reality you would want the direction column to be shifted itself. Here is what I believe to be the corrected version (only the last line is changed):

    direction = uptrend + downtrend
    if direction.iloc[0] == 0:
        direction.iloc[0] = 1
    direction = direction.replace(0, nan).ffill()

    # Offset
    if offset != 0:
        long = long.shift(offset)
        short = short.shift(offset)
        direction = direction.shift(offset)
twopirllc commented 2 months ago

Hello @severin-meng,

Doh! 🤦🏼‍♂️ Thanks for noticing the copy/paste error lol. 🤣

Kind Regards, KJ