declare lower;
input length = 14;
input over_Bought = 60;
input over_Sold = 25;
input mid_line = 50;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
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 MidLine = mid_line;
RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > RSI[5] then color.GREEN else if RSI < RSI[5] then color.RED else color.gray);
##################################################################
input lengthdmi = 14;
input averageTypedmi = AverageType.WILDERS;
def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATR = MovingAverage(averageTypedmi, TrueRange(high, close, low), lengthdmi);
plot "DI+" = 100 * MovingAverage(averageTypedmi, plusDM, lengthdmi) / ATR;
"DI+".AssignValueColor(if "DI+" > 25 then color.LIME else if "DI+" < 25 then color.PINK else color.gray);
plot UpSignal = if RSI >= 60 and "DI+" crosses above 25 then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
OverSold.SetDefaultColor(Color.WHITE);
OverBought.SetDefaultColor(Color.WHITE);
MidLine.SetDefaultColor(Color.GRAY);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);