subgraph. This declaration is used when your study uses values that are considerably lower or higher than price history or volume values.
declare lower;
# User Inputs
input show_RSNHBP = yes; #Hint show_RSNHBP: Set to "Yes" to display RS New High Before Price (RSNHBP). The Pink Dot
input show_RSNH = yes; #Hint show_RSNH: Set to "Yes" to display RS New High. The Green Dot.
#Relative Strength Type - Candlestick to be added later.
input graphStyle = {default "Line"}; #Hint graphStyle: Only available format is Line.
#3 Month, 6 Month, 1 Year RS
input TimeFrame = {default "Three_Months", "Six_Months", "1_Year"}; #Hint TimeFrame: Select the appropriate timeframe to calculate Relative Strength.
#Index SymbolRelation
input CorrelationWithSecurity = "SPX"; #Hint CorrelationWithSecurity: Select appropriate Index against which Relative Strength will be calculated.
#Calculation TimeFrame
def aggregationperiod = AggregationPeriod.DAY;
#Chart Normalized Relative Strength Rating on Last Bar
def isLastBar = BarNumber() == HighestAll(if !IsNaN(close) then BarNumber() else Double.NaN);
#Turn on or off Alerts when cycling charts
input Alerts_On = yes; #Hint Alerts_On: Set to "Yes" to receive sound alerts when triggered.
#Add Chart Bubbble to Graph
input RS_Rating_ChartBubble = yes; #Hint RS_Rating_ChartBubble: Set to "Yes" to display current Normalized RS Rating (not the same as MarketSmith).
#Establish look back length:
def Length = if TimeFrame == TimeFrame.Three_Months then 63 else if TimeFrame == TimeFrame.Six_Months then 126 else 252;
#Get Index Close/Open/High/Low - Prep for Candlestick RS.
def indexopen = open(CorrelationWithSecurity, aggregationperiod);
def indexhigh = high(CorrelationWithSecurity, aggregationperiod);
def indexlow = low(CorrelationWithSecurity, aggregationperiod);
def indexclose = close(CorrelationWithSecurity, aggregationperiod);
#Get Relative Strength - Prep for Candlestick RS.
def RSopen = open / indexopen;
def RShigh = high / indexhigh;
def RSlow = low / indexlow;
def RSclose = close / indexclose;
#Normalize Relative Strength
def newRngMax = 99; #Maximum normalized value
def newRngMin = 1; #Minimum normalized value
def HHDataclose = HighestAll(RSclose);
def LLDataclose = LowestAll(RSclose);
plot normalizeRSclose = ((( newRngMax - newRngMin ) * ( RSclose - LLDataclose )) / ( HHDataclose - LLDataclose )) + newRngMin;
AddLabel(normalizeRSclose , Round(normalizeRSclose, 0), color.black);
AssignBackgroundColor( if normalizeRSclose >= 80 then Color.GREEN else color.black);
normalizeRSclose.assignValueColor (Color.black);