Accumulation/Distribution Divergence for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Typically, the Accum Dist indicator is used to identify divergences between price activity and the indicator itself. As with other divergences, if the market reaches new highs while the indicator is stagnant or falling, the current trend may be weakening suggesting a possible reversal. Conversely, if the market reaches new lows while the indicator is stagnant or rising, the trend may be weakening perhaps indicating a reversal.
Based on this description, I asked @korygill to help me plot the previous day high and low of the default AccumDistBuyPr indicator provided by ThinkorSwim. Since we're looking for possible divergences, we would need to also plot the previous day high and low of the stock. Luckily, there is already a built-in indicator to help you with that. It's called DailyHighLow.

Putting the two together, you will have this:



thinkScript Code

Code:
#
# Accumulation_Distribution_Divergence
# Assembled by Kory Gill (@korygill) for BenTen at usethinkscript.com
#

declare lower;
declare once_per_bar;

input OpenTime = 0930;

def bn = BarNumber();
def nan = double.NaN;
def sft = SecondsFromTime(Opentime);
# plot p1 = sft;

def data = if close > close[1] then close - Min(close[1], low) else if close<close[1] then close - Max(close[1], high) else 0;
def SumData = if bn == 1 then data else SumData[1] + data;
def ADBP = SumData;
# dont use built in function, it's slow.  Avoid calling TotalSum on each subsequent bar.
# def ADBP = AccumDistBuyPr().AccDist;
def hVal;
def lVal;

if bn == 1 then
{
    hVal = nan;
    lVal = nan;
}
else if bn == 2 then
{
    hVal = ADBP;
    lVal = ADBP;
}
else
{
    if sft == 0 then
    {
        hVal = ADBP;
        lVal = ADBP;
    }
    else
    {
        hVal = Max(hVal[1], ADBP);
lVal = Min(lVal[1], ADBP);
    }
}

def pdh = if sft[-1] == 0 then hVal else pdh[1];
def pdl = if sft[-1] == 0 then lVal else pdl[1];

plot ppdh = pdh;
plot ppdl = pdl;
ppdh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdh.SetDefaultColor(GetColor(1));
ppdl.SetDefaultColor(GetColor(0));

#plot ph = hVal;
#plot pl = lVal;

plot pADBP = ADBP;

#def openADBP = if sft == 0 then ADBP else openADBP[1];
#def PO = openADBP;
@diazlaz has done some fantastic enhancements to this indicator. Once I have his permission to share, I'll drop the code in here also.
 
P

pk1729

Member
VIP
This is interesting. Do you have any example very you saw divergence?

Looking forward to diazlaz enhancements :)
 
BenTen

BenTen

Administrative
Staff
VIP
@pk1729 Take a look at the screenshot in the original thread. I saw a few from it. What I usually do is compare the current Buying Pressure line (in white at the lower study) to the current stock price. Sort of like looking at the rate of change for both.

Here we have the same screenshot from above but highlighted with possible divergences.

 
allpozitiv

allpozitiv

New member
2019 Donor
VIP
@BenTen, I am just wondering if there is the permission from @diazlaz granted for improved indicator to share, as you wrote in post#1 below?
 
P

pk1729

Member
VIP
@BenTen, I am just wondering if there is the permission from @diazlaz granted for improved indicator to share, as you wrote in post#1 below?
+1 @BenTen can you share any updates from @diazlaz ?
 
P

Piper2808t

Member
2019 Donor
VIP
Hi great indicator may this be placed in a column when accumulation dist crosses above pplh line and when it crosses below ppld line thanks much
 
M

mansor

Member
@BenTen how is this different than QQE. I generally getting a sense that some scripts is a derivation or a nuance of another script..
 
BenTen

BenTen

Administrative
Staff
VIP
@mansor This is completely different, it doesn't use RSI.
 

Similar threads

Top