Draw high and low of first 30 min candle - Help please...

kabira

Member
VIP
I have tried this but if I change the time frame from 30 min to 5 min it is giving me High and Low of the first 5 min candle. I just need to draw the High and Low of first 30 min candle and it should NOT change if I change to different time frame something similar to DailyHighLow TOS indicator. Thanks in Advance.


def newDay = GetDay() <> GetDay()[1];
rec firstOpen = if newDay then open else firstOpen[1];
rec firstHigh = if newDay then high else firstHigh[1];
rec firstLow = if newDay then low else firstLow[1];
rec firstClose = if newDay then close else firstClose[1];
#plot priceOpen = firstOpen;
plot priceHigh = firstHigh;
plot priceLow = firstLow;
#plot priceClose = firstClose;

I tried this too

input aggregationPeriod = AggregationPeriod.THIRTY_MIN;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

def newDay = GetDay() <> GetDay()[1];
rec firstOpen = if newDay then open else firstOpen[1];
rec firstHigh = if newDay then high else firstHigh[1];
rec firstLow = if newDay then low else firstLow[1];
rec firstClose = if newDay then close else firstClose[1];
#plot priceOpen = firstOpen;
#plot priceHigh = firstHigh;
#plot priceLow = firstLow;
#plot priceClose = firstClose;



plot priceHigh;
plot priceLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
priceHigh = firstHigh;
priceLow = firstLow;
# priceHigh = Highest(high(period = aggregationPeriod)[-displace], length);
# priceLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}
else {
priceHigh = firstHigh;
priceLow = firstLow;
# priceHigh = Highest(high(period = aggregationPeriod)[-displace], length);
# priceLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

priceHigh.SetDefaultColor(GetColor(4));
priceHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priceLow.SetDefaultColor(GetColor(4));
priceLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Solution
Look for an ORB (Opening Range Breakout) indicator. There are many to choose from. I like this one (or a variant of it):
ORB4v_2021_03_27a_JQ (Web view)
I think I am using a slightly older version, but you can adjust the end points of the opening range (you want it to start at 0930 and end at 1000 to catch the first half hour

-mashume
Look for an ORB (Opening Range Breakout) indicator. There are many to choose from. I like this one (or a variant of it):
ORB4v_2021_03_27a_JQ (Web view)
I think I am using a slightly older version, but you can adjust the end points of the opening range (you want it to start at 0930 and end at 1000 to catch the first half hour

-mashume
 
Solution
I have tried this but if I change the time frame from 30 min to 5 min it is giving me High and Low of the first 5 min candle. I just need to draw the High and Low of first 30 min candle and it should NOT change if I change to different time frame something similar to DailyHighLow TOS indicator. Thanks in Advance.
hal_orb

def newDay = GetDay() <> GetDay()[1];
rec firstOpen = if newDay then open else firstOpen[1];
rec firstHigh = if newDay then high else firstHigh[1];
rec firstLow = if newDay then low else firstLow[1];
rec firstClose = if newDay then close else firstClose[1];
#plot priceOpen = firstOpen;
plot priceHigh = firstHigh;
plot priceLow = firstLow;
#plot priceClose = firstClose;

I tried this too

input aggregationPeriod = AggregationPeriod.THIRTY_MIN;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

def newDay = GetDay() <> GetDay()[1];
rec firstOpen = if newDay then open else firstOpen[1];
rec firstHigh = if newDay then high else firstHigh[1];
rec firstLow = if newDay then low else firstLow[1];
rec firstClose = if newDay then close else firstClose[1];
#plot priceOpen = firstOpen;
#plot priceHigh = firstHigh;
#plot priceLow = firstLow;
#plot priceClose = firstClose;



plot priceHigh;
plot priceLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
priceHigh = firstHigh;
priceLow = firstLow;
# priceHigh = Highest(high(period = aggregationPeriod)[-displace], length);
# priceLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}
else {
priceHigh = firstHigh;
priceLow = firstLow;
# priceHigh = Highest(high(period = aggregationPeriod)[-displace], length);
# priceLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

priceHigh.SetDefaultColor(GetColor(4));
priceHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priceLow.SetDefaultColor(GetColor(4));
priceLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


comments on your codes

Code:
def newDay = GetDay() <> GetDay()[1];
rec firstOpen = if newDay then open else firstOpen[1];
rec firstHigh = if newDay then high else firstHigh[1];
rec firstLow = if newDay then low else firstLow[1];
rec firstClose = if newDay then close else firstClose[1];
#plot priceOpen = firstOpen;
plot priceHigh = firstHigh;
plot priceLow = firstLow;
#plot priceClose = firstClose;

this is reading prices and keeping them during each day. but it is reading the wrong prices. it doesn't use any 2nd aggregation, so it is just reading from a bar, at chart time.

-------------------------


Code:
# orb30_b

#I tried this too

input aggregationPeriod = AggregationPeriod.THIRTY_MIN;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

def newDay = GetDay() <> GetDay()[1];
rec firstOpen = if newDay then open else firstOpen[1];
rec firstHigh = if newDay then high else firstHigh[1];
rec firstLow = if newDay then low else firstLow[1];
rec firstClose = if newDay then close else firstClose[1];
#plot priceOpen = firstOpen;
#plot priceHigh = firstHigh;
#plot priceLow = firstLow;
#plot priceClose = firstClose;


plot priceHigh;
plot priceLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
priceHigh = firstHigh;
priceLow = firstLow;
# priceHigh = Highest(high(period = aggregationPeriod)[-displace], length);
# priceLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}
else {
priceHigh = firstHigh;
priceLow = firstLow;
# priceHigh = Highest(high(period = aggregationPeriod)[-displace], length);
# priceLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

priceHigh.SetDefaultColor(GetColor(4));
priceHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priceLow.SetDefaultColor(GetColor(4));
priceLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


addchartbubble(1, low,
(!IsNaN(close(period = aggregationPeriod)[-1]))
, ( if (!IsNaN(close(period = aggregationPeriod)[-1])) then color.yellow else color.gray), no);
#

this has same problem as first one.
rec firstOpen = if newDay then open else firstOpen[1];
it uses the same formula. doesn't use 2nd aggregation.

added a bubble to verify values,
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
this is 0 on the last bars that span the 2nd aggregation time. if orb time of 30min and chart time of 5min , 30/5 = 6 , 6 bars will be 0. all other bars will be 1.
not sure if this is what you intended.

it uses the same formula in both sections of the if then, so the plots equal the values in the first part.
priceHigh = firstHigh;
this has no effect.
input showOnlyLastPeriod = no;


--------------------


this version will let you pick the orb time,
and to show just the current day or all days.


Code:
# orb30_c

def na = double.nan;
def bn = barnumber();

input orb_time = AggregationPeriod.THIRTY_MIN;
input show_only_current_day = yes;

def newDay = GetDay() <> GetDay()[1];
def current_day = (getday() == getlastday());

def firstOpen = if newDay then open(period = orb_time) else firstOpen[1];
def firstHigh = if newDay then high(period = orb_time) else firstHigh[1];
def firstLow = if newDay then low(period = orb_time) else firstLow[1];
def firstClose = if newDay then close(period = orb_time) else firstClose[1];

plot priceHigh;
plot priceLow;
if show_only_current_day and !current_day then {
 priceHigh = na;
 priceLow = na;
} else {
 priceHigh = firstHigh;
 priceLow = firstLow;
}

priceHigh.SetDefaultColor(GetColor(4));
priceHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priceLow.SetDefaultColor(GetColor(4));
priceLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


addchartbubble(0, low,
(!IsNaN(close(period =  orb_time)[-1]))
#priceHigh = firstHigh;
#priceLow = firstLow;
, ( if (!IsNaN(close(period =  orb_time)[-1])) then color.yellow else color.gray), no);
#

------------------


https://usethinkscript.com/threads/help-creating-an-orb-study.16312/#post-129686
posts 2 and 3 are a couple other orb versions
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
430 Online
Create Post

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