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.02k stars 986 forks source link

HiLo is not working perfectly, same numbers printing many time. #514

Open whatismyname21 opened 2 years ago

whatismyname21 commented 2 years ago

Which version are you running? The lastest version is on Github. Pip is for major releases.

import pandas_ta as ta
print(ta.version)

Do you have TA Lib also installed in your environment?

$ pip list

Did you upgrade? Did the upgrade resolve the issue?

$ pip install -U git+https://github.com/twopirllc/pandas-ta

Describe the bug A clear and concise description of what the bug is.

To Reproduce Provide sample code.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Thanks for using Pandas TA!

twopirllc commented 2 years ago

Hello @whatismyname21,

I can not help you as you have not completed the above form nor have you provided enough evidence (context, data, reproducible code, screenshots) to convince us that this is anything but a baseless claim.

Clearly not a lot of the same number printing many times:

Screen Shot 2022-04-12 at 6 35 32 AM

Kind Regards, KJ

whatismyname21 commented 2 years ago

Hi Kevin

I have used below code

HILO = ta.hilo(df["High"],df["Low"],df["Close"], high_length=2, low_length=4)

Price is moving but i am getting same result many time. Please find attached screenshot.

Thanks Aj

twopirllc commented 2 years ago

@whatismyname21,

Again:

Thanks for providing the indicator and parameters that are not working.

KJ

whatismyname21 commented 2 years ago

Hi Kevin

Please answer in line...

whatismyname21 commented 2 years ago
Screenshot 2022-04-12 at 11 12 59 PM
twopirllc commented 2 years ago

@whatismyname21

Thanks, we are getting there... What ticker/symbol?

There is no such Pandas TA version: 1.3.4

import pandas_ta as ta
print(ta.version)
whatismyname21 commented 2 years ago

Sorry to bug you, but my main strategy is on Gann HiLo

Version - 0.3.14b0 Ticker name - AAPL Today's data

Screenshot 2022-04-12 at 11 53 08 PM
twopirllc commented 2 years ago

@whatismyname21

Your small ma lengths can cause the conditional logic to repeat values until the close price either exceeds the previous high/low sma values.

You should add the sma's and compare for yourself that the logic is working as implemented.

df = # your ohlcv data
df.ta.sma(2, append=True)
df.ta.sma(4, append=True)
df.ta.hilo(high_length=2, low_length=4, append=True)
print(df)

HILO core logic:

def hilo(high, low, close, high_length=None, low_length=None, mamode=None, offset=None, **kwargs):
    """Indicator: Gann HiLo (HiLo)"""
    # Validate Arguments
    # ...

    high_ma = ma(mamode, high, length=high_length)
    low_ma = ma(mamode, low, length=low_length)

    for i in range(1, m):
        if close.iloc[i] > high_ma.iloc[i - 1]:
            hilo.iloc[i] = long.iloc[i] = low_ma.iloc[i]
        elif close.iloc[i] < low_ma.iloc[i - 1]:
            hilo.iloc[i] = short.iloc[i] = high_ma.iloc[i]
        else:
            hilo.iloc[i] = hilo.iloc[i - 1]
            long.iloc[i] = short.iloc[i] = hilo.iloc[i - 1]

    # ...
twopirllc commented 2 years ago

Yahoo Finance: AAPL (1min) - HILO(2,4) + SMA(2) + SMA(4) yf-aapl-1m-hilo_2_4.csv

Screen Shot 2022-04-12 at 11 45 01 AM
twopirllc commented 2 years ago

@whatismyname21,

Lately, I have been speeding up indicators on the development branch. When I get to this one, I'll double check it.