cainnitelord
New member
Hi, I have a extremely simple watchlist script, it just shows a # from 1-99 to rank relative strength related to SPX
code works perfectly fine, it's just that when I try to sort it high to low, it would show 99, 98, 97, 9, 89, 88, 85, 8, 79, 72, 7, 69, 68, 67 etc....
you see the problem? 9 was thought by the sorting system as higher than 89, 8 was thought higher than 79, why?
you can see I tried to make it a 1 day simple moving average of itself trying to fix the problem but nope, doesn't work.
code is this:
#3 Month, 6 Month, 1 Year RS
input TimeFrame = {default "Three_Months", "1_Year"};
#Index SymbolRelation
input CorrelationWithSecurity = "SPX";
#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);
#Establish look back length:
def Length = if TimeFrame == TimeFrame.Three_Months then 63 else 252;
#Get Index Close/Open/High/Low - Prep for Candlestick RS.
def indexclose = close(CorrelationWithSecurity, aggregationperiod);
def RSclose = close / indexclose;
def barCount = IF !IsNaN(close) THEN IF IsNaN(barCount[1]) THEN 1 ELSE barCount[1] + 1 ELSE barCount[1];
#Normalize Relative Strength
def newRngMax = 99; #Maximum normalized value
def newRngMin = 1; #Minimum normalized value
def HHDataclose = HighestAll(RSclose);
def LLDataclose = LowestAll(RSclose);
def normalizeRSclose = ((( newRngMax - newRngMin ) * ( RSclose - LLDataclose )) / ( HHDataclose - LLDataclose )) + newRngMin;
DEF normalizeRSclose111 = Round(MovingAverage(averageType.SIMPLE, normalizeRSclose, 1),0);
AddLabel(yes, normalizeRSclose111,if normalizeRSclose>75 then color.green else if normalizeRSclose<30 then color.red else color.white);
code works perfectly fine, it's just that when I try to sort it high to low, it would show 99, 98, 97, 9, 89, 88, 85, 8, 79, 72, 7, 69, 68, 67 etc....
you see the problem? 9 was thought by the sorting system as higher than 89, 8 was thought higher than 79, why?
you can see I tried to make it a 1 day simple moving average of itself trying to fix the problem but nope, doesn't work.
code is this:
#3 Month, 6 Month, 1 Year RS
input TimeFrame = {default "Three_Months", "1_Year"};
#Index SymbolRelation
input CorrelationWithSecurity = "SPX";
#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);
#Establish look back length:
def Length = if TimeFrame == TimeFrame.Three_Months then 63 else 252;
#Get Index Close/Open/High/Low - Prep for Candlestick RS.
def indexclose = close(CorrelationWithSecurity, aggregationperiod);
def RSclose = close / indexclose;
def barCount = IF !IsNaN(close) THEN IF IsNaN(barCount[1]) THEN 1 ELSE barCount[1] + 1 ELSE barCount[1];
#Normalize Relative Strength
def newRngMax = 99; #Maximum normalized value
def newRngMin = 1; #Minimum normalized value
def HHDataclose = HighestAll(RSclose);
def LLDataclose = LowestAll(RSclose);
def normalizeRSclose = ((( newRngMax - newRngMin ) * ( RSclose - LLDataclose )) / ( HHDataclose - LLDataclose )) + newRngMin;
DEF normalizeRSclose111 = Round(MovingAverage(averageType.SIMPLE, normalizeRSclose, 1),0);
AddLabel(yes, normalizeRSclose111,if normalizeRSclose>75 then color.green else if normalizeRSclose<30 then color.red else color.white);