Accumulation/Distribution Indicator for ThinkorSwim

netleo

New member
Lifetime
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?

Thank you in advance,
 

anty

New member
VIP
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);
 

samks_30

New member
2019 Donor
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"));
 

tomsk

Well-known member
VIP
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
# http://traders.com/Documentation/FEEDbk_docs/2018/08/TradersTips.html

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:

nemg28

New member
VIP
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:

tomsk

Well-known member
VIP
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;
 

nemg28

New member
VIP
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.
 

tomsk

Well-known member
VIP
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
 
I'm attempting to make a MTF accumulation distribution script. I can't seem to get it right. Any help would be appreciated. Thank you all.

My coding attempt:

Code:
declare lower;
input = {"1 min", "3 min", "5 min", "15 min", "30 min", "60 min", "120 min", "Daily"},

plot AccDist = TotalSum(volume * CloseLocationValue());
plot ZeroLine = 0;

AccDist.SetDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(5));
 

BuddyLee

New member
Hi first time post, I really appreciate any help on this subject as TOS support and my own 10+ hrs of troublshooting doesn't get anywhere (I'm not very knowledgable)

Under Marketwatch tab, study alerts, and using the study alert on upper right corner.
I'm try to setup a study alert using AccumulationDistrbution in 5 min time frame, for spikes above >=1000 or 18, most of these appear in the premarket/aftermarket. Please see the pdf linked. I'm getting erroneous false alarm signals as seen in the preview window. Please see pics link:

Any thoughts or feedback would be appreciated. Thank you in advance!
 

germanburrito

Active member
accu/dis by mobious with clouds https://tos.mx/S0u7Gih
35T4SP6.png

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);
addCloud(accDist, mean, color.green, color.red);  
addCloud(0, mean, color.green, Color.YELLOW);    
# End Code
 
Last edited:

rad14733

Well-known member
VIP
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...

qTo0ih2.jpg


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

KJ1zNYU.jpg
 
Last edited:

theLEMband

New member
VIP
@anty This looks interesting, thanks for the contribution! Is there any information on this on the internet? How are you using this?

The overbought & oversold lines are not used and can be removed from the script.
 

Similar threads

Top