# Opening Price of any period

##### Active member
2019 Donor
Opening Price of any period, 60, 120, 240 etc with a horizontal line with a small margin to the right of the chart, lets say a new hour started and you wanted the open of that bar, could some code this? thanks

##### Active member
2019 Donor
Can someone help me with this, it seems quite simple but when you have zero programming skills its difficult

#### korygill

##### Well-known member
VIP
try this and if it's not want you want, draw a picture of what you want or describe it in greater detail. i am not 100% this is what you are looking for.
https://tos.mx/qmFCgel

Code:
input agg = AggregationPeriod.TWO_HOURS;
def data = close(period = agg);
plot AggClose = if !IsNaN(data) then data else data[1];

#### korygill

##### Well-known member
VIP
Update: use this link for Open, i mistakenly used close
https://tos.mx/NRifurx
Code:
input agg = AggregationPeriod.TWO_HOURS;
def data = open(period = agg);
plot AggClose = if !IsNaN(data) then data else data[1];

Screenshot I put on imgur

##### Active member
2019 Donor
If I wanted to use 12 hour period how would I add that I noticed that TOS didn’t have this aggregation period, btw thanks for taking the time to do this

#### Citizen Quasar

##### New member
I am seeking to obtain the open/close/high/low of the very first bar and to use this value as the starting point for a horizontal line. Any help or advice will be greatly appreciated.

#### horserider

##### Well-known member
VIP
I am seeking to obtain the open/close/high/low of the very first bar and to use this value as the starting point for a horizontal line. Any help or advice will be greatly appreciated.

See if this fits what you want. Let us know how you are using it please.

Code:
``````# Draw horizontal line at market open price.
# Most code extracted from another study but forgot where.
# By Horserider.

input openingPMTime  = 0400.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input openingTime  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.

def isDaily = If (GetAggregationPeriod() == AggregationPeriod.DAY, yes, no);

def isPreMarket = If (GetDay() == GetLastDay() and SecondsTillTime(openingPMTime) < 0, yes, no);
input LineWidth = 1;
def na = Double.NaN;

def isBelowDaily = If (GetAggregationPeriod() < AggregationPeriod.DAY, yes, no);
def isToday = If (GetDay() == GetLastDay() and SecondsFromTime(openingPMTime) >= 0, yes, no);
def day = GetDay();

def PMopenBar = day != day[1];
def PMOpen = if PMopenBar then open else PMOpen[1];

plot PlotPMOLine = if isToday and isBelowDaily then PMOpen else na;
PlotPMOLine.SetDefaultColor(CreateColor(77, 166, 255));
PlotPMOLine.SetLineWeight(LineWidth);
PlotPMOLine.SetPaintingStrategy(PaintingStrategy.DASHES);
PlotPMOLine.HideTitle();
PlotPMOLine.HideBubble();``````

##### Active member
2019 Donor
See if this fits what you want. Let us know how you are using it please.

Code:
``````# Draw horizontal line at market open price.
# Most code extracted from another study but forgot where.
# By Horserider.

input openingPMTime  = 0400.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input openingTime  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.

def isDaily = If (GetAggregationPeriod() == AggregationPeriod.DAY, yes, no);

def isPreMarket = If (GetDay() == GetLastDay() and SecondsTillTime(openingPMTime) < 0, yes, no);
input LineWidth = 1;
def na = Double.NaN;

def isBelowDaily = If (GetAggregationPeriod() < AggregationPeriod.DAY, yes, no);
def isToday = If (GetDay() == GetLastDay() and SecondsFromTime(openingPMTime) >= 0, yes, no);
def day = GetDay();

def PMopenBar = day != day[1];
def PMOpen = if PMopenBar then open else PMOpen[1];

plot PlotPMOLine = if isToday and isBelowDaily then PMOpen else na;
PlotPMOLine.SetDefaultColor(CreateColor(77, 166, 255));
PlotPMOLine.SetLineWeight(LineWidth);
PlotPMOLine.SetPaintingStrategy(PaintingStrategy.DASHES);
PlotPMOLine.HideTitle();
PlotPMOLine.HideBubble();``````
Thanks for the rply, the chart is blank am i suppose to do something in the code ?

##### Active member
2019 Donor
what I was trying to do is the following, at a certain time like 6 am or 10 am I wanted a horizontal line at the opening of the bar, so at 720 (6 am) and 240-minute bar (10 am) there would be a horizontal line to the right of the chart maybe not all the way across just by a margin, using this for \$ES futures, the above code I tried to see if I could do something but not code orientated for that

#### GeneHo

##### New member
2019 Donor
Is there a script to draw horiz line of high / low of 1st bar (after market open), it can be in any time frame.

#### horserider

##### Well-known member
VIP
Is there a script to draw horiz line of high / low of 1st bar (after market open), it can be in any time frame.
Check Post 10 See if that helps.

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?