Price levels after specific bar

CharlieK

New member
On an intraday, 5 minute chart... After the 15th 5 minute bar completes, I would like an automatic price level drawn at the high of the day up to that point... And another price level at the low of the day, up to that point. The price levels would stay there for the rest of the day. And the next day... the lines don't appear, until the 15th 5 minute bar completes.

Is that possible?
 
On an intraday, 5 minute chart... After the 15th 5 minute bar completes, I would like an automatic price level drawn at the high of the day up to that point... And another price level at the low of the day, up to that point. The price levels would stay there for the rest of the day. And the next day... the lines don't appear, until the 15th 5 minute bar completes.

Is that possible?

Try this

Screenshot 2023-06-06 121310.png
Code:
#Price levels after specific bar
input bars    = 15;
input ORBegin = 0930;
def ORA       = if SecondsFromTime(ORBegin) == 0
                then 1
                else ORA[1] + 1;
def oractive = if ORA < bars - 1 then 1 else 0;


def endbn = if SecondsFromTime(ORBegin) == 0 then BarNumber() + bars - 1 else endbn[1];
def endh  = if Between(BarNumber(), endbn - bars , endbn - 1) then Highest(high, bars ) else endh[1];

def endl = if Between(BarNumber(), endbn - bars , endbn - 1) then Lowest(low, bars ) else endl[1];

plot h = if GetDay() == GetLastDay() and BarNumber() > HighestAll(endbn) then endh else Double.NaN;
plot l = if GetDay() == GetLastDay() and BarNumber() > HighestAll(endbn)  then endl else Double.NaN;
 
Thank you, I agree this is great. What would be the code modification to have the lines extend visually to the left so they start at the beginning of the day?

In addition to the request above for extending lines left, is it possible for these upper/lower lines to remain visible on the chart even after market close? Currently this indicator 'disaappears' after market close. Thanx.
 
Last edited by a moderator:
Thank you, I agree this is great. What would be the code modification to have the lines extend visually to the left so they start at the beginning of the day?

In addition to the request above for extending lines left, is it possible for these upper/lower lines to remain visible on the chart even after market close? Currently this indicator 'disaappears' after market close. Thanx.

See if this helps.

Screenshot 2023-07-03 200224.png
Code:
#Price levels after specific bar
input bars    = 15;
input ORBegin = 0930;
def ORA       = if SecondsFromTime(ORBegin) == 0
                then 1
                else ORA[1] + 1;
def oractive = if ORA < bars - 1 then 1 else 0;


def endbn = if SecondsFromTime(ORBegin) == 0 then BarNumber() + bars - 1 else endbn[1];
def endh  = if Between(BarNumber(), endbn - bars , endbn - 1) then Highest(high, bars ) else endh[1];

def endl = if Between(BarNumber(), endbn - bars , endbn - 1) then Lowest(low, bars ) else endl[1];

plot h = if getday() >= getlastday() then highestall(if GetDay() == GetLastDay() and BarNumber() > HighestAll(endbn) then endh else Double.NaN) else double.nan;
plot l = if getday() >= getlastday() then highestall(if GetDay() == GetLastDay() and BarNumber() > HighestAll(endbn)  then endl else Double.NaN) else double.nan;
 
Thank you! My preference is for charts to not display pre-market/after-hours. Is there a modification that allows the code to work without pre/post market hours? I'm curious what part of the code specifies extended hours. Appreciate your help.
 
Thank you! My preference is for charts to not display pre-market/after-hours. Is there a modification that allows the code to work without pre/post market hours? I'm curious what part of the code specifies extended hours. Appreciate your help.

This should now work whether or not extended hours (pre/post) are displayed on the chart being viewed. Also now the last day's plot should remain even when extended hours are not shown.

The code was modified to meet your request. There are some annotations and optional test bubbles to verify the code.

The image shows a chart with no extended hours and below it one with extended hours
Screenshot 2023-07-04 124517.png

Code:
#Price levels after specific bar v1
#Modified to work on charts whether extended hours are displayed or not
input bars    = 15;
input ORBegin = 0930;

#Thisday snippet
def ymd      = GetYYYYMMDD();
def candles  = !IsNaN(close);
def capture  = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
#Identifies each day with visible bars starting with #1
def thisDay  = (HighestAll(dayCount) - dayCount) + 1 ;

def endbn = if SecondsFromTime(ORBegin) == 0 then BarNumber() + bars - 1 else endbn[1];

def endh  = if Between(BarNumber(), endbn - bars , endbn) then Highest(high, bars ) else endh[1];

def endl = if Between(BarNumber(), endbn - bars , endbn ) then Lowest(low, bars  ) else endl[1];

#Plot of highs/lows (endh/endl) based upon the first x bars input, projected after those first x bars
plot hafter_endbn = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() > endbn  then endh else Double.NaN;
plot lafter_endbn = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() > endbn then endl else Double.NaN;
hafter_endbn.SetDefaultColor(Color.CYAN);
lafter_endbn.SetDefaultColor(Color.CYAN);

#Offset ([-bars]) of endh/endl to backfill those plots over the first x bars
plot h_after_offset = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() <= endbn then endh[-bars] else Double.NaN;
plot l_after_offset = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() <= endbn  then endl[-bars] else Double.NaN;
h_after_offset.SetPaintingStrategy(PaintingStrategy.DASHES);
h_after_offset.SetDefaultColor(Color.WHITE);
l_after_offset.SetPaintingStrategy(PaintingStrategy.DASHES);
l_after_offset.SetDefaultColor(Color.WHITE);

input test = yes;
AddChartBubble(test and BarNumber() <= endbn, endl[-bars], thisDay + " \n" + endh + " \n" + endl, if low == endl[-bars] then Color.WHITE else if high == endh[-bars] then Color.YELLOW else if BarNumber() == endbn[-bars] then Color.MAGENTA else Color.GRAY, no);
 
  • Like
Reactions: ARL
This is excellent, SZ. Thank you! I enjoy how you go (typically) the mile or two extra in your craft by adding features that I hadn't thought about but are quite interesting and helpful to have. The annotations give me a much better idea of what the code is doing and how it's doing it.

FYI, I changed the input bars to 8. I think the first 30 minutes of the stock's behavior within this study structure is all that's needed to estimate better what it's capable of doing the rest of the day (with the help of other time-frame analysis, of course).
 

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