True Barcolor
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeswithashish

//@version=5
indicator(title='SuperDuper Trend', overlay=true, shorttitle='SuperDuper trend')

//variable declaration
volMA = ta.sma(volume, 20)
volcheck = volume > volMA
atr = ta.atr(20)
range1=math.max(open, close)-math.min(open, close)
avgbarsize=ta.sma(range1, 100)
cur_bar_len=range1>avgbarsize
var Stoploss = high

//finding true bull and bear bars
bearcandle = close < open and volcheck and close < low[1] and volume > volume[1] and cur_bar_len and close<Stoploss
bullcandle = close > open and volcheck and close > high[1] and volume > volume[1] and cur_bar_len and close>Stoploss

//continuation criteria
greenbar = ta.barssince(bullcandle)
redbar = ta.barssince(bearcandle)

//finding reversal candle
exitbar= (greenbar<redbar and volume>volMA and volume>volume[1] and close<low[1]) or (greenbar>redbar and volume>volMA and volume>volume[1] and close>high[1])

//setting up bar color based whther they are color based reversal candle
barcolor(greenbar==0?color.green:redbar==0?color.red:exitbar?color.blue:color.silver, title='Bar color')
var trade=0
//setting up the stoplosses
if bullcandle and (trade==0 or trade==-1)
    Stoploss:= low-atr
    trade:=1

if bearcandle and (trade==1 or trade==0)
    Stoploss:=high+atr
    trade:=-1

if bullcandle and trade==1
    Stoploss:= math.max(Stoploss, low-atr)

if bearcandle and trade==-1
    Stoploss:= math.min(Stoploss, high+atr)
    
//plotting trailing stoploss
plot(Stoploss, title="stoploss line", style=plot.style_stepline_diamond, color=(greenbar > redbar ? color.green : color.red), linewidth=2)

//Labelling of the potential entry points
text1=bullcandle?"B":bearcandle?"S":na
ourlabel=label.new(x=bar_index, y=na, text=text1,yloc=bearcandle? yloc.abovebar:yloc.belowbar,  color=bullcandle?color.green:bearcandle?color.red:na, textcolor=color.white,  style=bearcandle?label.style_label_down:bullcandle?label.style_label_up:label.style_none , size=size.tiny)