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 =...
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;

addcloud( top, bot, color.green, color.red);

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

T11On7m.jpg
 

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

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;

addcloud( top, bot, color.green, color.red);

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

TNHVQnE.jpg
 
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.
Fantastic, appreciate the feedback. Look forward to your additional examples.
 
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

kXSnyom5AZjqUth?width=994&height=734&cropmode=none.png
 
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.

https://usethinkscript.com/threads/extend-high-and-lows-to-the-right-of-the-chart.7134/

robert's forum, the source of the code in previous link
https://researchtrade.com/forum/read.php?7,2258,page=19

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
https://usethinkscript.com/threads/how-to-plot-line-between-2-point.6945/#post-67309
https://usethinkscript.com/threads/aggregated-fib-fan.7274/

there are other ways to do this, including using fold.
 
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.

https://usethinkscript.com/threads/extend-high-and-lows-to-the-right-of-the-chart.7134/

robert's forum, the source of the code in previous link
https://researchtrade.com/forum/read.php?7,2258,page=19

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
https://usethinkscript.com/threads/how-to-plot-line-between-2-point.6945/#post-67309
https://usethinkscript.com/threads/aggregated-fib-fan.7274/

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.

Yp2cwuKiSrKVTU?width=1038&height=781&cropmode=none.png
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
 
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
i've been rereading this thread. sorry, i missed your post 6 when i asked earlier about your rules. i will make another version of my study to include your rules.
 
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


# https://usethinkscript.com/threads/sma-and-accumulation-divergence-scan-or-indicator.7305/#post-70878
# 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;
AddCloud( top, bot, Color.GREEN, Color.RED);

#


test FB , day chart

RKoHE4J.jpg



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:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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