• Get $40 off VIP by signing up for a free account! Sign Up

Derivative RSI Oscillator for ThinkorSwim

horserider

Well-known member
VIP
This is a triple smoothed RSI designed to show smoother and clearer oscillator swings compared to other RSI or momentum studies.

Code:
#  Derivative RSI Oscillator
#  Can be used alone as a smoother RSI or as part of the Charting Wealth strategy when combined    with the MACD and MAs Charting Wealth study.
#  By Horserider 12/25/2019
#

declare lower;

input length = 14;
input length1 = 5;
input length2 = 3;
input length3 = 9;
input price = close;


def NetChgAvg = WildersAverage(price - price[1], length);
def TotChgAvg = WildersAverage(AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = (50 * (ChgRatio + 1) - 50);

#################################
plot  ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.YELLOW);
ZeroLine.SetLineWeight(1);

input averageType = AverageType.EXPONENTIAL;
input averageType2 = averageType.SIMPLE;
def x = MovingAverage(averageType,RSI, length1);
def x2 = MovingAverage(averageType, x, length2);
def xs = MovingAverage(averageType2, x2 , length3);
def rsi__linediff = x2 - xs;

plot RSI_Line = rsi__linediff;
RSI_Line.SetDefaultColor(GetColor(1));

RSI_Line.SetDefaultColor(GetColor(5));
RSI_Line.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RSI_Line.SetLineWeight(3);
RSI_Line.DefineColor("Positive and Up", Color.GREEN);
RSI_Line.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI_Line.DefineColor("Negative and Down", Color.RED);
RSI_Line.DefineColor("Negative and Up", Color.DARK_RED);
RSI_Line.AssignValueColor(if RSI_Line >= 0 then if RSI_Line > RSI_Line[1] then RSI_Line.color("Positive and Up") else RSI_Line.color("Positive and Down") else if RSI_Line < RSI_Line[1] then RSI_Line.color("Negative and Down") else RSI_Line.color("Negative and Up"));

2019-12-25-TOS-CHARTS.png
 
Last edited:

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

I've played around with it by forcing in code to see if the concept of divergence signals can work like RSI does. I think it works well, I like it. I don't understand why use simple and wilders moving averages though instead of exponential but those seem to actually work better for the purpose of finding divergence, atleast when I was backtesting.
 
@wtf_dude If I remember those may have been from the Charting Wealth strategy I was trying to mirror. I put this up as a separate study also for anyone wanting a smoother RSI. Play with lengths all you want and report back if you find a sweet spot.
 
Wondering if it`s possible to create an alert when the RSI line is close to cross the zero line? Would like the alert to trigger when line crosses 0.50 value from the upside and -0.50 from the downside. Can this be done? @horserider
 
@zeek See if this works.

Alert(RSI_Line crosses below .5, "", Alert.BAR, Sound.Bell);
Alert(RSI_Line crosses above -.5, "", Alert.BAR, Sound.Bell);
 
Works great, thanks (y) @horserider

I have another request for this oscillator and was wondering if it would be possible to make it work with multiple timeframes? Basically, i would like to see the RSI swings from two different timeframes on one chart/timeframe. Is there any way to add a timeframe input selector to the settings which would open the possibility to have two different oscillators on the same chart showing the swings from both a 1min and 3min as an example?
 
@zeek Have fun.

Code:
#  Derivative RSI Oscillator
#  Can be used alone as a smoother RSI or as part of the Carting Wealth strategy when combined    with the MACD and MAs Charting Wealth study.
#  By Horserider 12/25/2019
#  Added One higher time frame option per Zeek request 7/3/2020

declare lower;
input n = 10 ;
input length = 14;
input length1 = 3;
input length2 = 5;
input length3 = 9;
input price = close;
input overbought = 4;
input oversold = -4;

def NetChgAvg = WildersAverage(price - price[1], length);
def TotChgAvg = WildersAverage(AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = (50 * (ChgRatio + 1) - 50);

#################################
plot  ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.YELLOW);
ZeroLine.SetLineWeight(1);

plot ob = overbought;
ob.SetDefaultColor(Color.GRAY);
ob.SetLineWeight(1);

plot os = oversold;
os.SetDefaultColor(Color.GRAY);
os.SetLineWeight(1);

input averageType = AverageType.EXPONENTIAL;
input averageType2 = AverageType.SIMPLE;
def x = MovingAverage(averageType, RSI, length1);
def x2 = MovingAverage(averageType, x, length2);
def xs = MovingAverage(averageType2, x2 , length3);
def rsi__linediff = x2 - xs;

plot RSI_Line = rsi__linediff;
RSI_Line.SetDefaultColor(GetColor(1));

#RSI_Line.SetDefaultColor(GetColor(5));
RSI_Line.SetPaintingStrategy(PaintingStrategy.LINE);
RSI_Line.SetLineWeight(3);
RSI_Line.DefineColor("Positive and Up", Color.GREEN);
RSI_Line.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI_Line.DefineColor("Negative and Down", Color.RED);
RSI_Line.DefineColor("Negative and Up", Color.DARK_RED);
RSI_Line.AssignValueColor(if RSI_Line >= 0 then if RSI_Line > RSI_Line[1] then RSI_Line.Color("Positive and Up") else RSI_Line.Color("Positive and Down") else if RSI_Line < RSI_Line[1] then RSI_Line.Color("Negative and Down") else RSI_Line.Color("Negative and Up"));

#########################################
#AssignPriceColor(if  RSI_Line >= 0 then if RSI_Line > RSI_Line[1] then RSI_Line.color("Positive and Up") else RSI_Line.color("Positive and Down") else if RSI_Line < RSI_Line[1] then RSI_Line.color("Negative and Down") else RSI_Line.color("Negative and Up"));

#########################################
input agg1 = AggregationPeriod.DAY;
def priceagg = close(period = agg1);
def NetChgAvgagg = WildersAverage(priceagg - priceagg[1], length);
def TotChgAvgagg = WildersAverage(AbsValue(priceagg - priceagg[1]), length);
def ChgRatioagg = if TotChgAvgagg != 0 then NetChgAvgagg / TotChgAvgagg else 0;

def RSIagg = (50 * (ChgRatioagg + 1) - 50);

#################################

def xagg = MovingAverage(averageType, RSIagg, length1);
def x2agg = MovingAverage(averageType, xagg, length2);
def xsagg = MovingAverage(averageType2, x2agg , length3);
def rsi__linediffagg = x2agg - xsagg;

plot RSI_Lineagg = rsi__linediffagg;
RSI_Lineagg.SetDefaultColor(GetColor(1));

#RSI_Line.SetDefaultColor(GetColor(5));
RSI_Lineagg.SetPaintingStrategy(PaintingStrategy.LINE);
RSI_Lineagg.SetLineWeight(3);
RSI_Lineagg.DefineColor("Positive and Up", Color.GREEN);
RSI_Lineagg.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI_Lineagg.DefineColor("Negative and Down", Color.RED);
RSI_Lineagg.DefineColor("Negative and Up", Color.DARK_RED);
RSI_Lineagg.AssignValueColor(if RSI_Lineagg >= 0 then if RSI_Lineagg > RSI_Lineagg[1] then RSI_Lineagg.Color("Positive and Up") else RSI_Lineagg.Color("Positive and Down") else if RSI_Lineagg < RSI_Lineagg[1] then RSI_Lineagg.Color("Negative and Down") else RSI_Lineagg.Color("Negative and Up"));
 
Hi @horserider ..... is there a way to freeze the zero line for this indicator. At the moment it floats around based on the value of positive or negative values across the screen. I am overlaying it with a momentum oscillator that is somewhat different values than this RSI indicator so the right axis comes up as a percentage scale ( which is fine) But even on its own the RSI zero line floats rather than fixed at the center (Price axis center) of the window it is in. Thank you

BTW I would not be concerned if the RSI bars in the histogram would overrun,,,,,, go beyond the border of the window..... with this type mod to freeze the zero line.. Thanks
 
Last edited by a moderator:
Can someone help me make a label for the upper chart to show which direction the RSI line is currently going. So for example if price is "positive and up" the label will say this and be colored according to the study.

Trying to clean up my charts and have less lower indicators on them so it would be useful to have a label instead.
 
Can someone help me make a label for the upper chart to show which direction the RSI line is currently going. So for example if price is "positive and up" the label will say this and be colored according to the study.

Trying to clean up my charts and have less lower indicators on them so it would be useful to have a label instead.
Code:
#  Derivative RSI Oscillator

#  Can be used alone as a smoother RSI or as part of the Carting Wealth strategy when combined    with the MACD and MAs Charting Wealth study.

#  By Horserider 12/25/2019

#  Added One higher time frame option per Zeek request 7/3/2020



# Upper Label mod by WTF_Dude



declare upper;

input n = 10 ;

input length = 14;

input length1 = 3;

input length2 = 5;

input length3 = 9;

input price = close;

input overbought = 4;

input oversold = -4;



def NetChgAvg = WildersAverage(price - price[1], length);

def TotChgAvg = WildersAverage(AbsValue(price - price[1]), length);

def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;



def RSI = (50 * (ChgRatio + 1) - 50);



#################################

def  ZeroLine = 0;



def ob = overbought;



def os = oversold;





input averageType = AverageType.EXPONENTIAL;

input averageType2 = AverageType.SIMPLE;

def x = MovingAverage(averageType, RSI, length1);

def x2 = MovingAverage(averageType, x, length2);

def xs = MovingAverage(averageType2, x2 , length3);

def rsi__linediff = x2 - xs;



def RSI_Line = rsi__linediff;


#########################################

addlabel(yes, "D.RSI: " + if  RSI_Line >= 0  and RSI_Line > RSI_Line[1] then "Positive and Up" else if  RSI_Line >= 0 and RSI_Line < RSI_Line[1] then "Postive and Down" else if RSI_Line<0 and  RSI_Line < RSI_Line[1] then "Negative and Down" else "Negative and Up", if  RSI_Line>= 0  and RSI_Line > RSI_Line[1] then  Color.GREEN else if  RSI_Line >= 0 and RSI_Line < RSI_Line[1] then  Color.DARK_GREEN else if RSI_Line<0 and  RSI_Line < RSI_Line[1] then COLOR.RED else COLOR.DARK_RED);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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