Need formula for Stochastic-Momentum-Index Indicator


#1

Hi All,
Need formula for Stochastic-Momentum-Index Indicator.
%K and %D Calculation formula.

Please don’t give for normal Stochastic Oscillator.


#2

Formula for Stochastic Momentum Index Indicator;-

In order to calculate SMI, start from “N”. Lets suppose N=10. After choosing a Period, determine the Center of High and Low Range during the period. In order to do so, use the following formula:

Lets suppose “C” is the center of High and Low, then:

C = (High MAX + Low MIN) / 2

Where

High MAX = The Highest Figure in the Range.
Low MIN = The Lowest Figure in the Range.

After calculating a center point of the range, subtract distance of Current Close from the Center of the Range.

H = CC TODAY – C

Where

CC TODAY = Current Closing Price.
C = Center of High/Low Range.

In order to smooth the output of “H”, use a 3-period Exponential Moving Average. Following will be the procedure of smoothing “H”.

HS1 = (H) * (3) * Exponential Moving Average
HS2 = (HS1) * (3) * Exponential Moving Average

After smoothing “H”, smooth the difference of High and Low Price during the period using same 3-Period Exponential Moving Average. Divide the results of Second Smoothing by 2:

DHL1 = (High MAX – Low MIN) * (3) * Exponential Moving Average
DHL2 = (High MAX – Low MIN) * (3) * Exponential Moving Average / 2

In order to Calculate SMI, divide HS2 by DHL2. Multiplying the output by 100 will provide results in the form of a percentage.

SMI TODAY = (HS2 / DHL2) * 100

%K and %D calculation formula;-

%K = (Current Close - Lowest Low)/(Highest High - Lowest Low) * 100
%D = 3-day SMA of %K

Lowest Low = lowest low for the look-back period
Highest High = highest high for the look-back period
%K is multiplied by 100 to move the decimal point two places

The default setting for the Stochastic Oscillator is 14 periods, which can be days, weeks, months or an intraday timeframe. A 14-period %K would use the most recent close, the highest high over the last 14 periods and the lowest low over the last 14 periods. %D is a 3-day simple moving average of %K. This line is plotted alongside %K to act as a signal or trigger line.

Fast Stochastic Oscillator:

Fast %K = %K basic calculation
Fast %D = 3-period SMA of Fast %K
Slow Stochastic Oscillator:

Slow %K = Fast %K smoothed with 3-period SMA
Slow %D = 3-period SMA of Slow %K
The Full Stochastic Oscillator is a fully customizable version of the Slow Stochastic Oscillator. Users can set the look-back period, the number of periods to slow %K and the number of periods for the %D moving average. The default parameters were used in these examples: Fast Stochastic Oscillator (14,3), Slow Stochastic Oscillator (14,3) and Full Stochastic Oscillator (14,3,3).

Full Stochastic Oscillator:

Full %K = Fast %K smoothed with X-period SMA
Full %D = X-period SMA of Full %K


#3

I tried my best to put the above in the logic in python code, but iam getting wrong results, can you please help me

def Stochastic_Mom_index(df,n):

Mid = (df['high'] + df['low'])/2
maxH = max(df['high'])
minL = min(df['low'])

H = df['close']-Mid
HS1 = H * df['close'].ewm(span=3).mean()
HS2 = HS1 * df['close'].ewm(span=3).mean()

DHL1 = (maxH - minL) * df['close'].ewm(span=3).mean()
DHL2 = (maxH - minL) * df['close'].ewm(span=3).mean() / 2

SMI = (HS2 / DHL2) * 100

fstochk = pd.Series(( df['close'] - minL ) / (maxH - minL) * 100,name='StochK')
fstochD = pd.Series(3 - (fstochk * df['close'].ewm(span=3).mean()),name = 'StochD')

sStochK = pd.Series(fstochk * df['close'].ewm(span=3).mean(),name='slowStochK')
sStochD = pd.Series(3 - (sStochK * df['close'].ewm(span=3).mean()),name='slowStochD')

df = df.join(fstochk)
df = df.join(fstochD)
df = df.join(sStochK)
df =df.join(sStochD)

return df