RSI Supply/Demand For ThinkOrSwim

Ahmar824

Member
RSI Supply/Demand For ThinkOrSwim

A script that draws supply and demand zones based on the RSI indicator. For example if RSI is under 30 a supply zone is drawn on the chart and extended for as long as there isn't a new crossunder 30. Same goes for above 70. The threshold which by default is set to 30, which means 30 is added to 0 and subtracted from 100 to give us the classic 30/70 threshold on RSI , can be set in the indicator settings.

By only plotting the Demand Below Supply Above indicator you get automatic SD level that is updated every time RSI reaches either 30 or 70. If you plot the Resistance Zone / Support Zone you get an indicator that extends the zone instead of overwrite the earlier zone. Due to the zone being extended the chart can get a bit messy if there isn't a clear range going on.

There is also a "confirmation bars" setting where you can tell the script how many bars under over 30 / 70 you want before a zone is drawn.

@samer800 Need help converting this one, Can you help?
https://www.tradingview.com/script/m6dD8tBf-RSI-Based-Automatic-Supply-and-Demand/

Really just need to have only one zone. 60 OB and 40 OS and 14 day length

Thank you!
 
Last edited by a moderator:
@samer800 Need help converting this one, Can you help?
https://www.tradingview.com/script/m6dD8tBf-RSI-Based-Automatic-Supply-and-Demand/

Really just need to have only one zone. 60 OB and 40 OS and 14 day length
Thank you!
check the below.

CSS:
#//© shtcoinr, updated to v4 wijth additional zones and settings by Lij_MC
#study(title="RSI Supply/Demand", shorttitle="RSI S/D", overlay=true)
# Converted by Sam4Cok@Samer800 - 12/2022

input SelectZone = {Default "Supply Demand Zone", "Support Resistance Zone", "Both Zones"};
input rsiLength = 14;    # "RSI 1 Length"
input rsiObOs   = {default "70 / 30", "75 / 25", "80 / 20", "85 / 15", "90 / 10", "95 / 5"};# "OB / OS"
input NumberOfConfirmationBars = 3;    # "Confirmation Bars"
input ShowBreaks = no;

def na = Double.NaN;
def last = isNaN(Close);
def zone = if SelectZone==SelectZone."Supply Demand Zone" then 1 else
           if SelectZone==SelectZone."Support Resistance Zone" then -1 else 0;
#---- Colors
DefineGlobalColor("SDColor"    , CreateColor(23,105,170));
DefineGlobalColor("SupZoneColor" , Color.DARK_GREEN);
DefineGlobalColor("ResZoneColor" , Color.DARK_RED);
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
script fixnan {
    input source = close;
    def fix = if !IsNaN(source) then source else fix[1];
    plot result = fix;
}
def RSI1 = RSI(Price = close, Length = rsiLength);
def RSI1OB = if rsiObOs == rsiObOs."70 / 30" then 70 else
             if rsiObOs == rsiObOs."75 / 25" then 75 else
             if rsiObOs == rsiObOs."80 / 20" then 80 else
             if rsiObOs == rsiObOs."90 / 10" then 90 else
             if rsiObOs == rsiObOs."95 / 5" then 95 else 100;
def RSI1OS = if rsiObOs == rsiObOs."70 / 30" then 30 else
             if rsiObOs == rsiObOs."75 / 25" then 25 else
             if rsiObOs == rsiObOs."80 / 20" then 20 else
             if rsiObOs == rsiObOs."90 / 10" then 10 else
             if rsiObOs == rsiObOs."95 / 5" then 5 else 0;

def RSI1incrementer_up   = if RSI1 > RSI1OB then 1 else 0;
def RSI1incrementer_down = if RSI1 < RSI1OS then 1 else 0;
def RSI1incrementer_both = if RSI1 > RSI1OB or RSI1 < RSI1OS then 1 else 0;

def RSI1rsx;

if RSI1incrementer_both {
    RSI1rsx = nz(RSI1rsx[1], 0) + RSI1incrementer_both;
} else {
    RSI1rsx = 0;
}

def RSI1rxH = if RSI1rsx >= NumberOfConfirmationBars then high else na;
def RSI1rxL = if RSI1rsx >= NumberOfConfirmationBars then low else na;

def RSI1rH = fixnan(RSI1rxH);
def RSI1rL = fixnan(RSI1rxL);

def RSI1rsu;

if RSI1incrementer_up {
    RSI1rsu = nz(RSI1rsu[1], 0) + RSI1incrementer_up;
    } else {
    RSI1rsu = 0;
  }
def RSI1rssH = if RSI1rsu >= NumberOfConfirmationBars then high else na;
def RSI1rssL = if RSI1rsu >= NumberOfConfirmationBars then low else na;
def RSI1ResistanceZoneHigh = fixnan(RSI1rssH);
def RSI1ResistanceZoneLow  = fixnan(RSI1rssL);

def RSI1rsd;

if RSI1incrementer_down {
    RSI1rsd = nz(RSI1rsd[1], 0) + RSI1incrementer_down;
    } else {
    RSI1rsd = 0;
 }

def RSI1rsrH = if RSI1rsd >= NumberOfConfirmationBars then high else na;
def RSI1rsrL = if RSI1rsd >= NumberOfConfirmationBars then low else na;
def RSI1SupportZoneHigh = fixnan(RSI1rsrH);
def RSI1SupportZoneLow  = fixnan(RSI1rsrL);

def RSI1_ResZoneColor = if RSI1ResistanceZoneHigh != RSI1ResistanceZoneHigh[1] or last then na else 1;
def RSI1_SupZoneColor = if RSI1SupportZoneLow     !=  RSI1SupportZoneLow[1] or last then  na else 1;
def RSI1SDColor       = if RSI1rH != RSI1rH[1] or last then na else 1;

def RSI1RZHigh = if zone<=0 and RSI1_ResZoneColor then RSI1ResistanceZoneHigh else na; # "Resistance Zone - High"
def RSI1RZLow  = if zone<=0 and RSI1_ResZoneColor then RSI1ResistanceZoneLow else na;  # "Resistance Zone - Low"
AddCloud(RSI1RZHigh[-1], RSI1RZLow[-1], GlobalColor("ResZoneColor"), GlobalColor("ResZoneColor"), yes);

def RSI1SZHigh = if zone<=0 and RSI1_SupZoneColor then RSI1SupportZoneHigh else na; # "Support Zone - High"
def RSI1SZLow  = if zone<=0 and RSI1_SupZoneColor then RSI1SupportZoneLow else na;  # "Support Zone - Low"
AddCloud(RSI1SZHigh[-1], RSI1SZLow[-1], GlobalColor("SupZoneColor"), GlobalColor("SupZoneColor"), yes);

def RSI1rHi = if zone>=0 and RSI1SDColor then RSI1rH else na; # "Supply Demand - High"
def RSI1rLo = if zone>=0 and RSI1SDColor then RSI1rL else na; # "Supply Demand - Low"
AddCloud(RSI1rHi[-1],RSI1rLo[-1], GlobalColor("SDColor"), GlobalColor("SDColor"), yes);

#--- Signals
def UpCond = (close > RSI1rH) and (RSI1rH == RSI1rH[1]);
def UpCount = if UpCond then UpCount[1] + 1 else 0;
def CrossUp = UpCount==NumberOfConfirmationBars;
AddChartBubble(ShowBreaks and CrossUp,low, "Break", Color.GREEN, no);
#----
def DnCond = (close < RSI1rL) and (RSI1rL == RSI1rL[1]);
def DnCount = if DnCond then DnCount[1] + 1 else 0;
def CrossDn = DnCount==NumberOfConfirmationBars;

AddChartBubble(ShowBreaks and CrossDn,high, "Break", Color.RED, YES);

#---- END CODE
 
Last edited by a moderator:
added option for manual entry of Ob/OS

CSS:
#//© shtcoinr, updated to v4 wijth additional zones and settings by Lij_MC
#study(title="RSI Supply/Demand", shorttitle="RSI S/D", overlay=true)
# Converted by Sam4Cok@Samer800 - 12/2022 - Update, Added manual OB/OS option

input SelectZone = {Default "Supply Demand Zone", "Support Resistance Zone", "Both Zones"};
input rsiLength = 14;    # "RSI 1 Length"
input rsiObOs   = {"Manual", default "70 / 30", "75 / 25", "80 / 20", "90 / 10", "95 / 5"};# "OB / OS"
input OverboughtManualSelect = 70;
input OversoldManualSelect = 30;
input NumberOfConfirmationBars = 3;    # "Confirmation Bars"
input ShowBreaks = no;


def na = Double.NaN;
def last = isNaN(Close);
def zone = if SelectZone==SelectZone."Supply Demand Zone" then 1 else
           if SelectZone==SelectZone."Support Resistance Zone" then -1 else 0;
#---- Colors
DefineGlobalColor("SDColor"    , CreateColor(23,105,170));
DefineGlobalColor("SupZoneColor" , Color.DARK_GREEN);
DefineGlobalColor("ResZoneColor" , Color.DARK_RED);
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
script fixnan {
    input source = close;
    def fix = if !IsNaN(source) then source else fix[1];
    plot result = fix;
}
def RSI1 = RSI(Price = close, Length = rsiLength);
def RSI1OB = if rsiObOs == rsiObOs."Manual" then OverboughtManualSelect else
             if rsiObOs == rsiObOs."70 / 30" then 70 else
             if rsiObOs == rsiObOs."75 / 25" then 75 else
             if rsiObOs == rsiObOs."80 / 20" then 80 else
             if rsiObOs == rsiObOs."90 / 10" then 90 else
             if rsiObOs == rsiObOs."95 / 5" then 95 else 100;

def RSI1OS = if rsiObOs == rsiObOs."Manual" then OversoldManualSelect else
             if rsiObOs == rsiObOs."70 / 30" then 30 else
             if rsiObOs == rsiObOs."75 / 25" then 25 else
             if rsiObOs == rsiObOs."80 / 20" then 20 else
             if rsiObOs == rsiObOs."90 / 10" then 10 else
             if rsiObOs == rsiObOs."95 / 5" then 5 else 0;

def RSI1incrementer_up   = if RSI1 > RSI1OB then 1 else 0;
def RSI1incrementer_down = if RSI1 < RSI1OS then 1 else 0;
def RSI1incrementer_both = if RSI1 > RSI1OB or RSI1 < RSI1OS then 1 else 0;

def RSI1rsx;

if RSI1incrementer_both {
    RSI1rsx = nz(RSI1rsx[1], 0) + RSI1incrementer_both;
} else {
    RSI1rsx = 0;
}

def RSI1rxH = if RSI1rsx >= NumberOfConfirmationBars then high else na;
def RSI1rxL = if RSI1rsx >= NumberOfConfirmationBars then low else na;

def RSI1rH = fixnan(RSI1rxH);
def RSI1rL = fixnan(RSI1rxL);

def RSI1rsu;

if RSI1incrementer_up {
    RSI1rsu = nz(RSI1rsu[1], 0) + RSI1incrementer_up;
    } else {
    RSI1rsu = 0;
  }
def RSI1rssH = if RSI1rsu >= NumberOfConfirmationBars then high else na;
def RSI1rssL = if RSI1rsu >= NumberOfConfirmationBars then low else na;
def RSI1ResistanceZoneHigh = fixnan(RSI1rssH);
def RSI1ResistanceZoneLow  = fixnan(RSI1rssL);

def RSI1rsd;

if RSI1incrementer_down {
    RSI1rsd = nz(RSI1rsd[1], 0) + RSI1incrementer_down;
    } else {
    RSI1rsd = 0;
 }

def RSI1rsrH = if RSI1rsd >= NumberOfConfirmationBars then high else na;
def RSI1rsrL = if RSI1rsd >= NumberOfConfirmationBars then low else na;
def RSI1SupportZoneHigh = fixnan(RSI1rsrH);
def RSI1SupportZoneLow  = fixnan(RSI1rsrL);

def RSI1_ResZoneColor = if RSI1ResistanceZoneHigh != RSI1ResistanceZoneHigh[1] or last then na else 1;
def RSI1_SupZoneColor = if RSI1SupportZoneLow     !=  RSI1SupportZoneLow[1] or last then  na else 1;
def RSI1SDColor       = if RSI1rH != RSI1rH[1] or last then na else 1;

def RSI1RZHigh = if zone<=0 and RSI1_ResZoneColor then RSI1ResistanceZoneHigh else na; # "Resistance Zone - High"
def RSI1RZLow  = if zone<=0 and RSI1_ResZoneColor then RSI1ResistanceZoneLow else na;  # "Resistance Zone - Low"
AddCloud(RSI1RZHigh[-1], RSI1RZLow[-1], GlobalColor("ResZoneColor"), GlobalColor("ResZoneColor"), yes);

def RSI1SZHigh = if zone<=0 and RSI1_SupZoneColor then RSI1SupportZoneHigh else na; # "Support Zone - High"
def RSI1SZLow  = if zone<=0 and RSI1_SupZoneColor then RSI1SupportZoneLow else na;  # "Support Zone - Low"
AddCloud(RSI1SZHigh[-1], RSI1SZLow[-1], GlobalColor("SupZoneColor"), GlobalColor("SupZoneColor"), yes);

def RSI1rHi = if zone>=0 and RSI1SDColor then RSI1rH else na; # "Supply Demand - High"
def RSI1rLo = if zone>=0 and RSI1SDColor then RSI1rL else na; # "Supply Demand - Low"
AddCloud(RSI1rHi[-1],RSI1rLo[-1], GlobalColor("SDColor"), GlobalColor("SDColor"), yes);

#--- Signals
def UpCond = (close > RSI1rH) and (RSI1rH == RSI1rH[1]);
def UpCount = if UpCond then UpCount[1] + 1 else 0;
def CrossUp = UpCount==NumberOfConfirmationBars;
AddChartBubble(ShowBreaks and CrossUp,low, "Break", Color.GREEN, no);
#----
def DnCond = (close < RSI1rL) and (RSI1rL == RSI1rL[1]);
def DnCount = if DnCond then DnCount[1] + 1 else 0;
def CrossDn = DnCount==NumberOfConfirmationBars;

AddChartBubble(ShowBreaks and CrossDn,high, "Break", Color.RED, YES);

#---- END CODE
 
Hello @samer800 and @Ahmar824 , This is a fantastic find and i am going to try this on Monday. Meanwhile is there any explanation to how to use this indicator, just so i can understand this indicator properly and not miss anything. Thanks in advance.
 
Hello @samer800 and @Ahmar824 , This is a fantastic find and i am going to try this on Monday. Meanwhile is there any explanation to how to use this indicator, just so i can understand this indicator properly and not miss anything. Thanks in advance.
From the Tradingview site: https://www.tradingview.com/script/m6dD8tBf-RSI-Based-Automatic-Supply-and-Demand/
A script that draws supply and demand zones based on the RSI indicator. For example if RSI is under 30 a supply zone is drawn on the chart and extended for as long as there isn't a new crossunder 30. Same goes for above 70. The threshold which by default is set to 30, which means 30 is added to 0 and subtracted from 100 to give us the classic 30/70 threshold on RSI , can be set in the indicator settings.

By only plotting the Demand Below Supply Above indicator you get automatic SD level that is updated every time RSI reaches either 30 or 70. If you plot the Resistance Zone / Support Zone you get an indicator that extends the zone instead of overwrite the earlier zone. Due to the zone being extended the chart can get a bit messy if there isn't a clear range going on.

There is also a "confirmation bars" setting where you can tell the script how many bars under over 30 / 70 you want before a zone is drawn.
 

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