本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=2
//Stochastic Momentum Index
// Author: Surjith S M (India)
// Copyright: CC 3.0
//Thanks UCSgears, lonestar108
study("Stochastics Momentum Index", shorttitle = "Stoch_MTM")
a = input(10, "Percent K Length")
b = input(3, "Percent D Length")
ob = input(40, "Overbought")
os = input(-40, "Oversold")
// Range Calculation
ll = lowest (low, a)
hh = highest (high, a)
diff = hh - ll
rdiff = close - (hh+ll)/2
avgrel = ema(ema(rdiff,b),b)
avgdiff = ema(ema(diff,b),b)
// SMI calculations
SMI = avgdiff != 0 ? (avgrel/(avgdiff/2)*100) : 0
SMIsignal = ema(SMI,b)
emasignal = ema(SMI, 10)
h0 = hline(40)
h1 = hline(-40)
//Color Definition for Stochastic Line
//col = SMI >= 40 ? green : SMI <= -40 ? red : black
plot(SMIsignal, title="Stochastic", style=line, color=black)
plot(emasignal, title="EMA", style=line, color=red)
level_40 = 40
level_40smi = SMIsignal > level_40 ? SMIsignal : level_40
level_m40 = -40
level_m40smi = SMIsignal < level_m40 ? SMIsignal : level_m40
p1 = plot(level_40)
p2 = plot(level_40smi)
p3 = plot(level_m40)
p4 = plot(level_m40smi)
fill(p1, p2, color=red, transp=40, title='OverSold')
fill(p3, p4, color=green, transp=40, title='OverBought')