# Can I have the exact formula for Stochastic momentum index which is in zerodha platform so that I can use it in algo trading

df[‘stoch_sig’]= round(ta.momentum.StochasticOscillator(df[‘high’], df[‘low’], df[‘close’],14, 3,).stoch_signal(),2)
df[‘stoch’]= round(ta.momentum.StochasticOscillator(df[‘high’], df[‘low’], df[‘close’],14, 3,).stoch(),2)

but it is giving stochastic value not stochastic momentum value.

def SMI(dfHigh, dfLow, dfClose, period = 13, fast_period = 2, slow_period = 25, signal_period = 9):
rolling_high = rolling_window(dfHigh,period)
rolling_low = rolling_window(dfLow,period)

``````centre = np.zeros(len(rolling_high))
HL_diff = np.copy(centre)
for i in range(len(centre)):
centre[i] = (np.max(rolling_high[i]) + np.min(rolling_low[i])) / 2
HL_diff[i] = np.max(rolling_high[i]) - np.min(rolling_low[i])

centre = np.concatenate((((dfHigh[:period-1] + dfLow[:period-1]) / 2),centre))
HL_diff = np.concatenate(((dfHigh[:period-1] - dfLow[:period-1]),HL_diff))

c_diff = dfClose - centre
num1 = EMA(c_diff,slow_period)
den1 = EMA(HL_diff,slow_period)
num2 = EMA(num1[slow_period-1:], fast_period)
den2 = EMA(den1[slow_period-1:], fast_period) / 2
SMI = 100 * (num2 / den2)
signal = EMA(SMI[1:], signal_period)
SMI = np.concatenate((np.array([np.nan] * (slow_period-1)), SMI))
signal = np.concatenate((np.array([np.nan] * (slow_period)), signal))
return((SMI,signal))``````
1 Like