Super_OB_OS Indicator for ThinkorSwim

Christopher84

Active member
VIP
This is a lower study that I have designed to identify overbought and oversold conditions. Works very well with the Confirmation Level Lower study and Confirmation Candles. Pay close attention to when the Confirmation Level Line or the Super OB OS Line goes flat in OB or OS zones (tends to lead to reversal). See what you think.

6SZ3XEY.png


Code:
#Super_OB_OS_Lower
#Created by Christopher84 04/22/2021

declare lower;

#RSI
def price = close;
def RSI_length = 14;
def RSI_AverageType = AverageType.WILDERS;
def RSI_OB = 70;
def RSI_OS = 30;

def NetChgAvg = MovingAverage(RSI_AverageType, price - price[1], RSI_length);
def TotChgAvg = MovingAverage(RSI_AverageType, AbsValue(price - price[1]), RSI_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def conditionOB1 = RSI > RSI_OB;
def conditionOS1 = RSI < RSI_OS;

#MFI
def MFI_Length = 14;
def MFIover_Sold = 20;
def MFIover_Bought = 80;
def movingAvgLength = 1;
def MoneyFlowIndex = Average(moneyflow(high, close, low, volume, MFI_Length), movingAvgLength);

def conditionOB2 = MoneyFlowIndex > MFIover_Bought;
def conditionOS2 = MoneyFlowIndex < MFIover_Sold;

#Forecast
def na = Double.NaN;
def MidLine = 50;
def Momentum = MarketForecast().Momentum;
def NearT =  MarketForecast().NearTerm;
def Intermed = MarketForecast().Intermediate;
def FOB = 80;
def FOS = 20;
def upperLine = 110;

def conditionOB3 = Intermed > FOB;
def conditionOS3 = Intermed < FOS;

def conditionOB4 = NearT > FOB;
def conditionOS4 = NearT < FOS;

#Polarized Fractal Efficiency
def PFE_length = 5;#Typically 10
def smoothingLength = 2.5;#Typically 5
def PFE_diff = close - close[PFE_length - 1];
def val = 100 * Sqrt(Sqr(PFE_diff) + Sqr(PFE_length)) / sum(Sqrt(1 + Sqr(close - close[1])), PFE_length - 1);
def PFE = ExpAverage(if PFE_diff > 0 then val else -val, smoothingLength);
def UpperLevel = 50;
def LowerLevel = -50;

def conditionOB5 = PFE > UpperLevel;
def conditionOS5 = PFE < LowerLevel;

#Bollinger Bands PercentB
input BBPB_averageType = AverageType.Simple;
def displace = 0;
def BBPB_length = 5;#Typically 20
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def BBPB_OB = 100;
def BBPB_OS = 0;
def upperBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).LowerBand;
def PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
def HalfLine = 50;
def UnitLine = 100;

def conditionOB6 = PercentB > BBPB_OB;
def conditionOS6 = PercentB < BBPB_OS;

#Projection Oscillator
def ProjectionOsc_length = 9;#Typically 10
def MaxBound = HighestWeighted(high, ProjectionOsc_length, LinearRegressionSlope(price=high, length=ProjectionOsc_length));
def MinBound = LowestWeighted(low, ProjectionOsc_length, LinearRegressionSlope(price=low, length=ProjectionOsc_length));
def ProjectionOsc_diff = MaxBound - MinBound;
def PROSC = if ProjectionOsc_diff != 0 then 100 * (close - MinBound) / ProjectionOsc_diff else 0;
def PROSC_OB = 80;
def PROSC_OS = 20;

def conditionOB7 = PROSC > PROSC_OB;
def conditionOS7 = PROSC < PROSC_OS;

#OB/OS Calculation

def OB_Level = conditionOB1 + conditionOB2 + conditionOB3 + conditionOB4 + conditionOB5 + conditionOB6 + conditionOB7;
def OS_Level = conditionOS1 + conditionOS2 + conditionOS3 + conditionOS4 + conditionOS5 + conditionOS6 + conditionOS7;

plot Concensus_Line = OB_Level - OS_Level;

plot Zero_Line = 0;
Zero_Line.SetPaintingStrategy(PaintingStrategy.LINE);
Zero_Line.SetLineWeight(1);
Zero_Line.SetDefaultColor(Color.LIGHT_GRAY);

plot Super_OB = 4;
Super_OB.SetPaintingStrategy(PaintingStrategy.LINE);
Super_OB.SetLineWeight(1);
Super_OB.SetDefaultColor(Color.RED);

plot Super_OS = -2;
Super_OS.SetPaintingStrategy(PaintingStrategy.LINE);
Super_OS.SetLineWeight(1);
Super_OS.SetDefaultColor(Color.LIGHT_GREEN);

Concensus_Line.AssignValueColor(
if Concensus_Line > Concensus_Line[1] and Concensus_Line >= Zero_Line then Color.RED
else if Concensus_Line < Concensus_Line[1] and Concensus_Line >= Zero_Line then Color.DARK_RED
else if Concensus_Line < Concensus_Line[1] and Concensus_Line < Zero_Line then Color.Green else
if Concensus_Line > Concensus_Line[1] and Concensus_Line < Zero_Line then Color.DARK_Green
else Color.GRAY);


AddCloud(Concensus_Line, Super_OB, Color.RED, Color.CURRENT);
AddCloud(Concensus_Line, Super_OS, Color.CURRENT, Color.LIGHT_GREEN);
 

Christopher84

Active member
VIP
Running it now thanks so much
Just something to note that may help you, it seems that any time the Confirmation Lower study or the Super OB/OS is in the OB/OS zones (whether one or both indicators are in the OB/OS zones) and either of the lines goes flat, the likelihood for reversal is high.
 
Last edited:

Jonas99

Member
VIP
This is a lower study that I have designed to identify overbought and oversold conditions. Works very well with the Confirmation Level Lower study and Confirmation Candles. Pay close attention to when the Confirmation Level Line or the Super OB OS Line goes flat in OB or OS zones (tends to lead to reversal). See what you think.

6SZ3XEY.png


Code:
#Super_OB_OS_Lower
#Created by Christopher84 04/22/2021

declare lower;

#RSI
def price = close;
def RSI_length = 14;
def RSI_AverageType = AverageType.WILDERS;
def RSI_OB = 70;
def RSI_OS = 30;

def NetChgAvg = MovingAverage(RSI_AverageType, price - price[1], RSI_length);
def TotChgAvg = MovingAverage(RSI_AverageType, AbsValue(price - price[1]), RSI_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def conditionOB1 = RSI > RSI_OB;
def conditionOS1 = RSI < RSI_OS;

#MFI
def MFI_Length = 14;
def MFIover_Sold = 20;
def MFIover_Bought = 80;
def movingAvgLength = 1;
def MoneyFlowIndex = Average(moneyflow(high, close, low, volume, MFI_Length), movingAvgLength);

def conditionOB2 = MoneyFlowIndex > MFIover_Bought;
def conditionOS2 = MoneyFlowIndex < MFIover_Sold;

#Forecast
def na = Double.NaN;
def MidLine = 50;
def Momentum = MarketForecast().Momentum;
def NearT =  MarketForecast().NearTerm;
def Intermed = MarketForecast().Intermediate;
def FOB = 80;
def FOS = 20;
def upperLine = 110;

def conditionOB3 = Intermed > FOB;
def conditionOS3 = Intermed < FOS;

def conditionOB4 = NearT > FOB;
def conditionOS4 = NearT < FOS;

#Polarized Fractal Efficiency
def PFE_length = 5;#Typically 10
def smoothingLength = 2.5;#Typically 5
def PFE_diff = close - close[PFE_length - 1];
def val = 100 * Sqrt(Sqr(PFE_diff) + Sqr(PFE_length)) / sum(Sqrt(1 + Sqr(close - close[1])), PFE_length - 1);
def PFE = ExpAverage(if PFE_diff > 0 then val else -val, smoothingLength);
def UpperLevel = 50;
def LowerLevel = -50;

def conditionOB5 = PFE > UpperLevel;
def conditionOS5 = PFE < LowerLevel;

#Bollinger Bands PercentB
input BBPB_averageType = AverageType.Simple;
def displace = 0;
def BBPB_length = 5;#Typically 20
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def BBPB_OB = 100;
def BBPB_OS = 0;
def upperBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).LowerBand;
def PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
def HalfLine = 50;
def UnitLine = 100;

def conditionOB6 = PercentB > BBPB_OB;
def conditionOS6 = PercentB < BBPB_OS;

#Projection Oscillator
def ProjectionOsc_length = 9;#Typically 10
def MaxBound = HighestWeighted(high, ProjectionOsc_length, LinearRegressionSlope(price=high, length=ProjectionOsc_length));
def MinBound = LowestWeighted(low, ProjectionOsc_length, LinearRegressionSlope(price=low, length=ProjectionOsc_length));
def ProjectionOsc_diff = MaxBound - MinBound;
def PROSC = if ProjectionOsc_diff != 0 then 100 * (close - MinBound) / ProjectionOsc_diff else 0;
def PROSC_OB = 80;
def PROSC_OS = 20;

def conditionOB7 = PROSC > PROSC_OB;
def conditionOS7 = PROSC < PROSC_OS;

#OB/OS Calculation

def OB_Level = conditionOB1 + conditionOB2 + conditionOB3 + conditionOB4 + conditionOB5 + conditionOB6 + conditionOB7;
def OS_Level = conditionOS1 + conditionOS2 + conditionOS3 + conditionOS4 + conditionOS5 + conditionOS6 + conditionOS7;

plot Concensus_Line = OB_Level - OS_Level;

plot Zero_Line = 0;
Zero_Line.SetPaintingStrategy(PaintingStrategy.LINE);
Zero_Line.SetLineWeight(1);
Zero_Line.SetDefaultColor(Color.LIGHT_GRAY);

plot Super_OB = 4;
Super_OB.SetPaintingStrategy(PaintingStrategy.LINE);
Super_OB.SetLineWeight(1);
Super_OB.SetDefaultColor(Color.RED);

plot Super_OS = -2;
Super_OS.SetPaintingStrategy(PaintingStrategy.LINE);
Super_OS.SetLineWeight(1);
Super_OS.SetDefaultColor(Color.LIGHT_GREEN);

Concensus_Line.AssignValueColor(
if Concensus_Line > Concensus_Line[1] and Concensus_Line >= Zero_Line then Color.RED
else if Concensus_Line < Concensus_Line[1] and Concensus_Line >= Zero_Line then Color.DARK_RED
else if Concensus_Line < Concensus_Line[1] and Concensus_Line < Zero_Line then Color.Green else
if Concensus_Line > Concensus_Line[1] and Concensus_Line < Zero_Line then Color.DARK_Green
else Color.GRAY);


AddCloud(Concensus_Line, Super_OB, Color.RED, Color.CURRENT);
AddCloud(Concensus_Line, Super_OS, Color.CURRENT, Color.LIGHT_GREEN);
@Christopher84 I just tried it out, really like it. Thanks so much for sharing!
 

kici

New member
VIP
This is a lower study that I have designed to identify overbought and oversold conditions. Works very well with the Confirmation Level Lower study and Confirmation Candles. Pay close attention to when the Confirmation Level Line or the Super OB OS Line goes flat in OB or OS zones (tends to lead to reversal). See what you think.

6SZ3XEY.png


Code:
#Super_OB_OS_Lower
#Created by Christopher84 04/22/2021

declare lower;

#RSI
def price = close;
def RSI_length = 14;
def RSI_AverageType = AverageType.WILDERS;
def RSI_OB = 70;
def RSI_OS = 30;

def NetChgAvg = MovingAverage(RSI_AverageType, price - price[1], RSI_length);
def TotChgAvg = MovingAverage(RSI_AverageType, AbsValue(price - price[1]), RSI_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def conditionOB1 = RSI > RSI_OB;
def conditionOS1 = RSI < RSI_OS;

#MFI
def MFI_Length = 14;
def MFIover_Sold = 20;
def MFIover_Bought = 80;
def movingAvgLength = 1;
def MoneyFlowIndex = Average(moneyflow(high, close, low, volume, MFI_Length), movingAvgLength);

def conditionOB2 = MoneyFlowIndex > MFIover_Bought;
def conditionOS2 = MoneyFlowIndex < MFIover_Sold;

#Forecast
def na = Double.NaN;
def MidLine = 50;
def Momentum = MarketForecast().Momentum;
def NearT =  MarketForecast().NearTerm;
def Intermed = MarketForecast().Intermediate;
def FOB = 80;
def FOS = 20;
def upperLine = 110;

def conditionOB3 = Intermed > FOB;
def conditionOS3 = Intermed < FOS;

def conditionOB4 = NearT > FOB;
def conditionOS4 = NearT < FOS;

#Polarized Fractal Efficiency
def PFE_length = 5;#Typically 10
def smoothingLength = 2.5;#Typically 5
def PFE_diff = close - close[PFE_length - 1];
def val = 100 * Sqrt(Sqr(PFE_diff) + Sqr(PFE_length)) / sum(Sqrt(1 + Sqr(close - close[1])), PFE_length - 1);
def PFE = ExpAverage(if PFE_diff > 0 then val else -val, smoothingLength);
def UpperLevel = 50;
def LowerLevel = -50;

def conditionOB5 = PFE > UpperLevel;
def conditionOS5 = PFE < LowerLevel;

#Bollinger Bands PercentB
input BBPB_averageType = AverageType.Simple;
def displace = 0;
def BBPB_length = 5;#Typically 20
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def BBPB_OB = 100;
def BBPB_OS = 0;
def upperBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).LowerBand;
def PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
def HalfLine = 50;
def UnitLine = 100;

def conditionOB6 = PercentB > BBPB_OB;
def conditionOS6 = PercentB < BBPB_OS;

#Projection Oscillator
def ProjectionOsc_length = 9;#Typically 10
def MaxBound = HighestWeighted(high, ProjectionOsc_length, LinearRegressionSlope(price=high, length=ProjectionOsc_length));
def MinBound = LowestWeighted(low, ProjectionOsc_length, LinearRegressionSlope(price=low, length=ProjectionOsc_length));
def ProjectionOsc_diff = MaxBound - MinBound;
def PROSC = if ProjectionOsc_diff != 0 then 100 * (close - MinBound) / ProjectionOsc_diff else 0;
def PROSC_OB = 80;
def PROSC_OS = 20;

def conditionOB7 = PROSC > PROSC_OB;
def conditionOS7 = PROSC < PROSC_OS;

#OB/OS Calculation

def OB_Level = conditionOB1 + conditionOB2 + conditionOB3 + conditionOB4 + conditionOB5 + conditionOB6 + conditionOB7;
def OS_Level = conditionOS1 + conditionOS2 + conditionOS3 + conditionOS4 + conditionOS5 + conditionOS6 + conditionOS7;

plot Concensus_Line = OB_Level - OS_Level;

plot Zero_Line = 0;
Zero_Line.SetPaintingStrategy(PaintingStrategy.LINE);
Zero_Line.SetLineWeight(1);
Zero_Line.SetDefaultColor(Color.LIGHT_GRAY);

plot Super_OB = 4;
Super_OB.SetPaintingStrategy(PaintingStrategy.LINE);
Super_OB.SetLineWeight(1);
Super_OB.SetDefaultColor(Color.RED);

plot Super_OS = -2;
Super_OS.SetPaintingStrategy(PaintingStrategy.LINE);
Super_OS.SetLineWeight(1);
Super_OS.SetDefaultColor(Color.LIGHT_GREEN);

Concensus_Line.AssignValueColor(
if Concensus_Line > Concensus_Line[1] and Concensus_Line >= Zero_Line then Color.RED
else if Concensus_Line < Concensus_Line[1] and Concensus_Line >= Zero_Line then Color.DARK_RED
else if Concensus_Line < Concensus_Line[1] and Concensus_Line < Zero_Line then Color.Green else
if Concensus_Line > Concensus_Line[1] and Concensus_Line < Zero_Line then Color.DARK_Green
else Color.GRAY);


AddCloud(Concensus_Line, Super_OB, Color.RED, Color.CURRENT);
AddCloud(Concensus_Line, Super_OS, Color.CURRENT, Color.LIGHT_GREEN);
What about your other indicator there with the Look to buy/sell, momentum, breakout etc? :)
 

Docbrown83

New member
Great Script!!!

Is there any way you can share the labels you have with your chart (i.e. Look_to_Buy, Look_to_Sell, Increasing Momentum, Decreasing Momentum, etc...)?
 

Similar threads

Top