Reversal Indicator For ThinkOrSwim

hi everyone could someone be so kind to convert this pinecode into tos?
https://www.tradingview.com/script/mWiAL3w7-Reversal-Indicator/
it seams really helpful to find reversal candle and I would like to test it with price action.
thank you guys
check the below

CSS:
# 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
 
check the below

CSS:
# 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
thank you so much,
as usual you are a kind genius!
will play with it!!
 
@samer800 or @BenTen or anyone - Can you please help with alerts?

The requirement is that the alert should trigger only after the completion of the current candle, and it should be based on the confirmation of either a bullish or bearish signal (ie. confirmation exists). I attempted to implement this, but unfortunately, it didn't work as intended.

Ruby:
Alert(bullReversalConfirm and BarNumber() == HighestAll(BarNumber()), "Bull Reversal Confirmation", Alert.BAR, Sound.Ding);

Alert(bearReversalConfirm and BarNumber() == HighestAll(BarNumber()), "Bear Reversal Confirmation", Alert.BAR, Sound.Bell);

Thank you!
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
296 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top