declare lower;
#RSI
input length = 14;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot lline = 50;
RSI.AssignValueColor(if RSI >= 50 then Color.GREEN else Color.RED);
#RSI.DefineColor("Positive and Up", Color.GREEN);
#RSI.DefineColor("Positive and Down", Color.DARK_GREEN);
#RSI.DefineColor("Negative and Down", Color.RED);
#RSI.DefineColor("Negative and Up", Color.DARK_RED);
#RSI.AssignValueColor(if RSI >= 50 then if RSI > RSI[1] then RSI.Color("Positive and Up") else #RSI.Color("Positive and Down") else if RSI < RSI[1] then RSI.Color("Negative and Down") else #RSI.Color("Negative and Up"));
OverSold.SetDefaultColor(GetColor(7));
OverBought.SetDefaultColor(GetColor(7));
# RSI Week
input averageType3 = AverageType.WILDERS;
input agg3 = AggregationPeriod.WEEK;
def c3 = close(period = agg3);
def NetChgAvg3 = MovingAverage(averageType3, c3 - c3[1], length);
def TotChgAvg3 = MovingAverage(averageType3, AbsValue(c3 - c3[1]),length);
def ChgRatio3 = if TotChgAvg3 != 0 then NetChgAvg3 / TotChgAvg3 else 0;
def RSIW = 50 * (ChgRatio3 + 1);
def DWAVGRSI = (RSI + RSIW) /2 ;
plot DWAVGRSIP = DWAVGRSI ;
DWAVGRSIP.AssignValueColor( Color.CYAN);
addCloud(RSI, DWAVGRSI, color.RED, color.GREEN);