Multiple Time Frame RSI in One Study


Category:
0
0

A couple questions regarding RSI.

  1. I have used the aggregate RSI code to show RSI on an hourly, daily, weekly (attached). My question is, can this be set up to have them all on one plot? If i’m looking at AMZN on hourly, I want to see the daily and weekly all together. If not, I assume the only way to do so is by grouping the studies together (attached). Here is my study: http://tos.mx/xhhxaF
  2. Is it possible to have a chart like AMZN and have the RSI on it as well as the NDX RSI? If so, can the option of looking at AMZN on any time frame and NDX be the daily or the ability to choose the index same time frame as well. Also would like to include SPX, RUT, etc. if possible.
Attachments:
Marked as spam
Posted by (Questions: 21, Answers: 47)
Asked on January 6, 2018 12:06 pm
843 views
0

We’re going to have to change the title of your question. “RSI Aggregate”is not necessarily inaccurate (depends on how visitors interpret that phrase). The standard term used to describe what you are working with is “Multiple Time Frames”. This term deals with the method of grouping multiple aggregation periods together in the same chart study. Aggregation, in this context means the time frame. So if we use the phrase “Multiple Time Frame” we are certain that everyone of our future visitors are going to understand the context perfectly.

( at January 6, 2018 2:21 pm)
0
Private answer

Using the share link you provided, I downloaded your custom study and examined the code. I can see where the errors are. However I can’t help but notice in the screenshot you provided that you clearly have RSI code that plot daily and weekly time frames. Those are working correctly. However I suspect you simply made copy errors when trying to group them all together into the same study.

Let’s break this down into pieces. I perceive you will benefit more from me treating this as an opportunity for instruction rather than just give you the answers. First we’ll look at the section that is supposed to be for the daily time frame:

#DAILY Aggregation Period
def DailyNetChgAvg = MovingAverage(averageType, close(period = AggregationPeriod.DAY) - close(period = AggregationPeriod.DAY)[1], length);
def DailyTotChgAvg = MovingAverage(averageType, AbsValue(close(period = AggregationPeriod.DAY) - close(period = AggregationPeriod.DAY)[1]), length);
def DailyChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

The first error is found on the very last statement. You define DailyChgRatio but mistakenly use elements from the chart time frame for it’s computation. It should read:

def DailyChgRatio = if DailyTotChgAvg != 0 then DailyNetChgAvg / DailyTotChgAvg else 0;

The same mistake is found for the weekly. I won’t repeat that code here, but you should see the changes that are required.

The next mistakes are found in the plot statements. Once again, we’ll just take a peak at the daily time frame.

plot DailyRSI = RSI + (DailyChgRatio +1);

You see here you are mixing the chart time frame RSI with the daily change ratio. We can look to the standard RSI implementation to understand how to fix this:

plot DailyRSI = 50 * (DailyChgRatio +1);

I’ll give you time to let this all settle in and get things patched up and working. Just post a reply in the comments section of this answer when you are ready for me to explain how to achieve the items mentioned in item 2 of your question.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 6, 2018 3:48 pm
0

I appreciate the feedback. I do indeed see the issues I made and understand it now. I have made the appropriate adjustments. What I’m trying to achieve (if at all possible), is instead of writing each code one for RSI, one for Daily and one for Weekly (like the photo above) and have the three grouped together in the lower part of the chart is to have them all in one code (link below). When I do have them in one study (name: RSIAlerts) I don’t get 3 lines, here’s my updated source in trying to have them all in one study (http://tos.mx/iMuWvl).

I really do appreciate the feedback and look forward to your reply and the second part of this question.

( at January 6, 2018 8:52 pm)
0

Wait, OPERATOR ERROR! I didn’t have the show plot checked on the daily and weekly. Man I feel stupid! Thank you again for the assistance. This is wonderful! Looking forward to the second part

( at January 6, 2018 8:56 pm)
0
Private answer

Ok, for the solution to item 2 I will cut the RSI code down to the very bare minimum. I will also exclude the Multiple Time Frame tricks described in my first response. The idea here is make sure it is very easy for you to spot the changes required to get the RSI to plot for a ticker symbol of your own choosing.

Notice there are two ways to do the user input for the ticker symbol. I have included both, but one is marked out as a comment. That’s the one that would let you enter any ticker symbol you want. The one that is active creates a list that limits the selection to three ticker symbols.

Here is the code:

declare lower;
#input tickerSymbol = "NDX";
input tickerSymbol = {default NDX, SPX, RUT};
input length = 14;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, close(symbol = tickerSymbol) - close(symbol = tickerSymbol)[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(close(symbol = tickerSymbol) - close(symbol = tickerSymbol)[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);

Screenshot below shows the output. Chart on the left is NDX, with standard RSI. Chart on the right is AAPL with this custom study applied.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 7, 2018 9:38 am
0

Thank you again for the assistance!

( at January 7, 2018 10:05 pm)