RSI Wave Signals For ThinkOrSwim

Smoothed RSI with optimized trailing moving average. Look for cross above or cross under signals for buy and sell orders respectively.
https://www.tradingview.com/script/gztIGBjt-RSI-Wave-Signals/

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

// Optimized Trend Tracker function under copyright and courtesy of KivancOzbilgic.

//@version=5
indicator("RSI Wave Signals", overlay=false)

period1 = input(2,"Period For MA")
mtp1 = input.float(0.7,"Trailing Percentage of MA",step=0.1)


rsiLength = input(12,"RSI Length")

ottFunction(src,length,percent)=>
    valpha=2/(length+1)
    vud1=src>src[1] ? src-src[1] : 0
    vdd1=src<src[1] ? src[1]-src : 0
    vUD=math.sum(vud1,9)
    vDD=math.sum(vdd1,9)
    vCMO=nz((vUD-vDD)/(vUD+vDD))
    VAR=0.0
    VAR:=nz(valpha*math.abs(vCMO)*src)+(1-valpha*math.abs(vCMO))*nz(VAR[1])
    MAvg=VAR
    fark=MAvg*percent*0.01
    longStop = MAvg - fark
    longStopPrev = nz(longStop[1], longStop)
    longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
    shortStop =  MAvg + fark
    shortStopPrev = nz(shortStop[1], shortStop)
    shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
    dir = 1
    dir := nz(dir[1], dir)
    dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
    MT = dir==1 ? longStop: shortStop
    OTT=MAvg>MT ? MT*(200+percent)/200 : MT*(200-percent)/200
    [dir,OTT[2],MAvg]

//MACD Calculations//

rsi = ta.rsi(close,rsiLength)+1000

[dir1,ott1,sl1] = ottFunction(rsi,period1,mtp1)

plot(ott1,title="OTT",linewidth=1,color=color.white)
plot(sl1,title="SL",linewidth=2,color=color.aqua)

overSoldLevel = input(40,title="Oversold Level") +1000
overBoughtLevel = input(60,title="Overbought Level") +1000

plot(overSoldLevel, title="Oversold",style=plot.style_circles,color=color.blue)
plot(overBoughtLevel, title="Overbought",style=plot.style_circles,color=color.blue)
converted. pls try.
CSS:
#// © bartua
#// Optimized Trend Tracker function under copyright and courtesy of KivancOzbilgic.
#  https://www.tradingview.com/script/gztIGBjt-RSI-Wave-Signals/
#  indicator("RSI Wave Signals", overlay=false)
#  Converted and mod by Sam4Cok@Samer800 11/2022
declare lower;
input BarColor  = no;
input ShowCloud = yes;      #"Highlighter On/Off ?"
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};
input Source     = close;
input length     = 2;       # OTT Period
input percent    = 0.7;     # OTT Optimization Coeff
input rsiLength  = 12;      # "RSI Period"
input overBought = 60;      # "Over Bought Limit"
input overSold   = 40;      # "Over Sold Limit"
input showSignals = yes;    # "Show Support Line Crossing Signals?"
input ColorOttLine = no;    #="Show OTT Color Changes?"

def na = Double.NaN;

def c = Source;
def h = high;
def l = low;
def mPlot = ohlc4;

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = ((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * (VAR[1]);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * (WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = ((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = (valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * (VARl[1]);
    plot return = VARl;
}
#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * srcl + (1 - wwalpha) * (WWMA[1]);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}
#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then DEMA(src, length) else
     if type == "TMA" then Average(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length))) else Double.NaN;
    plot result = ma;
}
#OTT(Source, percent) =>
script OTT {
    input Source    = close;
    input percent   = 0;
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot return = MT;
}

def nRsi = RSI(Length = rsiLength) + 1000;
def MAvg = getMA(nRsi, length, MovAvgType);

def MT   = OTT(MAvg, percent);
def OTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;

plot SupportLine = MAvg;  # "Support Line"
SupportLine.SetDefaultColor(CreateColor(5, 133, 225));

def OTTC = if ColorOttLine then if OTT[2] > OTT[3] then 1 else -1 else 0;
plot pALL = If(IsNaN(c), na, OTT[2]); # "OTT LINE"
pALL.SetLineWeight(2);
pALL.AssignValueColor(if OTTC > 0 then Color.GREEN else
                      if OTTC < 0 then Color.RED else CreateColor(255, 82, 82));

def overSoldLevel = overSold + 1000;
def overBoughtLevel = overBought + 1000;
plot midLine = if(isNaN(c),na,(overSoldLevel + overBoughtLevel) / 2);
midLine.SetDefaultColor(Color.DARK_GRAY);
midLine.SetStyle(Curve.SHORT_DASH);
plot obLevel = if(isNaN(c),na,overBoughtLevel);
obLevel.SetDefaultColor(Color.GRAY);
obLevel.SetStyle(Curve.MEDIUM_DASH);
plot osLevel = if(isNaN(c),na,overSoldLevel);
osLevel.SetDefaultColor(Color.GRAY);
osLevel.SetStyle(Curve.MEDIUM_DASH);

#---- Signals
def buySignalk   = If(showSignals, Crosses(MAvg, OTT[2], CrossingDirection.ABOVE), na);
def sellSignalk = If(showSignals, Crosses(MAvg, OTT[2], CrossingDirection.BELOW), na);
def longFillColor = if ShowCloud then if MAvg > OTT then yes else na else na;
def shortFillColor = if ShowCloud then if MAvg < OTT then yes else na else na;

plot buySignal = if buySignalk then pALL else na;
buySignal.SetStyle(Curve.POINTS);
buySignal.SetDefaultColor(Color.GREEN);
buySignal.SetLineWeight(3);

plot sellSignal = if sellSignalk then pALL else na;
sellSignal.SetStyle(Curve.POINTS);
sellSignal.SetDefaultColor(Color.RED);
sellSignal.SetLineWeight(3);

#--- Clouds
AddCloud(If(longFillColor, Double.POSITIVE_INFINITY, na), Double.NEGATIVE_INFINITY, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(If(shortFillColor, Double.POSITIVE_INFINITY, na), Double.NEGATIVE_INFINITY, Color.DARK_RED, Color.DARK_RED);

#--- Bubbles

#--- Price Color
def ExtUp =  MAvg>pALL and MAvg>=MAvg[1] and pALL>=pALL[1];
def Up    =  MAvg>pALL and MAvg<MAvg[1] and pALL<pALL[1];
def ExtDn =  MAvg<pALL and MAvg<=MAvg[1] and pALL<=pALL[1];
def Dn    =  MAvg<pALL and MAvg>MAvg[1] and pALL>pALL[1];
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if ExtUp then Color.GREEN else
                 if Up then Color.DARK_GREEN else
                 if ExtDn then Color.RED else
                 if Dn then Color.DARK_RED else Color.GRAY);

#---- END 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
187 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