[HELP] Need calculate Stochastic oscillator using pyhton

 

Hi everyone,

I'm trying to calculate Stochastic 5 3 3 oscillator using python but the result is different from chart MT5. Please help.

My code below

def calculate_stochastic_oscillator(df):

    df['low_min'] = df['low'].rolling(window=5).min()
    df['high_max'] = df['high'].rolling(window=5).max()
    df['%K'] = (df['close'] - df['low_min']) / (df['high_max'] - df['low_min']) * 100
    df['%D'] = df['%K'].rolling(window=3).mean()

    return df
 
uppppppppppppppp, somebody helppppp