using below period aggregation

shakib3585

Active member
VIP
Hello All,

Extract previous week's High, Low, Close data using 4 hour or, any below period aggregation
Can 4-hour or any below aggregation data can be utilized to find previous week's high, low and close. The reason is during pre/post market session, the previous week's high, low close cannot be compared with active data. Any help is greatly appreciated. @SleepyZ would you care to step in.

Thank you
 
Last edited by a moderator:
Hello All,

Extract previous week's High, Low, Close data using 4 hour or, any below period aggregation
Can 4-hour or any below aggregation data can be utilized to find previous week's high, low and close. The reason is during pre/post market session, the previous week's high, low close cannot be compared with active data. Any help is greatly appreciated. @SleepyZ would you care to step in.

Thank you hal_www

yes, data can be read and stored, and be compared to future data.


please edit and rephrase your post. it doesn't make sense.
you ask for something, then state the 'reason' is it can't be done ???
why are you mentioning aggregation ? you are guessing at methods to create something. don't do that. just describe the desired output.

are you asking to,
.. find the high, low, close from the previous week, including pre market prices?

see how short and simple that is.



learn how to think like this and compose better questions,
tell us,
1. where you want to see something, chart, watchlist, scan,
2. what do you want to see , lines, label, bubble, shading, characters in a column,
3. when do you want to see it , just on last bar, last day, all bars, ...
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello All,

Extract previous week's High, Low, Close data using 4 hour or, any below period aggregation
Can 4-hour or any below aggregation data can be utilized to find previous week's high, low and close. The reason is during pre/post market session, the previous week's high, low close cannot be compared with active data. Any help is greatly appreciated. @SleepyZ would you care to step in.

Thank you

this will plot lines at the highest and lowest prices, of the previous week. whi2 , wlo2
works with or without extended hours turned on

Code:
# prev_week_hi_lo


def bn = double.nan;
def na = double.nan;
def cls2 = if isnan(close) then cls2[1] else close;

def currentday = if GetLastDay() == GetDay() then 1 else 0;
def currentweek = if GetLastweek() == Getweek() then 1 else 0;


def o = open;
def h = high;
def l = low;
def c = close;

def wnum = getweek();
def yr = getyear();

# whi = current week   whi2 = prev week
def whi;
def wlo;
def wcls;
def whi2;
def wlo2;
def wcls2;
if bn == 1 then {
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;

} else if wnum[1] != wnum[0] then {
# first bar in week period
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = whi[1];
 wlo2 = wlo[1];
 wcls2 = wcls[1];

} else if wnum[1] == wnum[0] then {
#  bars in same week
 whi = max(h, whi[1]);
 wlo = if wlo[1] == 0 then l else min(l, wlo[1]);
 wcls = c;
 whi2 = whi2[1];
 wlo2 = wlo2[1];
 wcls2 = wcls2[1];

} else {
 whi = 0;
 wlo = 0;
 wcls = 0;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;
}


plot zhi2 = if whi2 > 0 and !isnan(close) then whi2 else na;
plot zlo2 = if wlo2 > 0 and !isnan(close) then wlo2 else na;
zhi2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#x.SetDefaultColor(Color.red);
#x.setlineweight(1);
#x.hidebubble();


addchartbubble(0, low,
whi + "\n" +
whi2 + "\n" +
wlo + "\n" +
wlo2
, color.yellow, no);

addverticalline(0 and wnum[1] != wnum[0], "-", color.cyan);
#
 
Last edited:
this will plot lines at the highest and lowest prices, of the previous week. whi2 , wlo2
works with or without extended hours turned on

Code:
# prev_week_hi_lo


def bn = double.nan;
def na = double.nan;
def cls2 = if isnan(close) then cls2[1] else close;

def currentday = if GetLastDay() == GetDay() then 1 else 0;
def currentweek = if GetLastweek() == Getweek() then 1 else 0;


def o = open;
def h = high;
def l = low;
def c = close;

def wnum = getweek();
def yr = getyear();

# whi = current week   whi2 = prev week
def whi;
def wlo;
def wcls;
def whi2;
def wlo2;
def wcls2;
if bn == 1 then {
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;

} else if wnum[1] != wnum[0] then {
# first bar in week period
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = whi[1];
 wlo2 = wlo[1];
 wcls2 = wcls[1];

} else if wnum[1] == wnum[0] then {
#  bars in same week
 whi = max(h, whi[1]);
 wlo = if wlo[1] == 0 then l else min(l, wlo[1]);
 wcls = c;
 whi2 = whi2[1];
 wlo2 = wlo2[1];
 wcls2 = wcls2[1];

} else {
 whi = 7;
 wlo = 0;
 wcls = 0;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;
}


plot zhi2 = if whi2 > 0 and !isnan(close) then whi2 else na;
plot zlo2 = if wlo2 > 0 and !isnan(close) then wlo2 else na;
zhi2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#x.SetDefaultColor(Color.red);
#x.setlineweight(1);
#x.hidebubble();


addchartbubble(0, low,
whi + "\n" +
whi2 + "\n" +
wlo + "\n" +
wlo2
, color.yellow, no);

addverticalline(0 and wnum[1] != wnum[0], "-", color.cyan);
#
Apologies for the confusion and mesmerized by your code. Thank you, Mr. Rocket! One request please, can you plot the previous week's close on this code @halcyonguy
 
Last edited:
Apologies for the confusion and mesmerized by your code. Thank you, Mr. Rocket! One request please, can you plot the previous week's close on this code @halcyonguy

here you go
added close line. i made it cyan and width of 2, to make it easier to see, because candles are probably going to be crossing it.

Code:
# prev_week_hi_lo


def bn = double.nan;
def na = double.nan;
def cls2 = if isnan(close) then cls2[1] else close;

def currentday = if GetLastDay() == GetDay() then 1 else 0;
def currentweek = if GetLastweek() == Getweek() then 1 else 0;


def o = open;
def h = high;
def l = low;
def c = close;

def wnum = getweek();
def yr = getyear();

# whi = current week   whi2 = prev week
def whi;
def wlo;
def wcls;
def whi2;
def wlo2;
def wcls2;
if bn == 1 then {
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;

} else if wnum[1] != wnum[0] then {
# first bar in week period
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = whi[1];
 wlo2 = wlo[1];
 wcls2 = wcls[1];

} else if wnum[1] == wnum[0] then {
#  bars in same week
 whi = max(h, whi[1]);
 wlo = if wlo[1] == 0 then l else min(l, wlo[1]);
 wcls = c;
 whi2 = whi2[1];
 wlo2 = wlo2[1];
 wcls2 = wcls2[1];

} else {
 whi = 0;
 wlo = 0;
 wcls = 0;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;
}


plot zhi2 = if whi2 > 0 and !isnan(close) then whi2 else na;
plot zlo2 = if wlo2 > 0 and !isnan(close) then wlo2 else na;
plot zcls2 = if wcls2 > 0 and !isnan(close) then wcls2 else na;
zhi2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zcls2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi2.SetDefaultColor(Color.yellow);
zlo2.SetDefaultColor(Color.yellow);
zcls2.SetDefaultColor(Color.cyan);
zcls2.setlineweight(2);
#x.hidebubble();


addchartbubble(0, low,
whi + "\n" +
whi2 + "\n" +
wlo + "\n" +
wlo2
, color.yellow, no);

addverticalline(0 and wnum[1] != wnum[0], "-", color.cyan);
#
 
here you go
added close line. i made it cyan and width of 2, to make it easier to see, because candles are probably going to be crossing it.

Code:
# prev_week_hi_lo


def bn = double.nan;
def na = double.nan;
def cls2 = if isnan(close) then cls2[1] else close;

def currentday = if GetLastDay() == GetDay() then 1 else 0;
def currentweek = if GetLastweek() == Getweek() then 1 else 0;


def o = open;
def h = high;
def l = low;
def c = close;

def wnum = getweek();
def yr = getyear();

# whi = current week   whi2 = prev week
def whi;
def wlo;
def wcls;
def whi2;
def wlo2;
def wcls2;
if bn == 1 then {
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;

} else if wnum[1] != wnum[0] then {
# first bar in week period
 whi = h;
 wlo = l;
 wcls = c;
 whi2 = whi[1];
 wlo2 = wlo[1];
 wcls2 = wcls[1];

} else if wnum[1] == wnum[0] then {
#  bars in same week
 whi = max(h, whi[1]);
 wlo = if wlo[1] == 0 then l else min(l, wlo[1]);
 wcls = c;
 whi2 = whi2[1];
 wlo2 = wlo2[1];
 wcls2 = wcls2[1];

} else {
 whi = 0;
 wlo = 0;
 wcls = 0;
 whi2 = 0;
 wlo2 = 0;
 wcls2 = 0;
}


plot zhi2 = if whi2 > 0 and !isnan(close) then whi2 else na;
plot zlo2 = if wlo2 > 0 and !isnan(close) then wlo2 else na;
plot zcls2 = if wcls2 > 0 and !isnan(close) then wcls2 else na;
zhi2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zcls2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi2.SetDefaultColor(Color.yellow);
zlo2.SetDefaultColor(Color.yellow);
zcls2.SetDefaultColor(Color.cyan);
zcls2.setlineweight(2);
#x.hidebubble();


addchartbubble(0, low,
whi + "\n" +
whi2 + "\n" +
wlo + "\n" +
wlo2
, color.yellow, no);

addverticalline(0 and wnum[1] != wnum[0], "-", color.cyan);
#
Thank you, Mr. Rocket!
 
Hello, I am new to this forum and ran across this post. Is there way to add an alert to this script of price crossing above or below the high, low and close? If it is possible


thank you
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
315 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