Accumulation/Distribution Indicator for ThinkorSwim

@Mr_Wheeler

You are getting the "too complicated" symbol on the top of your column because watchlists need to have one plot at the most, there are way too many in this script. There are also many many extraneous charting statements which shouldn't be in a watchlist column.

Here is the pared-down version which provides the same logic and data w/o the superfluous code:
Stages Watchlist: Acceleration, Deceleration, Accumulation, Distribution extracted from:
https://usethinkscript.com/threads/...tion-indicator-for-thinkorswim.951/#post-7724
Shared Watchlist column link: http://tos.mx/3XF6kkW Click here for --> Easiest way to load shared links
Ruby:
input MAlength = 21;

def WAD = AccumDistBuyPr();
def VMA = Average(WAD, MAlength);

def vwma8 = Sum(volume * close, 8) / Sum(volume, 8);
def vwma21 = Sum(volume * close, 21) / Sum(volume, 21);
def vwma34 = Sum(volume * close, 34) / Sum(volume, 34);

def bullish = if vwma8 > vwma21 and vwma21 > vwma34 then 1 else 0;
def bearish = if vwma8 < vwma21 and vwma21 < vwma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;

AddLabel (yes, if bullish then "Stage: Acceleration" else if bearish then "Stage: Deceleration" else if close >= VMA then "Stage: Accumulation" else "stage: Distribution", if bullish then Color.GREEN else if bearish then Color.RED else if close >= VMA then Color.YELLOW else Color.ORANGE);
 
Last edited:
@Mr_Wheeler , can you post a photo of the watchlist and explain it a bit? Thank you in advance
Since you're interested in my setup I'll explain it. I'll bookmark this post for future references.
Current setup
QeL0ceV.png

The break down.
syv63kh.png

  • I've selected the "last price" , 9, 50, and 200 MA which represent moving averages.
  • I'm using "weighted" moving averages.
MJXAgAz.png


F14qsE7.png

  • "Ck 1st", "ck 2nd" "ck 3rd" and "check 4th" mean check the columns in that order.
  • "9 Abv 50" translates to the 9 MDA above the 50 MDA. If the 9 MDA is above the 50 MDA then the square turns green. if the 9ma is bellow the 50 DMA then the square turns white.
  • the numbers inside those colored squares represent the % value the 9 MDA is away from crossing the 50 MDA for instance, or how much of a percentage the 9 MDA is above the 50 MDA .

Look at $RLX, the "9 ABV 200" is green, and has "7.29" in that green square. That means $RLX's 9 MDA is 7.29 percent above the 200 MDA.
WzlSW4x.png

Code:
# avgs_per_diff_00

declare lower;

input avg1Type = Averagetype.weighted;
input avg2type = Averagetype.weighted;
input Avg1Length = 9;
input Avg2Length = 200;

def avg1 = MovingAverage(avg1Type, close, avg1Length);
def avg2 = MovingAverage(avg2Type, close, avg2Length);
def avgup = (avg1 > avg2);

#def AvgPercent = MovingAverage(avg1Type, close, avg1Length)-MovingAverage(avg2Type, close, avg2Length);
# plot percentDiff = (absValue(avgPercent)/movingaverage(avg1type,close,avg1length)) *100;

def Avg12diff = avg1 - avg2;

plot percentDiff = (absValue(avg12diff)/avg1) *100;
percentDiff.DefineColor("Up", color.green);
percentDiff.DefineColor("Down", color.red);
percentDiff.AssignValueColor(if avgup then percentDiff.color("up") else percentDiff.color("down"));


AssignBackgroundColor(if Avg1 is greater than or equal to Avg2 then (CreateColor(0, 102, 0)) else Color.light_GRAY);
 
Since you're interested in my setup I'll explain it. I'll bookmark this post for future references.
Current setup
QeL0ceV.png

The break down.
syv63kh.png

  • I've selected the "last price" , 9, 50, and 200 MA which represent moving averages.
  • I'm using "weighted" moving averages.
MJXAgAz.png


F14qsE7.png

  • "Ck 1st", "ck 2nd" "ck 3rd" and "check 4th" mean check the columns in that order.
  • "9 Abv 50" translates to the 9 MDA above the 50 MDA. If the 9 MDA is above the 50 MDA then the square turns green. if the 9ma is bellow the 50 DMA then the square turns white.
  • the numbers inside those colored squares represent the % value the 9 MDA is away from crossing the 50 MDA for instance, or how much of a percentage the 9 MDA is above the 50 MDA .

Look at $RLX, the "9 ABV 200" is green, and has "7.29" in that green square. That means $RLX's 9 MDA is 7.29 percent above the 200 MDA.
WzlSW4x.png

Code:
# avgs_per_diff_00

declare lower;

input avg1Type = Averagetype.weighted;
input avg2type = Averagetype.weighted;
input Avg1Length = 9;
input Avg2Length = 200;

def avg1 = MovingAverage(avg1Type, close, avg1Length);
def avg2 = MovingAverage(avg2Type, close, avg2Length);
def avgup = (avg1 > avg2);

#def AvgPercent = MovingAverage(avg1Type, close, avg1Length)-MovingAverage(avg2Type, close, avg2Length);
# plot percentDiff = (absValue(avgPercent)/movingaverage(avg1type,close,avg1length)) *100;

def Avg12diff = avg1 - avg2;

plot percentDiff = (absValue(avg12diff)/avg1) *100;
percentDiff.DefineColor("Up", color.green);
percentDiff.DefineColor("Down", color.red);
percentDiff.AssignValueColor(if avgup then percentDiff.color("up") else percentDiff.color("down"));


AssignBackgroundColor(if Avg1 is greater than or equal to Avg2 then (CreateColor(0, 102, 0)) else Color.light_GRAY);
Since you're interested in my setup I'll explain it. I'll bookmark this post for future references.
Current setup
QeL0ceV.png

The break down.
syv63kh.png

  • I've selected the "last price" , 9, 50, and 200 MA which represent moving averages.
  • I'm using "weighted" moving averages.
MJXAgAz.png


F14qsE7.png

  • "Ck 1st", "ck 2nd" "ck 3rd" and "check 4th" mean check the columns in that order.
  • "9 Abv 50" translates to the 9 MDA above the 50 MDA. If the 9 MDA is above the 50 MDA then the square turns green. if the 9ma is bellow the 50 DMA then the square turns white.
  • the numbers inside those colored squares represent the % value the 9 MDA is away from crossing the 50 MDA for instance, or how much of a percentage the 9 MDA is above the 50 MDA .

Look at $RLX, the "9 ABV 200" is green, and has "7.29" in that green square. That means $RLX's 9 MDA is 7.29 percent above the 200 MDA.
WzlSW4x.png

Code:
# avgs_per_diff_00

declare lower;

input avg1Type = Averagetype.weighted;
input avg2type = Averagetype.weighted;
input Avg1Length = 9;
input Avg2Length = 200;

def avg1 = MovingAverage(avg1Type, close, avg1Length);
def avg2 = MovingAverage(avg2Type, close, avg2Length);
def avgup = (avg1 > avg2);

#def AvgPercent = MovingAverage(avg1Type, close, avg1Length)-MovingAverage(avg2Type, close, avg2Length);
# plot percentDiff = (absValue(avgPercent)/movingaverage(avg1type,close,avg1length)) *100;

def Avg12diff = avg1 - avg2;

plot percentDiff = (absValue(avg12diff)/avg1) *100;
percentDiff.DefineColor("Up", color.green);
percentDiff.DefineColor("Down", color.red);
percentDiff.AssignValueColor(if avgup then percentDiff.color("up") else percentDiff.color("down"));


AssignBackgroundColor(if Avg1 is greater than or equal to Avg2 then (CreateColor(0, 102, 0)) else Color.light_GRAY);
Mr_Wheeler - thank you so much for taking the time out to explain!
 
Hi everyone,

Does anybody have the code for Accumulation/Distribution volume Indicator with Moving Average for ThinkorSwim?

Many thanks!
 
I cut and pasted a couple indicators (can't remember where from) to come up with the following modified Williams Accumulation Distribution indicator.

Code:
declare lower;
input overBought = -20;
input overSold = -80;
input MAlength = 21;
input price = close;
input ChartBubblesOn = no;

plot WAD = AccumDistBuyPr();
WAD.SetDefaultColor(GetColor(1));



plot VMA = Average(WAD, MAlength);
VMA.SetDefaultColor(GetColor(0));

def WADDownCross = Crosses(( WAD < 0) != 0, 0.5, yes );
plot SignalDn = if WADDownCross then VMA else Double.NaN;
SignalDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SignalDn.SetDefaultColor(Color.DOWNTICK);
SignalDn.SetLineWeight(5);

def WADUpCross = Crosses(( WAD > 0) != 0, 0.5, yes );
plot SignalUp = if WADUpCross then VMA else Double.NaN;
SignalUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SignalUp.SetDefaultColor(Color.UPTICK);
SignalUp.SetLineWeight(5);

AddCloud(WAD, VMA, Color.UPTICK);


def VMAUpCross = Crosses((VMA > WAD) != 0, 0.5, no );# && VMAUpCross
#rec flip = if VMAUpCross == VMAUpCross[1] then 0 else 1;
plot ArrowUp = if VMAUpCross then VMA else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.CYAN);

def VMADnCross = Crosses((VMA < WAD) != 0, 0.5, no );# && VMAUpCross
#rec flop = if VMADnCross or flop then 1 else 0;
plot ArrowDn = if VMADnCross then VMA else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.YELLOW);

def relativeVMA = Round((VMA - LowestAll(VMA)) / (HighestAll(VMA) - LowestAll(VMA)), 2) * 100;
AddLabel(yes, Concat( Round(relativeVMA, 2), Concat("", "%")), if relativeVMA > 80 then Color.RED else if relativeVMA < 20 then Color.GREEN else Color.GRAY );

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = Sum(tmp1, MAlength);
def d4 = Sum(tmp2, MAlength);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (MAlength + 1) * AbsValue(ad3) / 100;
def asd = CompoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);
VMA.SetDefaultColor(GetColor(0));

def vwma8 = Sum(volume * close, 8) / Sum(volume, 8);
def vwma21 = Sum(volume * close, 21) / Sum(volume, 21);
def vwma34 = Sum(volume * close, 34) / Sum(volume, 34);

def bullish = if vwma8 > vwma21 and vwma21 > vwma34 then 1 else 0;
def bearish = if vwma8 < vwma21 and vwma21 < vwma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;

AddLabel (yes, if bullish then "Stage: Acceleration" else if bearish then "Stage: Deceleration" else if close >= VMA then "Stage: Accumulation" else "stage: Distribution", if bullish then Color.GREEN else if bearish then Color.RED else if close >= VMA then Color.YELLOW else Color.ORANGE);

VMA.AssignValueColor(if bearish then Color.RED else if bullish and close >= VMA then Color.GREEN else Color.GRAY);

def accumulationToAcceleration = if (bullish and close >= VMA) then 1 else 0;
AddChartBubble(ChartBubblesOn and accumulationToAcceleration and !accumulationToAcceleration[1], close, "Entering Acceleration", Color.GREEN);

def distributionToDeceleration = if (bearish and close <= VMA) then 1 else 0;
AddChartBubble(ChartBubblesOn and distributionToDeceleration and !distributionToDeceleration[1], close, "Entering Deceleration", Color.RED);
Do you happen to have a scan for this as well?
 

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
408 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