Better RSI For ThinkOrSwim

i couldnt find this TV conversion. anyway i could get it converted?
https://www.tradingview.com/script/eTXGWWm3-Better-RSI-with-bullish-bearish-market-cycle-indicator/

//@version=3
study("Better RSI")
cycler = na
myPeriod = input(defval = 14, type=integer, title="Period")
src = input(close, type=source)
showCycler = input(true,'Show cycler?')
lvl = input(50, 'Cycler level on plot')
myRSI = rsi(src, myPeriod)
firstcolor = color(white,10)
secondcolor = color(orange,50)
thirdcolor = gray

h30 = hline(30,color=firstcolor,linestyle=dashed,title='Low')
h70 = hline(70,color=firstcolor,linestyle=dashed,title = 'High')
h20 = hline(20, color=secondcolor,linestyle = solid,title='Second low')
h80 = hline(80, color=secondcolor,linestyle=solid,title='Second high')
//h50 = hline(50, color=orange, title= 'Mid line')
h40 = hline(40, color = thirdcolor, linestyle = dashed,title = '40 line')
h60 = hline(60, color = thirdcolor, linestyle = dashed, title = '60 line')
//fill(h30,h20,red,transp=80, title='Oversold color')
//fill(h80,h70,red,transp=80, title='Overbought color')
fill(h30,h70,fuchsia,transp=90, title= 'Background color')
//cond =? red:white
RSIplot = plot(myRSI,color=white,linewidth=2,transp=0,title="RSI")
plot(myRSI >= 70 or myRSI<= 30? myRSI:na,style = linebr,linewidth=3,color=red,transp = 0, title = 'Oversold color')

//cycler
cycler := if myRSI > 69 or myRSI< 31
a = if myRSI > 69
1 // bullish
else
2 // bearish
a
else
b = if (nz(cycler[1]) == 1 and myRSI < 39) or (nz(cycler[1]) == 2 and myRSI > 61)
0
else
nz(cycler[1])
b


mycolor = if cycler == 0
white
else
c = if cycler == 1
lime
else
red
c

plot(showCycler? lvl:na, style = line, color = mycolor, transp = 30, linewidth=2, title = 'Cycler colors')
//@
use below code.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © JayTradingCharts
#https://www.tradingview.com/script/AkWCX6pt-RSI-Divergence-Indicator-w-Alerts/
#study("RSI Divergence Indicator w/Alerts")
# Converted by Sam4Cok@Samer800 - 09/2022
# updated by Sam4Cok@Samer800 - 11/2023 -- added cycle line
declare lower;

input len = 14;           # "RSI Period"
input src = close;        # "RSI Source"
input overBought = 70;    # "Over Bought Limit"
input overSold = 30;      # "Over Sold Limit"
input alerts   = yes;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};

def na = double.NaN;
def last = isNaN(close);
def nRSI = RSI(Price = src, length= len);

#//cycler
def cycler = if nRSI > 69 or nRSI< 31 then
             if nRSI > 69 then 1 else 2 else
             if (cycler[1] == 1 and nRSI < 39) or (cycler[1] == 2 and nRSI > 61) then 0 else cycler[1];
def mycolor = cycler;
def obos = nRSI >= overBought or nRSI <= overSold;
plot osc = if obos then nRSI else na;
osc.SetDefaultColor(Color.CYAN);
osc.SetLineWeight(2);
plot myRSI = nRSI;
myRSI.SetDefaultColor(CreateColor(186,115,193));
myRSI.SetLineWeight(2);

plot midLine = if last then na else 50;
midLine.AssignValueColor(if mycolor==0 then Color.GRAY else
                         if mycolor==1 then Color.GREEN else Color.RED);
plot obLevel = if last then na else overBought;
obLevel.SetDefaultColor(Color.GRAY);
plot osLevel = if last then na else overSold;
osLevel.SetDefaultColor(Color.GRAY);

plot obPLevel = if last then na else 80;
obPLevel.SetDefaultColor(Color.DARK_GRAY);
plot osNLevel = if last then na else 20;
osNLevel.SetDefaultColor(Color.DARK_GRAY);


#---- Background
AddCloud(obLevel, osLevel, CreateColor(62, 8, 103));

#----Div-----------
input ShowLastDivLines = yes;
input ShowLastHiddenDivLines = no;
input DivBull = yes;      # "Plot Bullish"
input DivBear = yes;      # "Plot Bearish"
input DivHiddenBull = no; # "Plot Hidden Bullish"
input DivHiddenBear = no; # "Plot Hidden Bearish"
input LookBackRight  = 5; # "Pivot Lookback Right"
input LookBackLeft  = 5;  # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = nRSI;

def h = high;
def l = low;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
   if (HL > 0) {
        _V = if _BN > lbL + 1 and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_inRange(cond) =>
script _inRange {
    input cond = yes;
    input rangeUpper = 60;
    input rangeLower = 5;
        def bars = if cond then 0 else bars[1] + 1;
        def inrange =  (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl_ = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph_ = findpivots(divSrc, 1, LookBackLeft, LookBackRight);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,LookBackLeft);
def phh = highest(divSrc,LookBackLeft);
def sll = lowest(l, LookBackLeft);
def shh = highest(h, LookBackLeft);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then sll else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc <= 40;
def bullCond = plFound and oscHL and priceLL;
#// Hidden Bullish
def oscLL = divSrc < vlFound and inRangePl;
def priceHL = l > plPrice and divSrc <= 50;
def hiddenBullCond = plFound and oscLL and priceHL;
#// Regular Bearish
def inRangePh = _inRange(phFound[1],MaxLookback,MinLookback);
def oscLH   = divSrc < vhFound and inRangePh;
def priceHH = h > phPrice and divSrc >= 60;;
def bearCond = phFound and oscLH and priceHH;
#// Hidden Bearish
def oscHH = divSrc > vhFound and inRangePh;
def priceLH = h < phPrice and divSrc >= 50;
def hiddenBearCond = phFound and oscHH and priceLH;

#------ Bubbles
def bullBub  = DivBull and bullCond;
def HbullBub = DivHiddenBull and hiddenBullCond;
def bearBub  = DivBear and bearCond;
def HbearBub = DivHiddenBear and hiddenBearCond;

addchartbubble(bullBub, divSrc, "R", color.GREEN, no);
addchartbubble(bearBub, divSrc, "R", CreateColor(156,39,176), yes);
addchartbubble(HbullBub, divSrc, "H", color.DARK_green, no);
addchartbubble(HbearBub, divSrc, "H", color.DARK_red, yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar = if ph then bar else lastPhBar[1];
def prePhBar = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def HighPivots = ph and bar >= HighestAll(priorPHBar) and bar <= HighestAll(lastBearBar);
def LowPivots  = pl and bar >= HighestAll(priorPLBar) and bar <= HighestAll(lastBullBar);

def pivotHigh = if HighPivots then divSrc else na;
def pivotLow  = if LowPivots  then divSrc else na;

plot PlotHline = if ShowLastDivLines then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.RED);

plot PlotLline = if ShowLastDivLines then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.GREEN);

#--- Hidden Lines
#-- Bear Line
def priorHPHBar = if hiddenBearCond then prePhBar else priorHPHBar[1];
#-- Bull Line
def priorHPLBar = if hiddenBullCond then prePlBar else priorHPLBar[1];

def lastHBullBar = if hiddenBullCond then bar else lastHBullBar[1];
def lastHBearBar = if hiddenBearCond then bar else lastHBearBar[1];

def HighHPivots = ph and bar >= HighestAll(priorHPHBar) and bar <= HighestAll(lastHBearBar);
def LowHPivots  = pl and bar >= HighestAll(priorHPLBar) and bar <= HighestAll(lastHBullBar);

def pivotHidHigh = if HighHPivots then divSrc else na;
def pivotHidLow  = if LowHPivots  then divSrc else na;

plot PlotHBearline = if ShowLastHiddenDivLines then pivotHidHigh else na;
PlotHBearline.EnableApproximation();
PlotHBearline.SetDefaultColor(Color.DARK_RED);

plot PlotHBullline = if ShowLastHiddenDivLines then pivotHidLow else na;
PlotHBullline.EnableApproximation();
PlotHBullline.SetDefaultColor(Color.DARK_GREEN);


#-- END of CODE
 

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
523 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