How To Plot Daily RSI on Hourly Chart


Category:
0
0

I am learning how to script on the TOS platform. I like a grid chart on a primary aggregation and I would

like to have an RSI label on a 1 hour chart with the RSI Daily aggregation value. This would allow me to

monitor the daily time and learn more skills about secondary aggregations. I am new to this site and I am glad

to be here. Thanks Kevin

 

RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 7)
Asked on January 6, 2017 5:13 pm
1454 views
2
Private answer

The built in RSI study provided by Thinkorswim is our starting point. I have modified the code to reference the daily time frame. Screenshot attached. You see the Daily on the left and the Hourly on the right. The cross-hairs on the charts point to the same day. You can see the value on the RSI Daily is a nearly exact match for the RSI plotted on the Hourly chart.

Be sure to up-vote this answer if it correctly answered your question! Thanks.

Here is the code:

#
# TD Ameritrade IP Company, Inc. (c) 2007-2016
#
declare lower;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, close(period = AggregationPeriod.DAY) - close(period = AggregationPeriod.DAY)[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(close(period = AggregationPeriod.DAY) - close(period = AggregationPeriod.DAY)[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.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));

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on January 6, 2017 7:45 pm
0

Thanks to the help I got it was possible to script a label that you can put on a flexible grid to monitor
all your trade vehicles with the RSI Alert, bubble, arrow and background option. This trade philosophy was
taken by author Dr Alexander Elder to trade with the tide, take advantage of the waves and ignore the ripples.
If any has suggestions that fit this Philosophy I would love to hear about.

Kevin

declare upper;
input showlabel = yes;
input showalert = no;
input changeBackground = no;
input showBubble = yes;
input BubbleOffset = 12 ;
input length = 14;
input zero = 50;
input SOS = 30;
input SOB = 70;
input price = close;
input averageType = AverageType.WILDERS;
input Agg = AggregationPeriod.day;

input periodStartEST = 930;
input periodEndEST = 1600;

DefineGlobalColor(”sob”, Color.DARK_GREEN);
DefineGlobalColor(”SOS”, Color.RED);
DefineGlobalColor(”Rsi”, Color.BLACK);
DefineGlobalColor(”zero”, Color.cyan);
DefineGlobalColor(”bubble”, Color.cyan);
DefineGlobalColor(”alert”, Color.PINK);
DefineGlobalColor(”SIG”, Color.DARK_GRAY);
DefineGlobalColor(”alert”, Color.PINK);

# Define a variable for RTH Alert Active
def periodStart = if secondsTillTime(periodStartEST) 0 then 1 else 0;
def periodEnd = if secondsTillTime(periodEndEST) 0 then 1 else 0;

def inPeriod = if periodStart then 1 else if periodEnd then 0 else inPeriod[1];

def NetChgAvg = MovingAverage(averageType, close(period = Agg) – close(period = Agg)[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(close(period = Agg) – close(period = Agg)[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def myRSI = 50 * (ChgRatio + 1);

def RsiIncrease = myRSI > myRSI[1];
def RsiDecrease = myRSi < myRSI[1]; def RsiIncreaseBars = if RsiIncrease then RsiIncreaseBars[1] + 1 else 0; def RsiDecreaseBars = if RsiDecrease then RsiIncreaseBars[1] + 1 else 0; Def BarSignal = rsiIncreaseBars + RsiDecreaseBars; AddLabel(showlabel, " RSI(D) = (" + round(myRSI,1) + ") " + " (" + Barsignal + ") ", if myRsi > 52
then GlobalColor(”sob”) else if myrsi < 48 then GlobalColor("sos")else GlobalColor("bubble")); Def AlertSOS = MyRsi < SOS; Def AlertSOB = MyRsi > SOB;

alert(showalert and alertSOB and inperiod, ”RSI DAILY OVERBOUGHT ”, alert.bar, sound.ding);
alert(showalert and alertSOS and inperiod, ”RSI DAILY OVERSOLD PANIC”, alert.bar, sound.ding);

assignBackgroundColor( if alertsob or alertsos and inperiod and changeBackground then GlobalColor(”alert”) else color.current);

# Code to paint arrows

plot crossingAbove = Crosses(myRsi, sob, CrossingDirection.ABOVE);
crossingabove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
crossingAbove.setlineweight(5);
crossingAbove.setDefaultColor(globalcolor(”SIG”));

plot crossingbelow = Crosses(myRsi, sos, CrossingDirection.below);
crossingbelow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossingbelow.setlineweight(5);
crossingbelow.setDefaultColor(globalcolor(”SIG”));

# Add chart bubble for description of arrow

addchartBubble(showBubble and alertSob,
high + BubbleOffset, ” RSID (” + round(myRsi,1) + ”) ”,GlobalColor(”bubble”), yes);

addchartBubble(showBubble and alertSos,
low – BubbleOffset, ” RSID (” + round(myRsi,1) + ”) ”,GlobalColor(”bubble”), no);

( at January 8, 2017 4:12 pm)
0
Private answer

You did it! I studied what you did, I learned secondary aggregation, That is huge to me.

Big thanks and I found a good forum “Community” to be a part of.

Thanks so much

Kevin

 

Marked as spam
Posted by (Questions: 2, Answers: 7)
Answered on January 8, 2017 9:14 am
0

Kevin,

I am pretty new to tos, which code did you apply and where did you apply it to (I see the declare lower from pete and your declare upper, kind of confused on where to apply this to)? I know how to add studies, however when i do add pete’s code from above I am not seeing the RSI value shown circled red in that screenshot from above. My apologies in advance if these are dumb questions, just trying to learn and make my money back from my early mistakes in trading.

TIA

Alex

( at April 12, 2017 9:36 am)
0

I’ll let Kevin respond regarding his own code. But I understand your confusion and wanted to let you know that the code I provided is a completely different study than the code that Kevin plotted. In regards to your question about the screenshots I provided. The RSI value circled in red. That screenshot shows the RSI value on the hourly chart to the right matches the RSI value on the daily chart to the left. Those values are circled to ensure the matching values are clearly seen. Simply put, the code I published plots the daily value of the RSI on a intraday timeframe chart.

( at April 12, 2017 11:31 am)
0

Hi try this study in TOS but I am getting error in these line. please fix it and post it again. Thanks
# Define a variable for RTH Alert Active
def periodStart = if secondsTillTime(periodStartEST) 0 then 1 else 0;
def periodEnd = if secondsTillTime(periodEndEST) 0 then 1 else 0;

( at May 23, 2018 10:26 pm)