How can ichimoku lines values ​be obtained with the pandas_ta library in Python?

643 Views Asked by At

Anyone familiar with the pandas_ta library? I use the following code to get ichimoku values:

ichi = ta.ichimoku(df['high'], df['low'], df['close'], include_chikou=True)

Ichi type should be data frame but the output is a 2-member tuple. Does anyone know where the problem comes from?

2

There are 2 best solutions below

0
On

Since a tuple is returned, you can use this code

def add_ichi(self, tenkan: int = 9, kijun: int = 26, senkou: int = 52, offset: int = 26) -> None:
        df_ichi = ta.ichimoku(self.df["high"], self.df["low"], self.df["close"], tenkan=tenkan, kijun=kijun, senkou=senkou, offset=offset)
        df_ichi[0].columns = ["spanA", "spanB", "tenkan_sen", "kijun_sen", "chikou_span"]
        df_ichi[1].columns = ["spanA_future", "spanB_future"]
        self.df["spanA_future"] = df_ichi[1]["spanA_future"]
        self.df["spanB_future"] = df_ichi[1]["spanB_future"]

For example, df_ichi[1]["spanA_future"] - we move the data from tuple [1] to the Pandas dataframe column df["spanA_future"]

1
On

The ichimoku function returns 2 dataframes. The first df with values up until the current candle and one for the forward looking part of the cloud.