# https://www.tradingview.com/v/mWiAL3w7/
#//@StrategicalCharts
#indicator("Reversal Indicator", overlay=true)
# request from https://usethinkscript.com member
# Converted by Sam4Cok@Samer800 - 07/2023
#// inputs
input bbLength = 19; # "BBands Length"
input bbMultiplier = 2; # "BBands Multiplier"
input showCheckmarks = yes; # "Show Checkmarks"
input showTrendBars = yes; # "Show TrendBars"
input atrPeriod = 10; # "ATR Length"
input factor = 3.0; # "Factor"
input isRsi = {default "No", "Yes"}; # "RSI confluence"
input rsiLen = 14; # "RSI Length"
input rsiOverSold = 30; # "RSI Oversold"
input rsiOverBought = 70; # "RSI Overbought"
def na = Double.NaN;
#-- SuperTrend
script supertrend {
input src = hl2;
input factor = 3;
input atrPeriod = 10;
def atr = ATR(Length = atrPeriod);
def lowerBand;
def upperBand;
def upperBand1 = src + factor * atr;
def lowerBand1 = src - factor * atr;
def prevLowerBand = (lowerBand[1]);
def prevUpperBand = (upperBand[1]);
lowerBand = if lowerBand1 > prevLowerBand or close[1] < prevLowerBand then lowerBand1 else prevLowerBand;
upperBand = if upperBand1 < prevUpperBand or close[1] > prevUpperBand then upperBand1 else prevUpperBand;
def direction;# = na
def superTrend;# = na
def prevSuperTrend = superTrend[1];
if IsNaN(atr[1]) {
direction = 1;
} else if prevSuperTrend == prevUpperBand {
direction = if close > upperBand then -1 else 1;
} else {
direction = if close < lowerBand then 1 else -1;
}
superTrend = if direction == -1 then lowerBand else upperBand;
plot dir = direction;
}
#//calculate bollinger bands
def basis = Average(close, bbLength);
def dev = bbMultiplier * StDev(close, bbLength);
def upper = basis + dev;
def lower = basis - dev;
#//calculate RSI
def vrsi = RSI(Price = close, LEngth = rsiLen);
def rsiBull = (vrsi crosses above rsiOverSold);
def rsiBear = (vrsi crosses below rsiOverBought);
#// Reversal Bar - Bullish Signal
#// Pseudo: went out lower band AND red candle AND came back in AND green candle
def bullRev = low[1] < lower[1] and close[1] < open[1] and close > lower and close > open ;
#// Pseudo: everything above AND candle close above signal candles wick.
def bullRevConfirm = low[2] < lower[2] and close[2] < open[2] and close[1] > lower[1] and close[1] > open[1] and close > high[1];
#// Reversal Bar - Bearish Signal
#// Pseudo: went out upper band AND green candle AND came back in AND red candle
def bearRev = high[1] > upper[1] and close[1] > open[1] and close < upper and close < open;
#// Pseudo: everything above AND candle close below signal candles wick.
def bearRevConfirm = high[2] > upper[2] and close[2] > open[2] and close[1] < upper[1] and close[1] < open[1] and close < low[1];
def bullReversal;
def bearReversal;
def bullReversalConfirm;
def bearReversalConfirm;
switch (isRsi) {
case "Yes" :
bullReversal = bullRev and rsiBull;
bearReversal = bearRev and rsiBear;
bullReversalConfirm = no;
bearReversalConfirm = no;
case "No" :
bullReversal = bullRev;
bearReversal = bearRev;
bullReversalConfirm = bullRevConfirm;
bearReversalConfirm = bearRevConfirm;
}
#//calculate super trend for green/red bars
def direction = supertrend(hl2, factor, atrPeriod);
def dir = direction < 0;
#// UI
plot upReversal = if bullReversal then low else na;
upReversal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
upReversal.SetDefaultColor(Color.CYAN);
upReversal.SetLineWeight(2);
plot dnReversal = if bearReversal then high else na;
dnReversal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
dnReversal.SetDefaultColor(Color.MAGENTA);
dnReversal.SetLineWeight(2);
plot upConfirm = if showCheckmarks and bullReversalConfirm then low else na;
upConfirm.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upConfirm.SetDefaultColor(Color.WHITE);
upConfirm.SetLineWeight(2);
plot dnConfirm = if showCheckmarks and bearReversalConfirm then high else na;
dnConfirm.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
dnConfirm.SetDefaultColor(Color.YELLOW);
dnConfirm.SetLineWeight(2);
AssignPriceColor(if showTrendBars then (if dir then color.green else color.red) else Color.CURRENT);#:na, title="Trend Bars")
AssignPriceColor(if bullReversal then color.CYAN else Color.CURRENT);#:na, title="Bull Reversal Bar")
AssignPriceColor(if bearReversal then Color.MAGENTA else Color.CURRENT);#, title="Bear Reversal Bar")
#-- END of CODE