Overnight High and Low

rlohmeyer

Active member
The following code is actually 2 separate indicators, which combined can give me the High and Low for the period between 1600 EST and 930 EST. However, it is not not an elegant solution since I generally have to uncheck the plot for one of the highs or lows to actually get the actual high or low for the period. I am not great with time functions. In any of you great coders could help it would be much appreciated. I have worked on ways to combine these 2 in some way but failed. @Mobious code is included and then additional code I scrounged. @SleepyZ @samer800 if you have time. I gave it about 18 hours and then gave up with my non-elegant solution below.
overnight.jpg



Code:
#Places vertical lines at start and end times and draws High and Low Lines


input onb = 1600;
input one = 930;
def SOD = secondsFromTime(1600) > 0;
def EOD = secondsFromTime(930) > 0;
def ST = SecondsFromTime(onb) ==0;
def ET = SecondsFromTime(one) ==0;
def OVN = Gettime() > sod;


AddVerticalLine(ST,"Market Open",Color.RED,Curve.points);
AddVerticalLine(ET," Market Closed",Color.RED,Curve.points);

input Date = 20130801;#hint Date: Set the date you want see.<b>\n(Enter in YYYYMMDD)</b>

def timeTest = getYyyyMmDd() == date;
def H = if timetest and sod then high else double.nan;
def L = if timetest and sod then low else double.nan;

plot HLine = highestall(h);
Hline.SetPaintingStrategy(PaintingStrategy.triangles);
Hline.setlineweight(3);
Hline.SetDefaultColor(Color.dark_green);
Hline.HideBubble();
Hline.HideTitle();


plot LLine = lowestall(l);
Lline.SetPaintingStrategy(PaintingStrategy.triangles);
Lline.setlineWeight(3);
Lline.SetDefaultColor(Color.dark_red);
Lline.HideBubble();
Lline.HideTitle();


#Mobius code...using a different method draws High and Low Lines for Globex but doesn't include after hours till midnight EST
def ph = high[1];
def pl = low[1];

def bar = BarNumber();

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());


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

def ONhighBar = if GlobeX and h == ONhigh then Bar else double.nan;

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

def ONlowBar = if GlobeX and low == ONlow then Bar else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then ONhigh
                    else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)then ONlow
                   else OverNightLow[1];
def ONH_ = if OverNightHigh > 0 then OverNightHigh else Double.NaN;
def ONL_ =  if OverNightLow > 0 then OverNightLow else Double.NaN;


plot ONH = if Hline > ONH_ then Hline else ONH_;
ONH.SetPaintingStrategy(PaintingStrategy.triangles);
ONH.setlineweight(3);
ONH.SetDefaultColor(Color.dark_green);
ONH.HideBubble();
ONH.HideTitle();


plot ONL = if Lline < ONL_ then Lline else ONL_;
ONL.SetPaintingStrategy(PaintingStrategy.triangles);
ONL.setlineWeight(3);
ONL.SetDefaultColor(Color.dark_red);ONL.HideBubble();
ONL.HideTitle();
 
Solution
I found the answer with Anthropic AI help: Here is the code if interested:

Code:
# Overnight Market High and Low Indicator

def omo = 1600;  # Overnight Market Open
def omc = 930;   # Overnight Market Close

# Input for specific date
input Date = 20241126;  # hint Date: Set the date you want to see. (Enter in YYYYMMDD)

# Function to check if we're in the overnight session
def isOvernightSession =
    (getYyyyMmDd() == Date and secondsFromTime(omo) >= 0) or
    (getYyyyMmDd() == Date + 1 and secondsFromTime(omc) < 0);

# Vertical lines for overnight market open and close
AddVerticalLine(secondsFromTime(omo) == 0, "Overnight Market Open", Color.RED, Curve.points);
AddVerticalLine(secondsFromTime(omc) == 0, "Overnight Market Close"...
I found the answer with Anthropic AI help: Here is the code if interested:

Code:
# Overnight Market High and Low Indicator

def omo = 1600;  # Overnight Market Open
def omc = 930;   # Overnight Market Close

# Input for specific date
input Date = 20241126;  # hint Date: Set the date you want to see. (Enter in YYYYMMDD)

# Function to check if we're in the overnight session
def isOvernightSession =
    (getYyyyMmDd() == Date and secondsFromTime(omo) >= 0) or
    (getYyyyMmDd() == Date + 1 and secondsFromTime(omc) < 0);

# Vertical lines for overnight market open and close
AddVerticalLine(secondsFromTime(omo) == 0, "Overnight Market Open", Color.RED, Curve.points);
AddVerticalLine(secondsFromTime(omc) == 0, "Overnight Market Close", Color.RED, Curve.points);

# Capture high and low during the overnight session
def H = if isOvernightSession then high else double.nan;
def L = if isOvernightSession then low else double.nan;

# Plot highest high
plot HLine = highestAll(H);
HLine.SetPaintingStrategy(PaintingStrategy.triangles);
HLine.SetLineWeight(3);
HLine.SetDefaultColor(Color.GREEN);
HLine.HideBubble();
HLine.HideTitle();

# Plot lowest low
plot LLine = lowestAll(L);
LLine.SetPaintingStrategy(PaintingStrategy.triangles);
LLine.SetLineWeight(3);
LLine.SetDefaultColor(Color.RED);
LLine.HideBubble();
LLine.HideTitle();
 
Solution

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