lonestar108

SMI Bars

Uses SMI (Stochastic Momentum Index) to set bar colors:

When SMI above overbought, bar color is red.
When SMI is between 0 and overbought, bar color is maroon
When SMI is between oversold and 0, bar color is green
When SMI is below oversold, bar color is lime.
When SMI crosses above or below 0, bar color is orange.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

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.

Want to use this script on a chart?
//Stochastic Momentum Index
//SMI Code by UCSgears, adapted to bars by lonestar108
study("SMI Bars", shorttitle = "SMI_Bars", overlay=true)
a = input(5, "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
// Nested Moving Average for smoother curves
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)


barcolor(cross(SMI,0) and SMI > 0 ? orange : na)
barcolor(cross(SMI,0) and SMI < 0 ? orange : na)
barcolor(SMI > ob ? red : na)
barcolor((SMI > 0 and SMI <=ob) ? maroon : na)
barcolor((SMI <= 0 and SMI >=os) ? green : na)
barcolor(SMI < os ? lime : na)


//END