petergluis
Active member
I converted Dynamic RSI to ThinkorSwim. The Dynamic RSI indicator is a kind of exponential RSI . The overbought and oversold levels (respectively HiLine and LoLine) are calculated according to the recent highest and lowest values of the Dynamic RSI line.
https://www.tradingview.com/script/2FYksyrm-Dynamic-RSI/
https://www.tradingview.com/script/2FYksyrm-Dynamic-RSI/
Ruby:
#https://www.tradingview.com/script/2FYksyrm-Dynamic-RSI/
#© Dreadblitz
declare lower;
def DZbuy = 0.1;
def DZsell = 0.1;
input period = 14;
input averageType = AverageType.WILDERS;
Def Lb = 60;
input price = close;
input length = 14;
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);
RSI.DefineColor("UpTrend", Color.GREEN);
RSI.DefineColor("DownTrend", Color.RED);
RSI.SetLineWeight(3);
RSI.SetPaintingStrategy(PaintingStrategy.LINE);
RSI.SetStyle(Curve.FIRM);
RSI.AssignValueColor(if RSI > RSI [1] then RSI.Color("UpTrend") else RSI.Color("DownTrend"));
def RSILine = 50 * (ChgRatio + 1);
def jh = highest(RSILine, Lb);
def jl = lowest(RSILine, Lb);
def jc = (wma((jh-jl)*0.5,Period) + wma(jl,Period));
def Hiline = jh - jc * DZbuy;
def Loline = jl + jc * DZsell;
def R = (4 * RSILine + 3 * RSILine[1] + 2 * RSILine[2] + RSILine[3] ) / 10;
plot a = R;
a.DefineColor("UpTrend", Color.light_GREEN);
a.DefineColor("DownTrend", Color.light_RED);
a.SetLineWeight(2);
a.SetPaintingStrategy(PaintingStrategy.LINE);
a.SetStyle(Curve.FIRM);
a.AssignValueColor(if a >a [1] then a.Color("UpTrend") else a.Color("DownTrend"));
plot b = Hiline;
b.SetDefaultColor(GetColor(4));
b.SetLineWeight(2);
plot c = Loline;
c.SetDefaultColor(GetColor(9));
c.SetLineWeight(2);
plot d = jc;
d.DefineColor("UpTrend", Color.cyan);
d.DefineColor("DownTrend", Color.magenta);
d.SetLineWeight(2);
d.SetPaintingStrategy(PaintingStrategy.LINE);
d.SetStyle(Curve.FIRM);
d.AssignValueColor(if RSI > d then d.Color("UpTrend") else d.Color("DownTrend"));
Addcloud(RSI, a, color.green, color.red);
Plot overbought =80;
overbought.SetDefaultColor(GetColor(5));
plot oversold = 20;
oversold.SetDefaultColor(GetColor(6));
Last edited by a moderator: