Opening Price of any period

Trading51

Active member
2019 Donor
VIP
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
 

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

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];
 
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
LiFxx5z.png
 

Attachments

  • LiFxx5z.png
    LiFxx5z.png
    412.3 KB · Views: 100
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
 
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. :oops:
 
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. :oops:

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();
 
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 ?
 
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
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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