@samer800 Possible to make this a MTF study?
I created another study which allows me to just add another timeframe to my chart (I just called it MTFRSISupplyDemandZone). I am able to reference another higher timeframe rsi supply/demand zone on a lower timeframe chart (i.e. 15 minute zones on a 3-minute chart).
Just add the following line to the original code preferably towards the top, right underneath the other inputs.
input baseperiod = aggregationPeriod.FIVE_MIN ;
def open = open(Period = baseperiod);
def close = close(Period = baseperiod);
def high = high(Period = baseperiod);
def low = low(Period = baseperiod);
This will allow you to select the time period you would like the code to reference for the RSI.
Here is the full code for simplicity purposes:
#//© 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;
input baseperiod = aggregationPeriod.FIVE_MIN ;
def open = open(Period = baseperiod);
def close = close(Period = baseperiod);
def high = high(Period = baseperiod);
def low = low(Period = baseperiod);
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