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;
Last edited by a moderator: