i am getting wrong value in calculating heikin ashi using python code

Viewed 40

I get a different value for only the Open price while finding out the Heikin Ashi candlestick pattern using Python code. Below is the python function to generate the HA Candlestick. The open price for 2022-07-11 is as follow : 123.92 - in heikin ashi value. (source data from broker python api) 124.25 - in fyers web chart. 123.92 - in google finance

I found there is a difference in the Open price, but the rest of the columns look fine. Could anyone please suggest if the python code is wrong?

def heikin_ashi(df):
df = df
print(df)
# to find Hikin Ashi pattern.
df['ha_open'] = ((df['open'] + df['close'])).shift(1) / 2
df['ha_close'] = (df['open'] + df['high'] + df['low'] + df['close']) / 4
df['ha_high'] = df['high']
df['ha_low'] = df['low']
# to create xlsx file with OHLC data.
# df.to_excel(report_dir + "OHLC_" + report_name, sheet_name='candle')
df = df.round({'ha_open': 2, 'ha_high': 2, 'ha_low': 2, 'ha_close': 2})

df = df[['timestamp','open','high','low','close','volume','ha_open','ha_high','ha_low','ha_close']]
return df

This takes a pandas dataframe as a input paramater and generate Heikin Ashi OHLC value. Example for dataframe output.

enter image description here

0 Answers
Related