Given the following script, I am trying to simply color a label...Works fine if as long as the value of the RSI isn't 0...Problem is RSI can be 0 and the label unfortunately disappears...
Any thoughts? Thanks in advance...
Code:
declare lower;
input showRSI = yes;
input showRSIlabel = yes;
def na = double.nan;
def length2 = 14;
def averageType = AverageType.WILDERS;
def price2 = close;
def NetChgAvg2 = MovingAverage(averageType, price2 - price2[1], length2);
def TotChgAvg2 = MovingAverage(averageType, AbsValue(price2 - price2[1]), length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;
plot RSI = if showRSI then 50 * (ChgRatio2 + 1) else na;
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);
def RSIlabel = 50 * (ChgRatio2 + 1);
AddLabel(if showRSILabel then RSILabel else na," " + "RSI: " + Round(RSIlabel,4) + " ", if RSILabel < 1 then Color.GREEN else if RSILabel > 99 then Color.RED else CreateColor(0, 102, 204));
Any thoughts? Thanks in advance...
Last edited: