Display RSI and MACD Chart Label For Different Time Frames


Category:
0
0

Hi Hanh,

Thank you for responding to all of our questions so promptly on a Saturday! (: How could I modify this text so that it would achieve the following:  I want to view the 15 minute chart but would like to display the RSI/MACD from the 1 Hour.

I have provided the code that you created below for your reference:

AddLabel(yes, Concat(“RSI: “, RSI().”RSI”), if MACD().”Diff” is greater than 0 then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 9, Answers: 4)
Asked on April 11, 2020 2:19 pm
190 views
1
Private answer

The only way to do this while referencing a higher time frame than your chart is to copy the entire code from both of the built-in chart studies and combine them into one. The code below contains both elements along with a single statement to generate the chart label. There are two user inputs to let you set the time frame and the label prefix from the user settings. This enables you to add the custom chart study to the same chart multiple times with different settings.

input timeFrame = AggregationPeriod.DAY;
input chartLabelText = "Daily RSI/MACD";
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
input length = 14;
input rsiAverageType = AverageType.WILDERS;
def value = MovingAverage(macdAverageType, close(period = timeFrame), fastLength) - MovingAverage(macdAverageType, close(period = timeFrame), slowLength);
def avg = MovingAverage(macdAverageType, value, MACDLength);
def diff = value - avg;
def netChangeAverage = MovingAverage(rsiAverageType, close(period = timeFrame) - close(period = timeFrame)[1], length);
def totalChangeAverage = MovingAverage(rsiAverageType, AbsValue(close(period = timeFrame) - close(period = timeFrame)[1]), length);
def changeRatio = if totalChangeAverage != 0 then netChangeAverage / totalChangeAverage else 0;
def rsi = 50 * (changeRatio + 1);
AddLabel(yes, Concat(chartLabelText, Concat(" : ", rsi)), if diff > 0 then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on April 11, 2020 4:22 pm