Confirmation Candles Indicator For ThinkorSwim

i'm using v3.0, dated 4/20/21, i believe. this is on the lower. at the moment, i'm just going to use it and not the upper and let it color the upper candles. i see what you're saying about the nuances of the lower indicator but, truth to tell, it's a lot for me to take in, especially as i go through my nightly look-see at symbols of interest. i've been using agreement_level > 3 as the trigger for those vertical lines. i'll have to look at your C> >=0 and what what it tells me. more later. thanks again for your hard work on this.
 
Last edited:
i want to scan the red and green arrow in the upper study. Do you think is possible to create one?
Possibly. I use one of the original versions in my watchlist. The complex code makes it slow to load, however, it improved about 24 hours after I set it up. The green and red arrows are determined by the confirmation level.
 
@Christopher84, I appreciate the improvements you've made to your indicator. Thank you! Here's a 5 min ES chart. As you can see, it did a nice job finding a long and a short between 1:30 and 4pm. About 6pm, the MACD BB indicated a potential long, but your indicator made it easy to disregard that and watch for a short entry.

Thank you again for sharing your work! And for making it easy to adjust the display so that my upper chart can stay uncluttered.

 
Possibly. I use one of the original versions in my watchlist. The complex code makes it slow to load, however, it improved about 24 hours after I set it up. The green and red arrows are determined by the confirmation level.
thanks for the good work. can you share that code please?
 
thanks for the good work. can you share that code please?
Here's the code for the watchlist. I like to sort this column in my watchlist to show potential OB/OS conditions within my list. I have reworked the code and it works great!

Code:
#Confirmation Level Lower developed 04/15/2021 by Christopher Wilson
#Select the level of agreement among the 13 indicators included.
#Modified 05/12/2021 removed Pivot Study and dialed in levels.

#MACD with Price

declare lower;
def price = close;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};
def MACDLevel = 0.0;

def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
def Value;
def Avg;

switch (MACD_AverageType) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = fastEMA - slowEMA;
    Avg = ExpAverage(Value, MACDLength);}
def Diff = Value - Avg;
def Level = MACDLevel;

def condition1 = Value[1] <= Value;

#RSI

input RSI_length = 14;
input RSI_AverageType = AverageType.WILDERS;


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 condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;

#MFI

input 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 MFIOverBought = MFIover_Bought;
def MFIOverSold = MFIover_Sold;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;

#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 condition4 = (Intermed[1] <= Intermed) or (NearT >= MidLine);

#EMA_1
input EMA_length = 12;
def displace = 0;
def AvgExp = ExpAverage(price[-displace], EMA_length);

def condition6 = (price >= AvgExp) and (AvgExp[2] <= AvgExp);

#EMA_2
input EMA_2length = 20;
def displace2 = 0;
def AvgExp2 = ExpAverage(price[-displace2], EMA_2length);

def condition7 = (price >= AvgExp2) and (AvgExp2[2] <= AvgExp2);

#DMI Oscillator
input DMI_length = 5;
input averageType = AverageType.WILDERS;

def diPlus = DMI(DMI_length, averageType)."DI+";
def diMinus = DMI(DMI_length, averageType)."DI-";

def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

def condition8 = Osc >= ZeroLine;

#Trend_Periods

input TP_fastLength = 3;
input TP_slowLength = 4;

def Periods = sign(ExpAverage(close, TP_fastLength) - ExpAverage(close, TP_slowLength));

def condition9 = Periods > 0;

#Polarized Fractal Efficiency

input PFE_length = 5;
input smoothingLength = 2.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 condition10 = PFE > ZERoLine;

#Bollinger Bands PercentB

input BBPB_averageType = AverageType.Simple;
input BBPB_length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.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 condition11 = PercentB > 50;

#STARC Bands
def ATR_length = 15;
def SMA_lengthS = 6;
def multiplier_factor = 1.25;
def valS = Average(price, SMA_lengthS);
def average_true_range = Average(TrueRange(high, close, low), length = ATR_length);
def Upper_BandS = valS[-displace] + multiplier_factor * average_true_range[-displace];
def Middle_BandS = valS[-displace];
def Lower_BandS = valS[-displace] - multiplier_factor * average_true_range[-displace];

def condition12 = (Upper_BandS[1] <= Upper_BandS) and (Lower_BandS[1] <= Lower_BandS); 

#Projection Oscillator
def ProjectionOsc_length = 30;#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 condition13 = (PROSC > 50);

#Trend Confirmation
#Confirmation_Factor range 1-13.

input Confirmation_Factor = 7;
#Use for testing conditions individually.
#def Agreement_Level = condition1;
plot Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12 + condition13;

def Sell_Alert = Agreement_Level >= 9;
def Buy_Alert = Agreement_Level <= 2 ;


def Factor_Line = Confirmation_Factor;

AssignBackgroundColor(if Sell_Alert then color.LIGHT_RED else if Buy_Alert then color.dark_green else color.black);
 
Last edited:
I have been working on an Idea I am calling confirmation candles. I often times find myself trying to find agreement among the numerous indicators that I use to help guide my decisions. Unfortunately, a lot of the time this creates indicator overload and analysis paralysis. So I have included 13 indicators of trend within this indicator. You can choose how many of the 13 indicators have to be in agreement in order to confirm the trend. I may have gone a bit overboard here, however it makes it adaptable to individual risk tolerance and trading style. Checkout the image below. If anyone likes this idea/indicator, I am happy to share the script.

7ItcupI.png

tOhnko8.png


Code:
#
#Confirmation Candles V.8
#Created 04/15/2021 by Christopher84
#Select the level of agreement among the 14 indicators included.
#Changed 04/19/2021 to V.3 - Removed ChaikinOsc and replaced with STARCBands. Added squeeze alert.
#Changed 04/20/2021 to V.4 - Added Keltner Channel, Labels, and Buy and Sell Zones. Mean Reversion and Breakout Labels added. Reversal_Alert points added.
#Changed 4/22/2021 to V.5 - Removed Buy/Sell clouds. Created new reversal alert buy(gray points) and take profit (red points). Increase factorK.
#Changed 4/23/2021 to V.6 - Refined reversal signals. Fully integrated Super_OB_OS indicator. Fixed candles going yellow if colored_candles is off.
#Changed 4/26/2021 to V.7 - Refined reversal signals and included Keltner Bandwidth. Adjusted Keltner Channel levels.
#Changed 4/27/2021 to V.8 - Improved reversal signals and included support and resistance zones.

#Keltner Channel
declare upper;
def displace = 0;
input factorK = 2.0;
input lengthK = 20;
def price = close;
input averageType = AverageType.SIMPLE;
def trueRangeAverageType = AverageType.SIMPLE;
def BulgeLengthK = 150;
def SqueezeLengthK = 150;
def BulgeLengthK2 = 40;
def SqueezeLengthK2 = 40;
input BulgeLengthPrice = 75;
input SqueezeLengthPrice = 75;
input BulgeLengthPrice2 = 20;
input SqueezeLengthPrice2 = 20;

def shift = factorK * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengthK);
def averageK = MovingAverage(averageType, price, lengthK);
def AvgK = averageK[-displace];
def Upper_BandK = averageK[-displace] + shift[-displace];
def Lower_BandK = averageK[-displace] - shift[-displace];

def conditionK1 = price >= Upper_BandK;
def conditionK2 = (Upper_BandK[1] < Upper_BandK) and (Lower_BandK[1] < Lower_BandK);
def conditionK2L = (Upper_BandK[2] < Upper_BandK[1]) and (Lower_BandK[2] < Lower_BandK[1]);
def conditionK3L = (Upper_BandK[3] < Upper_BandK[2]) and (Lower_BandK[3] < Lower_BandK[2]);
def conditionK3 = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);
def BandwidthK = (Upper_BandK - Lower_BandK) / AvgK * 100;
def condition_BWKUP = BandwidthK[1] < BandwidthK;
def condition_BWKDOWN = BandwidthK[1] > BandwidthK;
def BulgeK = Highest(BandwidthK, BulgeLengthK);
def SqueezeK = Lowest(BandwidthK, SqueezeLengthK);
def BulgeK2 = Highest(BandwidthK, BulgeLengthK2);
def SqueezeK2 = Lowest(BandwidthK, SqueezeLengthK2);

plot BulgePrice = Highest(price, BulgeLengthPrice);
BulgePrice.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
plot SqueezePrice = Lowest(price, SqueezeLengthPrice);
SqueezePrice.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);

plot BulgePrice2 = Highest(price, BulgeLengthPrice2);
BulgePrice2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
BulgePrice2.SetStyle(Curve.SHORT_DASH);
plot SqueezePrice2 = Lowest(price, SqueezeLengthPrice2);
SqueezePrice2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
SqueezePrice2.SetStyle(Curve.SHORT_DASH);

#MACD with Price
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};
def MACDLevel = 0.0;

def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
def Value;
def Avg;
switch (MACD_AverageType) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = fastEMA - slowEMA;
    Avg = ExpAverage(Value, MACDLength);
}
def Diff = Value - Avg;
def Level = MACDLevel;

def condition1 = Value[1] <= Value;

#RSI
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 condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;
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 MFIOverBought = MFIover_Bought;
def MFIOverSold = MFIover_Sold;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;
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 condition4 = (Intermed[1] <= Intermed) and (NearT >= MidLine);
def conditionOB3 = Intermed > FOB;
def conditionOS3 = Intermed < FOS;
def conditionOB4 = NearT > FOB;
def conditionOS4 = NearT < FOS;


#Pivot Signals
def n = 20;
def ticks = 2.0;
def bnOK = BarNumber() > n;
def isHigher = fold i = 1 to n + 1 with p = 1 while p do high > GetValue(high, -i);
def HH = if bnOK and isHigher and high == Highest(high, n) then high else Double.NaN;
def isLower = fold j = 1 to n + 1 with q = 1 while q do low < GetValue(low, -j);
def LL = if bnOK and isLower and low == Lowest(low, n) then low else Double.NaN;
def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

def UpPivotLow = !IsNaN(PivL);
#UpPivotLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#UpPivotLow.SetLineWeight(4);
#UpPivotLow.SetDefaultColor(Color.GREEN);

def DownPivotHigh = !IsNaN(PivH);
#DownPivotHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#DownPivotHigh.SetLineWeight(4);
#DownPivotHigh.SetDefaultColor(Color.RED);

def condition5 = !IsNaN(PivL);

#EMA_1
def EMA_length = 12;
def AvgExp = ExpAverage(price[-displace], EMA_length);

def condition6 = (price >= AvgExp) and (AvgExp[2] <= AvgExp);

#EMA_2
def EMA_2length = 20;
def displace2 = 0;
def AvgExp2 = ExpAverage(price[-displace2], EMA_2length);

def condition7 = (price >= AvgExp2) and (AvgExp[2] <= AvgExp);

#DMI Oscillator
def DMI_length = 5;#Typically set to 10
input DMI_averageType = AverageType.WILDERS;
def diPlus = DMI(DMI_length, DMI_averageType)."DI+";
def diMinus = DMI(DMI_length, DMI_averageType)."DI-";
def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

def condition8 = Osc >= ZeroLine;

#Trend_Periods
def TP_fastLength = 3;#Typically 7
def TP_slowLength = 4;#Typically 15
def Periods = Sign(ExpAverage(close, TP_fastLength) - ExpAverage(close, TP_slowLength));

def condition9 = Periods > 0;

#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 condition10 = PFE > 0;
def conditionOB5 = PFE > UpperLevel;
def conditionOS5 = PFE < LowerLevel;


#Bollinger Bands PercentB
input BBPB_averageType = AverageType.SIMPLE;
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 condition11 = PercentB > HalfLine;
def conditionOB6 = PercentB > BBPB_OB;
def conditionOS6 = PercentB < BBPB_OS;


#STARC Bands
def ATR_length = 15;
def SMA_lengthS = 6;
def multiplier_factor = 1.5;
def valS = Average(price, SMA_lengthS);
def average_true_range = Average(TrueRange(high, close, low), length = ATR_length);
def Upper_BandS = valS[-displace] + multiplier_factor * average_true_range[-displace];
def Middle_BandS = valS[-displace];
def Lower_BandS = valS[-displace] - multiplier_factor * average_true_range[-displace];

def condition12 = (Upper_BandS[1] <= Upper_BandS) and (Lower_BandS[1] <= Lower_BandS);

#Klinger Histogram
def Klinger_Length = 8;
def KVOsc = KlingerOscillator(Klinger_Length).KVOsc;
def KVOH = KVOsc - Average(KVOsc, Klinger_Length);
def condition13 = (KVOH > 0) and (KVOsc[1] <= KVOsc);

#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 condition14 = PROSC > 50;
def conditionOB7 = PROSC > PROSC_OB;
def conditionOS7 = PROSC < PROSC_OS;


#Trend Confirmation Calculator
#Confirmation_Factor range 1-15.
input coloredCandlesOn = yes;
input Confirmation_Factor = 3;
#Use for testing conditions individually. Remove # from line below and change Confirmation_Factor to 1.
#def Agreement_Level = condition1;
def Agreement_LevelOB = 12;
def Agreement_LevelOS = 3;

def Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12 + condition13 + condition14 + conditionK1 + conditionK2;

def conditionChannel1 = Upper_BandK > price;
def conditionChannel2 = Lower_BandK < price;

def UP = Agreement_Level >= Confirmation_Factor;
def DOWN = Agreement_Level <= Confirmation_Factor;

AssignPriceColor(if coloredCandlesOn and UP then Color.LIGHT_GREEN else if coloredCandlesOn and DOWN then Color.RED else Color.CURRENT);

#Additional Signals

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

def Concensus_Line = OB_Level - OS_Level;
def Zero_Line = 0;
def Super_OB = 4;
def Super_OS = -2;

def DOWN_OB = (Agreement_Level > Agreement_LevelOB) and (Concensus_Line > Super_OB);
def UP_OS = (Agreement_Level < Agreement_LevelOS) and (Concensus_Line < Super_OS);

def OS_Buy = UP_OS;
def OB_Sell = DOWN_OB;
def neutral = Concensus_Line < Super_OB and Concensus_Line > Super_OS;

#AddVerticalLine (OS_Buy and !OS_Buy[1], close, Color.GREEN, Curve.SHORT_DASH);
#AddVerticalLine (Neutral and !neutral[1], close, Color.Gray, Curve.SHORT_DASH);
#AddVerticalLine (OB_Sell and OB_Sell and !OB_Sell[1], close, Color.RED, Curve.SHORT_DASH);

def Buy_Opportnity = if OS_Buy then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
#AddCloud(Buy_Opportnity, Neutral, Color.LIGHT_GREEN, Color.LIGHT_RED);
def Sell_Opportnity = if OB_Sell then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
#AddCloud(Sell_Opportnity, Neutral, Color.LIGHT_RED, Color.LIGHT_RED);

def OB_Signal = price crosses below Upper_BandK;
#OB_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#OB_Signal.SetLineWeight(1);
#OB_Signal.SetDefaultColor(Color.RED);

def OS_Signal = price crosses above Lower_BandK;
#OS_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#OS_Signal.SetLineWeight(1);
#OS_Signal.SetDefaultColor(Color.GREEN);

#Squeeze Alert
def length = 20;
def BulgeLength = 150;
def SqueezeLength = 150;
def upperBandBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
def lowerBandBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;
def midLineBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).MidLine;
def Bandwidth = (upperBandBB - lowerBandBB) / midLineBB * 100;
def Bulge = Highest(Bandwidth, BulgeLength);
def Squeeze = Lowest(Bandwidth, SqueezeLength);

plot Squeeze_Alert = Bandwidth <= Squeeze;
Squeeze_Alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Squeeze_Alert.SetLineWeight(3);
Squeeze_Alert.SetDefaultColor(Color.YELLOW);

#Trend Signals
#Bollinger_Bands2
input lengthBB = 10;
input Num_Dev_DnBB = -0.8;
input Num_Dev_upBB = 0.8;

def price1 = open;
def sDev = StDev(data = price[-displace], length = lengthBB);
def MidLineBB2 = MovingAverage(averageType, data = price[-displace], length = lengthBB);
def LowerBandBB2 = MidLineBB2 + Num_Dev_DnBB * sDev;
def UpperBandBB2 = MidLineBB2 + Num_Dev_upBB * sDev;


def condition_Slope_RevUP = ((Agreement_Level[1] < Agreement_Level) or (Agreement_Level[2] >= Agreement_Level[1])) or ((Concensus_Line[1] < Concensus_Line) and (Concensus_Line[2] >= Concensus_Line[1]));
def condition_Slope_RevDOWN = ((Agreement_Level[1] > Agreement_Level) and (Agreement_Level[2] <= Agreement_Level[1])) or ((Concensus_Line[1] > Concensus_Line) and (Concensus_Line[2] <= Concensus_Line[1]));
def condition_Flat = (Agreement_Level[2] == Agreement_Level[1]) or (Concensus_Line[2] == Concensus_Line[1]);
def condition_Flat2 = ((Agreement_Level[1] == Agreement_Level) and (Concensus_Line[1] == Concensus_Line));
def condition_Flat3 = ((Agreement_Level[1] == Agreement_Level) or (Concensus_Line[1] == Concensus_Line));
def condition_OB = ((Agreement_Level >= 12) or (Concensus_Line >= 2));# and (price > Upper_BandK));
def condition_OS = ((Agreement_Level <= 2) or (Concensus_Line <= -2));# and (price < lower_BandK)
def condition_AC_SlopeDOWN = (Agreement_Level[1] > Agreement_Level) or (Concensus_Line[1] > Concensus_Line);
def condition_AC_SlopeUP = (Agreement_Level[1] < Agreement_Level) or (Concensus_Line[1] < Concensus_Line);

plot UPConfirmSignal = Agreement_Level crosses above Confirmation_Factor;
UPConfirmSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UPConfirmSignal.SetLineWeight(1);
UPConfirmSignal.SetDefaultColor(Color.GREEN);

plot DOWNConfirmSignal = Agreement_Level crosses below Confirmation_Factor;
DOWNConfirmSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DOWNConfirmSignal.SetLineWeight(1);
DOWNConfirmSignal.SetDefaultColor(Color.RED);

plot Reversal_Buy_1 = (BandwidthK crosses below BulgeK2) and (condition_OS);
Reversal_Buy_1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Buy_1.SetLineWeight(3);
Reversal_Buy_1.SetDefaultColor(Color.GREEN);

plot Reversal_Buy2 = (BandwidthK crosses above SqueezeK) and (condition_OS);
#((Agreement_Level < 2) and Concensus_Line < 0) and condition_Slope_RevUP and conditionK2 and condition_BWKDOWN;
Reversal_Buy2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Buy2.SetLineWeight(3);
Reversal_Buy2.SetDefaultColor(Color.GREEN);

plot Reversal_Buy_3 = (BandwidthK == BulgeK) and (Concensus_Line < 0) and condition_AC_SlopeUP;
Reversal_Buy_3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Buy_3.SetLineWeight(3);
Reversal_Buy_3.SetDefaultColor(Color.GREEN);

plot Reversal_Sell_1 = ((Agreement_Level crosses below 10) and (Concensus_Line crosses below Super_OB) and (price > Middle_BandS));
Reversal_Sell_1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Sell_1.SetLineWeight(3);
Reversal_Sell_1.SetDefaultColor(Color.RED);

plot Reversal_Sell_2 = (BandwidthK crosses below BulgeK2) and (Concensus_Line >= 0) and (Agreement_Level >= 5) and (condition_Flat3 or condition_AC_SlopeDOWN);
Reversal_Sell_2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Sell_2.SetLineWeight(3);
Reversal_Sell_2.SetDefaultColor(Color.RED);

plot Reversal_Sell_3 = (BandwidthK == SqueezeK) and condition_OB;
Reversal_Sell_3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Sell_3.SetLineWeight(3);
Reversal_Sell_3.SetDefaultColor(Color.RED);

#plot Reversal_MeanReversion = conditionK3 and (price > UpperBandBB2);
#Reversal_MeanReversion.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
#Reversal_MeanReversion.SetLineWeight(3);
#Reversal_MeanReversion.SetDefaultColor(Color.RED);

def condition_Reversal_CA_Buy = (Agreement_Level < 1) and (Agreement_Level[1] <= Agreement_Level);
def condition_Reversal_SOS_Buy = (Concensus_Line < -2) and (Concensus_Line[1] <= Concensus_Line);
#plot Reversal_Buy = (condition_Reversal_CA_Buy) or (condition_Reversal_SOS_Buy);
#Reversal_Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
#Reversal_Buy.SetLineWeight(1);
#Reversal_Buy.SetDefaultColor(Color.LIGHT_GRAY);

#Labels
def Buy = UP_OS;
def Sell = DOWN_OB;
AddLabel(yes, "Look_To_Buy", if Buy then Color.GREEN else Color.GRAY);
AddLabel(yes, "Look_To_Sell", if Sell then Color.RED else Color.GRAY);

def MomentumUP = Agreement_Level[1] < Agreement_Level;
def MomentumDOWN = Agreement_Level[1] > Agreement_Level;
AddLabel(yes, "Increasing Momentum", if MomentumUP then Color.GREEN else Color.GRAY);
AddLabel(yes, "Decreasing Momentum", if MomentumDOWN then Color.RED else Color.GRAY);

def conditionMR = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);
AddLabel(yes, "MEAN REVERSION", if conditionMR then Color.RED else Color.GRAY);

def conditionBO = ((Upper_BandS[1] < Upper_BandS) and (Lower_BandS[1] < Lower_BandS)) and ((Upper_BandK[1] < Upper_BandK) and (Lower_BandK[1] < Lower_BandK));
AddLabel(yes, "BREAKOUT", if conditionBO then Color.GREEN else Color.GRAY);

def conditionBD = ((Upper_BandS[1] > Upper_BandS) and (Lower_BandS[1] > Lower_BandS) and (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK));
AddLabel(yes, "BREAKDOWN", if conditionBD then Color.RED else Color.GRAY);

def Squeeze_Signal = Squeeze_Alert;
AddLabel(yes, "SQUEEZE ALERT", if Squeeze_Signal then Color.YELLOW else Color.GRAY);

CC: Confirmation Consensus

This is a new candle painting indicator CC Candles (Confirmation Consensus), that I have adapted from the original Confirmation Candles. The main difference between the two indicators is that Confirmation Candles confirms only positive factors for upward price movement, and CC Candles utilizes both positive and negative factors of price movement and weighs them against each other to derive the Consensus Level being above 0(up) or below 0 (down). There is a histagram style lower study that goes with it. Check it out! Big thanks to everyone trying out my work and giving feedback.

kaMjEs7.png


Code:
#(Consensus Confirmation) CC Candles V.1
#Created 04/28/2021 by Christopher84
#Based off of the Confirmation Candles Study. Main difference is that CC Candles weigh factors of positive and negative price movement to create the Consensus_Level. The Consensus_Level is considered positive if above zero and negative if below zero.

#Keltner Channel
declare upper;
def displace = 0;
input factorK = 2.0;
input lengthK = 20;
def price = close;
input averageType = AverageType.SIMPLE;
def trueRangeAverageType = AverageType.SIMPLE;
def BulgeLengthK = 150;
def SqueezeLengthK = 150;
def BulgeLengthK2 = 40;
def SqueezeLengthK2 = 40;
input BulgeLengthPrice = 75;
input SqueezeLengthPrice = 75;
input BulgeLengthPrice2 = 20;
input SqueezeLengthPrice2 = 20;


def shift = factorK * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengthK);
def averageK = MovingAverage(averageType, price, lengthK);
def AvgK = averageK[-displace];
def Upper_BandK = averageK[-displace] + shift[-displace];
def Lower_BandK = averageK[-displace] - shift[-displace];

def conditionK1 = price >= Upper_BandK;
def conditionK2 = (Upper_BandK[1] < Upper_BandK) and (Lower_BandK[1] < Lower_BandK);
def conditionK3D = price < Lower_BandK;
def conditionK4D = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);

def conditionK2L = (Upper_BandK[2] < Upper_BandK[1]) and (Lower_BandK[2] < Lower_BandK[1]);
def conditionK3L = (Upper_BandK[3] < Upper_BandK[2]) and (Lower_BandK[3] < Lower_BandK[2]);
def conditionK3 = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);

def BandwidthK = (Upper_BandK - Lower_BandK) / AvgK * 100;
def condition_BWKUP = BandwidthK[1] < BandwidthK;
def condition_BWKDOWN = BandwidthK[1] > BandwidthK;
def BulgeK = Highest(BandwidthK, BulgeLengthK);
def SqueezeK = Lowest(BandwidthK, SqueezeLengthK);
def BulgeK2 = Highest(BandwidthK, BulgeLengthK2);
def SqueezeK2 = Lowest(BandwidthK, SqueezeLengthK2);

plot BulgePrice = Highest(price, BulgeLengthPrice);
BulgePrice.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
plot SqueezePrice = Lowest(price, SqueezeLengthPrice);
SqueezePrice.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);

plot BulgePrice2 = Highest(price, BulgeLengthPrice2);
BulgePrice2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
BulgePrice2.SetStyle(Curve.SHORT_DASH);
plot SqueezePrice2 = Lowest(price, SqueezeLengthPrice2);
SqueezePrice2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
SqueezePrice2.SetStyle(Curve.SHORT_DASH);

#MACD with Price
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};
def MACDLevel = 0.0;

def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
def Value;
def Avg;
switch (MACD_AverageType) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = fastEMA - slowEMA;
    Avg = ExpAverage(Value, MACDLength);
}
def Diff = Value - Avg;
def Level = MACDLevel;

def condition1 = Value[1] <= Value;
def condition1D = Value[1] > Value;

#RSI
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 condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;
def condition2D = (RSI[3] > RSI) is true or (RSI < 20) is true;
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 MFIOverBought = MFIover_Bought;
def MFIOverSold = MFIover_Sold;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;
def condition3D = (MoneyFlowIndex[2] > MoneyFlowIndex) is true or (MoneyFlowIndex < 20) is true;
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 condition4 = (Intermed[1] <= Intermed) and (NearT >= MidLine);
def condition4D = (Intermed[1] > Intermed) and (NearT < MidLine);
def conditionOB3 = Intermed > FOB;
def conditionOS3 = Intermed < FOS;
def conditionOB4 = NearT > FOB;
def conditionOS4 = NearT < FOS;


#Pivot Signals
def n = 20;
def ticks = 2.0;
def bnOK = BarNumber() > n;
def isHigher = fold i = 1 to n + 1 with p = 1 while p do high > GetValue(high, -i);
def HH = if bnOK and isHigher and high == Highest(high, n) then high else Double.NaN;
def isLower = fold j = 1 to n + 1 with q = 1 while q do low < GetValue(low, -j);
def LL = if bnOK and isLower and low == Lowest(low, n) then low else Double.NaN;
def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

def UpPivotLow = !IsNaN(PivL);
#UpPivotLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#UpPivotLow.SetLineWeight(4);
#UpPivotLow.SetDefaultColor(Color.GREEN);

def DownPivotHigh = !IsNaN(PivH);
#DownPivotHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#DownPivotHigh.SetLineWeight(4);
#DownPivotHigh.SetDefaultColor(Color.RED);

def condition5 = !IsNaN(PivL);
def condition5D = !IsNaN(PivH);

#EMA_1
def EMA_length = 12;
def AvgExp = ExpAverage(price[-displace], EMA_length);

def condition6 = (price >= AvgExp) and (AvgExp[2] <= AvgExp);
def condition6D = (price < AvgExp) and (AvgExp[2] > AvgExp);

#EMA_2
def EMA_2length = 20;
def displace2 = 0;
def AvgExp2 = ExpAverage(price[-displace2], EMA_2length);

def condition7 = (price >= AvgExp2) and (AvgExp[2] <= AvgExp);
def condition7D = (price < AvgExp2) and (AvgExp[2] > AvgExp);

#DMI Oscillator
def DMI_length = 5;#Typically set to 10
input DMI_averageType = AverageType.WILDERS;
def diPlus = DMI(DMI_length, DMI_averageType)."DI+";
def diMinus = DMI(DMI_length, DMI_averageType)."DI-";
def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

def condition8 = Osc >= ZeroLine;
def condition8D = Osc < ZeroLine;

#Trend_Periods
def TP_fastLength = 3;#Typically 7
def TP_slowLength = 4;#Typically 15
def Periods = Sign(ExpAverage(close, TP_fastLength) - ExpAverage(close, TP_slowLength));

def condition9 = Periods > 0;
def condition9D = Periods < 0;

#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 condition10 = PFE > 0;
def condition10D = PFE < 0;
def conditionOB5 = PFE > UpperLevel;
def conditionOS5 = PFE < LowerLevel;


#Bollinger Bands PercentB
input BBPB_averageType = AverageType.SIMPLE;
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 condition11 = PercentB > HalfLine;
def condition11D = PercentB < HalfLine;
def conditionOB6 = PercentB > BBPB_OB;
def conditionOS6 = PercentB < BBPB_OS;


#STARC Bands
def ATR_length = 15;
def SMA_lengthS = 6;
def multiplier_factor = 1.5;
def valS = Average(price, SMA_lengthS);
def average_true_range = Average(TrueRange(high, close, low), length = ATR_length);
def Upper_BandS = valS[-displace] + multiplier_factor * average_true_range[-displace];
def Middle_BandS = valS[-displace];
def Lower_BandS = valS[-displace] - multiplier_factor * average_true_range[-displace];

def condition12 = (Upper_BandS[1] <= Upper_BandS) and (Lower_BandS[1] <= Lower_BandS);
def condition12D = (Upper_BandS[1] > Upper_BandS) and (Lower_BandS[1] > Lower_BandS);

#Klinger Histogram
def Klinger_Length = 8;
def KVOsc = KlingerOscillator(Klinger_Length).KVOsc;
def KVOH = KVOsc - Average(KVOsc, Klinger_Length);
def condition13 = (KVOH > 0) and (KVOsc[1] <= KVOsc);
def condition13D = (KVOH < 0) and (KVOsc[1] > KVOsc);

#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 condition14 = PROSC > 50;
def condition14D = PROSC < 50;
def conditionOB7 = PROSC > PROSC_OB;
def conditionOS7 = PROSC < PROSC_OS;


#Trend Confirmation Calculator
#Confirmation_Factor range 1-15.
input coloredCandlesOn = yes;
def Confirmation_Factor = 3;
#Use for testing conditions individually. Remove # from line below and change Confirmation_Factor to 1.
#def Agreement_Level = condition1;
def Agreement_LevelOB = 12;
def Agreement_LevelOS = 3;

def Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12 + condition13 + condition14 + conditionK1 + conditionK2;

def Agreement_LevelD = (condition1D + condition2D + condition3D + condition4D + condition5D + condition6D + condition7D + condition8D + condition9D + condition10D + condition11D + condition12D + condition13D + condition14D + conditionK3D + conditionK4D);

def Consensus_Level = Agreement_Level - Agreement_LevelD;

def conditionChannel1 = Upper_BandK > price;
def conditionChannel2 = Lower_BandK < price;

def UP = Consensus_Level >= 0;
def DOWN = Consensus_Level < 0;

AssignPriceColor(if coloredCandlesOn and UP then Color.LIGHT_GREEN else if coloredCandlesOn and DOWN then Color.RED else Color.CURRENT);

#Additional Signals

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

def Concensus_Line = OB_Level - OS_Level;
def Zero_Line = 0;
def Super_OB = 4;
def Super_OS = -2;

def DOWN_OB = (Agreement_Level > Agreement_LevelOB) and (Concensus_Line > Super_OB);
def UP_OS = (Agreement_Level < Agreement_LevelOS) and (Concensus_Line < Super_OS);

def OS_Buy = UP_OS;
def OB_Sell = DOWN_OB;
def neutral = Concensus_Line < Super_OB and Concensus_Line > Super_OS;

#AddVerticalLine (OS_Buy and !OS_Buy[1], close, Color.GREEN, Curve.SHORT_DASH);
#AddVerticalLine (Neutral and !neutral[1], close, Color.Gray, Curve.SHORT_DASH);
#AddVerticalLine (OB_Sell and OB_Sell and !OB_Sell[1], close, Color.RED, Curve.SHORT_DASH);

def Buy_Opportnity = if OS_Buy then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
#AddCloud(Buy_Opportnity, Neutral, Color.LIGHT_GREEN, Color.LIGHT_RED);
def Sell_Opportnity = if OB_Sell then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
#AddCloud(Sell_Opportnity, Neutral, Color.LIGHT_RED, Color.LIGHT_RED);

def OB_Signal = price crosses below Upper_BandK;
#OB_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#OB_Signal.SetLineWeight(1);
#OB_Signal.SetDefaultColor(Color.RED);

def OS_Signal = price crosses above Lower_BandK;
#OS_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#OS_Signal.SetLineWeight(1);
#OS_Signal.SetDefaultColor(Color.GREEN);

#Squeeze Alert
def length = 20;
def BulgeLength = 150;
def SqueezeLength = 150;
def upperBandBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
def lowerBandBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;
def midLineBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).MidLine;
def Bandwidth = (upperBandBB - lowerBandBB) / midLineBB * 100;
def Bulge = Highest(Bandwidth, BulgeLength);
def Squeeze = Lowest(Bandwidth, SqueezeLength);

plot Squeeze_Alert = Bandwidth <= Squeeze;
Squeeze_Alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Squeeze_Alert.SetLineWeight(3);
Squeeze_Alert.SetDefaultColor(Color.YELLOW);

#Trend Signals
#Bollinger_Bands2
input lengthBB = 10;
input Num_Dev_DnBB = -0.8;
input Num_Dev_upBB = 0.8;

def price1 = open;
def sDev = StDev(data = price[-displace], length = lengthBB);
def MidLineBB2 = MovingAverage(averageType, data = price[-displace], length = lengthBB);
def LowerBandBB2 = MidLineBB2 + Num_Dev_DnBB * sDev;
def UpperBandBB2 = MidLineBB2 + Num_Dev_upBB * sDev;


def condition_Slope_RevUP = ((Agreement_Level[1] < Agreement_Level) or (Agreement_Level[2] >= Agreement_Level[1])) or ((Concensus_Line[1] < Concensus_Line) and (Concensus_Line[2] >= Concensus_Line[1]));
def condition_Slope_RevDOWN = ((Agreement_Level[1] > Agreement_Level) and (Agreement_Level[2] <= Agreement_Level[1])) or ((Concensus_Line[1] > Concensus_Line) and (Concensus_Line[2] <= Concensus_Line[1]));
def condition_Flat = (Agreement_Level[2] == Agreement_Level[1]) or (Concensus_Line[2] == Concensus_Line[1]);
def condition_Flat2 = ((Agreement_Level[1] == Agreement_Level) and (Concensus_Line[1] == Concensus_Line));
def condition_Flat3 = ((Agreement_Level[1] == Agreement_Level) or (Concensus_Line[1] == Concensus_Line));
def condition_OB = ((Agreement_Level >= 12) or (Concensus_Line >= 2));# and (price > Upper_BandK));
def condition_OS = ((Agreement_Level <= 2) or (Concensus_Line <= -2));# and (price < lower_BandK)
def condition_AC_SlopeDOWN = (Agreement_Level[1] > Agreement_Level) or (Concensus_Line[1] > Concensus_Line);
def condition_AC_SlopeUP = (Agreement_Level[1] < Agreement_Level) or (Concensus_Line[1] < Concensus_Line);

plot UPConfirmSignal = Consensus_Level crosses above 0;
UPConfirmSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UPConfirmSignal.SetLineWeight(1);
UPConfirmSignal.SetDefaultColor(Color.GREEN);

plot DOWNConfirmSignal = Consensus_Level crosses below 0;
DOWNConfirmSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DOWNConfirmSignal.SetLineWeight(1);
DOWNConfirmSignal.SetDefaultColor(Color.RED);

plot Reversal_Buy_1 = (BandwidthK crosses below BulgeK2) and (condition_OS);
Reversal_Buy_1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Buy_1.SetLineWeight(3);
Reversal_Buy_1.SetDefaultColor(Color.GREEN);

plot Reversal_Buy2 = (BandwidthK crosses above SqueezeK) and (condition_OS);
#((Agreement_Level < 2) and Concensus_Line < 0) and condition_Slope_RevUP and conditionK2 and condition_BWKDOWN;
Reversal_Buy2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Buy2.SetLineWeight(3);
Reversal_Buy2.SetDefaultColor(Color.GREEN);

plot Reversal_Buy_3 = (BandwidthK == BulgeK) and (Concensus_Line < 0) and condition_AC_SlopeUP;
Reversal_Buy_3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Buy_3.SetLineWeight(3);
Reversal_Buy_3.SetDefaultColor(Color.GREEN);

plot Reversal_Sell_1 = ((Agreement_Level crosses below 10) and (Concensus_Line crosses below Super_OB) and (price > Middle_BandS));
Reversal_Sell_1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Sell_1.SetLineWeight(3);
Reversal_Sell_1.SetDefaultColor(Color.RED);

plot Reversal_Sell_2 = (BandwidthK crosses below BulgeK2) and (Concensus_Line >= 0) and (Agreement_Level >= 5) and (condition_Flat3 or condition_AC_SlopeDOWN);
Reversal_Sell_2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Sell_2.SetLineWeight(3);
Reversal_Sell_2.SetDefaultColor(Color.RED);

plot Reversal_Sell_3 = (BandwidthK == SqueezeK) and condition_OB;
Reversal_Sell_3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Sell_3.SetLineWeight(3);
Reversal_Sell_3.SetDefaultColor(Color.RED);

#plot Reversal_MeanReversion = conditionK3 and (price > UpperBandBB2);
#Reversal_MeanReversion.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
#Reversal_MeanReversion.SetLineWeight(3);
#Reversal_MeanReversion.SetDefaultColor(Color.RED);

def condition_Reversal_CA_Buy = (Agreement_Level < 1) and (Agreement_Level[1] <= Agreement_Level);
def condition_Reversal_SOS_Buy = (Concensus_Line < -2) and (Concensus_Line[1] <= Concensus_Line);
#plot Reversal_Buy = (condition_Reversal_CA_Buy) or (condition_Reversal_SOS_Buy);
#Reversal_Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
#Reversal_Buy.SetLineWeight(1);
#Reversal_Buy.SetDefaultColor(Color.LIGHT_GRAY);

#Labels
def Buy = UP_OS;
def Sell = DOWN_OB;
AddLabel(yes, "Look_To_Buy", if Buy then Color.GREEN else Color.GRAY);
AddLabel(yes, "Look_To_Sell", if Sell then Color.RED else Color.GRAY);

def MomentumUP = Agreement_Level[1] < Agreement_Level;
def MomentumDOWN = Agreement_Level[1] > Agreement_Level;
AddLabel(yes, "Increasing Momentum", if MomentumUP then Color.GREEN else Color.GRAY);
AddLabel(yes, "Decreasing Momentum", if MomentumDOWN then Color.RED else Color.GRAY);

def conditionMR = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);
AddLabel(yes, "MEAN REVERSION", if conditionMR then Color.RED else Color.GRAY);

def conditionBO = ((Upper_BandS[1] < Upper_BandS) and (Lower_BandS[1] < Lower_BandS)) and ((Upper_BandK[1] < Upper_BandK) and (Lower_BandK[1] < Lower_BandK));
AddLabel(yes, "BREAKOUT", if conditionBO then Color.GREEN else Color.GRAY);

def conditionBD = ((Upper_BandS[1] > Upper_BandS) and (Lower_BandS[1] > Lower_BandS) and (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK));
AddLabel(yes, "BREAKDOWN", if conditionBD then Color.RED else Color.GRAY);

def Squeeze_Signal = Squeeze_Alert;
AddLabel(yes, "SQUEEZE ALERT", if Squeeze_Signal then Color.YELLOW else Color.GRAY);

Here's the lower study.
Code:
#CC Candles Lower V.1
#Created 04/28/2021 by Christopher84


#Keltner Channel
declare lower;
def displace = 0;
input factorK = 2.0;
input lengthK = 20;
def price = close;
input averageType = AverageType.SIMPLE;
def trueRangeAverageType = AverageType.SIMPLE;
def BulgeLengthK = 150;
def SqueezeLengthK = 150;
def BulgeLengthK2 = 40;
def SqueezeLengthK2 = 40;
input BulgeLengthPrice = 75;
input SqueezeLengthPrice = 75;
input BulgeLengthPrice2 = 20;
input SqueezeLengthPrice2 = 20;
input BulgeLengthCC = 40;
input SqueezeLengthCC = 40;
input BulgeLengthCC2 = 8;
input SqueezeLengthCC2 = 8;

def shift = factorK * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengthK);
def averageK = MovingAverage(averageType, price, lengthK);
def AvgK = averageK[-displace];
def Upper_BandK = averageK[-displace] + shift[-displace];
def Lower_BandK = averageK[-displace] - shift[-displace];

def conditionK1 = price >= Upper_BandK;
def conditionK2 = (Upper_BandK[1] < Upper_BandK) and (Lower_BandK[1] < Lower_BandK);
def conditionK3D = price < Lower_BandK;
def conditionK4D = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);

def conditionK2L = (Upper_BandK[2] < Upper_BandK[1]) and (Lower_BandK[2] < Lower_BandK[1]);
def conditionK3L = (Upper_BandK[3] < Upper_BandK[2]) and (Lower_BandK[3] < Lower_BandK[2]);
def conditionK3 = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);

def BandwidthK = (Upper_BandK - Lower_BandK) / AvgK * 100;
def condition_BWKUP = BandwidthK[1] < BandwidthK;
def condition_BWKDOWN = BandwidthK[1] > BandwidthK;
def BulgeK = Highest(BandwidthK, BulgeLengthK);
def SqueezeK = Lowest(BandwidthK, SqueezeLengthK);
def BulgeK2 = Highest(BandwidthK, BulgeLengthK2);
def SqueezeK2 = Lowest(BandwidthK, SqueezeLengthK2);

#plot BulgePrice = Highest(price, BulgeLengthPrice);
#BulgePrice.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
#plot SqueezePrice = Lowest(price, SqueezeLengthPrice);
#SqueezePrice.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);

#plot BulgePrice2 = Highest(price, BulgeLengthPrice2);
#BulgePrice2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
#BulgePrice2.SetStyle(Curve.SHORT_DASH);
#plot SqueezePrice2 = Lowest(price, SqueezeLengthPrice2);
#SqueezePrice2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
#SqueezePrice2.SetStyle(Curve.SHORT_DASH);

#MACD with Price
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};
def MACDLevel = 0.0;

def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
def Value;
def Avg;
switch (MACD_AverageType) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = fastEMA - slowEMA;
    Avg = ExpAverage(Value, MACDLength);
}
def Diff = Value - Avg;
def Level = MACDLevel;

def condition1 = Value[1] <= Value;
def condition1D = Value[1] > Value;

#RSI
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 condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;
def condition2D = (RSI[3] > RSI) is true or (RSI < 20) is true;
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 MFIOverBought = MFIover_Bought;
def MFIOverSold = MFIover_Sold;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;
def condition3D = (MoneyFlowIndex[2] > MoneyFlowIndex) is true or (MoneyFlowIndex < 20) is true;
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 condition4 = (Intermed[1] <= Intermed) and (NearT >= MidLine);
def condition4D = (Intermed[1] > Intermed) and (NearT < MidLine);
def conditionOB3 = Intermed > FOB;
def conditionOS3 = Intermed < FOS;
def conditionOB4 = NearT > FOB;
def conditionOS4 = NearT < FOS;


#Pivot Signals
def n = 20;
def ticks = 2.0;
def bnOK = BarNumber() > n;
def isHigher = fold i = 1 to n + 1 with p = 1 while p do high > GetValue(high, -i);
def HH = if bnOK and isHigher and high == Highest(high, n) then high else Double.NaN;
def isLower = fold j = 1 to n + 1 with q = 1 while q do low < GetValue(low, -j);
def LL = if bnOK and isLower and low == Lowest(low, n) then low else Double.NaN;
def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

def UpPivotLow = !IsNaN(PivL);
#UpPivotLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#UpPivotLow.SetLineWeight(4);
#UpPivotLow.SetDefaultColor(Color.GREEN);

def DownPivotHigh = !IsNaN(PivH);
#DownPivotHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#DownPivotHigh.SetLineWeight(4);
#DownPivotHigh.SetDefaultColor(Color.RED);

def condition5 = !IsNaN(PivL);
def condition5D = !IsNaN(PivH);

#EMA_1
def EMA_length = 12;
def AvgExp = ExpAverage(price[-displace], EMA_length);

def condition6 = (price >= AvgExp) and (AvgExp[2] <= AvgExp);
def condition6D = (price < AvgExp) and (AvgExp[2] > AvgExp);

#EMA_2
def EMA_2length = 20;
def displace2 = 0;
def AvgExp2 = ExpAverage(price[-displace2], EMA_2length);

def condition7 = (price >= AvgExp2) and (AvgExp[2] <= AvgExp);
def condition7D = (price < AvgExp2) and (AvgExp[2] > AvgExp);

#DMI Oscillator
def DMI_length = 5;#Typically set to 10
input DMI_averageType = AverageType.WILDERS;
def diPlus = DMI(DMI_length, DMI_averageType)."DI+";
def diMinus = DMI(DMI_length, DMI_averageType)."DI-";
def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

def condition8 = Osc >= ZeroLine;
def condition8D = Osc < ZeroLine;

#Trend_Periods
def TP_fastLength = 3;#Typically 7
def TP_slowLength = 4;#Typically 15
def Periods = Sign(ExpAverage(close, TP_fastLength) - ExpAverage(close, TP_slowLength));

def condition9 = Periods > 0;
def condition9D = Periods < 0;

#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 condition10 = PFE > 0;
def condition10D = PFE < 0;
def conditionOB5 = PFE > UpperLevel;
def conditionOS5 = PFE < LowerLevel;


#Bollinger Bands PercentB
input BBPB_averageType = AverageType.SIMPLE;
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 condition11 = PercentB > HalfLine;
def condition11D = PercentB < HalfLine;
def conditionOB6 = PercentB > BBPB_OB;
def conditionOS6 = PercentB < BBPB_OS;


#STARC Bands
def ATR_length = 15;
def SMA_lengthS = 6;
def multiplier_factor = 1.5;
def valS = Average(price, SMA_lengthS);
def average_true_range = Average(TrueRange(high, close, low), length = ATR_length);
def Upper_BandS = valS[-displace] + multiplier_factor * average_true_range[-displace];
def Middle_BandS = valS[-displace];
def Lower_BandS = valS[-displace] - multiplier_factor * average_true_range[-displace];

def condition12 = (Upper_BandS[1] <= Upper_BandS) and (Lower_BandS[1] <= Lower_BandS);
def condition12D = (Upper_BandS[1] > Upper_BandS) and (Lower_BandS[1] > Lower_BandS);

#Klinger Histogram
def Klinger_Length = 8;
def KVOsc = KlingerOscillator(Klinger_Length).KVOsc;
def KVOH = KVOsc - Average(KVOsc, Klinger_Length);
def condition13 = (KVOH > 0) and (KVOsc[1] <= KVOsc);
def condition13D = (KVOH < 0) and (KVOsc[1] > KVOsc);

#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 condition14 = PROSC > 50;
def condition14D = PROSC < 50;
def conditionOB7 = PROSC > PROSC_OB;
def conditionOS7 = PROSC < PROSC_OS;


#Trend Confirmation Calculator
#Confirmation_Factor range 1-15.
input coloredCandlesOn = no;
input Confirmation_Factor = 3;
#Use for testing conditions individually. Remove # from line below and change Confirmation_Factor to 1.
#def Agreement_Level = condition1;
def Agreement_LevelOB = 12;
def Agreement_LevelOS = 3;

def Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12 + condition13 + condition14 + conditionK1 + conditionK2;

def Agreement_LevelD = (condition1D + condition2D + condition3D + condition4D + condition5D + condition6D + condition7D + condition8D + condition9D + condition10D + condition11D + condition12D + condition13D + condition14D + conditionK3D + conditionK4D);

plot Consensus_Level = Agreement_Level - Agreement_LevelD;

def conditionChannel1 = Upper_BandK > price;
def conditionChannel2 = Lower_BandK < price;

def UP = Consensus_Level >= 0;
def DOWN = Consensus_Level < 0;

Consensus_Level.AssignValueColor(
if Consensus_Level > Consensus_Level[1] and Consensus_Level >= 0 then Color.LIGHT_GREEN
else if Consensus_Level < Consensus_Level[1] and Consensus_Level >= 0 then Color.LIGHT_GREEN
else if Consensus_Level < Consensus_Level[1] and Consensus_Level < 0 then Color.RED else
if Consensus_Level > Consensus_Level[1] and Consensus_Level < 0 then Color.RED
else Color.GRAY);

def Zero_Line = 0;
#Zero_Line.SetStyle(Curve.SHORT_DASH);
#Zero_Line.SetLineWeight(1);
#Zero_Line.SetDefaultColor(Color.Gray);

plot BulgeCC = Highest(Consensus_Level, BulgeLengthCC);
BulgeCC.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);

plot SqueezeCC = Lowest(Consensus_Level, SqueezeLengthCC);
SqueezeCC.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);

plot BulgeCC2 = Highest(Consensus_Level, BulgeLengthCC2);
BulgeCC2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
BulgeCC2.SetStyle(Curve.SHORT_DASH);

plot SqueezeCC2 = Lowest(Consensus_Level, SqueezeLengthCC2);
SqueezeCC2.AssignValueColor(if (conditionK2) then Color.GREEN else if (conditionK3) then Color.RED else Color.GRAY);
SqueezeCC2.SetStyle(Curve.SHORT_DASH);
Hey been testing out this indicator and definitely some good signals...i was wonderin if you could expand on what the dots mean....i get green dots on the 5 min that appear on the candles as it trades...what are these signaling?
 
Hey been testing out this indicator and definitely some good signals...i was wonderin if you could expand on what the dots mean....i get green dots on the 5 min that appear on the candles as it trades...what are these signaling?
The green dots represent potential reversal buy signals. The red dots represent potential reversal Sell Signals or opportunities to take profit. I’ve also found that it’s not uncommon for price to come back to the levels where the signals fire support support or resistance.
 
The green dots represent potential reversal buy signals. The red dots represent potential reversal Sell Signals or opportunities to take profit. I’ve also found that it’s not uncommon for price to come back to the levels where the signals fire support support or resistance.
really cool yeah....when you had time if you could detail more of the labels and stuff too interms of what they mean which i am sure are valuable but just not sure whatt they are telling you....if you had time to really describe everything (i hadnt seen a post like that) woul be great! thanks for your hard work!
 
really cool yeah....when you had time if you could detail more of the labels and stuff too interms of what they mean which i am sure are valuable but just not sure whatt they are telling you....if you had time to really describe everything (i hadnt seen a post like that) woul be great! thanks for your hard work!
Hi Nicksmo,
This is on pg.4 of this thread. You might find it useful. Let me know if you have any additional questions.
L1Ql7aD.png
 
Thanks for sharing the code. I am using the V8 version and trying to build up a scanner using the following
Code:
shared_confirmation_candle()."Reversal_Buy_1" is true

but getting the following error

Code:
com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data.


Any way to pass this error. Thanks
 
@Christopher84, I appreciate the improvements you've made to your indicator. Thank you! Here's a 5 min ES chart. As you can see, it did a nice job finding a long and a short between 1:30 and 4pm. About 6pm, the MACD BB indicated a potential long, but your indicator made it easy to disregard that and watch for a short entry.

Thank you again for sharing your work! And for making it easy to adjust the display so that my upper chart can stay uncluttered.

How can I get the script for this lower indicator shown in the image below? Thanks very much!
share.svg


AlRxrGhl.jpg
 
Here's the code for the watchlist. I like to sort this column in my watchlist to show potential OB/OS conditions within my list. Remember, it may take 24 hours before it loads properly. After that, you should be good.

Code:
#Confirmation Level Lower Watchlist developed 04/15/2021 by Christopher Wilson
#Select the level of agreement among the 13 indicators included.

#MACD with Price

declare lower;
def price = close;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};
def MACDLevel = 0.0;

def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
def Value;
def Avg;

switch (MACD_AverageType) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = fastEMA - slowEMA;
    Avg = ExpAverage(Value, MACDLength);}
def Diff = Value - Avg;
def Level = MACDLevel;

def condition1 = Value[1] <= Value;

#RSI

input RSI_length = 14;
input RSI_AverageType = AverageType.WILDERS;


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 condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;

#MFI

input 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 MFIOverBought = MFIover_Bought;
def MFIOverSold = MFIover_Sold;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;

#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 condition4 = (Intermed[1] <= Intermed) and (NearT >= MidLine);

#VWAP_Pivot Signals
def n = 20;
def ticks = 2.0;
def bnOK = barNumber() > n;
def isHigher = fold i = 1 to n + 1 with p = 1 while p do high > GetValue(high, -i);
def HH = if bnOK and isHigher and high == Highest(high, n)then high else Double.NaN;
def isLower = fold j = 1 to n + 1 with q = 1 while q do low < GetValue(low, -j);
def LL = if bnOK and isLower and low == Lowest(low, n) then low else Double.NaN;
def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

def UpPivotLow = !isNaN(PivL);
def DownPivotHigh = !isNaN(PivH);

def condition5 = !isNaN(PivL);

#EMA_1
input EMA_length = 12;
def displace = 0;
def AvgExp = ExpAverage(price[-displace], EMA_length);

def condition6 = (price >= AvgExp) and (AvgExp[2] <= AvgExp);

#EMA_2
input EMA_2length = 20;
def displace2 = 0;
def AvgExp2 = ExpAverage(price[-displace2], EMA_2length);

def condition7 = (price >= AvgExp2) and (AvgExp2[2] <= AvgExp2);

#DMI Oscillator
input DMI_length = 5;
input averageType = AverageType.WILDERS;

def diPlus = DMI(DMI_length, averageType)."DI+";
def diMinus = DMI(DMI_length, averageType)."DI-";

def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

def condition8 = Osc >= ZeroLine;

#Trend_Periods

input TP_fastLength = 3;
input TP_slowLength = 4;

def Periods = sign(ExpAverage(close, TP_fastLength) - ExpAverage(close, TP_slowLength));

def condition9 = Periods > 0;

#Polarized Fractal Efficiency

input PFE_length = 5;
input smoothingLength = 2.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 condition10 = PFE > ZERoLine;

#Bollinger Bands PercentB

input BBPB_averageType = AverageType.Simple;
input BBPB_length = 5;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.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 condition11 = PercentB > 50;

#STARC Bands
def ATR_length = 15;
def SMA_lengthS = 6;
def multiplier_factor = 1.5;
def valS = Average(price, SMA_lengthS);
def average_true_range = Average(TrueRange(high, close, low), length = ATR_length);
def Upper_BandS = valS[-displace] + multiplier_factor * average_true_range[-displace];
def Middle_BandS = valS[-displace];
def Lower_BandS = valS[-displace] - multiplier_factor * average_true_range[-displace];

def condition12 = (Upper_BandS[1] <= Upper_BandS) and (Lower_BandS[1] <= Lower_BandS);


#Trend Confirmation
#Confirmation_Factor range 1-12.

input Confirmation_Factor = 6;
#Use for testing conditions individually.
#def Agreement_Level = condition1;
plot Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12;

def Sell_Alert = Agreement_Level >= 9;
def Buy_Alert = Agreement_Level <= 2 ;


def Factor_Line = Confirmation_Factor;

AssignBackgroundColor(if Sell_Alert then color.LIGHT_RED else if Buy_Alert then color.dark_green else color.black);
For the watchlist I added this as a custom code in my current watchlist, can you tell me whhat the #s mean example 0, 1, 2, then also the colors?

Looking at the last code i think Red means time to sell, and Dark Green time to buy, black is just in between?
 
For the watchlist I added this as a custom code in my current watchlist, can you tell me whhat the #s mean example 0, 1, 2, then also the colors?

Looking at the last code i think Red means time to sell, and Dark Green time to buy, black is just in between?
The #'s are indicating the confirmation level. The red means that it is in a potential OB zone. The green means that it is in a potential OS zone. I like to use that in conjunction with the Super OB/OS in my watchlist to catch some nice setups when the indicators are in agreement on OB/OS condition (shown with blue rectangles in image below). Here's the Super OB/OS code for the watchlist. If you put the columns together in your watchlist and sort by the confirmation level column, it gives a nice picture of OS/OB conditions in your watchlist.
yhKW9aS.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;

def Zero_Line = 0;
def Super_OB = 4;
def Super_OS = -2;

def OB = Concensus_Line >= Super_OB;
def OS = Concensus_Line <= Super_OS;

AssignBackgroundColor(if OB then color.light_red else if OS then color.dark_green else color.black);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
271 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top