Plot AccumDistBuyPr previous week's high low

shakib3585

Active member
VIP
Hello All,

I'm requesting help with a thinkscript that uses ThinkorSwim's default AccumDistBuyPr indicator to plot the high and low of the previous week as horizontal lines on the lower panel. I know @BenTen has a code that does the same except that it plots the previous day's high and low based on the default AccumDistBuyPr indicator. I do not know how to modify that code based on the week's data. Please help. @SleepyZ would you care to please help me.

Thank you

@SleepyZ, can you please help me with a script for this problem, thank you very much.
 
Last edited by a moderator:
I'm requesting help with a thinkscript that uses ThinkorSwim's default AccumDistBuyPr indicator to plot the high and low of the previous week as horizontal lines on the lower panel. I know @BenTen has a code that does the same except that it plots the previous day's high and low based on the default AccumDistBuyPr indicator. I do not know how to modify that code based on the week's data. Please help.

sorry, i have no idea what you are asking.
AccumDistBuyPr plots a line, that mimics the close prices candles, at a smaller scale. it has nothing to do with high or low of a period.
if you know of a code to use as a starting point,. post it and post a link to it. click on the post number in upper right corner, then copy the web link, to go right to that post.


if you want horizontal lines, at last weeks hi and low, just say that.
look at this and set the time to week
https://usethinkscript.com/threads/previous-hour-hours-high-low-close.17928/#post-137989
 
sorry, i have no idea what you are asking.
AccumDistBuyPr plots a line, that mimics the close prices candles, at a smaller scale. it has nothing to do with high or low of a period.
if you know of a code to use as a starting point,. post it and post a link to it. click on the post number in upper right corner, then copy the web link, to go right to that post.


if you want horizontal lines, at last weeks hi and low, just say that.
look at this and set the time to week
https://usethinkscript.com/threads/previous-hour-hours-high-low-close.17928/#post-137989
I have attached the code @halcyonguy . It plots the high and low of Accumulation/distribution based off previous day's distribution as horizontal lines. I am requesting the same but now it should be based off previous week's high and low value of the Accumulation/Distribution line . Thank you
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;

1708293804039.png


Would you please help to solve my problem @SleepyZ , I am struggling a lot


@SleepyZ would you please care to help
 
Last edited by a moderator:
I have attached the code @halcyonguy . It plots the high and low of Accumulation/distribution based off previous day's distribution as horizontal lines. I am requesting the same but now it should be based off previous week's high and low value of the Accumulation/Distribution line . Thank you
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;

View attachment 21100

Would you please help to solve my problem @SleepyZ , I am struggling a lot


@SleepyZ would you please care to help

This is hard coded to only find the high/low of the previous week.
Use this on a 10d timeframe chart.
The image is from the same period as the post #1 for comparion.
Refer to post #1 as to how this might be used.

Screenshot 2024-02-22 134014.png
Code:
#
# Accumulation_Distribution_Divergence
# Assembled by Kory Gill (@korygill) for BenTen at usethinkscript.com
# Added Previous Week H/L

declare lower;
declare once_per_bar;

input OpenTime = 0930;

def bn = BarNumber();
def nan = Double.NaN;
def sft = SecondsFromTime(OpenTime);


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;

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

#Previous Week High/Low

#Weeks Defined
def ymd   = GetWeek();
def count = if ymd != ymd[1] and !IsNaN(close) then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count + 1;
input vertical = yes;
AddVerticalLine(vertical and cond[1] == 3 and cond == 2, "Prevous Week Start", Color.WHITE);
AddVerticalLine(vertical and cond[1] == 2 and cond == 1, "Current Week Start", Color.WHITE);

def pwh =
     if cond[1] == 3 and cond == 2 then pdh
else if cond == 2 and sft[0] == 0 and pdh > pwh[1] then pdh
else if cond == 1 then pwh[1]
else pwh[1];

plot ppwh = if cond > 1 then Double.NaN else pwh;
ppwh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def pwl =
     if cond[1] == 3 and cond == 2 then pdl
else if cond == 2 and sft[0] == 0 and pdl < pwl[1] then pdl
else if cond == 1 then pwl[1]
else pwl[1];

plot ppwl = if cond > 1 then Double.NaN else pwl;
ppwl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input bubbles     = yes;
input bubblemover = 2;
def   mover       = bubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);

AddChartBubble(mover, ppdh, "dh", ppdh.TakeValueColor());
AddChartBubble(mover, ppdl, "dl", ppdl.TakeValueColor());
AddChartBubble(mover, ppwh, "wh", ppwh.TakeValueColor());
AddChartBubble(mover, ppwl, "wl", ppwl.TakeValueColor());

plot pADBP = ADBP;

#
 
This is hard coded to only find the high/low of the previous week.
Use this on a 10d timeframe chart.
The image is from the same period as the post #1 for comparion.
Refer to post #1 as to how this might be used.
Thank you so much, @SleepyZ . The code works great, except it only shows for the previous week. Can you please modify it so that it can show all other previous week's highs and lows of AccDistr since the IPO time for any stock (i.e., the previous highs and lows of AccDist inside the red box below. The aggregation period is (Max : 1D)). Thanks again
 

Attachments

  • Screenshot 2024-02-22 163252.png
    Screenshot 2024-02-22 163252.png
    341.6 KB · Views: 47
Thank you so much, @SleepyZ . The code works great, except it only shows for the previous week. Can you please modify it so that it can show all other previous week's highs and lows of AccDistr since the IPO time for any stock (i.e., the previous highs and lows of AccDist inside the red box below. The aggregation period is (Max : 1D)). Thanks again

This seems to work on a Day chart timeframe.

Screenshot 2024-02-23 044714.png
Code:
#
# Accumulation_Distribution_Divergence
# Assembled by Kory Gill (@korygill) for BenTen at usethinkscript.com
# Added Previous Week H/L

declare lower;
declare once_per_bar;

input OpenTime = 0930;

def bn = BarNumber();
def nan = Double.NaN;
def sft = SecondsFromTime(OpenTime);


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;

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

#Previous Week High/Low

#Weeks Defined
def ymd   = GetWeek();
def count = if ymd != ymd[1] and !IsNaN(close) then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count + 1;
input vertical = yes;
addverticalLine(ymd!=ymd[1],"",color.gray);

def pwh =
     if cond[1] != cond then pdh
else if cond and sft[0] == 0 and pdh > pwh[1] then pdh
else pwh[1];
def pwh1 = if cond!=Cond[-1] and sft[0] == 0 then pwh else pwh1[1];

plot ppwh = pwh1[1];
ppwh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def pwl =
     if cond[1] != cond then pdl
else if cond and sft[0] == 0 and pdl < pwl[1] then pdl
else pwl[1];
def pwl1 = if cond!=Cond[-1] and sft[0] == 0 then pwl else pwl1[1];

plot ppwl = pwl1[1];
ppwl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input bubbles     = yes;
input bubblemover = 2;
def   mover       = bubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);

AddChartBubble(mover, ppdh, "dh", ppdh.TakeValueColor());
AddChartBubble(mover, ppdl, "dl", ppdl.TakeValueColor());
AddChartBubble(mover, ppwh, "wh", ppwh.TakeValueColor());
AddChartBubble(mover, ppwl, "wl", ppwl.TakeValueColor());

plot pADBP = ADBP;

#
 

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