johnwang9

McClellan Summation Index

BATS:SPY   SPDR S&P 500 ETF TRUST
McClellan Summation Index is suitable for SPY, and not good for Nasdaq, and the exchange is selected NYSE, and I also change some parameters. I found the original indicator is better than all kinds of adjusted McClellan Summation Index, and I hope you enjoy this indicator, pleasure

indicator("McClellan Summation Index", shorttitle="McClellan Summation Index",  precision=1)

type=input.string("MSI", options=["MSI RSI", "MO", "MSI"])
//type=input.string("MO", options=["MSI RSI", "MO"])
limecolor = #00FF00
period_msi = timeframe.period
//period_msi = "D" //fixed to daily
prev = 1

headwind = input(70, title="Head Wind")
tailwind = input(30, title="Tail Wind")

length = input(14, title="RSI length")
exchange = input.string(defval="NYSE", title="Choose Exchange", options=["NASDAQ", "NYSE", "NASDAQ+NYSE"])

nasdaq_adv = request.security("ADVQ", period_msi, close)
nasdaq_dec = request.security("DECLQ", period_msi, close)
nyse_adv = request.security("ADVN", period_msi, close)
nyse_dec = request.security("DECN", period_msi, close)

adv = (exchange == "NASDAQ") ? nasdaq_adv : (exchange == "NYSE") ? nyse_adv : nasdaq_adv + nyse_adv
dec = (exchange == "NASDAQ") ? nasdaq_dec : (exchange == "NYSE") ? nyse_dec : nasdaq_dec + nyse_dec

// rana = ratio_adjusted_ned_advance
// rana = (sym(advissues) - sym(decissues)) / (sym(advissues) + sym(decissues)) * 1000
rana = (adv - dec) / (adv + dec) * 1000

advnema19 = ta.ema(rana, 19)
advnema39 = ta.ema(rana, 39)
osci = advnema19-advnema39
msi = ta.cum(osci)

// McClellan Oscillator
rsi_msi = ta.rsi(msi, length)
isMSIUpTrend() => rsi_msi > rsi_msi[prev]
isMSIDownTrend() => rsi_msi <= rsi_msi[prev]
isHeadWind() => rsi_msi >= headwind
isTailWind() => rsi_msi <= tailwind
crossDownHeadWind() => rsi_msi
crossUpTailWind() => rsi_msi


showosi() => ("MO" == type) ? true : false

plot(showosi() ? osci : na, style=plot.style_line, title="MO", linewidth=2, color=color.black)
plot(showosi() ? 0 : na, style=plot.style_line, title="0", linewidth=1, color=color.new(color.gray, 30))
plot(showosi() ? -100 : na, color=na)
plot(showosi() ? 100  : na, color=na)

ma_length = input(9, title="MO MA Length")
ma_mo = ta.ema(osci, ma_length)
plot(showosi() ? ma_mo : na, title="MA", linewidth=2, color=color.red)


isMOUpTrend() => ma_mo > ma_mo[prev]
isMODownTrend() => ma_mo <= ma_mo[prev]

bgcolor(showosi() ? (isMOUpTrend() ? color.new(limecolor, 80) : na  ) : na)
bgcolor(showosi() ? (isMODownTrend() ? color.new(color.red , 80): na) : na)

// McClellan Summation Index
showmsi() => ("MSI RSI" == type) ? true : false

plot(showmsi() ? 50 : na, title="50", style=plot.style_line, linewidth=1, color=color.new(color.gray, 30))
headline=plot(showmsi() ? headwind : na, style=plot.style_line, color=color.new(color.green, 20), title="headwind")
tailline=plot(showmsi() ? tailwind : na, style=plot.style_line, color=color.new(color.red, 20), title="tailwind")
rsiline= plot(showmsi() ? rsi_msi  : na, style=plot.style_line, color=color.black, linewidth=2, title="RSI_MSI")

headcolor = showmsi() ? (isHeadWind() and isMSIDownTrend() ? color.red : na) : na
tailcolor = showmsi() ? (isTailWind() and isMSIUpTrend()  ? limecolor : na ) : na
//fill(rsiline, headline, color=color.new(headcolor, 50))
//fill(rsiline, tailline, color=color.new(tailcolor, 50))
//bgcolor(showmsi() ? (isMSIUpTrend() ? color.new(limecolor, 80) : na  ) : na)
//bgcolor(showmsi() ? (isMSIDownTrend() ? color.new(color.red, 80): na) : na)

// McClellan Summation Index
headwind1 = input(1600, title="Head Wind")
alarm = input(800, title ="top alarm")
tailwind1 = input(-800, title="Tail Wind")
rana1 = (adv - dec)
advnema191 = ta.ema(rana1, 19)
advnema391 = ta.ema(rana1, 39)
osci1 = advnema191-advnema391
msi1 = ta.cum(osci1)
msiema = ta.ema(msi1, 10)
showrealmsi() => ("MSI" == type) ? true : false
headline1=plot(showrealmsi() ? headwind1 : na, style=plot.style_line, color=color.new(color.green, 0), title="headwind")
tailline1=plot(showrealmsi() ? tailwind1 : na, style=plot.style_line, color=color.new(color.red, 0), title="tailwind")
alarmline1=plot(showrealmsi() ? alarm : na, style=plot.style_line, color=color.new(color.blue, 0), title="alarmwind")
plot(showrealmsi() ? 0 : na, style=plot.style_line, title="0", linewidth=1, color=color.new(color.gray, 30))
msiline= plot(showrealmsi() ? msiema : na, style=plot.style_line, color=color.black, linewidth=2, title="MSI")

//headcolor = showmsi() ? (isHeadWind() and isMSIDownTrend() ? color.red : na) : na
//tailcolor = showmsi() ? (isTailWind() and isMSIUpTrend()  ? limecolor : na ) : na
//fill(rsiline, headline, color=color.new(headcolor, 50))
//fill(rsiline, tailline, color=color.new(tailcolor, 50))
//bgcolor(showmsi() ? (isMSIUpTrend() ? color.new(limecolor, 80) : na  ) : na)
//bgcolor(showmsi() ? (isMSIDownTrend() ? color.new(color.red, 80): na) : na)
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.