Dynamically Change Plot Length Based on Time of Day???

nerdytrader

New member
I was wondering if someone could point me in the right direction pertaining to how I could go about defining a time range that triggers a plot to change it's position on the x axis.

I've been working on refining my basic OHLC horizontal line code so it works well on all intraday timeframes.

I know how to plot any hortizontal line from any point on the x axis, for example from 200am to the right axis, or 8:14 to the right axis, Etc.

But I can't figure out how to dynamically change an x axis position based on the time of the day.

I would like to plot the intraday High and Low, between the time of 9:30am and 12:00pm, to begin at 600am and plot all the way to the price axis -
then after the time crosses 1200pm, I want the line to begin plotting from 930am on the x axis.

The reason for this is to eliminate clutter on the chart, organize the line lengths for my personal preference.

For whatever reason, I can't seem to make the code plot once the time crosses 1200pm. It only plots from one or the other time I define / plot.

My code is as followed:

input ExtendHL = yes;
input HideHL = no;

script pBars {
input pClose = close;
def pBars = if pClose != pClose[1]
then pClose[1] else pBars[1];
plot PriorBar = pBars;
}

def PrevRTH = pBars(RTH);
def xPrevRT = HighestAll(PrevRTH);
def PrevGlobex = pBars(Globex);
def xPrevGlobex = HighestAll(PrevGlobex);
def xGlobex = HighestAll(Globex);
def RegHrs = HighestAll(RTH);

def xHigh = high(period = Day);
def xLow = low(period = Day);

def Nan = Double.NaN;
def Bar = BarNumber();
def Axis = IsNaN(close);
def Today = GetDay() == GetLastDay();
def After600 = Today and SecondsFromTime(600) >= 0;

#***********Daily High
def High1 = (HighestAll(if Bar >= RegHrs and Bar < xGlobex then xhigh
else if xGlobex < RegHrs and Bar >= RegHrs then high else Nan));
plot HighRT = if !Today then Nan else if ExtendHL and After600 then High1 else if Axis then High1 else Nan ;

#***********Daily Low
def Low1 = (LowestAll(if Bar >= RegHrs and Bar < xGlobex then xlow
else if xGlobex < RegHrs and Bar >= RegHrs then low else Nan));
plot LowRT = if !Today then Nan else if ExtendHL and After600 then Low1 else if Axis then Low1 else Nan ;

######################

That is the code that plots the intraday High and Low. It plots from 600am and extends to the price axis.

I'd like for the plots to automatically switch from extending from 600am to extending from 930am once the intraday time has crossed 1200pm.
After the time crosses 1200pm, I would like the lines to remain extended from 930am until the time crosses 930am the following day, then which
it would again revert back to extending from the 600am time.

I hope I have properly explained what I'd like to achieve. If anyone can help me with this, I would greatly appreciate it. Thanks in advance!
 

Attachments

  • x.jpg
    x.jpg
    203.6 KB · Views: 69
I was wondering if someone could point me in the right direction pertaining to how I could go about defining a time range that triggers a plot to change it's position on the x axis.

I've been working on refining my basic OHLC horizontal line code so it works well on all intraday timeframes.

I know how to plot any hortizontal line from any point on the x axis, for example from 200am to the right axis, or 8:14 to the right axis, Etc.

But I can't figure out how to dynamically change an x axis position based on the time of the day.

I would like to plot the intraday High and Low, between the time of 9:30am and 12:00pm, to begin at 600am and plot all the way to the price axis -
then after the time crosses 1200pm, I want the line to begin plotting from 930am on the x axis.

The reason for this is to eliminate clutter on the chart, organize the line lengths for my personal preference.

For whatever reason, I can't seem to make the code plot once the time crosses 1200pm. It only plots from one or the other time I define / plot.

My code is as followed:

input ExtendHL = yes;
input HideHL = no;

script pBars {
input pClose = close;
def pBars = if pClose != pClose[1]
then pClose[1] else pBars[1];
plot PriorBar = pBars;
}

def PrevRTH = pBars(RTH);
def xPrevRT = HighestAll(PrevRTH);
def PrevGlobex = pBars(Globex);
def xPrevGlobex = HighestAll(PrevGlobex);
def xGlobex = HighestAll(Globex);
def RegHrs = HighestAll(RTH);

def xHigh = high(period = Day);
def xLow = low(period = Day);

def Nan = Double.NaN;
def Bar = BarNumber();
def Axis = IsNaN(close);
def Today = GetDay() == GetLastDay();
def After600 = Today and SecondsFromTime(600) >= 0;

#***********Daily High
def High1 = (HighestAll(if Bar >= RegHrs and Bar < xGlobex then xhigh
else if xGlobex < RegHrs and Bar >= RegHrs then high else Nan));
plot HighRT = if !Today then Nan else if ExtendHL and After600 then High1 else if Axis then High1 else Nan ;

#***********Daily Low
def Low1 = (LowestAll(if Bar >= RegHrs and Bar < xGlobex then xlow
else if xGlobex < RegHrs and Bar >= RegHrs then low else Nan));
plot LowRT = if !Today then Nan else if ExtendHL and After600 then Low1 else if Axis then Low1 else Nan ;

######################

That is the code that plots the intraday High and Low. It plots from 600am and extends to the price axis.

I'd like for the plots to automatically switch from extending from 600am to extending from 930am once the intraday time has crossed 1200pm.
After the time crosses 1200pm, I would like the lines to remain extended from 930am until the time crosses 930am the following day, then which
it would again revert back to extending from the 600am time.

I hope I have properly explained what I'd like to achieve. If anyone can help me with this, I would greatly appreciate it. Thanks in advance!

please try to rewrite this, it doesn't make any sense.
after 12, plot from 9:30... ??

I would like to plot the intraday High and Low, between the time of 9:30am and 12:00pm, to begin at 600am and plot all the way to the price axis -
then after the time crosses 1200pm, I want the line to begin plotting from 930am on the x axis.

if you want a line all across the chart, then what do you mean by doing something at noon?
there is no x axis. tell us what price levels you want a line at.
 

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