Divergence Histogram for Many Indicator for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
sVverAp.png

Author Message:

This script analyses divergences for 11 predefined indicators and then draws column on the graph. Red columns for negative divergence (means prices may go down or trend reversal), Lime columns for positive divergences (means prices may go up or trend reversal)

The script uses Pivot Points and on each bar it checks divergence between last Pivot Point and current High/Low and if it finds any divergence then immediately draws column. There is no Latency/Lag.

There are predefined 11 indicators in the script, which are RSI , MACD , MACD Histogram, Stochastic , CCI , Momentum, OBV, Diosc, VWMACD, CMF and MFI.

CODE:

CSS:
#// Indicator for TOS
#// © LonesomeTheBlue
#study("Divergence Histogram for many indicator", overlay=false, max_bars_back = 4000)
# Converted by Sam4Cok@Samer800 - 08/2024
Declare lower;

input PivotPointPeriod = 5;                  # "Pivot Point Period"
input MinimumNoOfDivergence = 1;             # "Minimum #Num of Divergence for Alert"
input CheckCutThroughInIndicators = no;      # "Check Cut-Through in indicators"

def na = Double.NaN;
def chcut = CheckCutThroughInIndicators;
def lrb = Min(Max(PivotPointPeriod, 1), 19);
#-- Color
DefineGlobalColor("up", CreateColor(0, 230, 118));
DefineGlobalColor("dn", CreateColor(255, 82, 82));
script Pivots {
    input series    = close;
    input leftBars  = 10;
    input rightBars = 10;
    input isHigh = yes;
    def na = Double.NaN;
    def HH = series == Highest(series, leftBars + 1);
    def LL = series == Lowest(series, leftBars + 1);
    def pivotRange = (leftBars + rightBars + 1);
    def leftEdgeValue = if series[pivotRange] == 0 then na else series[pivotRange];
    def pvtCond = !IsNaN(series) and !IsNaN(leftEdgeValue);
    def barIndexH = if pvtCond then
                    fold i = 1 to rightBars + 1 with p=1 while p do
                    series > GetValue(series, - i) else na;
    def barIndexL = if pvtCond then
                    fold j = 1 to rightBars + 1 with q=1 while q do
                    series < GetValue(series, - j) else na;
    def PivotPoint;
    if isHigh {
        PivotPoint = if HH and barIndexH then series else na;
    } else {
        PivotPoint = if LL and barIndexL then series else na;
    }
    plot pvt = PivotPoint;
}
#vwma(source, length)
script VWMA {
input src = close;
input len = 14;
input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    Plot result = VWMA;
}
# stoch(source, high, low, length) =>
script stoch {
    input src = close;
    input h = high;
    input l = low;
    input len = 14;
    def hh = Highest(h, len);
    def ll = Lowest(l, len);
    def stoch = 100 * (src - ll) / (hh - ll);
    plot return = if IsNaN(stoch) then 0 else stoch;
}
#mfi(src, length) =>
script mfi {
    input src = hlc3;
    input length = 14;
    input v = volume;
    def diff = src - src[1];
    def upper = Sum(v * (if diff <= 0 then 0 else src), length);
    def lower = Sum(v * (if diff >= 0 then 0 else src), length);
    def mfi = 100 - (100 / (1 + upper / lower));
    def mfiVal = if IsNaN(mfi) then mfiVal[1] else mfi;
    plot return = mfiVal;
}
#// check cut-through in indicators
script nocut1 {
    input indi = close;
    input len = 5;
    def src = if isNaN(GetValue(indi, len)) then 0 else GetValue(indi, len);
    def ln = indi - ((indi - src) / len);
    def ln1 = (indi - src) / len;
    def _ret = fold x = 1 to len - 1 with p=1 while p do
               GetValue(indi, x) <= (fold x1 = 1 to x with p1= ln do p1 - ln1);
    plot out = if isNaN(_ret) then 0 else _ret;
}
#// check cut-through in indicators
script nocut2 {
    input indi = close;
    input len = 5;
    def src = if isNaN(GetValue(indi, len)) then 0 else GetValue(indi, len);
    def ln = indi - ((indi - src) / len);
    def ln1 = (indi - src) / len;
    def _ret = fold x = 1 to len - 1 with p=1 while p do
               GetValue(indi, x) >= (fold x1 = 1 to x with p1= ln do p1 - ln1);
    plot out = if isNaN(_ret) then 0 else _ret;
}
script negadiv {
    input indi = close;
    input isok = no;
    input emptyh = no;
    input chcut  = no;
    input newtop = no;
    input topc = 5;
    def src = if isNaN(GetValue(indi, topc)) then 0 else GetValue(indi, topc);
    def cond = src > indi;
    def _ret = emptyh and !IsNaN(newtop) and cond and (!chcut or isok);
    plot out = if isNaN(_ret) then 0 else _ret;
}
script posidiv {
    input indi = close;
    input isok = no;
    input emptyl = no;
    input chcut  = no;
    input newbot = no;
    input botc = 5;
    def src = if isNaN(GetValue(indi, botc)) then 0 else GetValue(indi, botc);
    def cond = src < indi;
    def _ret = emptyl and !IsNaN(newbot) and cond and (!chcut or isok);
    plot out = if isNaN(_ret) then 0 else _ret;
}

#// RSI
def rsi = RSI(Price = close, length = 14);
#// MACD
def fastMACD = ExpAverage(close, 12);
def slowMACD = ExpAverage(close, 26);
def macd = fastMACD - slowMACD;
def sigLine = ExpAverage(macd, 9);
def deltamacd = macd - sigLine;
#// Momentum
def moment = close - close[10];
#// CCI
def avgCCI = Average(close, 10);
def linDev = LinDev(close, 10);
def CCI = if linDev == 0 then 0 else (close - avgCCI) / linDev / 0.015;
#// OBV
def Obv = TotalSum(Sign(close - close[1]) * volume);
#// Stoch
def stk = Average(stoch(close, high, low, 14), 3);
#// DIOSC
def DI = (high - high[1]) - (-(low - low[1]));
def trur = ATR(Length = 14);
def diosc1 = 100 * WildersAverage(DI, 14) / trur;
def diosc = if IsNaN(diosc1) then diosc[1] else diosc1;
#// volume weighted macd
def maFast = vwma(close, 12);
def maSlow = vwma(close, 26);
def vwmacd = maFast - maSlow;
#// Chaikin money flow
def Cmfm = (close - low - (high - close)) / (high - low);
def Cmfv = Cmfm * volume;
def cmf = Average(Cmfv, 21) / Average(volume, 21);
#// Moneyt Flow Index
def Mfi = mfi(close, 14);

# cal

def top = pivots(high[lrb], lrb, lrb, yes);
def bot = pivots(low[lrb], lrb, lrb, no);

def topc1 = if !IsNaN(top) then lrb else topc1[1] + 1;
def topc  = if topc1 < lrb then lrb else topc1;
def botc1 = if !IsNaN(bot) then lrb else botc1[1] + 1;
def botc  = if botc1 < lrb then lrb else botc1;

#// Negative Divergence (checking possible higher highs(lb=0))
def newtop = pivots(high, lrb, 0, yes); #  // check only left side
def hline = newtop - ((newtop - GetValue(high, topc)) / topc);
def diffN = (newtop - GetValue(high, topc)) / topc;
def emptyh = if !IsNaN(newtop) and newtop > GetValue(high, topc) then
             fold x = 1 to topc - 1 with p=1 while p do
             GetValue(close, x) <= (fold x1 = 1 to x with p1=hline do p1 - diffN) else no;
#// Positive Divergence (checking possible Lower lows(lb=0))
def newbot = pivots(low, lrb, 0, no); #  // check only left side
def lline  = newbot - ((newbot - GetValue(low, botc)) / botc);
def diffP  = (newbot - GetValue(low, botc)) / botc;
def emptyl = if !IsNaN(newbot) and newbot < GetValue(low, botc) then
             fold y = 1 to botc - 1 with q=1 while q do
             GetValue(close, y) >= (fold y1 = 1 to y with q1=lline do q1 - diffP) else no;
#--
def rsiokn = nocut1(rsi, topc);
def macdokn = nocut1(macd, topc);
def deltamacdokn = nocut1(deltamacd, topc);
def momentokn = nocut1(moment, topc);
def cciokn = nocut1(cci, topc);
def obvokn = nocut1(Obv, topc);
def stkokn = nocut1(stk, topc);
def dioscokn = nocut1(diosc, topc);
def vwmacdokn = nocut1(vwmacd, topc);
def cmfokn = nocut1(cmf, topc);
def mfiokn = nocut1(Mfi, topc);
#--
def rsiokp = nocut2(rsi, botc);
def macdokp = nocut2(macd, botc);
def deltamacdokp = nocut2(deltamacd, botc);
def momentokp = nocut2(moment, botc);
def cciokp = nocut2(cci, botc);
def obvokp = nocut2(Obv, botc);
def stkokp = nocut2(stk, botc);
def dioscokp = nocut2(diosc, botc);
def vwmacdokp = nocut2(vwmacd, botc);
def cmfokp = nocut2(cmf, botc);
def mfiokp = nocut2(Mfi, botc);
#--
def posidiv_1 = posidiv(rsi, rsiokp, emptyl, chcut, newbot, botc);
def negadiv_1 = negadiv(rsi, rsiokn, emptyh, chcut, newtop, topc);
def iff_1 = if negadiv_1 then -1 else 0;
def indi1 = if posidiv_1 then  1 else iff_1;
def posidiv_2 = posidiv(macd, macdokp, emptyl, chcut, newbot, botc);
def negadiv_2 = negadiv(macd, macdokn, emptyh, chcut, newtop, topc);
def iff_2 = if negadiv_2 then -1 else 0;
def indi2 = if posidiv_2 then 1 else iff_2;
def posidiv_3 = posidiv(deltamacd, deltamacdokp, emptyl, chcut, newbot, botc);
def negadiv_3 = negadiv(deltamacd, deltamacdokn, emptyh, chcut, newtop, topc);
def iff_3 = if negadiv_3 then -1 else 0;
def indi3 = if posidiv_3 then 1 else iff_3;
def posidiv_4 = posidiv(moment, momentokp, emptyl, chcut, newbot, botc);
def negadiv_4 = negadiv(moment, momentokn, emptyh, chcut, newtop, topc);
def iff_4 = if negadiv_4 then -1 else 0;
def indi4 = if posidiv_4 then 1 else iff_4;
def posidiv_5 = posidiv(cci, cciokp, emptyl, chcut, newbot, botc);
def negadiv_5 = negadiv(cci, cciokn, emptyh, chcut, newtop, topc);
def iff_5 = if negadiv_5 then -1 else 0;
def indi5 = if posidiv_5 then 1 else iff_5;
def posidiv_6 = posidiv(Obv, obvokp, emptyl, chcut, newbot, botc);
def negadiv_6 = negadiv(Obv, obvokn, emptyh, chcut, newtop, topc);
def iff_6 = if negadiv_6 then -1 else 0;
def indi6 = if posidiv_6 then 1 else iff_6;
def posidiv_7 = posidiv(stk, stkokp, emptyl, chcut, newbot, botc);
def negadiv_7 = negadiv(stk, stkokn, emptyh, chcut, newtop, topc);
def iff_7 = if negadiv_7 then -1 else 0;
def indi7 = if posidiv_7 then 1 else iff_7;
def posidiv_8 = posidiv(diosc, dioscokp, emptyl, chcut, newbot, botc);
def negadiv_8 = negadiv(diosc, dioscokn, emptyh, chcut, newtop, topc);
def iff_8 = if negadiv_8 then -1 else 0;
def indi8 = if posidiv_8 then 1 else iff_8;
def posidiv_9 = posidiv(vwmacd, vwmacdokp, emptyl, chcut, newbot, botc);
def negadiv_9 = negadiv(vwmacd, vwmacdokn, emptyh, chcut, newtop, topc);
def iff_9 = if negadiv_9 then -1 else 0;
def indi9 = if posidiv_9 then 1 else iff_9;
def posidiv_10 = posidiv(cmf, cmfokp, emptyl, chcut, newbot, botc);
def negadiv_10 = negadiv(cmf, cmfokn, emptyh, chcut, newtop, topc);
def iff_10 = if negadiv_10 then -1 else 0;
def indi10 = if posidiv_10 then 1 else iff_10;
def posidiv_11 = posidiv(Mfi, mfiokp, emptyl, chcut, newbot, botc);
def negadiv_11 = negadiv(Mfi, mfiokn, emptyh, chcut, newtop, topc);
def iff_11 = if negadiv_11 then -1 else 0;
def indi11 = if posidiv_11 then 1 else iff_11;

def totaldiv = indi1 + indi2 + indi3 + indi4 + indi5 + indi6 + indi7 + indi8 + indi9 + indi10 + indi11;
def col = if totaldiv > 0 then 1 else if totaldiv < 0 then -1  else 0;
plot divHist = if col then if AbsValue(totaldiv) >= MinimumNoOfDivergence then AbsValue(totaldiv) else na else na;
plot hiL =  if !isNaN(close) then 11 else na;
plot mid =  if !isNaN(close) then MinimumNoOfDivergence else na;
plot zero = if !isNaN(close) then 0 else na;
hiL.SetStyle(Curve.SHORT_DASH);
mid.SetStyle(Curve.SHORT_DASH);
hiL.SetDefaultColor(Color.DARK_GRAY);
mid.SetDefaultColor(Color.DARK_GRAY);
zero.SetDefaultColor(Color.GRAY);
divHist.SetLineWeight(5);
divHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
divHist.AssignValueColor(if col > 0 then GlobalColor("up") else GlobalColor("dn"));

AddChartBubble(col, divHist + 0.25, divHist, if col > 0 then Color.GREEN else Color.RED);


#-- END of CODE
 
sVverAp.png

Author Message:

This script analyses divergences for 11 predefined indicators and then draws column on the graph. Red columns for negative divergence (means prices may go down or trend reversal), Lime columns for positive divergences (means prices may go up or trend reversal)

The script uses Pivot Points and on each bar it checks divergence between last Pivot Point and current High/Low and if it finds any divergence then immediately draws column. There is no Latency/Lag.

There are predefined 11 indicators in the script, which are RSI , MACD , MACD Histogram, Stochastic , CCI , Momentum, OBV, Diosc, VWMACD, CMF and MFI.

CODE:

CSS:
#// Indicator for TOS
#// © LonesomeTheBlue
#study("Divergence Histogram for many indicator", overlay=false, max_bars_back = 4000)
# Converted by Sam4Cok@Samer800 - 08/2024
Declare lower;

input PivotPointPeriod = 5;                  # "Pivot Point Period"
input MinimumNoOfDivergence = 1;             # "Minimum #Num of Divergence for Alert"
input CheckCutThroughInIndicators = no;      # "Check Cut-Through in indicators"

def na = Double.NaN;
def chcut = CheckCutThroughInIndicators;
def lrb = Min(Max(PivotPointPeriod, 1), 19);
#-- Color
DefineGlobalColor("up", CreateColor(0, 230, 118));
DefineGlobalColor("dn", CreateColor(255, 82, 82));
script Pivots {
    input series    = close;
    input leftBars  = 10;
    input rightBars = 10;
    input isHigh = yes;
    def na = Double.NaN;
    def HH = series == Highest(series, leftBars + 1);
    def LL = series == Lowest(series, leftBars + 1);
    def pivotRange = (leftBars + rightBars + 1);
    def leftEdgeValue = if series[pivotRange] == 0 then na else series[pivotRange];
    def pvtCond = !IsNaN(series) and !IsNaN(leftEdgeValue);
    def barIndexH = if pvtCond then
                    fold i = 1 to rightBars + 1 with p=1 while p do
                    series > GetValue(series, - i) else na;
    def barIndexL = if pvtCond then
                    fold j = 1 to rightBars + 1 with q=1 while q do
                    series < GetValue(series, - j) else na;
    def PivotPoint;
    if isHigh {
        PivotPoint = if HH and barIndexH then series else na;
    } else {
        PivotPoint = if LL and barIndexL then series else na;
    }
    plot pvt = PivotPoint;
}
#vwma(source, length)
script VWMA {
input src = close;
input len = 14;
input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    Plot result = VWMA;
}
# stoch(source, high, low, length) =>
script stoch {
    input src = close;
    input h = high;
    input l = low;
    input len = 14;
    def hh = Highest(h, len);
    def ll = Lowest(l, len);
    def stoch = 100 * (src - ll) / (hh - ll);
    plot return = if IsNaN(stoch) then 0 else stoch;
}
#mfi(src, length) =>
script mfi {
    input src = hlc3;
    input length = 14;
    input v = volume;
    def diff = src - src[1];
    def upper = Sum(v * (if diff <= 0 then 0 else src), length);
    def lower = Sum(v * (if diff >= 0 then 0 else src), length);
    def mfi = 100 - (100 / (1 + upper / lower));
    def mfiVal = if IsNaN(mfi) then mfiVal[1] else mfi;
    plot return = mfiVal;
}
#// check cut-through in indicators
script nocut1 {
    input indi = close;
    input len = 5;
    def src = if isNaN(GetValue(indi, len)) then 0 else GetValue(indi, len);
    def ln = indi - ((indi - src) / len);
    def ln1 = (indi - src) / len;
    def _ret = fold x = 1 to len - 1 with p=1 while p do
               GetValue(indi, x) <= (fold x1 = 1 to x with p1= ln do p1 - ln1);
    plot out = if isNaN(_ret) then 0 else _ret;
}
#// check cut-through in indicators
script nocut2 {
    input indi = close;
    input len = 5;
    def src = if isNaN(GetValue(indi, len)) then 0 else GetValue(indi, len);
    def ln = indi - ((indi - src) / len);
    def ln1 = (indi - src) / len;
    def _ret = fold x = 1 to len - 1 with p=1 while p do
               GetValue(indi, x) >= (fold x1 = 1 to x with p1= ln do p1 - ln1);
    plot out = if isNaN(_ret) then 0 else _ret;
}
script negadiv {
    input indi = close;
    input isok = no;
    input emptyh = no;
    input chcut  = no;
    input newtop = no;
    input topc = 5;
    def src = if isNaN(GetValue(indi, topc)) then 0 else GetValue(indi, topc);
    def cond = src > indi;
    def _ret = emptyh and !IsNaN(newtop) and cond and (!chcut or isok);
    plot out = if isNaN(_ret) then 0 else _ret;
}
script posidiv {
    input indi = close;
    input isok = no;
    input emptyl = no;
    input chcut  = no;
    input newbot = no;
    input botc = 5;
    def src = if isNaN(GetValue(indi, botc)) then 0 else GetValue(indi, botc);
    def cond = src < indi;
    def _ret = emptyl and !IsNaN(newbot) and cond and (!chcut or isok);
    plot out = if isNaN(_ret) then 0 else _ret;
}

#// RSI
def rsi = RSI(Price = close, length = 14);
#// MACD
def fastMACD = ExpAverage(close, 12);
def slowMACD = ExpAverage(close, 26);
def macd = fastMACD - slowMACD;
def sigLine = ExpAverage(macd, 9);
def deltamacd = macd - sigLine;
#// Momentum
def moment = close - close[10];
#// CCI
def avgCCI = Average(close, 10);
def linDev = LinDev(close, 10);
def CCI = if linDev == 0 then 0 else (close - avgCCI) / linDev / 0.015;
#// OBV
def Obv = TotalSum(Sign(close - close[1]) * volume);
#// Stoch
def stk = Average(stoch(close, high, low, 14), 3);
#// DIOSC
def DI = (high - high[1]) - (-(low - low[1]));
def trur = ATR(Length = 14);
def diosc1 = 100 * WildersAverage(DI, 14) / trur;
def diosc = if IsNaN(diosc1) then diosc[1] else diosc1;
#// volume weighted macd
def maFast = vwma(close, 12);
def maSlow = vwma(close, 26);
def vwmacd = maFast - maSlow;
#// Chaikin money flow
def Cmfm = (close - low - (high - close)) / (high - low);
def Cmfv = Cmfm * volume;
def cmf = Average(Cmfv, 21) / Average(volume, 21);
#// Moneyt Flow Index
def Mfi = mfi(close, 14);

# cal

def top = pivots(high[lrb], lrb, lrb, yes);
def bot = pivots(low[lrb], lrb, lrb, no);

def topc1 = if !IsNaN(top) then lrb else topc1[1] + 1;
def topc  = if topc1 < lrb then lrb else topc1;
def botc1 = if !IsNaN(bot) then lrb else botc1[1] + 1;
def botc  = if botc1 < lrb then lrb else botc1;

#// Negative Divergence (checking possible higher highs(lb=0))
def newtop = pivots(high, lrb, 0, yes); #  // check only left side
def hline = newtop - ((newtop - GetValue(high, topc)) / topc);
def diffN = (newtop - GetValue(high, topc)) / topc;
def emptyh = if !IsNaN(newtop) and newtop > GetValue(high, topc) then
             fold x = 1 to topc - 1 with p=1 while p do
             GetValue(close, x) <= (fold x1 = 1 to x with p1=hline do p1 - diffN) else no;
#// Positive Divergence (checking possible Lower lows(lb=0))
def newbot = pivots(low, lrb, 0, no); #  // check only left side
def lline  = newbot - ((newbot - GetValue(low, botc)) / botc);
def diffP  = (newbot - GetValue(low, botc)) / botc;
def emptyl = if !IsNaN(newbot) and newbot < GetValue(low, botc) then
             fold y = 1 to botc - 1 with q=1 while q do
             GetValue(close, y) >= (fold y1 = 1 to y with q1=lline do q1 - diffP) else no;
#--
def rsiokn = nocut1(rsi, topc);
def macdokn = nocut1(macd, topc);
def deltamacdokn = nocut1(deltamacd, topc);
def momentokn = nocut1(moment, topc);
def cciokn = nocut1(cci, topc);
def obvokn = nocut1(Obv, topc);
def stkokn = nocut1(stk, topc);
def dioscokn = nocut1(diosc, topc);
def vwmacdokn = nocut1(vwmacd, topc);
def cmfokn = nocut1(cmf, topc);
def mfiokn = nocut1(Mfi, topc);
#--
def rsiokp = nocut2(rsi, botc);
def macdokp = nocut2(macd, botc);
def deltamacdokp = nocut2(deltamacd, botc);
def momentokp = nocut2(moment, botc);
def cciokp = nocut2(cci, botc);
def obvokp = nocut2(Obv, botc);
def stkokp = nocut2(stk, botc);
def dioscokp = nocut2(diosc, botc);
def vwmacdokp = nocut2(vwmacd, botc);
def cmfokp = nocut2(cmf, botc);
def mfiokp = nocut2(Mfi, botc);
#--
def posidiv_1 = posidiv(rsi, rsiokp, emptyl, chcut, newbot, botc);
def negadiv_1 = negadiv(rsi, rsiokn, emptyh, chcut, newtop, topc);
def iff_1 = if negadiv_1 then -1 else 0;
def indi1 = if posidiv_1 then  1 else iff_1;
def posidiv_2 = posidiv(macd, macdokp, emptyl, chcut, newbot, botc);
def negadiv_2 = negadiv(macd, macdokn, emptyh, chcut, newtop, topc);
def iff_2 = if negadiv_2 then -1 else 0;
def indi2 = if posidiv_2 then 1 else iff_2;
def posidiv_3 = posidiv(deltamacd, deltamacdokp, emptyl, chcut, newbot, botc);
def negadiv_3 = negadiv(deltamacd, deltamacdokn, emptyh, chcut, newtop, topc);
def iff_3 = if negadiv_3 then -1 else 0;
def indi3 = if posidiv_3 then 1 else iff_3;
def posidiv_4 = posidiv(moment, momentokp, emptyl, chcut, newbot, botc);
def negadiv_4 = negadiv(moment, momentokn, emptyh, chcut, newtop, topc);
def iff_4 = if negadiv_4 then -1 else 0;
def indi4 = if posidiv_4 then 1 else iff_4;
def posidiv_5 = posidiv(cci, cciokp, emptyl, chcut, newbot, botc);
def negadiv_5 = negadiv(cci, cciokn, emptyh, chcut, newtop, topc);
def iff_5 = if negadiv_5 then -1 else 0;
def indi5 = if posidiv_5 then 1 else iff_5;
def posidiv_6 = posidiv(Obv, obvokp, emptyl, chcut, newbot, botc);
def negadiv_6 = negadiv(Obv, obvokn, emptyh, chcut, newtop, topc);
def iff_6 = if negadiv_6 then -1 else 0;
def indi6 = if posidiv_6 then 1 else iff_6;
def posidiv_7 = posidiv(stk, stkokp, emptyl, chcut, newbot, botc);
def negadiv_7 = negadiv(stk, stkokn, emptyh, chcut, newtop, topc);
def iff_7 = if negadiv_7 then -1 else 0;
def indi7 = if posidiv_7 then 1 else iff_7;
def posidiv_8 = posidiv(diosc, dioscokp, emptyl, chcut, newbot, botc);
def negadiv_8 = negadiv(diosc, dioscokn, emptyh, chcut, newtop, topc);
def iff_8 = if negadiv_8 then -1 else 0;
def indi8 = if posidiv_8 then 1 else iff_8;
def posidiv_9 = posidiv(vwmacd, vwmacdokp, emptyl, chcut, newbot, botc);
def negadiv_9 = negadiv(vwmacd, vwmacdokn, emptyh, chcut, newtop, topc);
def iff_9 = if negadiv_9 then -1 else 0;
def indi9 = if posidiv_9 then 1 else iff_9;
def posidiv_10 = posidiv(cmf, cmfokp, emptyl, chcut, newbot, botc);
def negadiv_10 = negadiv(cmf, cmfokn, emptyh, chcut, newtop, topc);
def iff_10 = if negadiv_10 then -1 else 0;
def indi10 = if posidiv_10 then 1 else iff_10;
def posidiv_11 = posidiv(Mfi, mfiokp, emptyl, chcut, newbot, botc);
def negadiv_11 = negadiv(Mfi, mfiokn, emptyh, chcut, newtop, topc);
def iff_11 = if negadiv_11 then -1 else 0;
def indi11 = if posidiv_11 then 1 else iff_11;

def totaldiv = indi1 + indi2 + indi3 + indi4 + indi5 + indi6 + indi7 + indi8 + indi9 + indi10 + indi11;
def col = if totaldiv > 0 then 1 else if totaldiv < 0 then -1  else 0;
plot divHist = if col then if AbsValue(totaldiv) >= MinimumNoOfDivergence then AbsValue(totaldiv) else na else na;
plot hiL =  if !isNaN(close) then 11 else na;
plot mid =  if !isNaN(close) then MinimumNoOfDivergence else na;
plot zero = if !isNaN(close) then 0 else na;
hiL.SetStyle(Curve.SHORT_DASH);
mid.SetStyle(Curve.SHORT_DASH);
hiL.SetDefaultColor(Color.DARK_GRAY);
mid.SetDefaultColor(Color.DARK_GRAY);
zero.SetDefaultColor(Color.GRAY);
divHist.SetLineWeight(5);
divHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
divHist.AssignValueColor(if col > 0 then GlobalColor("up") else GlobalColor("dn"));

AddChartBubble(col, divHist + 0.25, divHist, if col > 0 then Color.GREEN else Color.RED);


#-- END of CODE

Hi Samer. This one does not work on ES or NQ?
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
383 Online
Create Post

Similar threads

Similar threads

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