MTF RSI Indicator For Thinkorswim

T

TradeUp

New member
VIP
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.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
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);
I got it from this page.
 
D

diazlaz

New member
VIP
Warehouse
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.
 

Top