RSI Based Automatic Supply and Demand For ThinkOrSwim

CashMoney

Member
VIP
Author states: 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.

U1lj6tW.png


Here is the original Tradingview code:
https://www.tradingview.com/script/m6dD8tBf-RSI-Based-Automatic-Supply-and-Demand/

The new ThinkOrSwim code can be found in the next post.
 
Last edited by a moderator:

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

Can someone convert this? Thank you
@samer800

https://www.tradingview.com/script/m6dD8tBf-RSI-Based-Automatic-Supply-and-Demand/

//@version=4
//© shtcoinr, updated to v4 wijth additional zones and settings by Lij_MC
study(title="RSI Supply/Demand", shorttitle="RSI S/D", overlay=true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ShowSD1 = input(false, "Supply Demand Zone", group = "Supply Demand 1", inline = "Supply Demand 1")
ShowSZ1 = input(false, "Support Zone", group = "Supply Demand 1", inline = "Supply Demand 1")
ShowRZ1 = input(false, "Resistance Zone", group = "Supply Demand 1", inline = "Supply Demand 1")
RSI1Length = input(7, minval=1, title="RSI 1 Length", group="Supply Demand 1")
RSI1OBOSIn = input(defval="70 / 30", title="OB / OS", options=["70 / 30", "75 / 25", "80 / 20", "85 / 15", "90 / 10", "95 / 5"], group="Supply Demand 1")
NumberOfConfirmationBarsRSI1 = input(3, title="Confirmation Bars", group="Supply Demand 1")
RSI1SDColorIn = input(color.new(color.blue, 85), "Fill Colors - Supply Demand", type = input.color, group="Supply Demand 1", inline = "Fill 1")
RSI1SupportColorIn = input(color.new(color.lime, 92), "Support", type = input.color, group="Supply Demand 1", inline = "Fill 1")
RSI1ResistanceColorIn = input(color.new(color.red, 92), "Resistance", type = input.color, group="Supply Demand 1", inline = "Fill 1")
RSI1 = rsi(close, RSI1Length)
RSI1OB = RSI1OBOSIn == "70 / 30" ? 70 :
RSI1OBOSIn == "75 / 25" ? 75 : RSI1OBOSIn == "80 / 20" ? 80 :
RSI1OBOSIn == "90 / 10" ? 90 : RSI1OBOSIn == "95 / 5" ? 95 : 100
RSI1OS = RSI1OBOSIn == "70 / 30" ? 30 :
RSI1OBOSIn == "75 / 25" ? 25 : RSI1OBOSIn == "80 / 20" ? 20 :
RSI1OBOSIn == "90 / 10" ? 10 : RSI1OBOSIn == "95 / 5" ? 5 : 0
RSI1incrementer_up = RSI1 > RSI1OB ? 1 : 0
RSI1incrementer_down = RSI1 < RSI1OS ? 1 : 0
RSI1incrementer_both = RSI1 > RSI1OB or RSI1 < RSI1OS ? 1 : 0
RSI1rsx = 0
if RSI1incrementer_both
RSI1rsx := nz(RSI1rsx[1], 0) + RSI1incrementer_both
RSI1rsx
else
RSI1rsx = 0
RSI1rsx
RSI1rxH = if RSI1rsx >= NumberOfConfirmationBarsRSI1
RSI1x = high
RSI1x
RSI1rxL = if RSI1rsx >= NumberOfConfirmationBarsRSI1
RSI1y = low
RSI1y
RSI1rH = fixnan(RSI1rxH)
RSI1rL = fixnan(RSI1rxL)
///////////////////////////////////////////////////////
RSI1rsu = 0
if RSI1incrementer_up
RSI1rsu := nz(RSI1rsu[1], 0) + RSI1incrementer_up
RSI1rsu
else
RSI1rsu = 0
RSI1rsu
RSI1rssH = if RSI1rsu >= NumberOfConfirmationBarsRSI1
RSI1x = high
RSI1x
RSI1rssL = if RSI1rsu >= NumberOfConfirmationBarsRSI1
RSI1y = low
RSI1y
RSI1ResistanceZoneHigh = fixnan(RSI1rssH)
RSI1ResistanceZoneLow = fixnan(RSI1rssL)
////////////////////////////////////////////////////////
RSI1rsd = 0
if RSI1incrementer_down
RSI1rsd := nz(RSI1rsd[1], 0) + RSI1incrementer_down
RSI1rsd
else
RSI1rsd = 0
RSI1rsd
RSI1rsrH = if RSI1rsd >= NumberOfConfirmationBarsRSI1
RSI1x = high
RSI1x
RSI1rsrL = if RSI1rsd >= NumberOfConfirmationBarsRSI1
RSI1y = low
RSI1y
RSI1SupportZoneHigh = fixnan(RSI1rsrH)
RSI1SupportZoneLow = fixnan(RSI1rsrL)
////////////////////////////////////////////////////////
RSI1_ResZoneColor = RSI1ResistanceZoneHigh != RSI1ResistanceZoneHigh[1] ? na : RSI1ResistanceColorIn
RSI1_SupZoneColor = RSI1SupportZoneLow != RSI1SupportZoneLow[1] ? na : RSI1SupportColorIn
RSI1SDColor = RSI1rH != RSI1rH[1]? na : RSI1SDColorIn
////////////////////////////////////////////////////////
RSI1RZHigh = plot(ShowRZ1 ? RSI1ResistanceZoneHigh : na, style=plot.style_cross, title="Resistance Zone - 1 - High", color=RSI1_ResZoneColor, transp=1)
RSI1RZLow = plot(ShowRZ1 ? RSI1ResistanceZoneLow : na, style=plot.style_cross, title="Resistance Zone - 1 - Low", transp=100)
fill(RSI1RZHigh, RSI1RZLow, color=RSI1_ResZoneColor, title="Support Zone - 1 - Fill")
RSI1SZHigh = plot(ShowSZ1 ? RSI1SupportZoneHigh : na, style=plot.style_cross, title="Support Zone - 1 - High", transp=100)
RSI1SZLow = plot(ShowSZ1 ? RSI1SupportZoneLow : na, style=plot.style_cross, title="Support Zone - 1 - Low", transp=100)
fill(RSI1SZHigh, RSI1SZLow, color=RSI1_SupZoneColor, title="Support Zone - 1 - Fill")
PlotRSI1rH = plot(ShowSD1 ? RSI1rH : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 1 - High")
PlotRSI1rL = plot(ShowSD1 ? RSI1rL : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 1 - Low")
fill(PlotRSI1rH, PlotRSI1rL, color=RSI1SDColor, title="Supply Demand - 1 - Fill")
////////////////////////////////////////////////////////
PriceInRSI1SDZone = (close <= RSI1rH) and (close >= RSI1rL) and (RSI1rH == RSI1rH[1])
PriceEntersRSI1SDZone = (PriceInRSI1SDZone and not PriceInRSI1SDZone[1])
alertcondition(PriceEntersRSI1SDZone, title='Alert - Price Enters S/D Zone 1', message='Price Enters S/D Zone 1 - RSI S/D')
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ShowSD2 = input(true, "Supply Demand Zone", group = "Supply Demand 2", inline = "Supply Demand 2")
ShowSZ2 = input(false, "Support Zone", group = "Supply Demand 2", inline = "Supply Demand 2")
ShowRZ2 = input(false, "Resistance Zone", group = "Supply Demand 2", inline = "Supply Demand 2")
RSI2Length = input(14, minval=1, title="RSI 2 Length", group="Supply Demand 2")
RSI2OBOSIn = input(defval="70 / 30", title="OB / OS", options=["70 / 30", "75 / 25", "80 / 20", "85 / 15", "90 / 10", "95 / 5"], group="Supply Demand 2")
NumberOfConfirmationBarsRSI2 = input(3, title="Confirmation Bars", group="Supply Demand 2")
RSI2SDColorIn = input(color.new(color.blue, 85), "Fill Colors - Supply Demand", type = input.color, group="Supply Demand 2", inline = "Fill 2")
RSI2SupportColorIn = input(color.new(color.lime, 92), "Support", type = input.color, group="Supply Demand 2", inline = "Fill 2")
RSI2ResistanceColorIn = input(color.new(color.red, 92), "Resistance", type = input.color, group="Supply Demand 2", inline = "Fill 2")
RSI2 = rsi(close, RSI2Length)
RSI2OB = RSI2OBOSIn == "70 / 30" ? 70 :
RSI2OBOSIn == "75 / 25" ? 75 : RSI2OBOSIn == "80 / 20" ? 80 :
RSI2OBOSIn == "90 / 10" ? 90 : RSI2OBOSIn == "95 / 5" ? 95 : 100
RSI2OS = RSI2OBOSIn == "70 / 30" ? 30 :
RSI2OBOSIn == "75 / 25" ? 25 : RSI2OBOSIn == "80 / 20" ? 20 :
RSI2OBOSIn == "90 / 10" ? 10 : RSI2OBOSIn == "95 / 5" ? 5 : 0
RSI2incrementer_up = RSI2 > RSI2OB ? 1 : 0
RSI2incrementer_down = RSI2 < RSI2OS ? 1 : 0
RSI2incrementer_both = RSI2 > RSI2OB or RSI2 < RSI2OS ? 1 : 0
RSI2rsx = 0
if RSI2incrementer_both
RSI2rsx := nz(RSI2rsx[1], 0) + RSI2incrementer_both
RSI2rsx
else
RSI2rsx = 0
RSI2rsx
RSI2rxH = if RSI2rsx >= NumberOfConfirmationBarsRSI2
RSI2x = high
RSI2x
RSI2rxL = if RSI2rsx >= NumberOfConfirmationBarsRSI2
RSI2y = low
RSI2y
RSI2rH = fixnan(RSI2rxH)
RSI2rL = fixnan(RSI2rxL)
///////////////////////////////////////////////////////
RSI2rsu = 0
if RSI2incrementer_up
RSI2rsu := nz(RSI2rsu[1], 0) + RSI2incrementer_up
RSI2rsu
else
RSI2rsu = 0
RSI2rsu
RSI2rssH = if RSI2rsu >= NumberOfConfirmationBarsRSI2
RSI2x = high
RSI2x
RSI2rssL = if RSI2rsu >= NumberOfConfirmationBarsRSI2
RSI2y = low
RSI2y
RSI2ResistanceZoneHigh = fixnan(RSI2rssH)
RSI2ResistanceZoneLow = fixnan(RSI2rssL)
////////////////////////////////////////////////////////
RSI2rsd = 0
if RSI2incrementer_down
RSI2rsd := nz(RSI2rsd[1], 0) + RSI2incrementer_down
RSI2rsd
else
RSI2rsd = 0
RSI2rsd
RSI2rsrH = if RSI2rsd >= NumberOfConfirmationBarsRSI2
RSI2x = high
RSI2x
RSI2rsrL = if RSI2rsd >= NumberOfConfirmationBarsRSI2
RSI2y = low
RSI2y
RSI2SupportZoneHigh = fixnan(RSI2rsrH)
RSI2SupportZoneLow = fixnan(RSI2rsrL)
////////////////////////////////////////////////////////
RSI2_ResZoneColor = RSI2ResistanceZoneHigh != RSI2ResistanceZoneHigh[1] ? na : RSI2ResistanceColorIn
RSI2_SupZoneColor = RSI2SupportZoneLow != RSI2SupportZoneLow[1] ? na : RSI2SupportColorIn
RSI2SDColor = RSI2rH != RSI2rH[1]? na : RSI2SDColorIn
////////////////////////////////////////////////////////
RSI2RZHigh = plot(ShowRZ2 ? RSI2ResistanceZoneHigh : na, style=plot.style_cross, title="Resistance Zone - 2 - High", transp=100)
RSI2RZLow = plot(ShowRZ2 ? RSI2ResistanceZoneLow : na, style=plot.style_cross, title="Resistance Zone - 2 - Low", transp=100)
fill(RSI2RZHigh, RSI2RZLow, color=RSI2_ResZoneColor, title="Support Zone - 2 - Fill")
RSI2SZHigh = plot(ShowSZ2 ? RSI2SupportZoneHigh : na, style=plot.style_cross, title="Support Zone - 2 - High", transp=100)
RSI2SZLow = plot(ShowSZ2 ? RSI2SupportZoneLow : na, style=plot.style_cross, title="Support Zone - 2 - Low", transp=100)
fill(RSI2SZHigh, RSI2SZLow, color=RSI2_SupZoneColor, title="Support Zone - 2 - Fill")
PlotRSI2rH = plot(ShowSD2 ? RSI2rH : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 2 - High")
PlotRSI2rL = plot(ShowSD2 ? RSI2rL : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 2 - Low")
fill(PlotRSI2rH, PlotRSI2rL, color=RSI2SDColor, title="Supply Demand - 2 - Fill")
////////////////////////////////////////////////////////
PriceInRSI2SDZone = (close <= RSI2rH) and (close >= RSI2rL) and (RSI2rH == RSI2rH[1])
PriceEntersRSI2SDZone = (PriceInRSI2SDZone and not PriceInRSI2SDZone[1])
alertcondition(PriceEntersRSI2SDZone, title='Alert - Price Enters S/D Zone 2', message='Price Enters S/D Zone 2 - RSI S/D')
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ShowSD3 = input(false, "Supply Demand Zone", group = "Supply Demand 3", inline = "Supply Demand 3")
ShowSZ3 = input(false, "Support Zone", group = "Supply Demand 3", inline = "Supply Demand 3")
ShowRZ3 = input(false, "Resistance Zone", group = "Supply Demand 3", inline = "Supply Demand 3")
RSI3Length = input(21, minval=1, title="RSI 3 Length", group="Supply Demand 3")
RSI3OBOSIn = input(defval="70 / 30", title="OB / OS", options=["70 / 30", "75 / 25", "80 / 20", "85 / 15", "90 / 10", "95 / 5"], group="Supply Demand 3")
NumberOfConfirmationBarsRSI3 = input(3, title="Confirmation Bars", group="Supply Demand 3")
RSI3SDColorIn = input(color.new(color.blue, 85), "Fill Colors - Supply Demand", type = input.color, group="Supply Demand 3", inline = "Fill 3")
RSI3SupportColorIn = input(color.new(color.lime, 92), "Support", type = input.color, group="Supply Demand 3", inline = "Fill 3")
RSI3ResistanceColorIn = input(color.new(color.red, 92), "Resistance", type = input.color, group="Supply Demand 3", inline = "Fill 3")
RSI3 = rsi(close, RSI3Length)
RSI3OB = RSI3OBOSIn == "70 / 30" ? 70 :
RSI3OBOSIn == "75 / 25" ? 75 : RSI3OBOSIn == "80 / 20" ? 80 :
RSI3OBOSIn == "90 / 10" ? 90 : RSI3OBOSIn == "95 / 5" ? 95 : 100
RSI3OS = RSI3OBOSIn == "70 / 30" ? 30 :
RSI3OBOSIn == "75 / 25" ? 25 : RSI3OBOSIn == "80 / 20" ? 20 :
RSI3OBOSIn == "90 / 10" ? 10 : RSI3OBOSIn == "95 / 5" ? 5 : 0
RSI3incrementer_up = RSI3 > RSI3OB ? 1 : 0
RSI3incrementer_down = RSI3 < RSI3OS ? 1 : 0
RSI3incrementer_both = RSI3 > RSI3OB or RSI3 < RSI3OS ? 1 : 0
RSI3rsx = 0
if RSI3incrementer_both
RSI3rsx := nz(RSI3rsx[1], 0) + RSI3incrementer_both
RSI3rsx
else
RSI3rsx = 0
RSI3rsx
RSI3rxH = if RSI3rsx >= NumberOfConfirmationBarsRSI3
RSI3x = high
RSI3x
RSI3rxL = if RSI3rsx >= NumberOfConfirmationBarsRSI3
RSI3y = low
RSI3y
RSI3rH = fixnan(RSI3rxH)
RSI3rL = fixnan(RSI3rxL)
///////////////////////////////////////////////////////
RSI3rsu = 0
if RSI3incrementer_up
RSI3rsu := nz(RSI3rsu[1], 0) + RSI3incrementer_up
RSI3rsu
else
RSI3rsu = 0
RSI3rsu
RSI3rssH = if RSI3rsu >= NumberOfConfirmationBarsRSI3
RSI3x = high
RSI3x
RSI3rssL = if RSI3rsu >= NumberOfConfirmationBarsRSI3
RSI3y = low
RSI3y
RSI3ResistanceZoneHigh = fixnan(RSI3rssH)
RSI3ResistanceZoneLow = fixnan(RSI3rssL)
////////////////////////////////////////////////////////
RSI3rsd = 0
if RSI3incrementer_down
RSI3rsd := nz(RSI3rsd[1], 0) + RSI3incrementer_down
RSI3rsd
else
RSI3rsd = 0
RSI3rsd
RSI3rsrH = if RSI3rsd >= NumberOfConfirmationBarsRSI3
RSI3x = high
RSI3x
RSI3rsrL = if RSI3rsd >= NumberOfConfirmationBarsRSI3
RSI3y = low
RSI3y
RSI3SupportZoneHigh = fixnan(RSI3rsrH)
RSI3SupportZoneLow = fixnan(RSI3rsrL)
////////////////////////////////////////////////////////
RSI3_ResZoneColor = RSI3ResistanceZoneHigh != RSI3ResistanceZoneHigh[1] ? na : RSI3ResistanceColorIn
RSI3_SupZoneColor = RSI3SupportZoneLow != RSI3SupportZoneLow[1] ? na : RSI3SupportColorIn
RSI3SDColor = RSI3rH != RSI3rH[1]? na : RSI3SDColorIn
////////////////////////////////////////////////////////
RSI3RZHigh = plot(ShowRZ3 ? RSI3ResistanceZoneHigh : na, style=plot.style_cross, title="Resistance Zone - 3 - High", transp=100)
RSI3RZLow = plot(ShowRZ3 ? RSI3ResistanceZoneLow : na, style=plot.style_cross, title="Resistance Zone - 3 - Low", transp=100)
fill(RSI3RZHigh, RSI3RZLow, color=RSI3_ResZoneColor, title="Support Zone - 3 - Fill")
RSI3SZHigh = plot(ShowSZ3 ? RSI3SupportZoneHigh : na, style=plot.style_cross, title="Support Zone - 3 - High", transp=100)
RSI3SZLow = plot(ShowSZ3 ? RSI3SupportZoneLow : na, style=plot.style_cross, title="Support Zone - 3 - Low", transp=100)
fill(RSI3SZHigh, RSI3SZLow, color=RSI3_SupZoneColor, title="Support Zone - 3 - Fill")
PlotRSI3rH = plot(ShowSD3 ? RSI3rH : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 3 - High")
PlotRSI3rL = plot(ShowSD3 ? RSI3rL : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 3 - Low")
fill(PlotRSI3rH, PlotRSI3rL, color=RSI3SDColor, title="Supply Demand - 3 - Fill")
////////////////////////////////////////////////////////
PriceInRSI3SDZone = (close <= RSI3rH) and (close >= RSI3rL) and (RSI3rH == RSI3rH[1])
PriceEntersRSI3SDZone = (PriceInRSI3SDZone and not PriceInRSI3SDZone[1])
alertcondition(PriceEntersRSI3SDZone, title='Alert - Price Enters S/D Zone 3', message='Price Enters S/D Zone 3 - RSI S/D')
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ShowSD4 = input(false, "Supply Demand Zone", group = "Supply Demand 4", inline = "Supply Demand 4")
ShowSZ4 = input(false, "Support Zone", group = "Supply Demand 4", inline = "Supply Demand 4")
ShowRZ4 = input(false, "Resistance Zone", group = "Supply Demand 4", inline = "Supply Demand 4")
RSI4Length = input(28, minval=1, title="RSI 4 Length", group="Supply Demand 4")
RSI4OBOSIn = input(defval="70 / 30", title="OB / OS", options=["70 / 30", "75 / 25", "80 / 20", "85 / 15", "90 / 10", "95 / 5"], group="Supply Demand 4")
NumberOfConfirmationBarsRSI4 = input(3, title="Confirmation Bars", group="Supply Demand 4")
RSI4SDColorIn = input(color.new(color.blue, 85), "Fill Colors - Supply Demand", type = input.color, group="Supply Demand 4", inline = "Fill 4")
RSI4SupportColorIn = input(color.new(color.lime, 92), "Support", type = input.color, group="Supply Demand 4", inline = "Fill 4")
RSI4ResistanceColorIn = input(color.new(color.red, 92), "Resistance", type = input.color, group="Supply Demand 4", inline = "Fill 4")
RSI4 = rsi(close, RSI4Length)
RSI4OB = RSI4OBOSIn == "70 / 30" ? 70 :
RSI4OBOSIn == "75 / 25" ? 75 : RSI4OBOSIn == "80 / 20" ? 80 :
RSI4OBOSIn == "90 / 10" ? 90 : RSI4OBOSIn == "95 / 5" ? 95 : 100
RSI4OS = RSI4OBOSIn == "70 / 30" ? 30 :
RSI4OBOSIn == "75 / 25" ? 25 : RSI4OBOSIn == "80 / 20" ? 20 :
RSI4OBOSIn == "90 / 10" ? 10 : RSI4OBOSIn == "95 / 5" ? 5 : 0
RSI4incrementer_up = RSI4 > RSI4OB ? 1 : 0
RSI4incrementer_down = RSI4 < RSI4OS ? 1 : 0
RSI4incrementer_both = RSI4 > RSI4OB or RSI4 < RSI4OS ? 1 : 0
RSI4rsx = 0
if RSI4incrementer_both
RSI4rsx := nz(RSI4rsx[1], 0) + RSI4incrementer_both
RSI4rsx
else
RSI4rsx = 0
RSI4rsx
RSI4rxH = if RSI4rsx >= NumberOfConfirmationBarsRSI4
RSI4x = high
RSI4x
RSI4rxL = if RSI4rsx >= NumberOfConfirmationBarsRSI4
RSI4y = low
RSI4y
RSI4rH = fixnan(RSI4rxH)
RSI4rL = fixnan(RSI4rxL)
///////////////////////////////////////////////////////
RSI4rsu = 0
if RSI4incrementer_up
RSI4rsu := nz(RSI4rsu[1], 0) + RSI4incrementer_up
RSI4rsu
else
RSI4rsu = 0
RSI4rsu
RSI4rssH = if RSI4rsu >= NumberOfConfirmationBarsRSI4
RSI4x = high
RSI4x
RSI4rssL = if RSI4rsu >= NumberOfConfirmationBarsRSI4
RSI4y = low
RSI4y
RSI4ResistanceZoneHigh = fixnan(RSI4rssH)
RSI4ResistanceZoneLow = fixnan(RSI4rssL)
////////////////////////////////////////////////////////
RSI4rsd = 0
if RSI4incrementer_down
RSI4rsd := nz(RSI4rsd[1], 0) + RSI4incrementer_down
RSI4rsd
else
RSI4rsd = 0
RSI4rsd
RSI4rsrH = if RSI4rsd >= NumberOfConfirmationBarsRSI4
RSI4x = high
RSI4x
RSI4rsrL = if RSI4rsd >= NumberOfConfirmationBarsRSI4
RSI4y = low
RSI4y
RSI4SupportZoneHigh = fixnan(RSI4rsrH)
RSI4SupportZoneLow = fixnan(RSI4rsrL)
////////////////////////////////////////////////////////
RSI4_ResZoneColor = RSI4ResistanceZoneHigh != RSI4ResistanceZoneHigh[1] ? na : RSI4ResistanceColorIn
RSI4_SupZoneColor = RSI4SupportZoneLow != RSI4SupportZoneLow[1] ? na : RSI4SupportColorIn
RSI4SDColor = RSI4rH != RSI4rH[1]? na : RSI4SDColorIn
////////////////////////////////////////////////////////
RSI4RZHigh = plot(ShowRZ4 ? RSI4ResistanceZoneHigh : na, style=plot.style_cross, title="Resistance Zone - 4 - High", transp=100)
RSI4RZLow = plot(ShowRZ4 ? RSI4ResistanceZoneLow : na, style=plot.style_cross, title="Resistance Zone - 4 - Low", transp=100)
fill(RSI4RZHigh, RSI4RZLow, color=RSI4_ResZoneColor, title="Support Zone - 4 - Fill")
RSI4SZHigh = plot(ShowSZ4 ? RSI4SupportZoneHigh : na, style=plot.style_cross, title="Support Zone - 4 - High", transp=100)
RSI4SZLow = plot(ShowSZ4 ? RSI4SupportZoneLow : na, style=plot.style_cross, title="Support Zone - 4 - Low", transp=100)
fill(RSI4SZHigh, RSI4SZLow, color=RSI4_SupZoneColor, title="Support Zone - 4 - Fill")
PlotRSI4rH = plot(ShowSD4 ? RSI4rH : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 4 - High")
PlotRSI4rL = plot(ShowSD4 ? RSI4rL : na, style=plot.style_cross, linewidth=1, title="Supply Demand - 4 - Low")
fill(PlotRSI4rH, PlotRSI4rL, color=RSI4SDColor, title="Supply Demand - 4 - Fill")
////////////////////////////////////////////////////////
PriceInRSI4SDZone = (close <= RSI4rH) and (close >= RSI4rL) and (RSI4rH == RSI4rH[1])
PriceEntersRSI4SDZone = (PriceInRSI4SDZone and not PriceInRSI4SDZone[1])
alertcondition(PriceEntersRSI4SDZone, title='Alert - Price Enters S/D Zone 4', message='Price Enters S/D Zone 4 - RSI S/D')
alertcondition(PriceEntersRSI1SDZone or PriceEntersRSI2SDZone or PriceEntersRSI3SDZone or PriceEntersRSI4SDZone, title='Alert - Price Enters Any S/D Zone', message='Price Enters Any S/D Zone - RSI S/D')
check the below.

CSS:
# // Indicator for TOS
#//© 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    - 11/2024

input timeframe = AggregationPeriod.MIN;
input showSupportZone = yes;     # "Support Zone"
input showResistanceZone = yes;  # "Resistance Zone"
input rsiSource = FundamentalType.CLOSE;
input rsiLength = 14;            # "RSI Length"
input overboughtLimit = 70;
input oversoldLimit = 30;
input NumberOfConfirmationBars = 3; # "Confirmation Bars"

def na = Double.NaN;
def last = IsNaN(close);
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
def src = Fundamental(rsiSource, Period = tf);

def RSI1 = RSI(Price = src, Length = rsiLength);
def RSI1incrementer_up   = if RSI1 > overboughtLimit then 1 else 0;
def RSI1incrementer_down = if RSI1 < oversoldLimit then 1 else 0;

def RSI1rsu = if RSI1incrementer_up then RSI1rsu[1] + 1 else 0;
def RSI1rssH = if RSI1rsu >= NumberOfConfirmationBars then high(Period = tf) else RSI1rssH[1];
def RSI1rssL = if RSI1rsu >= NumberOfConfirmationBars then low(Period = tf) else RSI1rssL[1];
def RSI1ResistanceZoneHigh = if RSI1rssH then RSI1rssH else na;
def RSI1ResistanceZoneLow  = if RSI1rssL then RSI1rssL else na;

def RSI1rsd = if RSI1incrementer_down then RSI1rsd[1] + 1 else 0;
def RSI1rsrH = if RSI1rsd >= NumberOfConfirmationBars then high(Period = tf) else RSI1rsrH[1];
def RSI1rsrL = if RSI1rsd >= NumberOfConfirmationBars then low(Period = tf) else RSI1rsrL[1];
def RSI1SupportZoneHigh = if RSI1rsrH then RSI1rsrH else na;
def RSI1SupportZoneLow  = if RSI1rsrL then RSI1rsrL else na;

#////////////////////////////////////////////////////////
def ResZone = if RSI1ResistanceZoneHigh !=  RSI1ResistanceZoneHigh[1] then  0 else ResZone[1] + 1;
def SupZone = if RSI1SupportZoneLow     !=  RSI1SupportZoneLow[1]     then  0 else SupZone[1] + 1;
#////////////////////////////////////////////////////////

plot RSI1RZHigh = if showResistanceZone and ResZone then RSI1ResistanceZoneHigh else na;
plot RSI1RZLow  = if showResistanceZone and ResZone then RSI1ResistanceZoneLow  else na;
plot RSI1SZHigh = if showSupportZone and SupZone then RSI1SupportZoneHigh else na;
plot RSI1SZLow  = if showSupportZone and SupZone then RSI1SupportZoneLow  else na;
def colRes = if low(Period = tf) > RSI1RZHigh then 1 else if high(Period = tf) < RSI1RZLow then -1 else colRes[1];
def colSup = if high(Period = tf) < RSI1SZLow then -1 else if low(Period = tf) > RSI1SZLow then 1 else colSup[1];
RSI1RZHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI1RZLow.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI1SZHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI1SZLow.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI1RZHigh.SetDefaultColor(Color.RED);
RSI1RZLow.SetDefaultColor(Color.RED);
RSI1SZHigh.SetDefaultColor(Color.GREEN);
RSI1SZLow.SetDefaultColor(Color.GREEN);
RSI1RZHigh.AssignValueColor(if colRes>0 then Color.GREEN else Color.RED);
RSI1RZLow.AssignValueColor(if colRes>0 then Color.GREEN else Color.RED);
RSI1SZHigh.AssignValueColor(if colSup<0 then Color.RED else Color.GREEN);
RSI1SZLow.AssignValueColor(if colSup<0 then Color.RED else Color.GREEN);

AddCloud(RSI1RZHigh, RSI1RZLow, Color.DARK_RED);
AddCloud(RSI1SZHigh, RSI1SZLow, Color.DARK_GREEN);

#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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