Premarket After-market For ThinkOrSwim

@Tom4235 I think this is what you're talking about.

Rich (BB code):
# Archive Name: GlobeX or Overnight High / Low v.07.2017
# Archive Section: Support Resistance
# Suggested Tos Name: GlobeX_HighLow_v2017_Mobius
# Archive Date: 5.06.2018 May 6, 2018
# Archive Notes: This looks to be a second version

# GlobeX or Overnight High / Low
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = 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];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
                   then ONlow
                   else OverNightLow[1];
plot ONH = if OverNightHigh > 0
           then OverNightHigh
           else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
plot ONL = if OverNightLow > 0
           then OverNightLow
           else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
ONL.HideBubble();
ONL.HideTitle();
AddLabel(GlobeX, "GlobeX Range = " + AsDollars(ONH - ONL), color.white);
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
Alert((close crosses above ONH) or (close crosses below ONL), "", Alert.Bar, Sound.Bell);
# End Code GlobeX or Overnight High / Low v.07.2017
hey, is it possible to have this without the bubbles saying ONL and OHL on graph? im just looking for lines showing the overnight/premarket low and high and nothing else. with this code i was able to edit the lines to be thinned, dashed and change color but not able to get rid of ONL and ONH bubbles on graphs
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

hey, is it possible to have this without the bubbles saying ONL and OHL on graph? im just looking for lines showing the overnight/premarket low and high and nothing else. with this code i was able to edit the lines to be thinned, dashed and change color but not able to get rid of ONL and ONH bubbles on graphs
TO delete chartbubble ,Delete the line that says

AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
 
TO delete chartbubble ,Delete the line that says

AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);

How would you add this to your watchlist column - where green is above the PM high and red is below?
 
How would you add this to your watchlist column - where green is above the PM high and red is below?
Here is watchlist script
Code:
# prehighlow_col_01

# -------------------
# halcyonguy
# 21-06-15
# column study. find highest and lowest in premarket, and compare to daytime highs/lows
# -------------------

# https://usethinkscript.com/threads/pm-high-low-on-watchlist.6893/
#khahuy12
#can someone create a premarket high low on watchlist? if current price greater then PM high then color greeen else red on watchlist?

input start = 0930;
input end = 1600;
# is current bar during normal trading hours?
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def prehi =
# starting pre, reset
if daytime[1] and !daytime then high
# if a higher high, set it to var
else if !daytime and high > prehi[1] then high
# else keep previous value
else prehi[1];

def prelo =
# starting pre, reset
if daytime[1] and !daytime then low
# if a lower low, set it to var
else if !daytime and low < prelo[1] then low
# else keep previous value
else prelo[1];

def dayhigher = ( high > prehi );
def daylower = ( low < prelo );

addlabel(1, (if close > prehi then ((close - prehi) + " above pre hi")
else if close < prelo then ((prelo - close) + " below pre low") else "in pre rng"), color.black);

assignbackgroundcolor( if dayhigher then color.green else if daylower then color.red else color.current );

# -----------------
# test data for upper study
#input show_test_data = no;
#addlabel( show_test_data , "pre high= " + prehi, color.yellow);
#addlabel( show_test_data , "pre low= " + prelo, color.yellow);
#
 
Last edited by a moderator:
Hi,
I would like to create the following:
1) I create a big watchlist at the beginning of the day
2)during the premarket i only like to see the stocks in my W/L where the current price of the stock is between the yesterday High and Yesterday Low
3) with that I can exclude the gappers and use this to narrow down my W/L
this is my code:
def lo = low(period = "day" )[1];
def hi = high(period = "day" )[1];
input PriceType = PriceType.MARK;
def lastPrice = close(priceType = PriceType.mark);
def s = if lastPrice < hi and lastprice > lo then 1 else 0;
plot signal = s within 1 bars;

but my codes gives me the message: Secondary period not allowed:day (on a intraday level). Anyone an idea?

Who can help me?
 
Last edited:
Welcome Xpulz to the forums.
There is no work-around to the limitation of no secondary aggregations can be used in the TOS Scan Hacker
a2.png

You can read about it here:
https://tlc.tdameritrade.com.sg/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters
 
If the issue is a daily aggregation period trying to be executed on an intraday scale (not sure if I understand secondary aggregation correctly) wouldn't it be possible to change the aggregation period to hour or mins covering the past day? Like maybe something below:

def hi = high(period = "hour" )[24];

I'm just beginning with thinkscript so please be kind of this is a silly idea.
 
If the issue is a daily aggregation period trying to be executed on an intraday scale (not sure if I understand secondary aggregation correctly) wouldn't it be possible to change the aggregation period to hour or mins covering the past day? Like maybe something below:

def hi = high(period = "hour" )[24];

I'm just beginning with thinkscript so please be kind of this is a silly idea.

I will refer you to Chapter 11. Referencing Secondary Aggregation for more information on the subject... Your idea would give the high of a single candle, without aggregation which would require Sum()...
 
so basically my idea is not possible :)

It's possible, just not straight forward. Even though we can't simply ask the D timeframe what its high and low are, we can still track that information manually in the current timeframe.

I added plots to this code so you can test it on a chart before you incorporate it into a scan. Remove the plots when adding it to a scan.
As soon as the market opens it will forget about yesterday and start tracking today so this is only useful until the market opens.

Ruby:
def regular = secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0;

def hi =
  if secondsFromTime(0930) == 0 then high
  else if regular then Max(high, hi[1]) else hi[1]
;

def lo =
  if secondsFromTime(0930) == 0 then low
  else if regular then Min(low, lo[1]) else lo[1]
;

plot h = hi;
h.SetDefaultColor(Color.GREEN);

plot l = lo;
l.SetDefaultColor(Color.RED);
 
If the issue is a daily aggregation period trying to be executed on an intraday scale (not sure if I understand secondary aggregation correctly) wouldn't it be possible to change the aggregation period to hour or mins covering the past day? Like maybe something below:

def hi = high(period = "hour" )[24];

I'm just beginning with thinkscript so please be kind of this is a silly idea.

You have sort of the right thinking and using an index to look backward a number of candles to match a higher timeframe is something we sometimes do depending on what we're trying to solve.

As rad said, in this case, even if it finds the candle you intend, it will get you the high of that candle at that time of day. Not the high of the day's candle. The price you get might be in the middle of the day's range.

A problem with looking back across days in intraday with extended hours enabled is there's not a fixed number of candles during extended hours. If there was no volume that period then there's no candle. So you end up getting a time of day you didn't intend and you could be looking at a different time each day.
 
As rad said, in this case, even if it finds the candle you intend, it will get you the high of that candle at that time of day. Not the high of the day's candle. The price you get might be in the middle of the day's range.
I see what you and rad are saying now, aggregationperiod is a point not a range. So can't you define an aggregationperiod and set a length and offset like in the script below and you could look back over x amount of days,hrs etc and grab the high and low and compare it to the current price?
reference DailyHighLow(aggregationPeriod = "hour", length = " ", displace = " ")
 
I see what you and rad are saying now, aggregationperiod is a point not a range. So can't you define an aggregationperiod and set a length and offset like in the script below and you could look back over x amount of days,hrs etc and grab the high and low and compare it to the current price?
reference DailyHighLow(aggregationPeriod = "hour", length = " ", displace = " ")
AggregationPeriod is more like a unit of measure. Time is broken into pieces sized as these AggregationPeriods and the open/high/low/close is reported for each piece. The aggregation period determines how much time each candle represents. On a 5D 15m chart, the AggregationPeriod is 15 minutes. The same is true for a 10D 15m chart or 15D 15m chart.

What you can and can't do depends on where you are in TOS. Secondary aggregation period means you're accessing a timeframe that doesn't match the timeframe of the chart or scan. In scans this is not allowed. In charts this is allowed but you can only access higher timeframes, not lower. It's not allowed if your chart is in a custom timeframe such as 39 minutes or 78 minutes charts few people use. And there's no way to access a custom timeframe as a secondary timeframe.

In a scan the example code you gave with only work if the scan timeframe is set to 1 hour, because then that timeframe and the one you specified in your code match and there is no secondary timeframe. In a chart, the example code you gave will work as long as your chart is set to 1 hour or less. If you use that on a 2 hour chart it will fail because 1 hour is lower than 2 hours. As I mentioned, due to TOS not charting extended hours periods that have no volume it's impossible to reliably count back to the correct candle intraday with extended hours enabled. Also, most symbols don't have 24 hour trading, so looking back [24] wouldn't give you what you expect even if extended hours data was consistent.

If you use a trendline drawing tool, it pops up a databox after you place the starting point which disappears when you place the end point. It tells you how many days, hours, bars the drawing spans, among other things. You can play around with that to see what I mean about [24] not finding the candle you think it will. See if you get the time of day you thought when it says 24 bars. And then look at the high of that candle compared to the high of that day and you can see what rad and I meant about why that won't work in this case.
 
Glad, now is all great

Please, could you tell me how to fix this code:

Code:
def close1 = if SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0  then close else close[1];
def change = (close / close1) - 1;
plot scan = round(change*100,2);
scan.AssignValueColor(if scan >= 0 then Color.UPTICK else Color.DOWNTICK);

See if this helps. It will save the close[1] during the times you defined. The scan will determine whether change from the last close to the close1 close is >=0 and return a '1' if true. You can check the computations by setting debug to yes and turn to no when done.

Screenshot-2021-08-11-091109.jpg
Ruby:
def close1 = if SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0  then close[1] else close1[1];
def change = (close / close1 - 1) * 100;
plot scan  = if change >= 0 then 1 else 0 ;
scan.AssignValueColor(if scan == 1 then Color.UPTICK else Color.DOWNTICK);

input debug = yes;
AddLabel(debug, close + " " + close1 + " " + change + " " + scan, if scan == 1 then Color.UPTICK else Color.DOWNTICK);
 
I need an item on the watchlist to indicate the pre-market high. I tried this code:

input timerange_begin = 0000;
input timerange_end = 0930;
plot PriceHigh = high;

But its showing the high of the day, not between those hours. I´m new to this, how do I make it so it only shows the high during that time frame?
 
I need an item on the watchlist to indicate the pre-market high. I tried this code:

input timerange_begin = 0000;
input timerange_end = 0930;
plot PriceHigh = high;

But its showing the high of the day, not between those hours. I´m new to this, how do I make it so it only shows the high during that time frame?

If your code gave you the high of the day, then you likely had your watchlist column set to 'Day',otherwise that should have given you just the last bar's high.

You need to set your watchlist column to an intraday timeframe with extended hours checked. Then try the following code in your watchlist.

Ruby:
def ph = if SecondsFromTime(0000) == 0
         then high
         else if SecondsTillTime(0930) > 0
         then Max(high, ph[1])
         else ph[1];

AddLabel(1, ph, Color.BLACK);
AssignBackgroundColor(if close > ph then Color.LIGHT_GREEN else Color.LIGHT_RED);
 
If your code gave you the high of the day, then you likely had your watchlist column set to 'Day',otherwise that should have given you just the last bar's high.

You need to set your watchlist column to an intraday timeframe with extended hours checked. Then try the following code in your watchlist.
I set it to 1 min ext hours checked and it working perfectly! Thank you so much!

One more thing, If I want to see the low between 9:30 and 13:00 for example, I only need to change the time frame and "high" to "low" right?
 
I set it to 1 min ext hours checked and it working perfectly! Thank you so much!

One more thing, If I want to see the low between 9:30 and 13:00 for example, I only need to change the time frame and "high" to "low" right?
That would require different logic, as follows

Ruby:
def pl = if SecondsFromTime(930) == 0
         then low
         else if SecondsTillTime(1300) >= 0
         then Min(low, pl[1])
         else pl[1];

AddLabel(1, pl, Color.BLACK);
 
@BenTen Is there a script available for after hours H/L i only have come across Pre Market H/L .

Perhaps this might help for stocks. It uses the modified volume profile script to generate the highs/lows.

Screenshot-2021-08-21-100419.jpg
Ruby:
input afterbegin = 1600;
input afterend   = 2359;
def aftermarket =  SecondsFromTime(afterbegin) > 0 and SecondsTillTime(afterend) >= 0;
def bars   = 2000;

input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default BAR};
input onExpansion = no;
input profiles = 1000;

def period;

switch (timePerProfile) {
case BAR:
    period = BarNumber() - 1;
}


def count = CompoundValue(1, if aftermarket and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
def con = CompoundValue(1, onExpansion, no);

def hProfile = if aftermarket and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if aftermarket and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if aftermarket and plotsDomain then hProfile else Double.NaN;
def ProfileLow = if aftermarket and plotsDomain then lProfile else Double.NaN;

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hrange.SetDefaultColor(Color.GREEN);
lrange.SetDefaultColor(Color.RED);
hrange.SetLineWeight(2);
lrange.SetLineWeight(2);

input bubblemover = 3;
def b  = bubblemover;
def b1 = b + 1;


input showbubbles = yes;
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b])  , hrange, AsText(hrange), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b]) , lrange, AsText(lrange), Color.LIGHT_RED, up = no);

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
380 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