OnChart RSI for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
sDNk0Jl.png

Author Message:

RSI superimposed on the chart!
This indicator clearly shows the overbought and oversold zones directly on the chart of any instrument!

CODE:

CSS:
#https://www.tradingview.com/v/vj20slRb/
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#//@Shuttle_Trader
#indicator(title="OnChart_RSI", overlay=true, shorttitle="OnChart_RSI")
# Converted and mod by Sam4Cok@Samer800    - 07/2023

input FilterSignals = {default "Volatility", "Volume", "ADX", "Regime", "All", "None"};# 'Filter Signals by'
input filterLength = 10;
input displayStyle = {"RSI Band", "Band Average Line",Default "Show Both", "Don't Show"};
input rsiLengthInput = 14;    # "RSI Length"
input rsiSourceInput = close; # "Source"
input SignalType =  {"Band Crosses",default "OB/OS Crosses", "Average Lines Crosses", "Don't Show"};    # "Signal type"
input overbought = 70;
input oversold = 30;
input showRsiLine = no;      # 'Show RSI Line'

def na = Double.NaN;
def src = rsiSourceInput;
def price = ohlc4;
# @regime_filter
def value1 = CompoundValue(1, 0.2 * (src - src[1]) + 0.8 * value1[1], 0.2 * (src - src[1]));
def value2 = CompoundValue(1, 0.1 * (high - low) + 0.8 * value2[1], 0.1 * (high - low));
def omega = AbsValue(value1 / value2);
def alpha1 = (-power(omega,2) + sqrt(power(omega, 4) + 16 * power(omega,2))) / 8;
def klmf = alpha1 * src + (1 - alpha1) * (klmf[1]);
def absCurveSlope = AbsValue(klmf - klmf[1]);
def exponentialAverageAbsCurveSlope = 1.0 * ExpAverage(absCurveSlope, 200);
def normalized_slope_decline = (absCurveSlope - exponentialAverageAbsCurveSlope) / exponentialAverageAbsCurveSlope;
def regime = normalized_slope_decline >= - 0.1;
#volumeBreak(thres) => 
def rsivol   = RSI(Price = volume, Length = filterLength);
def osc      = HullMovingAvg(rsivol, 10);
def volumeBreak = osc > 49;
#volatilityBreak(volmin, volmax)
def tr = TrueRange(high, close, low);
def volmin = ATR(LENGTH=1);
def volmax = ATR(LENGTH= filterLength);
def volatilityBreak = volmin > volmax;
def adx_ = ADX(Length = filterLength);
def nAdx = adx_ > WMA(adx_, filterLength);

def filter;
switch (FilterSignals) {
case "Volatility" :
    filter = volatilityBreak;
case "Volume" :
    filter = volumeBreak;
case "ADX" :
    filter = nAdx;
case "Regime" :
    filter = regime;
case "All" :
    filter = (volatilityBreak and volumeBreak and nAdx and regime);
case "None" :
    filter = 1;
}
# //Regular RSI, same as ta.rsi(src, per)
script rsi_rsi {
input src = close;
input per = 14;
      def alpha = 1.0/max(per, 1);
      def change = src - src[1];
      def _change = _change[1] + alpha * (change  - _change[1]);
      def _changa = _changa[1] + alpha * (AbsValue(change) - _changa[1]);
      def out = if _changa != 0 then 50 * (_change/_changa + 1) else 50;
      plot rsi_rsi = out;
}
def Regular = rsi_rsi(rsiSourceInput, rsiLengthInput);
def nRSI = Regular;

def maValue = WildersAverage(price, rsiLengthInput);
def hh = highest(high,rsiLengthInput);
def ll = lowest(low, rsiLengthInput);
def up_lev_line = WildersAverage(hh[1], rsiLengthInput);
def dn_lev_line = WildersAverage(ll[1], rsiLengthInput);
def rsi_range = (up_lev_line - dn_lev_line)/(overbought - oversold) * 100;
def rsi_line_chart = maValue + (nRSI - 50) / 100 * rsi_range;
def avg = (up_lev_line + dn_lev_line) / 2;

def BandUp; def BandDn;def BandMid;
Switch (displayStyle) {
Case "RSI Band" :
    BandUp = up_lev_line;
    BandDn = dn_lev_line;
    BandMid = na;
Case "Band Average Line" :
    BandUp = na;
    BandDn = na;
    BandMid = avg;
Case "Show Both" :
    BandUp = up_lev_line;
    BandDn = dn_lev_line;
    BandMid = avg;
Case "Don't Show" :
    BandUp = na;
    BandDn = na;
    BandMid = na;
}

#-- Buy/Sell
#input SignalType =  {default "Middle Crosses", "Levels Crosses", "Don't Show"};    # "Signal type"
def onRsi = WildersAverage(rsi_line_chart, rsiLengthInput*2);
def buy;# = (nRSI Crosses Above oversold) and filter;
def sell;# = (nRSI Crosses Below overbought) and filter;

Switch (SignalType) {
Case "OB/OS Crosses" :
    buy = (nRSI Crosses Above oversold) and filter;
    sell = (nRSI Crosses Below overbought) and filter;
Case "Band Crosses" :
    buy = (rsiSourceInput Crosses Above dn_lev_line) and filter;
    sell = (rsiSourceInput Crosses Below up_lev_line) and filter;
Case "Average Lines Crosses" :
    buy  = (avg Crosses Above onRsi) and filter;
    sell = (avg Crosses Below onRsi) and filter;
Case "Don't Show" :
    buy = na;
    sell = na;
}

AddChartBubble(buy, low, "UP", Color.GREEN, no);# color=#08f108
AddChartBubble(sell, high, "DN", Color.RED, yes);#color=#ee0e3f

#-- plot
def UP = (close Crosses Above up_lev_line);
def DN = (close Crosses Below dn_lev_line);

def rsi_channel_trend = if UP then 1 else if DN then -1 else rsi_channel_trend[1];

def rsiUp = nRSI >= overbought;
def rsiDn = nRSI <= oversold;
def top_color1 = rsiUp or rsiUp[1];
def bottom_color1 = rsiDn or rsiDn[1];
def col = if rsi_channel_trend>0 then 1 else
          if rsi_channel_trend<0 then -1 else 0;

def pp1_line = max(price,max(rsi_line_chart,rsi_line_chart[1]));
def pp2_line = min(price,min(rsi_line_chart,rsi_line_chart[1]));

def pp1 = pp1_line;
def pp2 = pp2_line;


plot rsiPlot = if showRsiLine then rsi_line_chart else na;    # "RSI"
plot rsiUpperBand = BandUp;#, "RSI Upper Band"
plot rsiLowerBand = BandDn;#, "RSI Lower Band"
plot rsiMidBand = BandMid;

rsiPlot.SetDefaultColor(CreateColor(228,194,0));
rsiUpperBand.SetDefaultColor(CreateColor(238,14,63));
rsiLowerBand.SetDefaultColor(CreateColor(8,241,8));
rsiMidBand.AssignValueColor(if col>0 then Color.GREEN else
                            if col<0 then Color.RED else Color.GRAY);

AddCloud(if top_color1 then pp1 else na, pp2, Color.DARK_RED);#CreateColor(255, 82, 82));
AddCloud(if top_color1 then pp1 else na, rsiUpperBand, Color.DARK_RED);#CreateColor(255, 82, 82));

AddCloud(if bottom_color1 then pp1 else na, pp2, Color.DARK_GREEN);#CreateColor(76, 175, 79));
AddCloud(if bottom_color1 then rsiLowerBand else na, pp2, Color.DARK_GREEN);#CreateColor(76, 175, 79));

AddCloud(if col>0 then rsiUpperBand else na,rsiLowerBand, Color.DARK_GREEN); #'TREND'
AddCloud(if col<0 then rsiUpperBand else na,rsiLowerBand, Color.DARK_RED);   #'TREND'

#-- END of CODE
 

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

Hi Guys,
I've the Up and Dn label stick onto the chart even after I remove the indicator ... not sure if anyone else have the same problem ... in any case, u can put a # in the following 2 line and those labels will be gone ...
Code:
#AddChartBubble(buy, low, "UP", Color.GREEN, no);# color=#08f108
#AddChartBubble(sell, high, "DN", Color.RED, yes);#color=#ee0e3f

Fyi
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
298 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