• Get $40 off VIP by signing up for a free account! Sign Up

Identify Closed hours High?

TOS-man

New member
Hi,

With following code, I'm only able to plot latest Closed hours High only. Closed hours are between 4:00 PM to 9:30 AM EST.

Is there a way to plot previous Closed hours High also?

Thanks!

Code:
input PlotOverNightExtremes = yes;
input DisplayPriceBubbleOnHiLowBar = yes;
input DisplayPriceBubbleOnRightEdge = yes;

def o = open;
def h = high;
def l = low;
def c = close;

def Post = secondsFromTime(1600);
def Pre = secondsTillTime(930);
def Closed  = Post >=0 or Pre>=0;

def bar = BarNumber();
def GlobeX = Closed;# GetTime() < RegularTradingStart(GetYYYYMMDD());

def ONhigh = if GlobeX and !GlobeX[1]
then h
else if GlobeX and h > ONhigh[1]
then h
else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh
then bar
else Double.NaN;

def ONlow = if GlobeX and !GlobeX[1]
then l
else if GlobeX and l < ONlow[1]
then l
else ONlow[1];

def ONlowBar = if GlobeX and l == ONlow
then bar
else Double.NaN;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

plot ONH = if OverNightHigh > 0
then OverNightHigh
else Double.NaN;

ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.LINE);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();

# Bubble code
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes and DisplayPriceBubbleOnHiLowBar, ONH, "ONH: " + ONH, createColor(204,204,255));

AddChartBubble(barNumber() == highestAll(barnumber()) and  PlotOverNightExtremes and DisplayPriceBubbleOnRightEdge, ONH, "ONH: " + ONH, createColor(204,204,255));

izfviQp.png
 
Solution
Hi,

With following code, I'm only able to plot latest Closed hours High only. Closed hours are between 4:00 PM to 9:30 AM EST.

Is there a way to plot previous Closed hours High also?

Thanks!

This hopefully plots the post close high on the days correctly. You can add more days by copying, pasting and editing the plots/styles and bubbles. The daysback in the plots start at zero and increment by 2, as you can see in the code, for each subsequent days post close days.


Capture.jpg
Ruby:
script onh_ {
input daysback = 1;

def ymd =  SecondsFromTime(1600) >= 0 or SecondsTillTime(0930) > 0;
def candles  = !IsNaN(close);
def capture  = ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1]...
Hi,

With following code, I'm only able to plot latest Closed hours High only. Closed hours are between 4:00 PM to 9:30 AM EST.

Is there a way to plot previous Closed hours High also?

Thanks!

This hopefully plots the post close high on the days correctly. You can add more days by copying, pasting and editing the plots/styles and bubbles. The daysback in the plots start at zero and increment by 2, as you can see in the code, for each subsequent days post close days.


Capture.jpg
Ruby:
script onh_ {
input daysback = 1;

def ymd =  SecondsFromTime(1600) >= 0 or SecondsTillTime(0930) > 0;
def candles  = !IsNaN(close);
def capture  = ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

input PlotOverNightExtremes = yes;
input DisplayPriceBubbleOnHiLowBar = yes;
input DisplayPriceBubbleOnRightEdge = yes;

def o = open;
def h = high;
def l = low;
def c = close;

def Post =  thisday==daysback and secondsFromTime(1600);
def Pre =   thisday==daysback and secondsTillTime(930);
def Closed  = thisday==daysback and (Post >=0 or Pre>=0);



def bar = BarNumber();
def GlobeX =  thisday==daysback and  Closed;# GetTime() < RegularTradingStart(GetYYYYMMDD());

def ONhigh = if thisday==daysback and  GlobeX and !GlobeX[1]
then h
else if thisday==daysback and GlobeX and h > ONhigh[1]
then h
else ONhigh[1];

def ONhighBar = if  thisday==daysback and GlobeX and h == ONhigh
then bar
else Double.NaN;

def ONlow = if  thisday==daysback and GlobeX and !GlobeX[1]
then l
else if  thisday==daysback and GlobeX and l < ONlow[1]
then l
else ONlow[1];

def ONlowBar = if  thisday==daysback and  GlobeX and l == ONlow
then bar
else Double.NaN;

def OverNightHigh = if  thisday==daysback and BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

plot ONH = if  thisday<=daysback and  OverNightHigh > 0
then OverNightHigh
else Double.NaN;

ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.LINE);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
}

plot onh0 = onh_(daysback = 0);
plot onh1 = onh_(daysback = 2);
plot onh2 = onh_(daysback = 4);
plot onh3 = onh_(daysback = 6);

onh0.setdefaultColor(color.blue);
onh1.setdefaultColor(color.blue);
onh2.setdefaultColor(color.blue);
onh3.setdefaultColor(color.blue);

input lineweight = 4;
onh0.setlineweight(lineweight);
onh1.setlineweight(lineweight);
onh2.setlineweight(lineweight);
onh3.setlineweight(lineweight);

addchartbubble(isnan(onh0[1]) and !isnan(onh0),onh0,onh0,createColor(204,204,255));
addchartbubble(isnan(onh1[1]) and !isnan(onh1),onh1,onh1,createColor(204,204,255));
addchartbubble(isnan(onh2[1]) and !isnan(onh2),onh2,onh2,createColor(204,204,255));
addchartbubble(isnan(onh3[1]) and !isnan(onh3),onh3,onh3,createColor(204,204,255));
 
Solution
This hopefully plots the post close high on the days correctly. You can add more days by copying, pasting and editing the plots/styles and bubbles. The daysback in the plots start at zero and increment by 2, as you can see in the code, for each subsequent days post close days.
Thank you SleepyZ.

Didn't know one can create block of script code and reuse it like here. Pretty cool..eh!

A question - is there a way to stop the ONH line print after trading day is over? It will help in avoiding the confusion due to to multiple lines on current day.

Thanks again!
 
Thank you SleepyZ.

Didn't know one can create block of script code and reuse it like here. Pretty cool..eh!

A question - is there a way to stop the ONH line print after trading day is over? It will help in avoiding the confusion due to to multiple lines on current day.

Thanks again!

Replace the following code which seems to limit the plot as you wish

Capture.jpg
Code:
plot ONH = if thisday<daysback-1 then double.nan else if thisday<=daysback  and  OverNightHigh > 0
then OverNightHigh
else Double.NaN;
 

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