RSI Trend For ThinkOrSwim

mbarcala

Active member
Here it's RSI Trend Indicator from Trading View converted to thinkscript. RSI Hull Trend is a hybrid indicator with RSI of HULL Signal. The Hull MA is combined with RSI to see if the Hull MA Buy/Sell Signal is in overbought or oversold condition. Buy Sell Signals are plotted based on settings of OB/OS or RSI. This indicator is very useful to see if the Trend is in Exhaustion or Beginning of a Trend.
Upper Indicator
https://usethinkscript.com/threads/break-keltner-bands-bkb-for-thinkorswim.11220/

photo
15580[/ATTACH]']
2DP7mQs.png


script
Code:
# RSITrend by traderharikrishna converted by mbarcala for thinkorswim.com
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# https://www.tradingview.com/script/LvEWCt8I-RSI-Trend/

declare lower;

input rsiLengthInput = 14;
input rsiLengthInput2 = 28;
input trendlen = 45;
input show_Baseline = yes;
input oversold = 30;
input overbought = 70;

def BBMC = HullMovingAvg(close, trendlen);
def MHULL = BBMC[0];
def SHULL = BBMC[2];

def frsi = HullMovingAvg(rsi(price = close, length = rsiLengthInput),10);
def srsi = HullMovingAvg(rsi(price = close, length = rsiLengthInput2),10);

def hullrsi1 = rsi(price = MHULL, length = rsiLengthInput);
def hullrsi2 = rsi(price = SHULL, length = rsiLengthInput);

DefineGlobalColor("Up",CreateColor(77,195,255));
DefineGlobalColor("Dn",CreateColor(255,51,221));

plot hu1 = if show_Baseline then hullrsi1 else frsi;
hu1.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else
                     if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

plot hu2 = if show_Baseline then hullrsi2 else srsi;
hu2.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else
                     if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

AddCloud(hu1, hu2, GlobalColor("Up"), GlobalColor("Dn"));

plot buysignal = if MHULL crosses above SHULL then hu1 else Double.NaN;
buysignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buysignal.SetDefaultColor(Color.GREEN);
buysignal.SetLineWeight(2);
buysignal.HideBubble();
buysignal.HideTitle();

plot sellsignal = if MHULL crosses below SHULL then hu1 else Double.NaN;
sellsignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellsignal.SetDefaultColor(Color.RED);
sellsignal.SetLineWeight(2);
sellsignal.HideBubble();
sellsignal.HideTitle();

plot mline = 50;
mline.SetDefaultColor(Color.GRAY);
mline.HideBubble();
mline.HideTitle();

def rsiUpperBand = overbought;
def rsiUpperBand2 = 90;
AddCloud(rsiUpperBand2, rsiUpperBand, CreateColor(148,0,0));

def rsiLowerBand = oversold;
def rsiLowerBand2 = 10;
AddCloud(rsiLowerBand, rsiLowerBand2, CreateColor(0,148,0));
 

Attachments

  • 2DP7mQs.png
    2DP7mQs.png
    377.2 KB · Views: 390
Last edited by a moderator:
This is amazing!! Thank you SO much for sharing! What can I add to the bottom of the script to alert when the green/red arrow are painted?
 
Alert(buysignal, "RSI TREND BUY", Alert.BAR, Sound.Chimes);
Alert(sellsignal, "RSI TREND SELL", Alert.BAR, Sound.Ding);
thanks so much jay!! I was wondering if you'd be able to take a look at another one of his indicators where I asked for a similar alert (it probably got bumped from my ask)...thanks for taking the time to help
 
me too having problem...normally i just copy and paste...can you look at the code again??
You requested that we try cutting & pasting this script again.
We did:
FcsWLlG.png


You didn't provide any details as to what issues you are having; so it is not possible to say where you went astray.

Here is a shared chart link: http://tos.mx/32K6xWM Click here for --> Easiest way to load shared links
This will provide you a chart to which this indicator has been applied.
 
Here it's RSI Trend Indicator from Trading View converted to thinkscript. RSI Hull Trend is a hybrid indicator with RSI of HULL Signal. The Hull MA is combined with RSI to see if the Hull MA Buy/Sell Signal is in overbought or oversold condition. Buy Sell Signals are plotted based on settings of OB/OS or RSI. This indicator is very useful to see if the Trend is in Exhaustion or Beginning of a Trend.
Upper Indicator
https://usethinkscript.com/threads/break-keltner-bands-bkb-for-thinkorswim.11220/

photo
15580[/ATTACH]']View attachment 15581

script
Code:
# RSITrend by traderharikrishna converted by mbarcala for thinkorswim.com
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# https://www.tradingview.com/script/LvEWCt8I-RSI-Trend/

declare lower;

input rsiLengthInput = 14;
input rsiLengthInput2 = 28;
input trendlen = 45;
input show_Baseline = yes;
input oversold = 30;
input overbought = 70;

def BBMC = HullMovingAvg(close, trendlen);
def MHULL = BBMC[0];
def SHULL = BBMC[2];

def frsi = HullMovingAvg(rsi(price = close, length = rsiLengthInput),10);
def srsi = HullMovingAvg(rsi(price = close, length = rsiLengthInput2),10);

def hullrsi1 = rsi(price = MHULL, length = rsiLengthInput);
def hullrsi2 = rsi(price = SHULL, length = rsiLengthInput);

DefineGlobalColor("Up",CreateColor(77,195,255));
DefineGlobalColor("Dn",CreateColor(255,51,221));

plot hu1 = if show_Baseline then hullrsi1 else frsi;
hu1.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else
                     if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

plot hu2 = if show_Baseline then hullrsi2 else srsi;
hu2.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else
                     if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

AddCloud(hu1, hu2, GlobalColor("Up"), GlobalColor("Dn"));

plot buysignal = if MHULL crosses above SHULL then hu1 else Double.NaN;
buysignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buysignal.SetDefaultColor(Color.GREEN);
buysignal.SetLineWeight(2);
buysignal.HideBubble();
buysignal.HideTitle();

plot sellsignal = if MHULL crosses below SHULL then hu1 else Double.NaN;
sellsignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellsignal.SetDefaultColor(Color.RED);
sellsignal.SetLineWeight(2);
sellsignal.HideBubble();
sellsignal.HideTitle();

plot mline = 50;
mline.SetDefaultColor(Color.GRAY);
mline.HideBubble();
mline.HideTitle();

def rsiUpperBand = overbought;
def rsiUpperBand2 = 90;
AddCloud(rsiUpperBand2, rsiUpperBand, CreateColor(148,0,0));

def rsiLowerBand = oversold;
def rsiLowerBand2 = 10;
AddCloud(rsiLowerBand, rsiLowerBand2, CreateColor(0,148,0));
Does anyone know how to get this to print buy/sell only if it is in oversold/overbought territory? Picture below for reference, red circles are what I only want to see while the yellow X is what I want to rid the code of.

I have exhausted hours trying to get it, but still a noob with coding.

also, is it possible to assign price color to only 1 candle while the rest of the candles go un-touched and remain red/green? I know some strings that will paint 1 bar but the rest of the bars turn grey.

I wanted to see if I could make my chart print a blue candle whenever RSI Trend fires, but the rest of the candles remain the same?

I was using this to paint the candles, but I only want 1 to paint.

AssignPriceColor(if MHULL > SHULL then GlobalColor("Up")
else if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

Thanks in advance everyone
2024-02-20_14h19_20.png
 
Does anyone know how to get this to print buy/sell only if it is in oversold/overbought territory? Picture below for reference, red circles are what I only want to see while the yellow X is what I want to rid the code of.

I have exhausted hours trying to get it, but still a noob with coding.

also, is it possible to assign price color to only 1 candle while the rest of the candles go un-touched and remain red/green? I know some strings that will paint 1 bar but the rest of the bars turn grey.

I wanted to see if I could make my chart print a blue candle whenever RSI Trend fires, but the rest of the candles remain the same?

I was using this to paint the candles, but I only want 1 to paint.

AssignPriceColor(if MHULL > SHULL then GlobalColor("Up")
else if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

Thanks in advance everyone
View attachment 21122
In case anyone else was interested, I did figure it out. I commented out hu2, since I wanted it simple looking as possible. Heres the code to only show signals if they are OB or OS.


Code:
declare lower;

input rsiLengthInputFast = 14;
input rsiLengthInputSlow = 28;
input trendlen = 45;
input show_Baseline = yes;
input oversold = 30;
input overbought = 70;

def BBMC = HullMovingAvg(close, trendlen);
def MHULL = BBMC[0];
def SHULL = BBMC[2];

def fastRSI = HullMovingAvg(RSI(price = close, length = rsiLengthInputFast), 10);
def slowRSI = HullMovingAvg(RSI(price = close, length = rsiLengthInputSlow), 10);

def hullrsiFast = RSI(price = MHULL, length = rsiLengthInputFast);
def hullrsiSlow = RSI(price = SHULL, length = rsiLengthInputSlow);

DefineGlobalColor("Up", CreateColor(77, 195, 255));
DefineGlobalColor("Dn", CreateColor(255, 51, 221));

#Add Red cloud
def rsiUpperBand = overbought;
def rsiUpperBand2 = 100;
AddCloud(rsiUpperBand2, rsiUpperBand, CreateColor(148, 0, 0));

#Add Green cloud
def rsiLowerBand = oversold;
def rsiLowerBand2 = 0;
AddCloud(rsiLowerBand, rsiLowerBand2, CreateColor(0, 148, 0));

#Plot the middle line
plot mline = 50;
mline.SetDefaultColor(Color.GRAY);
mline.HideBubble();
mline.HideTitle();

plot hullFast = if show_Baseline then hullrsiFast else fastRSI;
hullFast.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

#plot hullSlow = if show_Baseline then hullrsiSlow else slowRSI;
#hullSlow.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else if MHULL < SHULL then GlobalColor("Dn") #else Color.CURRENT);

# Add cloud between hullfast and hullSlow
#AddCloud(hullFast, hullSlow, GlobalColor("Up"), GlobalColor("Dn"));

#plot buysignal = if MHULL crosses above SHULL then hullFast else Double.NaN;
plot buysignal = if MHULL crosses above SHULL and hullrsiFast is less than rsilowerBand then hullFast else Double.NaN;
buysignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buysignal.SetDefaultColor(Color.GREEN);
#buysignal.SetLineWeight(2);
#buysignal.HideBubble();
#buysignal.HideTitle();

#plot sellsignal = if MHULL crosses below SHULL then hullFast else Double.NaN;
plot sellsignal = if MHULL crosses below SHULL and hullrsiFast is greater than rsiupperBand then hullFast else Double.NaN;
sellsignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellsignal.SetDefaultColor(Color.RED);
#sellsignal.SetLineWeight(2);
#sellsignal.HideBubble();
#sellsignal.HideTitle();
 
In case anyone else was interested, I did figure it out. I commented out hu2, since I wanted it simple looking as possible. Heres the code to only show signals if they are OB or OS.


Code:
declare lower;

input rsiLengthInputFast = 14;
input rsiLengthInputSlow = 28;
input trendlen = 45;
input show_Baseline = yes;
input oversold = 30;
input overbought = 70;

def BBMC = HullMovingAvg(close, trendlen);
def MHULL = BBMC[0];
def SHULL = BBMC[2];

def fastRSI = HullMovingAvg(RSI(price = close, length = rsiLengthInputFast), 10);
def slowRSI = HullMovingAvg(RSI(price = close, length = rsiLengthInputSlow), 10);

def hullrsiFast = RSI(price = MHULL, length = rsiLengthInputFast);
def hullrsiSlow = RSI(price = SHULL, length = rsiLengthInputSlow);

DefineGlobalColor("Up", CreateColor(77, 195, 255));
DefineGlobalColor("Dn", CreateColor(255, 51, 221));

#Add Red cloud
def rsiUpperBand = overbought;
def rsiUpperBand2 = 100;
AddCloud(rsiUpperBand2, rsiUpperBand, CreateColor(148, 0, 0));

#Add Green cloud
def rsiLowerBand = oversold;
def rsiLowerBand2 = 0;
AddCloud(rsiLowerBand, rsiLowerBand2, CreateColor(0, 148, 0));

#Plot the middle line
plot mline = 50;
mline.SetDefaultColor(Color.GRAY);
mline.HideBubble();
mline.HideTitle();

plot hullFast = if show_Baseline then hullrsiFast else fastRSI;
hullFast.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else if MHULL < SHULL then GlobalColor("Dn") else Color.CURRENT);

#plot hullSlow = if show_Baseline then hullrsiSlow else slowRSI;
#hullSlow.AssignValueColor(if MHULL > SHULL then GlobalColor("Up") else if MHULL < SHULL then GlobalColor("Dn") #else Color.CURRENT);

# Add cloud between hullfast and hullSlow
#AddCloud(hullFast, hullSlow, GlobalColor("Up"), GlobalColor("Dn"));

#plot buysignal = if MHULL crosses above SHULL then hullFast else Double.NaN;
plot buysignal = if MHULL crosses above SHULL and hullrsiFast is less than rsilowerBand then hullFast else Double.NaN;
buysignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buysignal.SetDefaultColor(Color.GREEN);
#buysignal.SetLineWeight(2);
#buysignal.HideBubble();
#buysignal.HideTitle();

#plot sellsignal = if MHULL crosses below SHULL then hullFast else Double.NaN;
plot sellsignal = if MHULL crosses below SHULL and hullrsiFast is greater than rsiupperBand then hullFast else Double.NaN;
sellsignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellsignal.SetDefaultColor(Color.RED);
#sellsignal.SetLineWeight(2);
#sellsignal.HideBubble();
#sellsignal.HideTitle();
what timeframe you're planning to use it for? Your previous post had a chart attachment that was set at 10m? Just trying to understand how you're thinking of using/applying it. TIA
 
Last edited:
what timeframe you're planning to use it for? Your previous post had a chart attachment that was set at 10m? Just trying to understand how you're thinking of using/applying it. TIA
I like to use it on the 2 minute, with a hull moving average on upper chart. THis way whenever my upper Hull Moving average shows buy/sell, I can reference it in the lower study to weed out any (potential) bad trades, i.e. if I get a long signal but the RSI trend is showing overbought, etc.
 
@khpro59
Can you share the script for using this on the upper chart?

Sure! and with this upper study, if you have agreement on the 2 and 5 within the upper hull MA, its pretty strong signal.

Code:
#Adaptive_hull

# READ ME: This version does not utilize keltner channels. Ignore change log regarding keltner channels

#https://usethinkscript.com/threads/can-someone-help-me-add-keltner-channels-to-this-hma.17909/
#Can someone help me add Keltner Channels to this HMA?
#khpro59  2/9

# khpro- Considering all Keltner channels have a middle moving average, I wanted to create a keltner Channel that uses an adaptive stytle Hull Moving Average.
# Special thanks to Usethinkscript community for helping me implement this idea and the use of others logic

input src = close;#, "Source", group = "Basic Settings")
input Power = 1;#, "Power", group = "Basic Settings")
input PhaseAccumulationCycles = 1.0;#, "Phase Accumulation Cycles", group = "Basic Settings")
input PhaseAccumulationPower = 1.0;#, "Phase Accumulation Power", group = "Basic Settings")
input colorBars = yes;#(true, "Color bars", group= "UI Options")
input showSigs = yes;#(true, "Show signals", group= "UI Options")

def na = Double.NaN;

Script calcComp {
input src = close;
    def out = (
         (0.0962 * src +
         0.5769 * src[2] -
         0.5769 * src[4] -
         0.0962 * src[6]) * (0.075 * src[1] + 0.54));
    plot return = out;
}
#iLwmp(src, len, pow) =>
script iLwmp {
    input src = close;
    input len1 = 10;
    input pow = 1;
    def len = if len1 < 2 then 2 else len1;
    def sumw_ = Power(len, pow);
    def sum_ = sumw_ * src;
    def sum1 = fold i = 1 to len with q=sum_ do
               q + Power(len - i, pow) * GetValue(src, i);
    def sumw1 = fold k = 1 to len with p=sumw_ do
               p + Power(len - k, pow);
    def sum = sum1;
    def sumw = sumw1;
    def iLwmp = sum / sumw;
    plot out = if isNaN(iLwmp) then (sum_/sumw_) else iLwmp;
}
#export paa(float src, float mult, float filt)=>
script paa {
    input src = close;
    input mult = 1;
    input filt = 0;
    def bar_index = AbsValue(BarNumber());
    def pi = Double.Pi;
    def degree = 180.0 / pi;
    def filter = Max(filt, 1);
    def I1;
    def Q1;
    def Phase;
    def period;
    def Smooth = if bar_index > 5 then
                 (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10 else Smooth[1];
    def ts = calcComp(Smooth);
    def Detrender = if bar_index > 5 then ts else Detrender[1];
    def qs = calcComp(Detrender);
    def Q1_ = if bar_index > 5 then qs else Q1[1];
    def I1_ = if bar_index > 5 then Detrender[3] else I1[1];
        I1 = 0.15 * I1_ + 0.85 * I1[1];
        Q1 = 0.15 * Q1_ + 0.85 * Q1[1];
    def Phase1 = Phase[1];
    def Phase2 = if AbsValue(I1) > 0 then degree * ATan(AbsValue(Q1 / I1)) else Phase1;
    def Phase3 = if I1 < 0 and Q1 > 0 then 180 - Phase2 else Phase2;
    def Phase4 = if I1 < 0 and Q1 < 0 then 180 + Phase3 else Phase3;
        Phase  = if I1 > 0 and Q1 < 0 then 360 - Phase4 else Phase4;
    def DeltaPhase1 = Phase[1] - Phase;
    def DeltaPhase2 = if Phase[1] < 90 and Phase > 270 then
                      360 + Phase[1] - Phase else DeltaPhase1;
    def DeltaPhase3 = Max(Min(DeltaPhase2, 60), 7);
    def DeltaPhase = DeltaPhase3;
    def PhaseSum;
    def preSum;
    def count;
    if (PhaseSum[1] < (mult * 360) and count[1] < 4500) {
        preSum = GetValue(DeltaPhase, count[1]);
        PhaseSum = PhaseSum[1] + (if isNaN(preSum) then 0 else preSum);
        count = count[1] + 1;
    } else {
        preSum = 0;
        PhaseSum = PhaseSum[1];
        count = 0;
    }
    def InstPeriod = if count > 0 then count else InstPeriod[1];
    def alpha = 2.0 / (1.0 + filter);
    def period1 = period[1] + alpha * (InstPeriod - period[1]);
        period = if Floor(period1) < 1 then 1 else Floor(period1);
    def paa = Floor(period);
    plot return = if isNaN(paa) then 1 else paa;
}
def paa_ = paa(src, PhaseAccumulationCycles, PhaseAccumulationPower);
def HmaLength = if paa_ < 2 then 2 else paa_;
def HalfPrd    = HmaLength / 2;
def HullPrd    = Sqrt(HmaLength);
def HalfPeriod = Floor(HalfPrd);
def HullPeriod = Floor(HullPrd);
def iLwmpHalf_ = iLwmp(src, HalfPeriod, Power);
def iLwmpHma_  = iLwmp(src, HmaLength, Power);
def iLwmpHalf  = iLwmpHalf_;
def iLwmpHma = iLwmpHma_;
def iLwmSrc  = (2.0 * iLwmpHalf) - iLwmpHma;
def hullout_ = iLwmp(iLwmSrc, HullPeriod, Power);
def hullout = hullout_;
def sig = hullout[1];
def colorout = hullout > sig;
def goLong  = Crosses(hullout, sig, CrossingDirection.ABOVE);
def goShort = Crosses(hullout, sig, CrossingDirection.BELOW);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout then Color.GREEN else Color.RED);

plot hullLine = hullout;
hullLine.SetLineWeight(1);
hullLine.AssignValueColor(if colorout then Color.GREEN else Color.RED);

AddChartBubble(goLong, low, "L", Color.CYAN, no);
AddChartBubble(goShort, high, "S", GetColor(2));

######################
#END ADAPTIVE HULL
######################
 

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