Pre-Market Questions & Answers

J007RMC

Well-known member
2019 Donor
Make sure your column is set to an intraday aggregation and extended hours is checked on.

Code:
#begin
#Hint: Displays After Hours & Pre Market change as a  percentage in custom column.
#WaterFrontTrader

#07/20/12: Initital Release
#08/13/12: Fixed to include pre-market and extended session

#"Show Extended Session" should be active on your chart

def Post = secondsFromTime(1600);
def Pre = secondsTillTime(930);
def Closed  = Post >=0 or Pre>=0;
def DayClose = if (Post>=0,close(period = "Day"),close(period = "Day")[1]);
#NN note:modified close to use ask
def Change = close(priceType = "ASK") - DayClose;
def Percent = round(((close - DayClose)/DayClose)*100);

plot change1 = percent;
change1.assignValueColor (color.BLACK);
assignBackgroundColor(if close< dayclose then color.red else if close>dayclose then color.green else color.current);
#end
 
Last edited by a moderator:
Sounds great! I'll be trying this out tomorrow morning.

I don't know. I pasted this code into a Custom Quotes column. Set the period for 1 hour and made sure Extended Hours trading was enabled. I got nothing but NAN for two days. Kind of disjointed,. as I think such an indicator would be ideal for knowing which stocks are going to GAP UP or DOWN the most.

Now... on Saturday, I tried setting the Period to Day, and I get all zeros!! I think it's working now. Seems to only work for the Day period. Hopefully I'll get some real numbers on Monday.

PS: Let me know if anybody gets this working on the shorter time frames.
 

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

@Townsend Hmm...That's interesting. I would assume the opposite since the Daily chart doesn't display after-hours and pre-market data. Let us know how it goes for you on Monday.
 
Monday morning, pre-market: no numbers. Nothing. But, bid/asked is not showing up on any of my charts, even though I'm looking at highlighted Extended Hours candles. Also, the regular %Change column on my Watchlist shows all zeros as well. So... maybe the problem is not the indicator, but rather some system wide or account problem. Do I have to have my TD account activated for extended hours trading?
 
If you are using Bid/ask intraday timeframe, e.g. 1 min depending on how you program the study you should usually see some numbers.
Make sure you test for NaN and you should be okay. All bets are off if you use daily aggregation

Here is an example of a Bid/Ask watchlist that does work fine on a 1 min chart

Code:
# Bid Ask Watchlist
# Mobius
# 2.26.2019

# aggregation must be less than daily

plot data = (((bid()+ask())/2-close from 1 bars ago)*100)/close from 1 bars ago;
def up = data > 0;
def down = data < 0;
data.assignValueColor(if up then color.dark_green else if down then color.red else color.yelloW);
 
Last edited:
May are reporting issues with this, I took a shot at it and could get it to work,

Below is the code,

Rich (BB code):
#begin
#Hint: Displays After Hours & Pre Market change as a  percentage in custom column.
#WaterFrontTrader

#07/20/12: Initital Release
#08/13/12: Fixed to include pre-market and extended session
#01/29/19: theelderwand: Fixed for latest version.

#"Show Extended Session" should be active on your chart

def Post = secondsFromTime(1600);
def Pre = secondsTillTime(930);
def Closed  = Post >=0 or Pre>=0;
def DayClose = if (Post>=0,close(period = "Day"),close(period = "Day")[1]);


#NN note:modified close to use ask
plot Change = ask() - DayClose;

Change.AssignValueColor (Color.BLACK);
AssignBackgroundColor(if Change < 0 then Color.LIGHT_RED else if Change > 0 then Color.LIGHT_GREEN else color.current);
#end
#Make sure your column is set to Day aggregation

Shareable link: https://tos.mx/Xxl2TSg

Settings
WEI9iY4.png


Screenshots
MRnzFou.png


hafpJd9.png
 
Hi - I am looking to plot a shaded box in my ToS with the premarket prices as the upper and lower bounds, shaded in between. However, these bounds should be limited to the high and low prices of the equity between 6:00am and 9:20am EST. My code is below, and I can't get it to work. Would love some help. (I realize code below is incomplete)

Code:
plot Data = close;


#defines PRE mkt hours I want to use as:
input openingESTime  = 0600.0;
input openingTime  = 0920.0;


def isDaily = If (GetAggregationPeriod() == AggregationPeriod.DAY, yes, no);


def isPreMarket = If (GetDay() == GetLastDay() and SecondsTillTime(openingTime) <300, yes, no);
input LineWidth = 1;
def na = Double.NaN;


def isBelowDaily = If (GetAggregationPeriod() < AggregationPeriod.DAY, yes, no);
def isToday = If (GetDay() == GetLastDay() and SecondsFromTime(openingESTime) >= 300, yes, no);
def day = GetDay();

def PMopenBar = day != day[1];
def PMOpen = if PMopenBar then open else PMOpen[1];

AddCloud(PMopenBar,PMopenBar);
 
This what you're looking for?
Code:
#
# see https://usethinkscript.com/threads/how-to-get-current-days-premarket-high.695/
#
declare once_per_bar;

input PlotPreMktLinesHrsPastOpen = yes;
input ShowChartBubbles = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH =  if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
            then PMHighBar
            else nan;
plot PML =  if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
            then PMLowBar
            else nan;

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PMHigh,
  "PM High",
  Color.Gray,
  1);

AddChartBubble(ShowChartBubbles and bar == HighestAll(lowBar),
  PMLow,
  "PM Low",
  Color.Gray,
  0);

AddCloud(PMH , PML , COLOR.GRAY);

# end of script
 
Agreed. This is terrific @tradebyday and thank you.

TWO follow-up questions.

1 - Can we change the time frame? Like, maybe have it paint at 915 or 900?

2 - Do you think there is a way to turn it into a scan?

Something to alert and say:
A) "These stocks just crossed the PM High or PM Low"
and/or
B) "These stocks just moved away from the PM High by 10%"

That way, we could see if things are going nuts before the open as a possible opportunity.
 
I will let someone else tag in for those changes, this was not my code, but modified it to have the cloud as requested. I am not too familiar wit setting up scans personally as I do not use them myself
 
Code:
#begin
#Hint: Displays After Hours & Pre Market change as a  percentage in custom column.
#WaterFrontTrader

#07/20/12: Initital Release
#08/13/12: Fixed to include pre-market and extended session
#01/29/19: theelderwand: Fixed for latest version.

#"Show Extended Session" should be active on your chart

def Post = secondsFromTime(1600);
def Pre = secondsTillTime(930);
def Closed  = Post >=0 or Pre>=0;
def DayClose = if (Post>=0,close(period = "Day"),close(period = "Day")[1]);
def Change = (ask() + bid())/2 - DayClose;
def Percent = round((Change/DayClose)*100);

#NN note:modified close to use ask
plot Percent1 = percent;
 
Percent1.AssignValueColor (Color.BLACK);
AssignBackgroundColor(if Percent < 0 then Color.LIGHT_RED else if Percent > 0 then Color.LIGHT_GREEN else color.current);
#end
#Make sure your column is set to an intraday aggregation and extended hours is checked on.

This displays it in percent. does anyone know how to concatenate the % sign at the end of the display?
 
Last edited:
So this is not elegant. But I figured the closes I can do is this for a search column to see pre market change, I want to see if premarket is rising or falling. And this at least gives me an idea. I was trying to figure out how to set 4 am open and subtract close at 9:30 am and could not get it to work. Then tried to do day open minus 11 30 minute bars, and could not figure out the script. So went with difference of a 4 hour bar close and prior 4 minute bar close. This would have to be looked at like an hour before market open but at least it can easily show trend in a column.

Code:
plot change = Round(((CLOSE("period" = AggregationPeriod.FOUR_HOURS)-close("period" = AggregationPeriod.FOUR_HOURS)[1])/(close("period" = AggregationPeriod.FOUR_HOURS)[1]))*100, 2);

AssignBackgroundColor(if change > 0 then Color.DARK_GREEN else Color.DARK_RED);
 
@J007RMC Hello. What can be changed in the script so that it displays changes in the price of the postmarket. Quite often, strong price changes occur on the postmarket, especially in cheap stacks. Thank you!
 
Does anyone know how to incorporate mark % change into a scan? Mark % change is the only % change that changes during pre-market but there's no way by default to use that in a scan. Any help would be greatly appreciated! Thanks

Edit: Why was my post moved to this thread? I was asking regarding a Scan, this thread is in regards to a column in a watchlist
 
Last edited by a moderator:
Everyone just use this its simple and a lot easier to read.
Here's my code for the 3 columns
bdT70N6.png

Column 1 - PM % Change - 1m Time Frame CHECK "included Extended Hours"
Code:
# Follow @Nick_Peist on Twitter
# 1m Time Frame CHECK "included Extended Hours"
def prevday=if getlastDay()==2 and getday()==365 then 1 else if getDay()<getlastDay() then 1 else 0;
def close1= if secondsfromTime(1200)>0 and secondsFromTime(1600)<0 and prevday then close else close1[1];
def prevclose = if SecondsTillTime(1559) == 0 then close else prevclose[1] ;
def last =if secondsFromTime(0930)<0 then  close else last[1];
plot pvc=close1;
plot last1=last;
def change=if last==0 then 0 else  (last-close1)/close1;
addlabel(yes,round(change,2)*100+" %",color.black);
assignBackgroundColor(if change>0 then color.green else if change<0 then color.red else color.black);

Column 2 - PM High - 1m Time Frame CHECK "included Extended Hours"
Code:
# Follow @Nick_Peist on Twitter
# 1m Time Frame CHECK "included Extended Hours"
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def hi = if isRollover and beforeStart then high else if beforeStart and high>hi[1] then high else hi[1];
addlabel(yes,hi);
#plot PreMarketVolume = vol;;

Column 3 - AH % Change - 1m Time Frame CHECK "included Extended Hours"
Code:
# Follow @Nick_Peist on Twitter
# 1m Time Frame CHECK "included Extended Hours"
def today=getday()==getlastDay();
def close1= if secondsfromTime(1200)>0 and secondsFromTime(1600)<0  then close else close1[1];
def change= (close(pricetype=pricetype.last)/close1)-1;
addlabel(yes,round(change*100,0)+"%",if change>0 then color.green else color.red);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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