Percent change comparing previous day close to premarket




I need help getting the code for the Mark % change from the previous day close for PreMkt … Every code I’ve used, I on;y get results after the open … I also want to be able to change the background color.


Thank you and Happy Trading! 

Marked as spam
Posted by (Questions: 3, Answers: 2)
Asked on March 30, 2020 7:05 am
Hi Peter, im trying to add color codes to this watchlist code you provided, but cant manage it to work: data.AssignValueColor(if data 0 then Color.BLACK else Color.WHITE); AssignBackgroundColor(if data > 0 then Color.GREEN else if data < 0 then Color.RED else Color.CURRENT);
( at February 22, 2024 4:40 pm)
Looks like you forgot to include an equals sign between 'data' and '0' in your AssignValueColor statement.
( at February 22, 2024 5:50 pm)
Private answer

The last bar of the regular session low has a time stamp that varies based on the selected time frame. For example on a 15 min chart the last bar of the regular session is stamped 15:45. For the 5 min time frame the last bar is stamped 15:55. You must keep this in mind when applying the code below. The default value for endTime is set for a 15 min time frame.

When creating a new custom watchlist column for this you will need to set the time frame as described above, adjust the endTime value accordingly and ensure that you have checked the boxed labeled "Include Extended-Hours Trading session".

If any of the stocks in your watchlist do not contain trade data for the regular session hours this code will not work and nothing can be done work around this. No data, means the result will be something other than what you expect.

Here is the code:

def endTime = 1545;
def regularSessionEnd = SecondsTillTime(endTime) == 0;
rec dailyClose = if regularSessionEnd then close else dailyClose[1];
plot percentChange = 100 * (close / dailyClose - 1);

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on March 30, 2020 12:07 pm
Thanks Pete ... question, it asked for a plot when I copy/paste ... I entered this: plot x = percentChange; Will that return the results as a % or decimal?
( at March 30, 2020 12:42 pm)
Sorry about that. I forgot to set the final statement in that code to plot instead of def. I updated my response to include that in the code.
( at March 30, 2020 1:14 pm)
I was looking for a way to create a custom column in the TOS watchlist that would give me the % change from the current days open to the currrent market price. I was able to modify this code to achieve this. not completely sure how the code works but it does. I also added a code to add color to the back ground and numbers base on a video you posted. Thanks. Please see below the code I came up with. Pete, if you see this maybe you can give an explanation to how my changes made this work? def startTime = 0900; def regularSessionstart = SecondsTillTime(startTime) == 0; rec dailyOpen = if regularSessionstart then close else dailyOpen[1]; plot percentChange = 100 * (dailyOpen / open - 1); PercentChange. AssignValueColor(if percentChange > 0 then Color.GREEN else if percentChange < 0 then Color.RED else Color.BLACK);
( at April 28, 2020 9:27 am)
Rather than that, how about I give you the link to a post that already requested this:
( at April 28, 2020 12:56 pm)