HighestAll/ LowestAll is not considering the aggregation period

EPrakash

New member
Hi all,

I am trying to draw previous day high, previous day low, last week high, last week low in the chart as 'Price Level'. [I know there is an option in thinkorswim to draw price level manually]. I wanted to draw this level in a study so that every time I input a new ticker, level will be automatically loaded.

def lastDayLow= low(period = 'Day')[1];
def lastDayHigh = high(period = 'Day')[1];
def lastWeekLow = low(period = 'Week')[1];
def lastWeekHigh = high(period = 'Week')[1];

plot dayLow = lastDayLow;
plot dayHigh = lastDayHigh;
plot weekLow = lastWeekLow;
plot weekHigh= lastWeekHigh;

When I tried this, I don't see price level line. I got a PaintingStrategy type - LINE. I tried with horizontal line and It draws on each bars. I did not get the horizontal line like 'Price Level' line.

Hence I used lowestAll like this,

plot dayLow = lowestAll(period = 'Day')[1]

I got the line as 'Price Level' line but it took the lowest price of the year though I have used the AggregationPeriod as 'Day'

Note:
When I try this - I draws the Price level line at 20.
plot a = 20;

So I thought of trying like this but it did not draw price level line
plot a = low(period="Day")[1];

Can someone help ?
 
Last edited:
Hi all,

I am trying to draw previous day high, previous day low, last week high, last week low in the chart as 'Price Level'. [I know there is an option in thinkorswim to draw price level manually]. I wanted to draw this level in a study so that every time I input a new ticker, level will be automatically loaded.

def lastDayLow= low(period = 'Day')[1];
def lastDayHigh = high(period = 'Day')[1];
def lastWeekLow = low(period = 'Week')[1];
def lastWeekHigh = high(period = 'Week')[1];

plot dayLow = lastDayLow;
plot dayHigh = lastDayHigh;
plot weekLow = lastWeekLow;
plot weekHigh= lastWeekHigh;

When I tried this, I don't see price level line. I got a PaintingStrategy type - LINE. I tried with horizontal line and It draws on each bars. I did not get the horizontal line like 'Price Level' line.

Hence I used lowestAll like this,

plot dayLow = lowestAll(period = 'Day')[1]

I got the line as 'Price Level' line but it took the lowest price of the year though I have used the AggregationPeriod as 'Day'

Note:
When I try this - I draws the Price level line at 20.
plot a = 20;

So I thought of trying like this but it did not draw price level line
plot a = low(period="Day")[1];

Can someone help ?
here is a study that draws lines across the chart, at the desired levels.
notes are included in the code.

Code:
# prevday_levels_onalldays_01
# halcyonguy
# 21-08-12
#
# find high and low , of 2 previous periods, day and week.
# draw a horizontal line across the chart, at the 4 price levels.
# can change the offset , to look at older periods.
# 2 yellow lines, identify the 2 time periods.
# bubbles on the right, identify the lines.
#  the bubbles list the offset.

def na = double.nan;
input offset = 1;

def lastDayLow = low(period = "Day")[offset];
def lastDayHigh = high(period = "Day")[offset];
def lastWeekLow = low(period = "Week")[offset];
def lastWeekHigh = high(period = "Week")[offset];

# use highestall() to find data from the current time period
plot daylow = highestall( if (!isnan(close) and isnan(close[-1])) then lastDayLow else 0);
plot dayhigh = highestall( if (!isnan(close) and isnan(close[-1])) then lastDayhigh else 0);
plot weeklow = highestall( if (!isnan(close) and isnan(close[-1])) then lastweekLow else 0);
plot weekhigh = highestall( if (!isnan(close) and isnan(close[-1])) then lastweekhigh else 0);

daylow.setdefaultcolor(color.magenta);
dayhigh.setdefaultcolor(color.magenta);
weeklow.setdefaultcolor(color.light_green);
weekhigh.setdefaultcolor(color.light_green);

# -------------------------
# place bubbles after last bar, to id the lines
def futurebar = 6;
def x = (!isnan(close[futurebar]) and isnan(close[futurebar -1]));
addchartbubble(x, daylow, "Day[" + offset + "] Low", color.magenta, yes);
addchartbubble(x, dayhigh, "Day[" + offset + "] High", color.magenta, yes);
addchartbubble(x, weeklow, "Week[" + offset + "] Low", color.cyan, yes);
addchartbubble(x, weekhigh, "Week[" + offset + "] High", color.cyan, yes);

# ---------------------
# horz lines, during the time period
def vert = 0.004;
def dy = (!isnan(close(period = "Day")[-offset]) and isnan(close(period = "Day")[-(offset+1)]));
plot dyloline = if dy then (daylow * (1 - vert)) else na;
dyloline.setdefaultcolor(color.yellow);
dyloline.setlineweight(3);

def wk = (!isnan(close(period = "week")[-offset]) and isnan(close(period = "week")[-(offset+1)]));
plot wkhiline = if wk then (weekhigh * (1 + vert)) else na;
wkhiline.setdefaultcolor(color.yellow);
wkhiline.setlineweight(3);
#

below, i used an offset of 2, to look back 2 periods ago. ( 0 is the current period)

vSudFqL.jpg
 
Last edited:
when using highestall( x ) , it will search all of the values of x, for all of the bars, and return the highest value.
if you want it to find data from a specific time or specific data set, you can add a formula inside of the highestall() , to filter the data that is passed on to highestall().

in the following formula,
plot daylow = highestall( if (!isnan(close) and isnan(close[-1])) then lastDayLow else 0)

this part,
if (!isnan(close) and isnan(close[-1]))

tests if the current bar is the last bar.
if it is , then the if-then returns lastDayLow.
if not the last bar, then the if-then returns 0.

highestall() then processes all of the if-then formula results and finds the highest value. because most results will be 0, just the desired period has the desired value, and is returned.
 
here is a study that draws lines across the chart, at the desired levels.
notes are included in teh code.

Code:
# prevday_levels_onalldays_01
# halcyonguy
# 21-08-12
#
# find high and low , of 2 previous periods, day and week.
# draw a horizontal line across the chart, at the 4 price levels.
# can change the offset , to look at older periods.
# 2 yellow lines, identify the 2 time periods.
# bubbles on the right, identify the lines.
#  the bubbles list the offset.

def na = double.nan;
input offset = 1;

def lastDayLow = low(period = "Day")[offset];
def lastDayHigh = high(period = "Day")[offset];
def lastWeekLow = low(period = "Week")[offset];
def lastWeekHigh = high(period = "Week")[offset];

# use highestall() to find data from the current time period
plot daylow = highestall( if (!isnan(close) and isnan(close[-1])) then lastDayLow else 0);
plot dayhigh = highestall( if (!isnan(close) and isnan(close[-1])) then lastDayhigh else 0);
plot weeklow = highestall( if (!isnan(close) and isnan(close[-1])) then lastweekLow else 0);
plot weekhigh = highestall( if (!isnan(close) and isnan(close[-1])) then lastweekhigh else 0);

daylow.setdefaultcolor(color.magenta);
dayhigh.setdefaultcolor(color.magenta);
weeklow.setdefaultcolor(color.light_green);
weekhigh.setdefaultcolor(color.light_green);

# -------------------------
# place bubbles after last bar, to id the lines
def futurebar = 6;
def x = (!isnan(close[futurebar]) and isnan(close[futurebar -1]));
addchartbubble(x, daylow, "Day[" + offset + "] Low", color.magenta, yes);
addchartbubble(x, dayhigh, "Day[" + offset + "] High", color.magenta, yes);
addchartbubble(x, weeklow, "Week[" + offset + "] Low", color.cyan, yes);
addchartbubble(x, weekhigh, "Week[" + offset + "] High", color.cyan, yes);

# ---------------------
# horz lines, during the time period
def vert = 0.004;
def dy = (!isnan(close(period = "Day")[-offset]) and isnan(close(period = "Day")[-(offset+1)]));
plot dyloline = if dy then (daylow * (1 - vert)) else na;
dyloline.setdefaultcolor(color.yellow);
dyloline.setlineweight(3);

def wk = (!isnan(close(period = "week")[-offset]) and isnan(close(period = "week")[-(offset+1)]));
plot wkhiline = if wk then (weekhigh * (1 + vert)) else na;
wkhiline.setdefaultcolor(color.yellow);
wkhiline.setlineweight(3);
#

below, i used an offset of 2, to look back 2 periods ago. ( 0 is the current period)

vSudFqL.jpg

Thank you. That works
 

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