SMA and Accumulation Divergence Scan or Indicator?

jphilli11

Member
Is anyone aware of a scan or indicator that compares the 1) slope of the price action to the 2) the slope of accumulation? Using a dynamic period of time to identify when they diverge? I.E. price is falling but accumulation is rising?

Specifically I'm hoping to find a scanner that uses criteria similar to this:

1. Daily chart
2. SMA 9
3. Accumulation length=14 (for smoothing)
4. Identifies starting position of the comparison as the bar of the last pivot down on price
5. identifies the ending position of the comparison as the bar in which accumulation ceases or drastically decreases
6. triggers based on the relationship between the two slopes. such as SMA -xx, Accumulation +xx (i don't know what the values would actually be and could probably experiment if the other components were working)

Below is a picture of NRXP from 4/26/2021 to 5/24/2021. You can see that as soon as the price began to fall on 4/27 the accumulation began rising. Then accumulation halted on 5/14/2021 and the price jumped on 5/20/2021. I've drawn an arrow on the two indicators to illustrate the pattern I'm looking for.

Hopefully this makes sense!


0U4sWc1ThBtedbw?width=669&height=638&cropmode=none.png
 
Solution
Here's a new version of this indicator as a lower study with up to 4 Accumulation Lengths to allow better visibility into what's going on. I use the first 3 at lengths of 3, 9, and 14. This paints up arrows at the divergence points on the lower study which helps keep my main chart from getting too crowded. Here are a few examples of this at work. This should definitely be used with other indicators for entry but it's a great addition to the toolbox.

Ch1Z7QVafKEvDh?width=1012&height=609&cropmode=none.png


Ouc998U1Ci37Zn?width=1035&height=591&cropmode=none.png


0_lrR5_WBVy6gp?width=1053&height=618&cropmode=none.png



Code:
declare lower;

#=======================================================
#               ACCUMULATION LINES
#=======================================================
input length_1 = 4; 
input length_2 = 9;
input length_3 = 14;
input length_4 =...

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

Generally we’re waiting for the accumulation to drop by the [drop %] AND be below the [fall below] threshold. So a minimum drop of 20% and the accumulation to be below a 1.5. This meets the first criteria but not the second.
This one is also a little outside the norm because the accumulation began a few days prior to the share price drop (normally it’s the same day or the following) - I’m not sure what’s going on with HIPO but it’s weird.

What we’re trying to identify is a stock who’s price is falling because market makers are pushing it down (stacking the bid and ask), triggering stop losses, and scooping up the cheapies. We enter the trade when the pressure seems to be subsiding and price is likely to rebound.

As far as when to enter HIPO - I don’t think this indicator will be helpful. Something different is happening here.

does this help?
Yes thank you! so then after after stock falls below 1.5 you would enter the trade. Thank you in advance.
 
Yes this helps I thought HIPO was weird too it just showed up on your scan the other day. But there is really no time frame or guidance as to when the stock might pop up? Is that correct?

Guidance for the pop - not really. It fairly subjective and depends heavily on the particular stock. I've noticed that they tend to move in predictable patterns (for each stock) so you can usually make an educated guess as to when it will make it's move. Its almost always within a few days though.

as far as when to enter, precisely? Again, I look at past alerts and try to gauge how it normally moves. In most cases I want to see a few other indicators agreeing such as MACD on pre-bullish move or the DPO_MOBO in pre-bullish.
 
Yes thank you! so then after after stock falls below 1.5 you would enter the trade. Thank you in advance.
I made some more changes after thinking about these examples. This new version will look at the w3 slope when evaluation w2 and not alert if w3 is climbing. It also widens the [fall below] range for w3 by 50%. Finally, I modified the way the slopes are calculated slightly to help better evaluate. I've tested against my normal "good" examples as well as EYEG and a few others and this seems to be superior. Take a look...


Code:
declare upper;
#=======================================================
#               pivot points code
#=======================================================
#Inputs
input     showbubble     = no;
input     Pivot_length   = 10;
input     Show_Pivot     = yes;
input     DisplayLabel   = no;   
input     compbars       = 20;  # pull in trend for longest period.  reduce within the specific groupings below
input     lowlevel       = 0.75;
input     highlevel      = 1.25;
input     fallbelow      = 1.5;
input     drop_percent   = 20;
input     override_drop_percent = 70;

#Variables
def       ttmtrenddwn    = reference ttm_trend( compBars = compBars ).trenddown;
def     VChaikin     = ChaikinOscillator().COSC / 1000;
def     vCCI         = CCI().CCI;
def     aggperiod    = if getaggregationperiod() == aggregationperiod.day then 1 else 0;
def     RVSD         = RelativeVolumeStDev()."RelVol";
def     Mobo         = FW_DPO_MOBO()."DPO";
def     vHigh        = high;
#def     vLow         = low;
#def     vOpen        = open;
#def     vClose       = close;
#def     vVolume      = volume;
def     nan          = Double.NaN;
def     bn           = BarNumber();

def     PPS          = IsNaN("value" = PPS().sellsignal) is false;

#=================================================
#            PPS Pivot Point
#================================================

def     hh =
        fold i = 1 to  Pivot_length + 1
        with p = 1
        while p       
        do PPS > getValue(PPS, -i);
def     PH =
            if (bn >  Pivot_length
                and PPS == highest(PPS,  Pivot_length)
                and hh)
            then PPS
            else double.NaN;
def     PHBar       = if !isNaN(PH) then bn else PHBar[1];
def     PHL         = if !isNaN(PH) then PH else PHL[1];
def     priorPHBar  = if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
def     HighPivots  = bn >= highestAll(priorPHBar);

def     DynamicLength = if bn - phbar < 2  then bn - priorPHBar else bn - phbar;

plot Pivot = PH and show_pivot;
pivot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_aRROW_DOWN);
pivot.SetDefaultColor(Color.orange);
pivot.SetLineWeight(5);

#============================================================
#          DIVERGENCE CODE
#============================================================





#==================================================================
#         1 week - 3 bar factors (short length manipulation)
#==================================================================
def     w1_length     = 3;


#==================================================================
#        2 week - 10 bar factors (medium length manipulation)
#==================================================================
def     w2_length = 9;
def     w2_Range = Highest(high, w2_length) - Lowest(low, w2_length);
def     w2_Ratio = w2_Range / w2_Range[w2_length];
def     w2_RatioMax = highest(w2_Ratio, 5);
def     w2_Drop_Percent = ( w2_RatioMax - w2_Ratio ) / w2_RatioMax * 100;

def     w2_Drop = if w2_RatioMax == w2_Ratio then 0 else if
                w2_Drop_Percent >  drop_percent                   
                then 1 else 0;

def     w2_Slope = w2_Ratio[w2_length + 1] - w2_RatioMax;
def     w2_Sign =
                If w2_Drop_Percent > override_drop_percent
                and w2_ratio <= lowlevel
                then -1
                else sign(w2_Slope);
        #override sign if the drop% > 70 and falls below lowlevel

def     w2_TrendDwn = sum(ttmtrenddwn > 0,w2_length );

#==================================================================
#======= 3 week - 15+ bar factors (long length manipulation)
#==================================================================
def     w3_length = 14;
def     w3_Range = Highest(high,w3_length) - Lowest(low, w3_length);
def     w3_Ratio = w3_Range / w3_Range[w3_length];

def     w3_RatioMax = highest(w3_Ratio, 3);
def     w3_Drop_Percent = ( w3_RatioMax - w3_Ratio ) / w3_RatioMax * 100;
def     w3_Drop = if
                w3_RatioMax == w3_Ratio then 0 else if
                w3_Drop_Percent > drop_percent / 2     
                then 1 else               
                0;

def     w3_Slope = w3_Ratio[w3_length + 1] - w3_RatioMax;
def     w3_Sign = sign(w3_Slope);

def     w3_TrendDwn = sum(ttmtrenddwn > 0,w3_length );             

#==================================================================
#                    PLOT POINTS
#==================================================================

def     w2_Diverge = if
            dynamiclength > w1_length #and dynamiclength <= w2_length + 3
            and w2_Drop
            and w2_Sign < 0
            and w2_ratiomax >= highlevel * .9
            and w2_ratio <= fallbelow
            and w2_TrendDwn >= w2_length *.5
            and mobo > mobo[1]
            and RVSD <= 1
            and VChaikin > VChaikin[1]
            and vCCi > vCCI[1]
            and w3_Ratio <= w3_Ratio[1]
            then 1 else
            0;

def     w3_Diverge = if
            dynamiclength >= w2_length -3
            and w3_Drop
            and w3_Sign < 0         
            and w3_ratiomax >= highlevel * .9
            and w3_ratio <= fallbelow * 1.5     
            and w3_TrendDwn >= w3_length *.5
            and RVSD <= 2.1
            then 1 else
            0;

def     divergence = if w2_Diverge then 1 else if w3_Diverge then 1 else 0;   #for scanner version

plot w2_alert = w2_diverge;
w2_alert.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);
w2_alert.SetDefaultColor(Color.CYAN);
w2_alert.SetLineWeight(5);

plot w_3alert = w3_diverge;
w_3alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
w_3alert.SetDefaultColor(Color.PINK);
w_3alert.SetLineWeight(5);

#==================================================================
#                    CHART BUBBLES
#==================================================================
AddChartBubble(w2_Diverge and !w2_Diverge[1] and showbubble and aggperiod, close,
                            "W2 " + Close
#                             "BarNum: " + bn
#                            + "\n" + "start: " + w2_Ratio[w2_length]
#                            + "\n" + "end: " + w2_Ratio[1]
#                            + "\n" + "sign: " + w2_sign                           
#                            + "\n" + "slope: " + w2_slope
#                            + "\n" + "D%: " +  ( w2_RatioMax - w2_Ratio ) / w2_ratiomax
#                            + "\n" + "D%: min " +  drop_percent
#                            + "\n" + "drop: " +  ( w2_RatioMax - w2_Ratio )
#                            + "\n" + "max: " + w2_RatioMax
#                            + "\n" + "cur: " + w2_Ratio
#                            + "\n" + "Chkn diff: " + (vchaikin[1] - vchaikin)
#                            + "\n" + "Chaikin[1]: " + vchaikin[1] 
#                            + "\n" + "CCI diff: " + (vcci[1] -  vcci)
#                            + "\n" + "CCI[1]: " + vcci[1]
                            , Color.CYAN, yes);


AddChartBubble(w3_Diverge and !w3_Diverge[1] and showbubble and aggperiod, close,
                            "W3 " + Close
#                            + "BarNum: " + bn
#                            + "\n" + "down: " + w3_TrendDwn
#                            + "\n" + "sign: " + w3_sign                           
#                            + "\n" + "slope: " + w3_slope
#                            + "\n" + "D%: " +  (w3_Ratio / w3_RatioMax ) / W3_RatioMax
#                            + "\n" + "drop: " +  ( w3_RatioMax - w3_Ratio )
#                            + "\n" + "cur: " + w3_Ratio
#                            + "\n" + "beg: " + w3_Ratio[w3_length + 1]
                            , Color.PINK, yes);
 
can you upload "EYEG" daily chart or go over it. It has the lowest o/s shares (showed up in the scan in post #30).

I have set show bubbles "yes", so 8/9 the bubble reads w2 2.27, start: 8.122, end: 4.96, sign: -1 , slope: -2.89. how would you interpret it? thanks

take a look at the latest version I just posted. I made some changes based on EYEG to improve functionality.
 
Here's a new version of this indicator as a lower study with up to 4 Accumulation Lengths to allow better visibility into what's going on. I use the first 3 at lengths of 3, 9, and 14. This paints up arrows at the divergence points on the lower study which helps keep my main chart from getting too crowded. Here are a few examples of this at work. This should definitely be used with other indicators for entry but it's a great addition to the toolbox.

Ch1Z7QVafKEvDh?width=1012&height=609&cropmode=none.png


Ouc998U1Ci37Zn?width=1035&height=591&cropmode=none.png


0_lrR5_WBVy6gp?width=1053&height=618&cropmode=none.png



Code:
declare lower;

#=======================================================
#               ACCUMULATION LINES
#=======================================================
input length_1 = 4; 
input length_2 = 9;
input length_3 = 14;
input length_4 = 19;
input factor = 0.75;
input bullish = 1.75;
input Show_Range1 = yes;
input Show_Range2 = yes;
input Show_Range3 = yes;
input Show_Range4 = no;

input mode = {default Range, ATR};
def     vHigh        = high;
def     vLow         = low;
def     nan          = Double.NaN;

def range1;
switch (mode) {
case Range:
    range1 = Highest(vhigh, length_1) - Lowest(vlow, length_1);
case ATR:
    range1 = reference ATR();
}

def range2;
switch (mode) {
case Range:
    range2 = Highest(vhigh, length_2) - Lowest(vlow, length_2);
case ATR:
    range2 = reference ATR();
}

def range3;
switch (mode) {
case Range:
    range3 = Highest(vhigh, length_3) - Lowest(vlow, length_3);
case ATR:
    range3 = reference ATR();
}
def range4;
switch (mode) {
case Range:
    range4 = Highest(vhigh, length_4) - Lowest(vlow, length_4);
case ATR:
    range4 = reference ATR();
}

plot RangeFactor = factor;
plot RangeBullish = bullish;


plot RangeRatio1 = if Show_Range1 then range1 / range1[length_1] else nan;
RangeRatio1.SetPaintingStrategy(PaintingStrategy.line);
RangeRatio1.DefineColor("Consolidation", color.light_green);
RangeRatio1.DefineColor("Non-consolidation", GetColor(1));
RangeRatio1.AssignValueColor( if (RangeRatio1 < RangeFactor) then RangeRatio1.Color("Consolidation") else RangeRatio1.Color("Non-consolidation"));
RangeFactor.SetDefaultColor(GetColor(2));

plot RangeRatio2 = if Show_Range2 then range2 / range2[length_2] else nan;
RangeRatio2.SetPaintingStrategy(PaintingStrategy.line);
RangeRatio2.DefineColor("Consolidation", color.yellow);
RangeRatio2.DefineColor("Non-consolidation", GetColor(1));
RangeRatio2.AssignValueColor( if (RangeRatio2 < RangeFactor) then RangeRatio2.Color("Consolidation") else RangeRatio2.Color("Non-consolidation"));
RangeFactor.SetDefaultColor(GetColor(3));

plot RangeRatio3 = if Show_Range3 then  range3 / range3[length_3] else nan;
RangeRatio3.SetPaintingStrategy(PaintingStrategy.line);
RangeRatio3.DefineColor("Consolidation", color.cyan);
RangeRatio3.DefineColor("Non-consolidation", GetColor(1));
RangeRatio3.AssignValueColor( if (RangeRatio3 < RangeFactor) then RangeRatio3.Color("Consolidation") else RangeRatio3.Color("Non-consolidation"));
RangeFactor.SetDefaultColor(GetColor(4));

plot RangeRatio4 = if Show_Range4 then range4 / range1[length_4] else nan;
RangeRatio4.SetPaintingStrategy(PaintingStrategy.line);
RangeRatio4.DefineColor("Consolidation", GetColor(4));
RangeRatio4.DefineColor("Non-consolidation", color.red);
RangeRatio4.AssignValueColor( if (RangeRatio4 < RangeFactor) then RangeRatio4.Color("Consolidation") else RangeRatio4.Color("Non-consolidation"));
RangeFactor.SetDefaultColor(GetColor(5));


#=======================================================
#               pivot points code
#=======================================================
#Inputs
#input     showbubble     = no;
input     Pivot_length   = 10;
#input     Show_Pivot     = yes;
input     DisplayLabel   = no;
input     compbars       = 20;  # pull in trend for longest period.  reduce within the specific groupings below
input     Fast_Length    = 4; #hint: for accumulation
input     Med_Length     = 9;
input     Slow_length    = 14;
def       ttmtrenddwn    = reference TTM_Trend( compBars = compbars ).trenddown;
input     lowlevel       = 0.75;
input     highlevel      = 1.5;
input     fallbelow      = 1.25;
input     drop_percent   = 20;
input     override_drop_percent = 70;

def     RVSD         = RelativeVolumeStDev()."RelVol";
def     Mobo         = FW_DPO_MOBO()."DPO";
def     LowBand      = FW_DPO_MOBO()."LOWERBANDP";
def     Mobo_True    = if Mobo > Mobo[1] or Mobo > LowBand then 1 else 0;
def     vTTM         = TTM_Wave()."Wave1";

def     bn           = BarNumber();
def     PPSdwn       = !IsNaN(PPS().”SellSignal”);
def     PPSup        = !IsNaN(PPS().”buySignal”);
#disused variables
#def     VChaikin     = ChaikinOscillator().COSC / 1000;
#def     vCCI         = CCI().CCI;
#def     vLow         = low;
#def     vOpen        = open;
#def     vClose       = close;
#def     vVolume      = volume;
#def     aggperiod    = if getaggregationperiod() == aggregationperiod.day then 1 else 0;

#=================================================
#            PPS Pivot Point
#================================================

def     hh =
        fold i = 1 to  Pivot_length + 1
        with p = 1
        while p       
        do PPSdwn > GetValue(PPSdwn, -i);
def     PH =
            if (bn >  Pivot_length
                and PPSdwn == Highest(PPSdwn,  Pivot_length)
                and hh)
            then PPSdwn
            else Double.NaN;
def     PHBar       = if !IsNaN(PH) then bn else PHBar[1];
def     PHL         = if !IsNaN(PH) then PH else PHL[1];
def     priorPHBar  = if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
def     HighPivots  = bn >= HighestAll(priorPHBar);

def     DynamicLength =
            if bn - PHBar < 2 
            then bn - priorPHBar     
            else bn - PHBar;

#============================================================
#          DIVERGENCE CODE
#============================================================

#==================================================================
#         1 week - 3 bar factors (short length manipulation)
#==================================================================
def     w1_length     = Fast_Length;
def     w1_Range      = Highest(vHigh, w1_length) - Lowest(vLow, w1_length);
def     w1_Ratio      = w1_Range / w1_Range[w1_length];

#def     w1_RatioMax   = highest(w1_Ratio, 2);
#def     w1_Drop       = if
#                        ( w1_RatioMax - w1_Ratio ) >  ( drop_percent / 100 )
#                        then 1 else 0;

#def     w1_Slope      = w1_Ratio[6] - w1_Ratio[1];
#def     w1_Sign       = sign(w1_Slope);

#def     w1_trendup    = sum(ttmtrendup > 0, w1_length );  # num of upsignals in last 5
#def     w1_TrendDwn   = sum(ttmtrenddwn > 0, w1_length ); #num of downsignals in last 5

#==================================================================
#        2 week - 10 bar factors (medium length manipulation)
#==================================================================
def     w2_length = Med_Length;
def     w2_Range = Highest(vHigh, w2_length) - Lowest(vLow, w2_length);
def     w2_Ratio = w2_Range / w2_Range[w2_length];
def     w2_RatioMax = Highest(w2_Ratio, 5);
def     w2_Drop_Percent = ( w2_RatioMax - w2_Ratio ) / w2_RatioMax * 100;

def     w2_Drop = if w2_RatioMax == w2_Ratio then 0 else if
                w2_Drop_Percent >  drop_percent                   
                then 1 else 0;

def     w2_Slope = w2_Ratio[w2_length + 1] - w2_RatioMax;
def     w2_Sign =
                if w2_Drop_Percent > override_drop_percent
                and w2_Ratio <= lowlevel
                then -1
                else Sign(w2_Slope);
        #override sign if the drop% > 70 and falls below lowlevel


def     w2_TrendDwn = Sum(ttmtrenddwn > 0, w2_length );

#==================================================================
#======= 3 week - 15+ bar factors (long length manipulation)
#==================================================================
def     w3_length = Slow_length;
def     w3_Range = Highest(high, w3_length) - Lowest(low, w3_length);
def     w3_Ratio = w3_Range / w3_Range[w3_length];

def     w3_RatioMax = Highest(w3_Ratio, 3);
def     w3_Drop_Percent = ( w3_RatioMax - w3_Ratio ) / w3_RatioMax * 100;
def     w3_Drop = if
                w3_RatioMax == w3_Ratio then 0 else if
                w3_Drop_Percent > drop_percent / 2     
                then 1 else               
                0;

def     w3_Slope = w3_Ratio[w3_length + 1] - w3_RatioMax;
def     w3_Sign = Sign(w3_Slope);

def     w3_TrendDwn = Sum(ttmtrenddwn > 0, w3_length );             

#==================================================================
#                    PLOT POINTS
#==================================================================

def     w2_Diverge = if
            DynamicLength > w1_length #and dynamiclength <= w2_length + 3
            and w2_Drop
            and w2_Sign < 0
            and w2_RatioMax >= highlevel * .9
            and w2_Ratio <= fallbelow
            and w2_TrendDwn >= w2_length * .5
            and RVSD <= 1
            and w3_Ratio <= w3_Ratio[1]
            and w1_Ratio < w1_Ratio[1]
            and !PPSup
            and Mobo_True
            and vTTM > vTTM[1]
            then 1 else
            0;

def     w3_Diverge = if
            DynamicLength >= w2_length - 3
            and w3_Drop
            and w3_Sign < 0         
            and w3_RatioMax >= highlevel * .9
            and w3_Ratio <= fallbelow * 1.5     
            and w3_TrendDwn >= w3_length * .5
            and RVSD <= 2.1
            #and w1_Ratio < w1_Ratio[1]
            and !PPSup
           # and Mobo_True
            #and vTTM > vTTM[1]
            then 1 else
            0;

def     divergence = if w2_Diverge or w3_Diverge then 1 else 0;   #for scanner version


plot w2_alert = If w2_Diverge then W2_Ratio else nan;
w2_alert.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
w2_alert.SetDefaultColor(color.yellow);
w2_alert.SetLineWeight(2);

plot w_3alert = if w3_Diverge then W3_RATIO else nan;
w_3alert.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
w_3alert.SetDefaultColor(color.cyan);
w_3alert.SetLineWeight(2);

#plot Pivot = PH and Show_Pivot;#hint: to show the downarrow used for pivot point
#Pivot.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#Pivot.SetDefaultColor(Color.plum);
#Pivot.SetLineWeight(5);

#==================================================================
#                    CHART BUBBLES (for upper study)
#==================================================================
#AddChartBubble(w2_Diverge and !w2_Diverge[1] and showbubble, close,
#                            "W2 " + close
#                             "BarNum: " + bn
#                            + "\n" + "start: " + w2_Ratio[w2_length]
#                            + "\n" + "end: " + w2_Ratio[1]
#                            + "\n" + "sign: " + w2_sign                           
#                            + "\n" + "slope: " + w2_slope
#                            + "\n" + "D%: " +  ( w2_RatioMax - w2_Ratio ) / w2_ratiomax
#                            + "\n" + "D%: min " +  drop_percent
#                            + "\n" + "drop: " +  ( w2_RatioMax - w2_Ratio )
#                            + "\n" + "max: " + w2_RatioMax
#                            + "\n" + "cur: " + w2_Ratio
#                            + "\n" + "Chkn diff: " + (vchaikin[1] - vchaikin)
#                            + "\n" + "Chaikin[1]: " + vchaikin[1] 
#                            + "\n" + "CCI diff: " + (vcci[1] -  vcci)
#                            + "\n" + "CCI[1]: " + vcci[1]
#                            , Color.CYAN, yes);


#AddChartBubble(w3_Diverge and !w3_Diverge[1] and showbubble, close,
#                            "W3 " + close
#                            + "BarNum: " + bn
#                            + "\n" + "down: " + w3_TrendDwn
#                            + "\n" + "sign: " + w3_sign                           
#                            + "\n" + "slope: " + w3_slope
#                            + "\n" + "D%: " +  (w3_Ratio / w3_RatioMax ) / W3_RatioMax
#                            + "\n" + "drop: " +  ( w3_RatioMax - w3_Ratio )
#                            + "\n" + "cur: " + w3_Ratio
#                            + "\n" + "beg: " + w3_Ratio[w3_length + 1]
#                            , Color.Plum, yes);
#def symbol = getsymbol();
#addlabel(yes, getsymbol(), color.white);
 
Solution
Absolutely. I've been playing with it ever since halcyonguy figured out the solution. I've made a few changes since my last post including:
1. an override to some of the paramaters if the Accumulation drops by more than 200%
2. set up a long and short accumulation period for comparison/confirmation.
long = 10
short = 3
3. changed the drop% trigger to a 5 bar span for the long acc and within 2 bars on the short
4. moved it to upper study and removed all the cloud and other indications that are not mobile friendly - thought those are really helpful and I use it on my desktop whenever I can.


I've noticed it gives false alerts if there's a large red or green bar within the study range so I just visually verify that there's been steady decline in price over the last 10 bars or so.

here's the study:
https://tos.mx/NIVsMIW
here's the scanner:
https://tos.mx/tNNoyvN







Code:
declare upper;

#============================================================
#          DIVERGENCE CODE
#============================================================

input showbubble = no;
def na = Double.NaN;
input lowlevel = 0.75;
input highlevel = 1.25;
input fallbelow = 1.25;
input drop_percent = 75;
input override_drop_percent = 200;

# ============================

# price movement

# use a short average of ttm trend, to determine price slope
input compBars = 5;
def ttmtrendup = reference ttm_trend( compBars = compBars ).trendup;
def ttmtrenddwn = reference ttm_trend( compBars = compBars ).trenddown;

def countups = sum(ttmtrendup > 0, compBars );  # num of upsignals in last 10
def countdwn = sum(ttmtrenddwn > 0, compBars ); #num of downsignals in last 10

def trndsign = if countups >= compBars *.75 then 1 else -1; #more than half upsignals
#def redcandle = open > close;
#def countred = sum(redcandle, compbars);

# code from AccumulationDistribution
input accumlength1 = 10;
def  range = Highest(high, accumlength1) - Lowest(low, accumlength1);
def RangeRatio = range / range[accumlength1];

input accumlength2 = 3;
def  range2 = Highest(high, accumlength2) - Lowest(low, accumlength2);
def RangeRatio2 = range2 / range2[accumlength2];

# smooth out accu line with an avg
input accumavg2_len = 4;
input accumavg2_type = AverageType.SIMPLE;
def RangeRatioavg = MovingAverage(accumavg2_type, RangeRatio, accumavg2_len);
def RangeRatioavg2 = RangeRatioavg;

# calc bar to bar4 change
def RangeRatioavgchg = RangeRatioavg[1] - RangeRatioavg;
def accsign = Sign(RangeRatioavgchg);

# ============================
def range2true = rangeratio2 - rangeratio2[1] > 0;
# use original accum signal to test for drop

def ratiomax = highest(RangeRatio, 5);

def accdrop2 = if
                ( Ratiomax -  RangeRatio ) >  ( drop_percent / 100 )
                and range2true within 2 bars   #added 8/5/21
                then 1 else 0;
def drop_max = (Ratiomax - rangeratio) * 100;

# ===================================================
def top = if
            accdrop2
            and RangeRatioavgchg > 0
            and accsign > 0
            and trndsign < 0
           # and reference ttm_trend().trenddown
            and RangeRatio[1] > highlevel
            and rangeratio < fallbelow
            and countdwn > compbars *.75
            #and countred > compbars *.75
            then 1 else
         if drop_max >= override_drop_percent
            and trndsign < 0
            and reference ttm_trend().trenddown
            and RangeRatio[1] > highlevel
            and rangeratio < fallbelow
            and countdwn > compbars *.75
            #and countred > compbars *.75
            then 1 else
            0;


plot toparrow = top;
toparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
toparrow.SetDefaultColor(Color.orange);
toparrow.SetLineWeight(5);

AddChartBubble(top and showbubble, close, "Enter Below " + Close, Color.CYAN, yes);
Hey Doc, I've been making more changes to this and fine-tuning it a bit more. I'd love to have you try it and give me any feedback/changes you think would make it more accurate. Below is the new code and a link to the indicator and scanner:

Changes:
1. pivot down is now tied to PPS signal instead of the pivot point of highest price
2. I've set up 3 separate timeframes that look at accumulation and price action on those scales. i.e 1 week, 2 week and 3 week+
3. fixed a slope and sign error from last version
4. changed TTM down % to 50% or more instead of 75%
5. 3-week drop only requires a 10% change since it has a longer average. 2 week still requires 20%
6. there is a 3 day overlap between 2 and 3 week timeframes to help capture movements on the fringes


Indicator:
http://tos.mx/2P85Cho

Scanner:
https://tos.mx/HNxcHmv


Code:
declare upper;
 #=======================================================
#               pivot points code
#=======================================================
#Inputs


#addchartbubble(PercentOfDayAvg > 200, close, PercentofDayAvg + "%", color.red, no);

input     showbubble = no;
input     Pivot_length = 10;
input     Show_Pivot = yes;
input     DisplayLabel = no;    #JQ 7.8.2018 added

def     RVSD = RelativeVolumeStDev()."RelVol";
def     Mobo = FW_DPO_MOBO()."DPO";
def     vHigh = high;  # creates the variable vHigh.  Use of the variable reduce data calls to tos iData server
def     vLow = low;
def     vOpen = open;
def     vClose = close;
def     vVolume = volume;
def     nan = Double.NaN;
# Bar Time & Date
def     bn = BarNumber();
def     currentBar = HighestAll(if !IsNaN(vHigh) then bn else nan);
def     PPS = IsNaN("value" = PPS().sellsignal) is false;
# pivot points
def     PH;
def     hh =
        fold i = 1 to  Pivot_length + 1
        with p = 1
        while p     
        do PPS > getValue(PPS, -i);
PH =
        if (bn >  Pivot_length and
            PPS == highest(PPS,  Pivot_length) and
            hh)
        then
            PPS
        else
            double.NaN;
def     PHBar = if !isNaN(PH)
                   then bn
                   else PHBar[1];
def     PHL = if !isNaN(PH)
                 then PH
                 else PHL[1];
def     priorPHBar = if PHL != PHL[1]
                        then PHBar[1]
                        else priorPHBar[1];
def     HighPivots = bn >= highestAll(priorPHBar);



def     DynamicLength =
                        if
                        bn - phbar < 2
                        then bn - priorPHBar
                        else bn - phbar;

#AddChartBubble(PH, close, "PH: " + PH
#                            + "\n" + "PHL: " + PHL
#                            + "\n" + "PHBar: " + PHBar 
#                            + "\n" + "hh: " + hh
#                            + "\n" + "PriorPH: " + PriorPHBar
#                            , Color.CYAN, yes);

plot Pivot = PH and show_pivot;
pivot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_aRROW_DOWN);
pivot.SetDefaultColor(Color.orange);
pivot.SetLineWeight(5);

#============================================================
#          DIVERGENCE CODE
#============================================================

def na = Double.NaN;
input lowlevel = 0.75;
input highlevel = 1.25;
input fallbelow = 1.5;
input drop_percent = 75;
input override_drop_percent = 200;


input compbars = 20;  # pull in trend for longest period.  reduce within the specific groupings below
def ttmtrendup = reference ttm_trend( compBars = compbars ).trendup;
def ttmtrenddwn = reference ttm_trend( compBars = compBars ).trenddown;


#======= 1 week - 5 bar factors (fast length manipulation)  *probably won't use because too volatile and unreliable
def     w1_length = 3;
def     w1_Range = Highest(high,w1_length) - Lowest(low, w1_length);
def     w1_Ratio = w1_Range / w1_Range[w1_length];

def     w1_RatioMax = highest(w1_Ratio, 2);
def     w1_Drop = if
                ( w1_RatioMax - w1_Ratio ) >  ( drop_percent / 100 )
                #and w1_Ratio > w2_Ratio
                then 1 else 0;

def     w1_Slope = w1_Ratio[6] - w1_Ratio[1];
def     w1_Sign = sign(w1_Slope);

def     w1_trendup = sum(ttmtrendup > 0, w1_length );  # num of upsignals in last 5
def     w1_TrendDwn = sum(ttmtrenddwn > 0, w1_length ); #num of downsignals in last 5

#==================================================================
#======= 2 week - 10 bar factors (medium length manipulation)
#==================================================================
def     w2_length = 9;
def     w2_Range = Highest(high, w2_length) - Lowest(low, w2_length);
def     w2_Ratio = w2_Range / w2_Range[w2_length];

def     w2_RatioMax = highest(w2_Ratio, 5);
def     w2_Drop = if
                ( w2_RatioMax - w2_Ratio ) / w2_RatioMax > .2
                and w1_Ratio > w2_Ratio
                then 1 else 0;

def     w2_Slope = w2_Ratio[w2_length + 1] - w2_Ratio[1];
def     w2_Sign = sign(w2_Slope);

def     w2_trendup = sum(ttmtrendup > 0, w2_length );  # num of upsignals in last 9
def     w2_TrendDwn = sum(ttmtrenddwn > 0,w2_length ); #num of downsignals in last 9

def     w2_Diverge = if
            dynamiclength > w1_length #and dynamiclength <= w2_length + 3
            and w2_Drop
            and w2_Sign < 0
            and w2_ratiomax >= highlevel * .9
            and w2_ratio <= fallbelow
            and w2_TrendDwn >= w2_length *.5
            and mobo > mobo[1]
            and RVSD <= 1
            then 1 else
            0;
 

AddChartBubble(w2_Diverge and showbubble, close,
                            "W2 " + Close
#                             "BarNum: " + bn
#                            + "\n" + "start: " + w2_Ratio[w2_length]
#                           + "\n" + "end: " + w2_Ratio[1]
#                          + "\n" + "sign: " + w2_sign                         
#                         + "\n" + "slope: " + w2_slope
#                            + "\n" + "D%: " +  ( w2_RatioMax - w2_Ratio ) / w2_ratiomax
#                            + "\n" + "D%: min " +  drop_percent
#                            + "\n" + "drop: " +  ( w2_RatioMax - w2_Ratio )
#                            + "\n" + "max: " + w2_RatioMax
#                            + "\n" + "cur: " + w2_Ratio
                            , Color.orange, yes);


#======= 3 week - 15 bar factors (slow length manipulation)
def     w3_length = 14;
def     w3_Range = Highest(high,w3_length) - Lowest(low, w3_length);
def     w3_Ratio = w3_Range / w3_Range[w3_length];

def     w3_RatioMax = highest(w3_Ratio, 3);
def     w3_Drop = if
                (w3_Ratio / w3_RatioMax ) / W3_RatioMax  >  .1
                #and w2_Ratio > w3_Ratio
                then 1 else
                #if ( w2_RatioMax - w2_Ratio ) / w2_ratiomax >  .35 then 1 else
                0;

def     w3_Slope = w3_Ratio[w2_length + 1] - w3_Ratio;
def     w3_Sign = sign(w3_Slope);

def     w3_trendup = sum(ttmtrendup > 0, w3_length );  # num of upsignals in last 10
def     w3_TrendDwn = sum(ttmtrenddwn > 0,w3_length ); #num of downsignals in last 10

def     w3_Diverge = if
            dynamiclength >= w3_length -3
            and w3_Drop
            and w3_Sign < 0       
            and w3_ratiomax >= highlevel
            and w2_ratio <= fallbelow    #w3 ratio too slow to use this but w2 is still good indication
            and w3_TrendDwn >= w3_length *.5
            and RVSD <= 2
            then 1 else
            0;
 
          
AddChartBubble(w3_Diverge and showbubble, close,
                            "W3 " + Close
#                            + "BarNum: " + bn
#                            + "\n" + "down: " + w3_TrendDwn
#                            + "\n" + "sign: " + w3_sign                         
#                            + "\n" + "slope: " + w3_slope
#                            + "\n" + "D%: " +  (w3_Ratio / w3_RatioMax ) / W3_RatioMax
#                            + "\n" + "drop: " +  ( w3_RatioMax - w3_Ratio )
#                            + "\n" + "max: " + w3_RatioMax
#                            + "\n" + "cur: " + w3_Ratio
                            , Color.orange, yes);



# ============================




def divergealert = if w2_diverge then 1 else    #for the scanner version
                   if w3_diverge then 1 else 0;

plot w2_alert = w2_diverge;
w2_alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
w2_alert.SetDefaultColor(Color.BLUE);
w2_alert.SetLineWeight(5);

plot w_3alert = w3_diverge;
w_3alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
w_3alert.SetDefaultColor(Color.orange);
w_3alert.SetLineWeight(5);
Hello on the Scanner is that for LONG or SHORT ? do you have the scanner for SHORTS thanks
 
Hello on the Scanner is that for LONG or SHORT ? do you have the scanner for SHORTS thanks

I don't have a version of this for short positions. I'm not sure this approach would make a good indicator for going short as, by the time it finds the downward pressure, it's already too late to take a good entry. I'll play around and see if it could be reworked someway.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
312 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