Dynamic RSI

a more powerful version of the RSI, that adapts to changing price condition and identifies overbought/oversold zones.

48 mins
Intermediate
youtube-video-thumbnail
Table of Contents
    Add a header to begin generating the table of contents
    Table of Contents
      Add a header to begin generating the table of contents

      Introduction

      In this tutorial, I’ll show you how to build a Dynamic RSI Indicator using thinkScript code for the ThinkOrSwim (TOS) trading platform. We’ll leverage code snippets, and our own logic, to create a powerful RSI indicator that adapts to market volatility.

      The Dynamic RSI indicator combines Bollinger Bands, trend lines, and various RSI metrics. The Bollinger Bands on the RSI chart help gauge overbought and oversold conditions, while trend lines provide support and resistance levels for potential trading signals.

      I’ll take you through, step-by-step, how to build the Dynamic RSI indicator for ThinkOrSwim below.

      Volatility Box Invite

      We are TOS Indicators.com, home of the Volatility Box.

      The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.

      We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.

      Futures Volatility Box - Trade Major Markets With an Edge

      Designed For: Futures, Micro-Futures and Index Market Traders
      Supported Models: Hourly Volatility Box models
      Supported Markets: 10 Major Futures Markets

      The Futures Volatility Box comes with:

      • 5 Volatility Models for each market
      • Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
      • Video Setup Guide
      • Trade Plan
      • Access to all members-only resources, including Squeeze Course

      Learn More About the Futures Volatility Box

      Trade futures and micro futures with a consistent volatility edge

      Stock Volatility Box - Powerful Web Based Volatility Platform

      Designed For: Stock and Options Traders
      Supported Models: Hourly and Daily Volatility Box models
      Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)

      A Stock Volatility Box membership includes access to: 

      • Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
      • Dashboard - A quick and easy way to view daily volatility model levels online
      • Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
      • Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
      • All Members Only Indicators - We don't nickel and dime you. Everything really is included.
      • And much more!

      Learn More About the Stock Volatility Box

      Trade stocks and options with a consistent volatility edge

      Dynamic RSI ThinkOrSwim Code

      In this section, I’ll take you through the process of building the actual indicator. I find this process to be helpful, because it forces you to understand the nooks and crannies hiding behind each line of the code. By building it from scratch, you know how the code functions, and when the different signals print.

      For Volatility Box members, the Dynamic RSI plays a key role in our Edge Signals indicator, which is our custom overbought/oversold indicator.

       

      Step 1: Setting Up Global Variables

      
      declare lower;
      input length = 14;
      input over_Bought = 70;
      input over_Sold = 30;
      input price = close;
      input averageType = AverageType.WILDERS;
      input showBreakoutSignals = no;
      input Volatility_Band = 14;
      input STDEV_Multiplier = 2;
      input RSI_Period = 14;
      input RSI_Price_Line = 2;
      

      This block initializes the parameters for the Dynamic RSI, such as the RSI period, overbought and oversold thresholds, and the Bollinger Band settings.

      Step 2: Define the Dynamic RSI Calculations

      To build the dynamic nature of the RSI, we start by defining the RSI values and add a yellow dynamic average line for smoother signal interpretation.

      
      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;
      
      def DYNRSI = reference RSI(RSI_Period);
      def Price1 = if averageType == AverageType.SIMPLE then Average(DYNRSI, RSI_Price_Line) else ExpAverage(DYNRSI, RSI_Price_Line);
      def SDBB = StDev(DYNRSI, Volatility_Band);
      

      Step 3: Plotting RSI and Bollinger Bands

      Next, we’ll plot the RSI values along with the middle lines and Bollinger Bands for overbought and oversold zones.

      
      plot RSI = 50 * (ChgRatio + 1);
      plot MiddleLine = 50;
      plot MiddleLine1 = 70;
      plot MiddleLine2 = 30;
      
      plot DYNAverage = Average(DYNRSI, Volatility_Band);
      DYNAverage.SetDefaultColor(Color.YELLOW);
      DYNAverage.SetLineWeight(2);
      
      plot UpperBollinger = DYNAverage + STDEV_Multiplier * SDBB;
      UpperBollinger.SetDefaultColor(Color.RED);
      plot LowerBollinger = DYNAverage - STDEV_Multiplier * SDBB;
      LowerBollinger.SetDefaultColor(Color.GREEN);
      

      Step 4: Adding Overbought and Oversold Signals

      To capture signals, we plot arrows for overbought and oversold levels, which trigger when the RSI crosses these boundaries.

      
      plot OverSold = over_Sold;
      plot OverBought = over_Bought;
      plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
      plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
      
      UpSignal.SetHiding(!showBreakoutSignals);
      DownSignal.SetHiding(!showBreakoutSignals);
      

      Step 5: Squeeze Detection with Bollinger Band Compression

      Identify squeeze conditions by analyzing the distance between the upper and lower Bollinger Bands. A squeeze is triggered when the bands come within a certain threshold, indicating compression.

      
      def BBDistance = if UpperBollinger - LowerBollinger <= 10 then 1 else 0;
      plot squeeze = if BBDistance then 50 else Double.nan;
      squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
      squeeze.SetLineWeight(4);
      squeeze.SetDefaultColor(Color.Red);
      

      Step 6: Incorporating Trend Lines

      We utilize Mobius’s auto trend line code to add trend lines for RSI levels, giving you objective support and resistance areas within the indicator.

      
      input TrendLineLength1 = 150;
      input TrendLineLength2 = 80;
      input TrendLineLength3 = 40;
      
      def Inertia1 = InertiaAll(RSI, TrendLineLength1);
      def Inertia2 = InertiaAll(RSI, TrendLineLength2);
      def Inertia3 = InertiaAll(RSI, TrendLineLength3);
      
      def TL_Bull1 = Inertia1 - (HighestAll(AbsValue(Inertia1 - RSI)) * 0.8);
      def TL_Bear1 = Inertia1 + (HighestAll(AbsValue(Inertia1 - RSI)) * 0.8);
      

      Conclusion

      By following this tutorial, you’ve now built a powerful Dynamic RSI Indicator for ThinkOrSwim.

      You can now incorporate these steps into your trading strategy and further refine the indicator by adjusting the parameters for your specific trading style. This tool not only gives a visual representation of overbought and oversold conditions but also layers on additional insights through trend lines and Bollinger Band squeezes.

      Hope you found this tutorial helpful. Thanks for following along, and as always, good luck trading!

      downloads

      Download the Dynamic RSI Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Download Indicator

      Download the Dynamic RSI Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Have your own idea?

      Let us help you turn your trading strategy into a powerful indicator, scan and backtester.