# MTF RSI Indicator For Thinkorswim

##### Member
2019 Donor
Hi,
Does anyone have or can code a multi time frame RSi indicator? I saw this video and thought it might help with trading. Thanks.

Solution
Try this code below. It's pulling the RSI from 10m, 30m, and hourly. Change it to whichever timeframe you want.

Code:
declare lower;

input length = 4;
input over_Bought = 70;
input over_Sold = 30;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, close(period = AggregationPeriod.FIVE_MIN) - close(period = AggregationPeriod.FIVE_MIN)[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(close(period = AggregationPeriod.FIVE_MIN) - close(period = AggregationPeriod.FIVE_MIN)[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...

#### BenTen

Staff member
Staff
VIP
Try this code below. It's pulling the RSI from 10m, 30m, and hourly. Change it to whichever timeframe you want.

Code:
declare lower;

input length = 4;
input over_Bought = 70;
input over_Sold = 30;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, close(period = AggregationPeriod.FIVE_MIN) - close(period = AggregationPeriod.FIVE_MIN)[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(close(period = AggregationPeriod.FIVE_MIN) - close(period = AggregationPeriod.FIVE_MIN)[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;
RSI.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);

RSI.DefineColor("OverBought", Color.GREEN);
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", Color.RED);
RSI.AssignValueColor(if RSI > over_Bought then RSI.Color("OverBought") else if RSI < over_Sold then RSI.Color("OverSold") else RSI.Color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
RSI.SetLineWeight (4);
###############################################
input length15 = 4;
input over_Bought15 = 70;
input over_Sold15 = 30;
input averageType15 = AverageType.WILDERS;

def NetChgAvg15 = MovingAverage(averageType15, close(period = AggregationPeriod.TEN_MIN) - close(period = AggregationPeriod.TEN_MIN)[1], length15);
def TotChgAvg15 = MovingAverage(averageType15, AbsValue(close(period = AggregationPeriod.TEN_MIN) - close(period = AggregationPeriod.TEN_MIN)[1]), length15);
def ChgRatio15 = if TotChgAvg15 != 0 then NetChgAvg15 / TotChgAvg15 else 0;
plot RSI15 = 50 * (ChgRatio15 + 1);
#plot OverSold15 = over_Sold15;
#plot OverBought15 = over_Bought15;
RSI15.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

RSI15.DefineColor("OverBought", Color.YELLOW);
RSI15.DefineColor("Normal", GetColor(7));
RSI15.DefineColor("OverSold", Color.RED);
RSI15.AssignValueColor(if RSI15 > over_Bought15 then RSI15.Color("OverBought") else if RSI15 < over_Sold15 then RSI15.Color("OverSold") else RSI15.Color("Normal"));
#OverSold15.SetDefaultColor(GetColor(8));
#OverBought15.SetDefaultColor(GetColor(8));
RSI15.SetLineWeight (3);

###############################################
input length30 = 4;
input over_Bought30 = 70;
input over_Sold30 = 30;
input averageType30 = AverageType.WILDERS;

def NetChgAvg30 = MovingAverage(averageType30, close(period = AggregationPeriod.THIRTY_MIN) - close(period = AggregationPeriod.THIRTY_MIN)[1], length30);
def TotChgAvg30 = MovingAverage(averageType30, AbsValue(close(period = AggregationPeriod.THIRTY_MIN) - close(period = AggregationPeriod.THIRTY_MIN)[1]), length30);
def ChgRatio30 = if TotChgAvg30 != 0 then NetChgAvg30 / TotChgAvg30 else 0;
plot RSI30 = 50 * (ChgRatio30 + 1);
#plot OverSold30 = over_Sold30;
#plot OverBough30 = over_Bought30;
RSI30.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
RSI30.DefineColor("OverBought", Color.GREEN);
RSI30.DefineColor("Normal", GetColor(7));
RSI30.DefineColor("OverSold", Color.RED);
RSI30.AssignValueColor(if RSI30 > over_Bought30 then RSI30.Color("OverBought") else if RSI30 < over_Sold30 then RSI30.Color("OverSold") else RSI30.Color("Normal"));
#OverSold30.SetDefaultColor(GetColor(8));
#OverBough30.SetDefaultColor(GetColor(8));
RSI30.SetLineWeight (3);
##################################################
############ HOUR #############################
input lengthh = 4;
input over_Boughth = 70;
input over_Soldh = 30;
input averageTypeh = AverageType.WILDERS;

#def NetChgAvgh = MovingAverage(averageTypeh, close(period = AggregationPeriod.hour) - close(period = AggregationPeriod.hour)[1], lengthh);
#def TotChgAvgh = MovingAverage(averageTypeh, AbsValue(close(period = AggregationPeriod.thirty_min) - close(period = AggregationPeriod.thirty_min)[1]), lengthh);

input price = close;

def NetChgAvgh = MovingAverage(averageType, price - price[1], length);
def TotChgAvgh = MovingAverage(averageType, AbsValue(price - price[1]), length);

def ChgRatioh = if TotChgAvgh != 0 then NetChgAvgh / TotChgAvgh else 0;
plot RSIh = 50 * (ChgRatioh + 1);
plot OverSoldh = over_Soldh;
plot OverBoughh = over_Boughth;
RSIh.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

RSIh.DefineColor("OverBought", Color.GREEN);
RSIh.DefineColor("Normal", GetColor(7));
RSIh.DefineColor("OverSold", Color.RED);
RSIh.AssignValueColor(if RSIh > over_Boughth then RSIh.Color("OverBought") else if RSIh < over_Soldh then RSIh.Color("OverSold") else RSIh.Color("Normal"));
#OverSold30.SetDefaultColor(GetColor(8));
#OverBough30.SetDefaultColor(GetColor(8));
RSIh.SetLineWeight (5);
plot DL = 10;
DL.HideBubble();
DL.SetDefaultColor(Color.WHITE);
DL.SetLineWeight(3);

#### diazlaz

##### Well-known member
2019 Donor
VIP
Thanks everyone. This topic brought up a question I had in mind and wanted to see if there is a workaround or Im approaching it wrong.

Seems the Aggregation Period in a Intraday can't access higher timeframe data and would need to have 2 charts one for lower time frame and the other for higher.

For example 1 min chart can't access aggregation of a daily or weekly (or at least have the data points to properly Calc the 14 points) when your in a 1 min?

Typing this on my phone so apologies in advance.

#### hectorgasm

##### Member
It does not repaint. It's following a similar logic of the DMI indicator If anyone has further improvements I'd be happy to listen

Works better on short timeframes and with a 200 length over the 1 hour timeframe

Code:
declare lower;

##Originally created by gasmos

input ap = AggregationPeriod.DAY;

DEF mthopen = ((HIGHEST(CLOSE)-LOWEST(CLOSE(period = ap)[1])) + (LOWEST(CLOSE)-HIGHEST(CLOSE(period = ap)[1]))) ;

input length = 200;

input over_Bought = 70;

input over_Sold = 30;

def price = mthopen;

input averageType = AverageType.WILDERS;

input showBreakoutSignals = no;

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 MIDLINE = 50;

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);

RSI.DefineColor("OverBought", GetColor(5));

RSI.DefineColor("Normal", GetColor(7));

RSI.DefineColor("OverSold", GetColor(1));

RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));

OverSold.SetDefaultColor(GetColor(8));

OverBought.SetDefaultColor(GetColor(8));

UpSignal.SetDefaultColor(Color.UPTICK);

UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

DownSignal.SetDefaultColor(Color.DOWNTICK);

DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#### Ahmar824

##### Member
Just a question can you make MTF RSI with yearly, monthly, weekly and daily time frame?

Last edited by a moderator: