After Hours & Pre Market Change Watchlist Column

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:

Townsend

Active member
VIP
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.
 

BenTen

Administrative
Staff
VIP
@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.
 

Townsend

Active member
VIP
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?
 

tomsk

Well-known member
VIP
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:

theelderwand

Active member
2019 Donor
VIP
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
 

cv40067

New member
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:

VicD

Member
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);
 

popovv

New member
@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!
 

kylexy

New member
@cv40067 Is there someway to pull the last price from after/pre hours to create the percentage? Using the (ask+bid)/2 is not very goof for after/per hours.
 

chada456

New member
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:

Trader47

New member
Chada456: Any answers? I am also looking for a script or a way to have a filter for maximum Mark% values in a scan filter for the pre-market. Thanks for any suggestions.
 

axlerod

Member
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);
 

evanevans

Member
While I'm searching around, just dropping this question here if anyone knows of a Watchlist Column script which will give just After Hours % change?
 

Slydog482

New member
VIP
@axlerod I love this Axel. Thank you so much. I was curious if you have a % calculation starting from market open (9:30 EST) to market close (4:00 EST). Or would we simply uncheck the extended hours box on one of these?
 

zeek

Active member
2019 Donor
I`ve tried all the different versions posted here and the only one showing the % change for afterhours is the one in post #20 but that one is not showing correct % values.

Can someone please post a working version for afterhours and % change only?

Also curious to know why we have to have separate columns for pre, regular and afterhours? Isn`t there a way to combine all and have just one column showing the % change no matter the trading hours?
 

XeoNoX

Well-known member
VIP
the post #20 by @axlerod appears to work, it rounds to the nearest whole number, if you want it to round differently just change the round variable
 

TheDakk

New member
the post #20 by @axlerod appears to work, it rounds to the nearest whole number, if you want it to round differently just change the round variable
I was trying to setup Column 3 in post #20, but it returns an insane number for all stocks. I assume it's not calculating correctly.

I would like to add the After Hours static number and percentage columns with the values that you see on many financial websites. Can anyone assist with this? I'm very new to thinkorswim desktop app. Thanks!
 

Similar threads

Top