Opening price horizontal plot

Kokebaaas

New member
Hello y'all!

I'm trying to get a script going that plots a horizontal line for the opening print, meaning the open price of the 9:30 am EST candle. I have this code going but it's ploting the line before the candle. Any idea how to have it just at that candle and expanding to the right?

Thanks in advance!

Code:
input showOnlyLastPeriod = yes;
def label = yes;

def isOpen = GetTime() crosses above RegularTradingStart(GetYYYYMMDD());
# def isClosed = GetTime() crosses RegularTradingEnd(GetYYYYMMDD());

# def prevClose = close[1];
def firstBarOpen = if isOpen and !isOpen[1] then open else firstBarOpen[1];
# def firstBarClose = if isClosed and !isClosed[1] then open else firstBarClose[1];

plot OpeningPrice;
OpeningPrice.SetPaintingStrategy(PaintingStrategy.LINE);
OpeningPrice.SetDefaultColor(Color.CYAN);
OpeningPrice.SetLineWeight(2);

def shouldHidePlot = showOnlyLastPeriod and !IsNaN(close(period = AggregationPeriod.DAY)[-1]);

if shouldHidePlot {
    OpeningPrice = Double.NaN;
} else {
    OpeningPrice = firstBarOpen;
}

AddLabel(label, "OP: " + AsDollars(OpeningPrice), Color.CYAN);
 

Attachments

  • Screenshot_139.png
    Screenshot_139.png
    54.7 KB · Views: 152
Hello y'all!

I'm trying to get a script going that plots a horizontal line for the opening print, meaning the open price of the 9:30 am EST candle. I have this code going but it's ploting the line before the candle. Any idea how to have it just at that candle and expanding to the right?

Thanks in advance!

Code:
input showOnlyLastPeriod = yes;
def label = yes;

def isOpen = GetTime() crosses above RegularTradingStart(GetYYYYMMDD());
# def isClosed = GetTime() crosses RegularTradingEnd(GetYYYYMMDD());

# def prevClose = close[1];
def firstBarOpen = if isOpen and !isOpen[1] then open else firstBarOpen[1];
# def firstBarClose = if isClosed and !isClosed[1] then open else firstBarClose[1];

plot OpeningPrice;
OpeningPrice.SetPaintingStrategy(PaintingStrategy.LINE);
OpeningPrice.SetDefaultColor(Color.CYAN);
OpeningPrice.SetLineWeight(2);

def shouldHidePlot = showOnlyLastPeriod and !IsNaN(close(period = AggregationPeriod.DAY)[-1]);

if shouldHidePlot {
    OpeningPrice = Double.NaN;
} else {
    OpeningPrice = firstBarOpen;
}

AddLabel(label, "OP: " + AsDollars(OpeningPrice), Color.CYAN);

This modification to your code approach (there are various ways to solve this) will limit the plot of the open to when isopen is true. The plot you were seeing before the open in your previous code was actually the extension of the open from the previous day as there was no end defined for it.

I like how you posted your code, a chart image and how you were approaching to solve it. Thank you!

Screenshot 2023-07-06 122618.png
Code:
input showOnlyLastPeriod = yes;
def label = yes;

def isOpen = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def firstBarOpen = if isOpen and !isOpen[1] then open else if !isOpen then Double.NaN else firstBarOpen[1];

plot OpeningPrice;
OpeningPrice.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpeningPrice.SetDefaultColor(Color.CYAN);
OpeningPrice.SetLineWeight(2);

def shouldHidePlot = showOnlyLastPeriod and !IsNaN(close(period = AggregationPeriod.DAY)[-1]);

if shouldHidePlot {
    OpeningPrice = Double.NaN;
} else {
    OpeningPrice = firstBarOpen;
}

AddLabel(label, "OP: " + AsDollars(OpeningPrice), Color.CYAN);
 

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

This modification to your code approach (there are various ways to solve this) will limit the plot of the open to when isopen is true. The plot you were seeing before the open in your previous code was actually the extension of the open from the previous day as there was no end defined for it.

I like how you posted your code, a chart image and how you were approaching to solve it. Thank you!
For some reason when I try to use it, it ends up staying at 0, unlike the screenshot you sent.
 
For some reason when I try to use it, it ends up staying at 0, unlike the screenshot you sent.
Just saw this.

Without your providing what chart settings you were using, the above used gettime() to establish the open. Gettime() in this instance needs extended hours displayed to work properly.

These modifications using secondsfromtime(0930) == 0 instead of gettime() should work whether extended hours are displayed or not.

The image below does not display extended hours.

Code:
input showOnlyLastPeriod = no;
def label = yes;

def isOpen = secondsfromTime(0930) == 0;#GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def firstBarOpen = if isOpen then open else  firstBarOpen[1];#if isOpen and !isOpen[1] then open else if !isOpen then Double.NaN else firstBarOpen[1];

plot OpeningPrice;
OpeningPrice.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpeningPrice.SetDefaultColor(Color.CYAN);
OpeningPrice.SetLineWeight(2);

def shouldHidePlot = showOnlyLastPeriod and !IsNaN(close(period = AggregationPeriod.DAY)[-1]);

if shouldHidePlot {
    OpeningPrice = Double.NaN;
} else {
    OpeningPrice = firstBarOpen;
}

AddLabel(label, "OP: " + AsDollars(OpeningPrice), Color.CYAN);
Screenshot 2023-09-19 073230.png
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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