# Accumulation/Distribution Indicator for ThinkorSwim

#### netleo

##### New member
A quick question: I'm trying to find accumulation/distribution indicator in ThinkorSwim (it should be a line based on 3 factors such as

Accumulation Distribution Components
• The calculation of the A/D consists of three components- money flow multiplier (MFM), money flow volume (MFV), and accumulation distribution line (ADL).
Money Flow Multiplier (MFM)
• MFM = ((Close – Low) – (High – Close)) / (High – Low)
Money Flow Volume (MFV)
• MFV = MFM x Volume on the Period

ThinkorSwim has AD indicator but its not a line and I believe its only based on price, not volume+price. Is there any way to obtain the code for AD indicator in ThinkorSwim?

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;

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);

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);``````

Code:
``````#KSK: Green candles can work as base; Big red candles as top
declare lower;

input max_distday = 9;
input accumulation_or_distribution = {"accum", default "dist"};

def uVolume = close("\$UVOL");
def dVolume = close("\$DVOL");

plot baseline = 0;
plot distribution_day = max_distday;

plot volume;

switch(accumulation_or_distribution){
case accum:
volume = uVolume / dVolume;
default:
volume = dVolume / uVolume;
}

volume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
volume.DefineColor("Positive", Color.UPTICK);
volume.DefineColor("Negative", Color.DOWNTICK);
volume.AssignValueColor(if volume >= max_distday then volume.color("Positive") else volume.color("Negative"));``````

TASC put together a study for thinkorswim based on the article “Portfolio Strategy Based On Accumulation/Distribution”, authored by Domenico D’Errico.

Code:
``````# Accumulation/Distribution
# Domenico D’Errico
# Technical Analysis of Stocks & Commodities, Aug 2018
# 8.7.2018

declare lower;

input length = 4;
input factor = 0.75;
input mode = {default Range, ATR};

def range;
switch (mode) {
case Range:
range = Highest(high, length) - Lowest(low, length);

case ATR:
range = reference ATR();
}

plot RangeRatio = range / range[length];
plot RangeFactor = factor;

RangeRatio.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RangeRatio.DefineColor("Consolidation", GetColor(4));
RangeRatio.DefineColor("Non-consolidation", GetColor(1));

RangeRatio.AssignValueColor( if (RangeRatio < RangeFactor) then RangeRatio.Color("Consolidation") else RangeRatio.Color("Non-consolidation"));
RangeFactor.SetDefaultColor(GetColor(7));``````

Last edited by a moderator:
I was looking for an indicator that would let me know when a stock would take off the next day or at least give me a warning sign, which is why I started to look for accumulation/ distribution indicator. I found this indicator called the major_accumulation_distribution_days 15 minute timeframe indicator on a website called easycators.com.

I noticed a pattern with the indicator, every time most of the bars crossed over or touched the 1.8 baseline (the baseline was originally higher but I changed it down to 1.8), the next day the stock would either jump up or down in price.

Here is an example of what I am noticing.

I am hoping someone will be able to create a scanner that scans for the days that most of the bars touch or crossover the 1.8 baseline from the code below.

Code:
``````declare lower;

input max_distday = 9;
input accumulation_or_distribution = {"accum", default "dist"};

def uVolume = close("\$UVOL");
def dVolume = close("\$DVOL");

plot baseline = 1.8;
plot distribution_day = max_distday;

plot volume;

switch(accumulation_or_distribution){
case accum:
volume = uVolume / dVolume;
default:
volume = dVolume / uVolume;
}

volume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
volume.DefineColor("Positive", Color.UPTICK);
volume.DefineColor("Negative", Color.DOWNTICK);
volume.AssignValueColor(if volume >= max_distday then volume.color("Positive") else volume.color("Negative"));``````

I also noticed on some days that if the bars accumulate and pass the 1.8 baseline. If the next day doesn't show any price movement, then typically that is showing that the stock is still consolidating and will breakout or down the next day.

Here are a few examples:

It would be much appreciated is someone could create a scanner for what I am trying to accomplish. Also let me know what you think about the pattern I recognized. I am still trying to find an indicator to let me know what direction the price will move the next day, so if anybody has any ideas, let me know and thank you!

Last edited by a moderator:
Here's the conversion of your study to a scan. Note that a scan only accepts a single plot statement

input accumulation_or_distribution = {"accum", default "dist"};

Code:
``````def uVolume = close("\$UVOL");
def dVolume = close("\$DVOL");

def baseline = 1.8;
def v;

switch(accumulation_or_distribution){
case accum:
v = uVolume / dVolume;
default:
v = dVolume / uVolume;
}

plot scan = v >= baseline;``````

Thank you @tomsk did you get any results from the scan? I have tried multiple times and haven't gotten any results. I don't really know much about coding so I'm guessing I have set up wrong. When I am adding in the study to scan, do I need to leave the scan as value or as true? Thank you again.

The conversion was based upon the study you supplied. Perhaps there may be some matches on some other days. In other words you may not get a high number of matches every day

accu/dis by mobious with clouds https://tos.mx/S0u7Gih

Code:
``````# Volume Tick Accumulation / Distribution

# Mobius

# V01

# Compares the single day accumulation / distribution of volume and tick count

declare lower;

def today = GetDay() == GetLastDay();

script AccDist {

input high = high;

input close = close;

input low = low;

input open = open;

input volume = volume;

def today = GetDay() == GetLastDay();

def AccDistSum = CompoundValue(1, (if today and  high - low > 0

then AccDistSum[1] + ((close - open) / (high - low) * volume)

else 0), 1);

plot data = AccDistSum;

}

plot AccDist = if today

then AccDist(high, close, low, open, volume)

else 0;

AccDist.SetDefaultColor(Color.CYAN);

AccDist.HideTitle();

plot AccDistT = if today

then AccDist(high, close, low, open, tick_count)

else 0;

AccDistT.SetDefaultColor(Color.YELLOW);

AccDistT.HideTitle();

plot mean = if today

then inertiaAll((AccDist + AccDistT) / 2)

else Double.NaN;

mean.SetDefaultColor(Color.GRAY);

mean.HideTitle();

plot "0" = if IsNaN(close) then Double.NaN else 0;

"0".SetStyle(Curve.Long_Dash);

"0".SetDefaultColor(Color.Pink);

"0".HideTitle();

accDist.AssignValueColor(if accDist > 0
then color.green
else color.red);
# End Code``````

Last edited:
I tried loading this, however, not working? I have loaded 100s of scripts, so not operator error

I tried loading this, however, not working? I have loaded 100s of scripts, so not operator error
It works based on Tick count so it doesn't appear to work with Time based charts...

Edited to add: I do see that the example in Post #5 is using a 5m chart and now it appears to be working on 3m and 5m whereas when I first loaded the indicator it only showed a red line or nothing at all on 3m Charts... Odd...!!!

Last edited:
I tried loading this, however, not working? I have loaded 100s of scripts, so not operator error

When I originally tested it I may have been looking back a few days and I see now that it is only painting for today, not for the past # days that the chart is set to...

I tried loading this, however, not working? I have loaded 100s of scripts, so not operator error
Did you ever get this to work? Its not thus far for me.

Did you ever get this to work? Its not thus far forit
it works, i use it everyday the code is right i is a five mnute chart

Edited to add: I do see that the example in Post #5 is using a 5m chart and now it appears to be working on 3m and 5m whereas when I first loaded the indicator it only showed a red line or nothing at all on 3m Charts... Odd...!!!

Doesn't work on anything above 30 min

Finally modified the Mobius acct/dist indicator to a month

If someone could fix it so it would display regardless of timeframe completely it would be great

Code:
``````# Volume Tick Accumulation / Distribution

# Mobius

# V01

# Compares the single day accumulation / distribution of volume and tick count

declare lower;

def Month = GetMonth() == GetLastMonth();

script AccDist {

input high = high;

input close = close;

input low = low;

input open = open;

input volume = volume;

def today = GetMonth() == GetLastMonth();

def AccDistSum = CompoundValue(1, (if today and  high - low > 0

then AccDistSum[1] + ((close - open) / (high - low) * volume)

else 0), 1);

plot data = AccDistSum;

}

plot AccDist = if Month

then AccDist(high, close, low, open, volume)

else 0;

AccDist.SetDefaultColor(Color.CYAN);

AccDist.HideTitle();

plot AccDistT = if Month

then AccDist(high, close, low, open, tick_count)

else 0;

AccDistT.SetDefaultColor(Color.YELLOW);

AccDistT.HideTitle();

plot mean = if Month

then inertiaAll((AccDist + AccDistT) / 2)

else Double.NaN;

mean.SetDefaultColor(Color.GRAY);

mean.HideTitle();

plot "0" = if IsNaN(close) then Double.NaN else 0;

"0".SetStyle(Curve.Long_Dash);

"0".SetDefaultColor(Color.Pink);

"0".HideTitle();

accDist.AssignValueColor(if accDist > 0
then color.green
else color.red);
# End Code``````

accu/dis by mobious with clouds https://tos.mx/S0u7Gih

Code:
``````# Volume Tick Accumulation / Distribution

# Mobius

# V01

# Compares the single day accumulation / distribution of volume and tick count

declare lower;

def today = GetDay() == GetLastDay();

script AccDist {

input high = high;

input close = close;

input low = low;

input open = open;

input volume = volume;

def today = GetDay() == GetLastDay();

def AccDistSum = CompoundValue(1, (if today and  high - low > 0

then AccDistSum[1] + ((close - open) / (high - low) * volume)

else 0), 1);

plot data = AccDistSum;

}

plot AccDist = if today

then AccDist(high, close, low, open, volume)

else 0;

AccDist.SetDefaultColor(Color.CYAN);

AccDist.HideTitle();

plot AccDistT = if today

then AccDist(high, close, low, open, tick_count)

else 0;

AccDistT.SetDefaultColor(Color.YELLOW);

AccDistT.HideTitle();

plot mean = if today

then inertiaAll((AccDist + AccDistT) / 2)

else Double.NaN;

mean.SetDefaultColor(Color.GRAY);

mean.HideTitle();

plot "0" = if IsNaN(close) then Double.NaN else 0;

"0".SetStyle(Curve.Long_Dash);

"0".SetDefaultColor(Color.Pink);

"0".HideTitle();

accDist.AssignValueColor(if accDist > 0
then color.green
else color.red);
# End Code``````
Hi @germanburrito , do you have a scanner for this script? If so, appreciate it if you could provide the code. Txs

Hi @germanburrito , do you have a scanner for this script? If so, appreciate it if you could provide the code. Txs
I dont im Sorry I wouldn't know how to set one up, also it repaints.

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