Multiple Time Frame (MTF) RSI Indicator for ThinkorSwim


Well-known member
Chart time frame plus choice of 2 additional time frames RSI. Cloud between chart time frame RSI and next highest time frame RSI. User can input two higher time frames. Make sure higher time frames are higher than chart time frame.

#MTF RSI Three standard ToS RSI studies with a choice of time frame for second and third RSI. Cloud between chart and second RSI.
# RSI with agg periods by Horserider. 5/12/2019

declare lower;
input length = 14;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.WILDERS;

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

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot lline = 50;

RSI.DefineColor("Positive and Up", Color.GREEN);
RSI.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI.DefineColor("Negative and Down", Color.RED);
RSI.DefineColor("Negative and Up", Color.DARK_RED);
RSI.AssignValueColor(if RSI >= 50 then if RSI > RSI[1] then RSI.Color("Positive and Up") else RSI.Color("Positive and Down") else if RSI < RSI[1] then RSI.Color("Negative and Down") else RSI.Color("Negative and Up"));


# RSI 2
input length2 = 14;
input price2 = close;
input averageType2 = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;

def c = close(period = agg);

def NetChgAvg2 = MovingAverage(averageType2, c - c[1], length2);
def TotChgAvg2 = MovingAverage(averageType2, AbsValue(c - c[1]),length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;

plot RSI2 = 50 * (ChgRatio2 + 1);

RSI2.DefineColor("Positive and Up", Color.GREEN);
RSI2.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI2.DefineColor("Negative and Down", Color.RED);
RSI2.DefineColor("Negative and Up", Color.DARK_RED);
RSI2.AssignValueColor(if RSI2 >= 50 then if RSI2 > RSI2[1] then RSI2.Color("Positive and Up") else RSI2.Color("Positive and Down") else if RSI2 < RSI2[1] then RSI2.Color("Negative and Down") else RSI2.Color("Negative and Up"));

# RSI 3
input length3 = 14;
input price3 = close;
input averageType3 = AverageType.WILDERS;
input agg3 = AggregationPeriod.WEEK;

def c3 = close(period = agg3);

def NetChgAvg3 = MovingAverage(averageType3, c3 - c3[1], length3);
def TotChgAvg3 = MovingAverage(averageType3, AbsValue(c3 - c3[1]),length3);
def ChgRatio3 = if TotChgAvg3 != 0 then NetChgAvg3 / TotChgAvg3 else 0;

plot RSI3 = 50 * (ChgRatio3 + 1);

RSI3.DefineColor("Positive and Up", Color.GREEN);
RSI3.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI3.DefineColor("Negative and Down", Color.RED);
RSI3.DefineColor("Negative and Up", Color.DARK_RED);
RSI3.AssignValueColor(if RSI3 >= 50 then if RSI3 > RSI3[1] then RSI3.Color("Positive and Up") else RSI3.Color("Positive and Down") else if RSI3 < RSI3[1] then RSI3.Color("Negative and Down") else RSI3.Color("Negative and Up"));

#addCloud(RSI, RSI2,,;

Last edited:
If I just want to add the mtf time frame script into existing RSI with divergence would the below code is sufficient or there is more to it?

input agg = AggregationPeriod.DAY;

Quick code. See if it works.

# RSI_With_Divergence
# Mobius
# V01.01.2013
# 4.15.2019
#hint:<b>RSI with Divergence</b>
# Note: Install this as a new study. Save this study using the name above (the first line of code RSI_With_Divergence).
# To use this study as a scan; DO NOT TRY TO LOAD IT DIRECTLY IN THE SCANNER, IT WILL THROW AN ERROR MESSAGE. Go to the scan tab. Delete any existing scan criteria. Click Add Study Filter. Click the window under Criteria. In that drop down menu click Custom. Delete the existing study. Click Add Condition. Click the down arrow in the Select A Condition window. Click Study. Scroll down the List till you find RSI_With_Divergence and click it. Click on the Plot window and you can choose Dhigh or Dlow in addition to the default plot RSI. If you choose either of the divergence siganls choose is True from the center column. Click on the aggregation period at the top left and set the aggregation period you want scaned. Then click Save and when the popup window shows the warning that this is a custom scan chose OK. Now put the list of stocks you wish to scan in the Scan In box and chose any list you want that to intersect with. If you wish to make this a Dynamic WatchList, save this scan with a name such as RSI_With_Div_WL then in your Gadgets box click the little gear icon, locate the name of the scan you just saved and click it. As equities match the scan criteria they will populate the list.

declare lower;

input n = 14;        #hint nRSI: Periods or length for RSI
input Over_Bought = 70; #hint Over_Bought: Over Bought line
input Over_Sold = 30;   #hint Over_Sold: Over Sold line

def o = open;
def h = high;
def l = low;

def x = BarNumber();

input agg = AggregationPeriod.DAY;
def c = close(period = agg);

def MidLine = 50;
def NetChgAvg = ExpAverage(c - c[1], n);
def TotChgAvg = ExpAverage(AbsValue(c - c[1]), n);
def ChgRatio = if TotChgAvg != 0
                  then NetChgAvg / TotChgAvg
                  else 0;
plot RSI = 50 * (ChgRatio + 1);
RSI.AssignValueColor(if RSI < Over_Sold
                     then color.yellow
                     else if RSI > Over_Bought
                     then color.yellow
                     else createColor(25, 75, 250));
plot OverSold = Over_Sold;
plot OverBought = Over_Bought;
def bar = BarNumber();
def Currh = if RSI > OverBought
                then fold i = 1 to Floor(n / 2)
                with p = 1
                while p
                do RSI > getValue(RSI, -i)
                else 0;
def CurrPivotH = if (bar > n and
                         RSI == highest(RSI, Floor(n/2)) and
                     then RSI
                     else double.NaN;
def Currl = if RSI < OverSold
                then fold j = 1 to Floor(n / 2)
                with q = 1
                while q
                do RSI < getValue(RSI, -j)
                else 0;
def CurrPivotL = if (bar > n and
                         RSI == lowest(RSI, Floor(n/2)) and
                     then RSI
                     else double.NaN;
def CurrPHBar = if !isNaN(CurrPivotH)
                then bar
                else CurrPHBar[1];
def CurrPLBar = if !isNaN(CurrPivotL)
                then bar
                else CurrPLBar[1];
def PHpoint = if !isNaN(CurrPivotH)
              then CurrPivotH
              else PHpoint[1];
def priorPHBar = if PHpoint != PHpoint[1]
                 then CurrPHBar[1]
                 else priorPHBar[1];
def PLpoint = if !isNaN(CurrPivotL)
              then CurrPivotL
              else PLpoint[1];
def priorPLBar = if PLpoint != PLpoint[1]
                 then CurrPLBar[1]
                 else priorPLBar[1];
def HighPivots = bar >= highestAll(priorPHBar);
def LowPivots = bar >= highestAll(priorPLBar);
def pivotHigh = if HighPivots
                then CurrPivotH
                else double.NaN;
plot PlotHline = pivotHigh;
plot pivotLow = if LowPivots
                then CurrPivotL
                else double.NaN;
plot PivotDot = if !isNaN(pivotHigh)
                then pivotHigh
                else if !isNaN(pivotLow)
                     then pivotLow
                     else double.NaN;

# End Code RSI with Divergence

If you guys have MTF RSI please post it. If not, would somebody please code it?

Thank you.
@horserider Thank you, but it doesn't seem to be correct. I'm on 8 minutes and selected to plot RSI on 15 minutes. I have a separate 15-min chart with RSI on it, the MTF RSI doesn't match the one on 15 minutes.
@horserider I've checked it again. It does not seem to match TOS' RSI on the same time frame.

Edit: I've found an issue and fixed it. Mobius' code uses a modified RSI not the original one, that was the issue.
Last edited by a moderator:
assignPriceColor(if RSI >= 50 then if RSI > RSI[1] then RSI.Color("Positive and Up") else RSI.Color("Positive and Down") else if RSI < RSI[1] then RSI.Color("Negative and Down") else RSI.Color("Negative and Up"));
@horserider thank you so much for the indicator, do you have any idea on how to make it MTF for the SLOWRSI? i've seen good results with the following setup. I just don't know how to put an aggregation to the close with the "def ema = ExpAverage(close, emaLength);"
# TD Ameritrade IP Company, Inc. (c) 2015-2020

declare lower;

input emaLength = 5;
input rsiLength = 10;
input over_bought = 80;
input over_sold = 20;

def ema = ExpAverage(close, emaLength);
def netChgAvg = WildersAverage(close - ema, rsiLength);
def totChgAvg = WildersAverage(AbsValue(close - ema), rsiLength);
def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0;

plot SlowRSI = 50 * (chgRatio + 1);
plot OverBought = over_bought;
plot MiddleLine = 50;
plot OverSold = over_sold;

Thanks for the indicator mine does not show the cloud or the green and red line it only shows as a single line.
@Katsu Make sure your current timeframe is not higher than what is being set in the indicator. Ex: If you have the RSI set to 2min chart but you're on the 5min chart, then most likely it will not display properly.
@Katsu Make sure to understand what you are using. This is the MTF version of the RSI indicator. It just allows you to view the RSI from a higher timeframe without changing to that timeframe. Does that make sense?

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
482 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.