1017 lượt xem
1017
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.
```//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```