OBV_RSI_MA Indicator For ThinkOrSwim
Requested by @AnimalMother. Here is the first attempt.
Requested by @AnimalMother. Here is the first attempt.
Code:
# OBV_RSI_MA
# 20211121 - barbaros
#
declare lower;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input src = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = yes;
#net volume of positive and negative volume
def obv = if (src - src[1]) > 0 then volume else
if (src - src[1]) < 0 then -volume else 0 * volume;
def cnv = TotalSum(obv); #cumulative net volume
def price = cnv;
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.SetDefaultColor(GetColor(8));
#Moving Averages
input MALength = 8;
input AverageType1 = AverageType.SIMPLE;
input MALength2 = 26;
input AverageType2 = AverageType.SIMPLE;
input MALength3 = 57;
input AverageType3 = AverageType.SIMPLE;
input MALength4 = 180;
input AverageType4 = AverageType.SIMPLE;
# plot the Moving Averages
def MA = MovingAverage(AverageType1, RSI, MALength);
plot pMA = MA;
def MA2 = MovingAverage(AverageType2, RSI, MALength2);
plot pMA2 = MA2;
def MA3 = MovingAverage (AverageType3, RSI, MALength3);
plot pMA3 = MA3;
def MA4 = MovingAverage(AverageType4, RSI, MALength4);
plot pMA4 = MA4;
plot mid = 50;
mid.SetPaintingStrategy(paintingStrategy = PaintingStrategy.DASHES);
mid.AssignValueColor(COLOR.magenta);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
OverBought.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));
plot UpSignal = if pMA3 crosses above mid then mid else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
UpSignal.SetHiding(!showBreakoutSignals);
Last edited by a moderator: