GlobeX or Overnight High / Low For ThinkOrSwim

Cybersloth

Member
Automatically Labelling Afterhours/Overnight Market Highs & Lows For ThinkOrSwim
Was in the Thinkscript Lounge over at TOS and stumbled onto this script helpfully provided by Mobius to a user inquiring about after-hours market highs and lows. For the script to function, time needs to be set to an intraday increment with afterhours checked ON


Code:
# GlobeX or Overnight High / Low
# Mobius
# V01.2012

input PlotOverNightExtremes = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def bar = barNumber();
def Intraday = GetAggregationPeriod() < AggregationPeriod.DAY;
def RTH = getTime() >= regularTradingStart(getYYYYMMDD()) and
          getTime() <= regularTradingEnd(getYYYYMMDD());
def ONhigh = if !RTH and RTH[1]
             then h
             else if !RTH and
                     h > ONhigh[1]
                  then h
                  else ONhigh[1];
def ONhighBar = if !RTH and h == ONhigh
                then BarNumber()
                else ONhighBar[1];
def ONlow = if !RTH and RTH[1]
            then l
            else if !RTH and l < ONlow[1]
                 then l
            else ONlow[1];
def ONlowBar = if !RTH and l == ONlow
               then BarNumber()
               else ONlowBar[1];
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
                    then h
                    else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
                   then l
                   else OverNightLow[1];
plot ONH = if Intraday and OverNightHigh > 0
           then OverNightHigh
           else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
plot ONL = if Intraday and OverNightLow > 0
           then OverNightLow
           else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", ONH.TakeValueColor());
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", ONL.TakeValueColor(), 0);
# End Code Overnight (GlobeX) high and low
 
Last edited by a moderator:
@Cybersloth - this script is awesome, however is there a way to have it plot from 1800 hours to 9:30? I want it to show me the high and low for /ES, /NQ, and /YM beginning at 6pm EST(1800) and end at 9:30EST. Thanks in advanced for any help you can offer.
 
hello, this code is very usefull, anyone knows how to modify so it plots every the overnight H/L of each day and not only the current day?
 
hello, this code is very usefull, anyone knows how to modify so it plots every the overnight H/L of each day and not only the current day?
try this it does plot a mid line and a midnight open as well:

declare upper;

input showONH_ONL = yes;
input showMidpoint = yes;
input showMidnightOpen = no;

# RTH session: 9:30 AM to 6:00 PM ET
def RTHStart = 0930;
def RTHEnd = 1800;

def seconds = SecondsFromTime(0);
def midnightBar = seconds == 0;

def midnightOpen = if midnightBar then open else midnightOpen[1];

# Identify when a new day starts
def newDay = GetDay() != GetDay()[1];

# Time filtering
def currentTime = GetTime();
def sessionStart = RegularTradingStart(GetYYYYMMDD());
def sessionEnd = RegularTradingEnd(GetYYYYMMDD());

# Identify if we are in the RTH session
def isRTH = currentTime >= sessionStart and currentTime < sessionEnd;
def isOvernight = !isRTH;

# Track overnight high and low
def ONHigh = if newDay then high else if isOvernight then Max(high, ONHigh[1]) else ONHigh[1];
def ONLow = if newDay then low else if isOvernight then Min(low, ONLow[1]) else ONLow[1];
def ONMid = (ONHigh + ONLow) / 2;

# Plotting
plot pONHigh = if showONH_ONL and isRTH then ONHigh else Double.NaN;
pONHigh.SetDefaultColor(Color.CYAN);
pONHigh.SetStyle(Curve.SHORT_DASH);
pONHigh.SetLineWeight(1);

plot pONLow = if showONH_ONL and isRTH then ONLow else Double.NaN;
pONLow.SetDefaultColor(Color.CYAN);
pONLow.SetStyle(Curve.SHORT_DASH);
pONLow.SetLineWeight(1);

plot pONMid = if showMidpoint and isRTH then ONMid else Double.NaN;
pONMid.SetDefaultColor(Color.GRAY);
pONMid.SetStyle(Curve.SHORT_DASH);
pONMid.SetLineWeight(1);
 

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