// indicator by ajay4sahu // strategy by sentello88 //@version=5 strategy(shorttitle='STA_Strategy', title='Buy Sell Signal Strategy', overlay=true, use_bar_magnifier = 1 ) BBperiod = input.int(defval=21, title='BB Period', minval=1) BBdeviations = input.float(defval=1.00, title='BB Deviations', minval=0.1, step=0.05) UseATRfilter = input(defval=true, title='ATR Filter') ATRperiod = input.int(defval=5, title='ATR Period', minval=1) hl = input(defval=false, title='Hide Labels') BBUpper = ta.sma(close, BBperiod) + ta.stdev(close, BBperiod) * BBdeviations BBLower = ta.sma(close, BBperiod) - ta.stdev(close, BBperiod) * BBdeviations currentATR = ta.atr(ATRperiod) TrendLine = 0.0 iTrend = 0.0 BBSignal = close > BBUpper ? 1 : close < BBLower ? -1 : 0 if BBSignal == 1 TrendLine := UseATRfilter ? low - currentATR : low if TrendLine < TrendLine[1] TrendLine := TrendLine[1] else if BBSignal == -1 TrendLine := UseATRfilter ? high + currentATR : high if TrendLine > TrendLine[1] TrendLine := TrendLine[1] else TrendLine := TrendLine[1] iTrend := TrendLine > TrendLine[1] ? 1 : TrendLine < TrendLine[1] ? -1 : iTrend[1] buyCondition = iTrend[1] == -1 and iTrend == 1 sellCondition = iTrend[1] == 1 and iTrend == -1 shortCondition = iTrend[1] == 1 and iTrend == -1 coverCondition = iTrend[1] == -1 and iTrend == 1 if buyCondition strategy.entry('Buy', strategy.long) if sellCondition strategy.close('Buy') if shortCondition strategy.entry('Short', strategy.short) if coverCondition strategy.close('Short') plot(TrendLine, color=iTrend > 0 ? color.blue : color.red, style=plot.style_line, linewidth=2, title='Trend Line') plotshape(series=buyCondition and not hl ? TrendLine - currentATR * 2 : na, text='Buy', style=shape.labelup, location=location.absolute, color=color.new(color.blue, 0), textcolor=color.new(color.white, 0), offset=0, size=size.auto) plotshape(series=sellCondition and not hl ? TrendLine + currentATR * 2 : na, text='Sell', style=shape.labeldown, location=location.absolute, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), offset=0, size=size.auto)