# 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!

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.

Code:
``````declare lower;

#=======================================================
#               ACCUMULATION LINES
#=======================================================
input length_1 = 4;
input length_2 = 9;
input length_3 = 14;
input length_4 =...``````
i don't use scans so i won't guarantee this work work in a scan.
this is a lower study to identify divergence of, AccumulationDistribution and a moving average of close.

what it does
...find the difference, bar to bar, of the 2 signals.
...find the sign of the 2 differences.
...compare the signs. after 2 bars of divergence, the signal is passed on to the counter.
...increment a counter when there is divergence

Ruby:
``````# diverg_smaaccum_01

declare lower;
# code from AccumulationDistribution
input length = 14;
input factor = 0.0;
def  range = Highest(high, length) - Lowest(low, length);
plot RangeRatio = range / range[length];
Rangeratio.SetDefaultColor(color.cyan);

def accchg = RangeRatio - RangeRatio[1];
def accsign = sign(accchg);

# -----------------------------------

input avg1_len = 9;
input avg1_type =  AverageType.simple;
def ma1 = MovingAverage(avg1_type, close, avg1_len);

def smachg = ma1 - ma1[1];
def smasign = sign (smachg);

# ------------------------------------------

#  cnt + if both chgs have same sign
def accsame = compoundvalue(1, (accsign == accsign[1]), 0);
def smasame = compoundvalue(1, (smasign == smasign[1]), 0);
def signcnt = accsame and smasame and (accsign <> smasign);

def divcnt = if signcnt then divcnt[1] + 1 else 0;

def top = if divcnt > 0 and accchg < 0 then Double.POSITIVE_INFINITY else Double.negative_INFINITY;
def bot = if divcnt > 0 and accchg > 0 then Double.POSITIVE_INFINITY else Double.negative_INFINITY;

#addchartbubble(1, 1, accsign + "\n" + accsign[1] + "\n" + smasign + "\n" + smasign[1] , color.cyan, no);
#``````

Thanks halcyonguy, this is great.

Question: it looks like the slope is calculating from one bar to the next, how would I anchor this to a pivot point (such as the bar in which price began to fall) and compare the slopes from that bar until the first bar in which accumulation falls dramatically?

I hope that makes sense?

i don't use scans so i won't guarantee this work work in a scan.
this is a lower study to identify divergence of, AccumulationDistribution and a moving average of close.

what it does
...find the difference, bar to bar, of the 2 signals.
...find the sign of the 2 differences.
...compare the signs. after 2 bars of divergence, the signal is passed on to the counter.
...increment a counter when there is divergence

Ruby:
``````# diverg_smaaccum_01

declare lower;
# code from AccumulationDistribution
input length = 14;
input factor = 0.0;
def  range = Highest(high, length) - Lowest(low, length);
plot RangeRatio = range / range[length];
Rangeratio.SetDefaultColor(color.cyan);

def accchg = RangeRatio - RangeRatio[1];
def accsign = sign(accchg);

# -----------------------------------

input avg1_len = 9;
input avg1_type =  AverageType.simple;
def ma1 = MovingAverage(avg1_type, close, avg1_len);

def smachg = ma1 - ma1[1];
def smasign = sign (smachg);

# ------------------------------------------

#  cnt + if both chgs have same sign
def accsame = compoundvalue(1, (accsign == accsign[1]), 0);
def smasame = compoundvalue(1, (smasign == smasign[1]), 0);
def signcnt = accsame and smasame and (accsign <> smasign);

def divcnt = if signcnt then divcnt[1] + 1 else 0;

def top = if divcnt > 0 and accchg < 0 then Double.POSITIVE_INFINITY else Double.negative_INFINITY;
def bot = if divcnt > 0 and accchg > 0 then Double.POSITIVE_INFINITY else Double.negative_INFINITY;

#addchartbubble(1, 1, accsign + "\n" + accsign[1] + "\n" + smasign + "\n" + smasign[1] , color.cyan, no);
#[/CODE
[/QUOTE]``````
@halcyonguy - thanks so much for sharing. I think pairing this with a Fisher indicator could be a nice combination in identifying price exhaustion.

A couple of questions:
What time frames do you use this on?
Are there any common thresholds you look for given what is plotted or based on your experience?
Any other tips or strategy you employ with this indicator?

Thx.

Last edited:
@halcyonguy - thanks so much for sharing. I think pairing this with a Fisher indicator could be a nice combination in identifying price exhaustion.

A couple of questions:
What time frames do you use this on?
Are there any common thresholds you look for given what is plotted or based on your experience?
Any other tips or strategy you employ with this indicator?

Thx.
you're welcome

i don't use this. i just made it. i read jphilli post, thought about it, and came up with that code. almost everything i post, i create after reading a post.

@halcyonguy - thanks so much for sharing. I think pairing this with a Fisher indicator could be a nice combination in identifying price exhaustion.

A couple of questions:
What time frames do you use this on?
Are there any common thresholds you look for given what is plotted or based on your experience?
Any other tips or strategy you employ with this indicator?

Thx.
Awesome questions - I'll do my best to answer.

1) timeframe is always on the daily
2) Accumulation threshold
[ ] begins to climb from below .75. at the same time as the price begins to fall
[ ] will exceed 1.75 before it releases
[ ] drops by roughly 20% or more to signal release
[ ] in the pic above it started at about .45 rose to 2 and then fell to 1.4ish
3) There's no real pattern to the price action other than its descending but can have green days which is why i'm wanting to watch the slope
4) this pattern doesn't seem to last longer than 2 or 3 weeks before triggering

I use this to figure out when the MM's (or whatever force) is driving the price down and accumulating shares cheaply and have decided they've had their fill. Once that happens (accumulation drop) the stock tends to have a large runup as it rebounds to it's natural level (and sometimes skyrockets with news).

I'll see if I can find my notes on a few other examples and post pics for you.

you're welcome

i don't use this. i just made it. i read jphilli post, thought about it, and came up with that code. almost everything i post, i create after reading a post.
Understood.
I threw the indicator on the chart to get an idea and also matched it up with 3xStochastics and found confluence between the two. Seems like a decent combination. I'll play with it and see if it leads to anything.
Standard Deviation lines also help for reference.

Awesome questions - I'll do my best to answer.

1) timeframe is always on the daily
2) Accumulation threshold
[ ] begins to climb from below .75. at the same time as the price begins to fall
[ ] will exceed 1.75 before it releases
[ ] drops by roughly 20% or more to signal release
[ ] in the pic above it started at about .45 rose to 2 and then fell to 1.4ish
3) There's no real pattern to the price action other than its descending but can have green days which is why i'm wanting to watch the slope
4) this pattern doesn't seem to last longer than 2 or 3 weeks before triggering

I use this to figure out when the MM's (or whatever force) is driving the price down and accumulating shares cheaply and have decided they've had their fill. Once that happens (accumulation drop) the stock tends to have a large runup as it rebounds to it's natural level (and sometimes skyrockets with news).

I'll see if I can find my notes on a few other examples and post pics for you.

Here's another example. NAOV dropped from \$1.20 to about .80c over 2 weeks all the while the accumulation continued to increase. Then the accumulation drops off about 20% and a few days later it runs 300%+. hard to see the accumulation changes because of the scale but it's there. The date range here is from 7/10-ish to 7/22/2021

Thanks halcyonguy, this is great.

Question: it looks like the slope is calculating from one bar to the next, how would I anchor this to a pivot point (such as the bar in which price began to fall) and compare the slopes from that bar until the first bar in which accumulation falls dramatically?

I hope that makes sense?
yes, it looks at the change from bar to bar. it could be changed to look at multiple bars, or 2 bars that are x bars apart.

if you want to find a value when a peak or valley(dip) occur, here are a couple of links for you to study. something to be aware of, usually to define a peak or valley, several bars have to occur after it happens, before it is identified. you can experiment with different offsets, on the left side and right side of the current bar. example, try 5 on the left( to look at the past 5 bars) and -2 ( to look at 2 future bars), with this example, your reference is 2 bars after it happens.

robert's forum, the source of the code in previous link

after you identify the bar that is a peak, then you have to save the value and calculate the slope to the current bar.

a couple of posts with studies that calculate slope

there are other ways to do this, including using fold.

@cos251 Off topic but what indicator/conditions did you use for your zero line on 3x?

This one is not as clean because the ACC started above the range factor but the pattern is still there. WTT between 4/27/2021 and 5/12

yes, it looks at the change from bar to bar. it could be changed to look at multiple bars, or 2 bars that are x bars apart.

if you want to find a value when a peak or valley(dip) occur, here are a couple of links for you to study. something to be aware of, usually to define a peak or valley, several bars have to occur after it happens, before it is identified. you can experiment with different offsets, on the left side and right side of the current bar. example, try 5 on the left( to look at the past 5 bars) and -2 ( to look at 2 future bars), with this example, your reference is 2 bars after it happens.

robert's forum, the source of the code in previous link

after you identify the bar that is a peak, then you have to save the value and calculate the slope to the current bar.

a couple of posts with studies that calculate slope

there are other ways to do this, including using fold.
Thank you so much! I'll dig into this tonight!

Here's the last one I'll bug you with. CAN made a small move in June on this same pattern.

Here's the last one I'll bug you with. CAN made a small move in June on this same pattern.

i see what you mean by wanting to base the slope from a previous peak and over multiple bars. my green cloud showed up 4 bars after the divergence stopped, so you missed half of the opposite move.

can you state your rules for divergent lines, how do you draw them on accumulationdistribution?
if price is going down, do you look for peaks to draw a line between, on accumulationdistribution?

i see what you mean by wanting to base the slope from a previous peak and over multiple bars. my green cloud showed up 4 bars after the divergence stopped, so you missed half of the opposite move.

can you state your rules for divergent lines, how do you draw them on accumulationdistribution?
if price is going down, do you look for peaks to draw a line between, on accumulationdistribution?
The rules are simply that
if price is moving down over several bars
and accumulation is rising over those same bars (not necessarily consecutive but overall)
then as soon as the accumulation value drops by 20% from previous bar enter the trade

I have no idea how to code this so I'm just manually spotting the pattern then creating watch lists and hoping to look back when the fall-off on accumulation occurs. I've been tinkering with the code from this indicator Auto Support/Resistance but haven't really figured it out

A good one to watch right now would be NSPR. There was a big price surge on 7/22 and now the price is falling while the accumulation skyrockets.

Take a look at ACER this morning. Price has been falling last 20 or so trading days and the accumulation was rising until yesterday, when it plummeted. This morning it gets an upgrade from Zack’s and, bam, she’s running premarket. I made 20% on a 24 hour hold (I may regret selling premarket but I’m happy with the nice return).

The rules are simply that
if price is moving down over several bars
and accumulation is rising over those same bars (not necessarily consecutive but overall)
then as soon as the accumulation value drops by 20% from previous bar enter the trade

I have no idea how to code this so I'm just manually spotting the pattern then creating watch lists and hoping to look back when the fall-off on accumulation occurs. I've been tinkering with the code from this indicator Auto Support/Resistance but haven't really figured it out

The rules are simply that
if price is moving down over several bars
and accumulation is rising over those same bars (not necessarily consecutive but overall)
then as soon as the accumulation value drops by 20% from previous bar enter the trade

I have no idea how to code this so I'm just manually spotting the pattern then creating watch lists and hoping to look back when the fall-off on accumulation occurs. I've been tinkering with the code from this indicator Auto Support/Resistance but haven't really figured it out

ver2 of accumulation divergent clouds,

changed formulas for price direction. used ttm_trend(2) to determine price direction
add an average line of accumulation
add a row of dots at 1 to represent accumulation direction, based on the average
add a row of arrows at 2 to represent price direction
add white down arrows, when accumulation drops by x%

if a x% drop happens , it overrides the accumulation signal and changes the dot to red
draw vertical clouds when accumulation and price are divergent, moving in opposite directions

inputs
levels for accumulation
...lowlevel = 0.75
...highlevel = 1.75
...drop_percent = 20

ttmtrend length for price direction
...compBars = 2

AccumulationDistribution
...accumlength = 14
create an average to determine direction
...accumavg2_len = 4
...accumavg2_type = SIMPLE

Ruby:
``````# diverg_smaaccum_02

# 1) timeframe is always on the daily
# 2) Accumulation threshold
#   [ ] begins to climb from below .75. at the same time as the price begins to fall
#   [ ] will exceed 1.75 before it releases
#   [ ] drops by roughly 20% or more to signal release
# 3) There's no real pattern to the price action other than its descending but can have green days which is why i'm wanting to watch the slope
# 4) this pattern doesn't seem to last longer than 2 or 3 weeks before triggering

declare lower;

def na = Double.NaN;

input lowlevel = 0.75;
plot r1 = lowlevel;
r1.SetDefaultColor(Color.GRAY);

input highlevel = 1.75;
plot r2 = highlevel;
r2.SetDefaultColor(Color.GRAY);

input drop_percent = 20;

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

# price movement

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

# draw arrows for price direction
def rowy = 2;
plot tup = if ttmtrendup then rowy else na;
tup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
tup.SetDefaultColor(Color.GREEN);
# x.setlineweight(1);
tup.hidebubble();

plot tdwn = if ttmtrenddwn then rowy else na;
tdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
tdwn.SetDefaultColor(Color.red);
tdwn.hidebubble();

def trndsign = if ttmtrendup then 1 else -1;

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

# code from AccumulationDistribution
input accumlength = 14;
#input factor = 0.0;
def  range = Highest(high, accumlength) - Lowest(low, accumlength);
plot RangeRatio = range / range[accumlength];
RangeRatio.SetDefaultColor(Color.CYAN);

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

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

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

# use original accum signal to test for drop
def accdrop2 = ( RangeRatio[1] -  RangeRatio ) >  ( drop_percent / 100 ) ;

plot accdrop = if accdrop2 then RangeRatio else na;
accdrop.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
accdrop.SetDefaultColor(Color.WHITE);

def RangeRatioavgchg2 = if accdrop2 then -1 else RangeRatioavgchg;
def accsign2 = Sign(RangeRatioavgchg2);

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

# draw dots for the accum/dist signal
def row1 = 1;
plot accdisup = if RangeRatioavgchg2 > 0 then row1 else na;
accdisup.SetPaintingStrategy(PaintingStrategy.points);
accdisup.SetDefaultColor(Color.GREEN);
accdisup.setlineweight(3);
accdisup.hidebubble();

plot accdisdwn = if RangeRatioavgchg2 < 0 then row1 else na;
accdisdwn.SetPaintingStrategy(PaintingStrategy.points);
accdisdwn.SetDefaultColor(Color.red);
accdisdwn.setlineweight(3);
accdisdwn.hidebubble();

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

#def diverg2 =  accsign <> smasign;
#def diverg2 =  accsign <> trndsign;

# if (sign * sign2 ) < 0 then opp
def diverg2 = (accsign2 * trndsign) < 0;

# ------------------------------------------

#addchartbubble(1, 1, accsign + "\n" + accsign[1] + "\n" + smasign + "\n" + smasign[1] , color.cyan, no);

def top = if diverg2 and RangeRatioavgchg < 0 then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
def bot = if diverg2 and RangeRatioavgchg > 0 then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;

#``````

test FB , day chart

the arrows on the upper chart are a modified ttm trend. what i used in the lower.

Ruby:
``````def na = double.nan;
input compBars = 2;
def ttmtrendup = reference ttm_trend( compBars = compBars ).trendup;
def ttmtrenddwn = reference ttm_trend( compBars = compBars ).trenddown;

plot tup = if ttmtrendup then low else na;
tup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
tup.SetDefaultColor(Color.green);
plot tdwn = if ttmtrenddwn then high else na;
tdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
tdwn.SetDefaultColor(Color.red);
#``````

Last edited:

87k+ Posts
268 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?