//@version=4 study(title="[RS]Normalized Standard Selector") // || Standardization/zscore Function f_zscore(_src, _length, _smooth)=> _mean = sma(_src, _length) _std = stdev(_src-_mean, _length) _value = (_src - _mean) / _std _dema = ema(ema(_value, _smooth), _smooth) [_value, _dema] int t_length = input(55) int smooth = input(5) [v0, d0] = f_zscore(ema(close, smooth), t_length, smooth) [v1, d1] = f_zscore(ema(close, smooth*3), t_length*3, smooth*3) plot(series=(v0>0?1:-1), title="0", color=color.blue, style=plot.style_columns) plot(series=(d0>0?1:-1), title="1", color=color.red, style=plot.style_columns) plot(series=(v1>0?1:-1), title="2", color=color.blue, style=plot.style_columns) plot(series=(d1>0?1:-1), title="3", color=color.red, style=plot.style_columns) hline(2) hline(0) hline(-4) f_normalize(_a, _b, _c, _d)=> _r = avg(_a > 0 ? 1 : -1, _b > 0 ? 1 : -1, _c > 0 ? 1 : -1, _d > 0 ? 1 : -1) a = f_normalize(v0, d0, v1, d1) plot(series=a, title="A", color=color.black, linewidth=2, style=plot.style_stepline, transp=0) msg00 = "Sideways" msg01 = "Bullish Trending" msg02 = "Bearish Trending" msg03 = "Atempting Reversal Downwards" msg04 = "Atempting Reversal Upwards" var int state = 0 if state != 0 and a == 0 state := 0 if state != 1 and a == 1 state := 1 if state != 2 and a == -1 state := 2 if state == 1 and change(a) < 0 state := 3 if state == 2 and change(a) > 0 state := 4 var label la = na if change(state) string _message = na if state == 0 _message := msg00 if state == 1 _message := msg01 if state == 2 _message := msg02 if state == 3 _message := msg03 if state == 4 _message := msg04 //label.delete(la) la := label.new(x=bar_index, y=-1-state*0.25, text=_message, xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 50), style=label.style_labelup, textcolor=color.black, size=size.small )