input length1 = 21;
input length2 = 35;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = no;
input averageType1 = AverageType.SIMPLE;
input averageType2 = AverageType.SIMPLE;
input averageType3 = AverageType.SIMPLE;
input averageType4 = AverageType.SIMPLE;
input crossingType = {default above, below};
def NetChgAvg = MovingAverage(averageType, price - price[1], length1);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def avg1 = MovingAverage(averageType1, price, length1);
def avg2 = MovingAverage(averageType2, price, length2);
plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
#RSI Labes above midline
AddLabel (yes, if RSI between 96 and 100 then "L1 Over-Consider Exit 96%-100%" else "", Color.RED);
AddLabel (yes, if RSI between 90 and 95.9999 then "L2 Over-90%-95%" else "", Color.YELLOW);
AddLabel (yes, if RSI between 79.99991 and 89.9999 then "L3 Over-79%-89%" else "", Color.cyan);
AddLabel (yes, if RSI between 70 and 79.9999 then "RSI 70%Range" else "", Color.GREEN);
AddLabel (yes, if RSI between 60 and 69.9999 then "RSI 60%Range " else "", Color.GREEN);
AddLabel (yes, if RSI between 51 and 59.9999 then "RSI 50%Range" else "", Color.GREEN);
AddLabel (yes, if RSI between 50 and 50.9999 then "RSI 50%Range" else "", Color.YELLOW);
#RSI Labels below midline
AddLabel (yes, if RSI between 40 and 49.9999 then "RSI 40%Range" else "", Color.RED);
AddLabel (yes, if RSI between 30 and 39.9999 then "RSI 30%Range" else "", Color.RED);
AddLabel (yes, if RSI between 21 and 29.9999 then "RSI 20%Range" else "", Color.RED);
AddLabel (yes, if RSI between 10 and 20.9999 then "L3 Under-11%-20%" else "", Color.cyan);
AddLabel (yes, if RSI between 6 and 9.9999 then "L2 Under-6%-10%" else "", Color.YELLOW);
AddLabel (yes, if RSI between 0 and 5.9999 then "L1 Under-Consider Exit 0%-6%" else "", Color.RED);
#MA Aligned
AddLabel (yes, if close < avg1 and close < avg2 then "(SELL)" + "" else "", Color.RED);
AddLabel (yes, if close > avg1 and close > avg2 then "(BUY)" + "" else "", Color.GREEN);
#Moving average labels
AddLabel (yes, if close < avg1 then "MA.21 SELL" + "" else "", Color.RED);
AddLabel (yes, if close > avg1 then "MA.21 BUY" + "" else "", Color.GREEN);
AddLabel (yes, if close < avg2 then "MA.35 SELL" + "" else "", Color.RED);
AddLabel (yes, if close > avg2 then "MA.35 BUY" + "" else "", Color.GREEN);