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.
Code:
#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;
#RSI
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"));
OverSold.SetDefaultColor(GetColor(7));
OverBought.SetDefaultColor(GetColor(7));
# 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"));
RSI2.setLineWeight(3);
# 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"));
RSI3.setLineWeight(5);
#addCloud(RSI, RSI2, color.green, color.red);
Last edited: