Accumulation Distribution Divergence indicator to end at 1600 hr.

shakib3585

Active member
VIP
Greetings All,

I have a question about the Accumulation Distribution Divergence indicator developed by @BenTen .
https://usethinkscript.com/threads/accumulation-distribution-divergence-for-thinkorswim.1546/

Thanks, Ben, for the awesome indicator. I was trying to make some edits to the code. The code indicates that the start time is 9:30, but the end time is the final hour of trading. I was wondering if I could make a code that suggests an end time of 4:00 p.m. I have tried to edit like the following but could not land to a definite solution,
Ruby:
#
# Accumulation_Distribution_Divergence
# Assembled by Kory Gill (@korygill) for BenTen at usethinkscript.com
#

declare lower;
declare once_per_bar;

input OpenTime = 0930;
input Endtime = 1600;
def startcounter = SecondsFromTime(OpenTime);
def endcounter = SecondsFromTime(Endtime);

def bn = BarNumber();
def nan = Double.NaN;
def sft = SecondsFromTime(OpenTime);
def cet = SecondsFromTime(Endtime);
def targetperiod = if sft >= 0 and cet >= 0 then 1 else 0;
# 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 targetperiod == 0
then
{
hVal = ADBP;
lVal = ADBP;
}
else
{
hVal = Max(hVal[1], ADBP);
lVal = Min(lVal[1], ADBP);
}
}

def pdh = if targetperiod and !targetperiod[1] then hVal else pdh[1];
def pdl = if targetperiod and !targetperiod[1] then lVal else pdl[1];
def pdm = 0.5 * (pdh + pdl);

plot ppdh = pdh;
plot ppdl = pdl;
plot ppdm = pdm;

ppdh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdm.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdh.SetDefaultColor(GetColor(1));
ppdl.SetDefaultColor(GetColor(0));
ppdm.SetDefaultColor(GetColor(9));

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

plot pADBP = ADBP; "

I was wondering if anyone could please help with how to make it calculate and plot until 4:00 p.m. Also, the plot for the next day doesn't appear until 9:30 a.m. Is it possible to see the next day's plot on the previous day. Can the same be made for a "daily chart"? If so, please share the solution.

Thank you,

Shakib
 
Last edited by a moderator:
Greetings All,

I have a question about the Accumulation Distribution Divergence indicator developed by @BenTen .
https://usethinkscript.com/threads/accumulation-distribution-divergence-for-thinkorswim.1546/

Thanks, Ben, for the awesome indicator. I was trying to make some edits to the code. The code indicates that the start time is 9:30, but the end time is the final hour of trading. I was wondering if I could make a code that suggests an end time of 4:00 p.m. I have tried to edit like the following but could not land to a definite solution,
Ruby:
#
# Accumulation_Distribution_Divergence
# Assembled by Kory Gill (@korygill) for BenTen at usethinkscript.com
#

declare lower;
declare once_per_bar;

input OpenTime = 0930;
input Endtime = 1600;
def startcounter = SecondsFromTime(OpenTime);
def endcounter = SecondsFromTime(Endtime);

def bn = BarNumber();
def nan = Double.NaN;
def sft = SecondsFromTime(OpenTime);
def cet = SecondsFromTime(Endtime);
def targetperiod = if sft >= 0 and cet >= 0 then 1 else 0;
# 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 targetperiod == 0
then
{
hVal = ADBP;
lVal = ADBP;
}
else
{
hVal = Max(hVal[1], ADBP);
lVal = Min(lVal[1], ADBP);
}
}

def pdh = if targetperiod and !targetperiod[1] then hVal else pdh[1];
def pdl = if targetperiod and !targetperiod[1] then lVal else pdl[1];
def pdm = 0.5 * (pdh + pdl);

plot ppdh = pdh;
plot ppdl = pdl;
plot ppdm = pdm;

ppdh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdm.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ppdh.SetDefaultColor(GetColor(1));
ppdl.SetDefaultColor(GetColor(0));
ppdm.SetDefaultColor(GetColor(9));

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

plot pADBP = ADBP; "

I was wondering if anyone could please help with how to make it calculate and plot until 4:00 p.m. Also, the plot for the next day doesn't appear until 9:30 a.m. Is it possible to see the next day's plot on the previous day. Can the same be made for a "daily chart"? If so, please share the solution.

Thank you,

Shakib

the end of a trading day is 4pm EST, which is 1600, which is what it is set to... so i don't understand what you want.
 

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