custom, dynamic, real-time %Change column


Category:
0
0

I would like to apply dynamic background color to watchlist fields based on a symbol’ real time %change from the previous days close. I would like this formula using %change to be dynamic so that the colors change as the %change from the close changes in real time. I’m unable to apply code to the %Change field that comes standard in a watchlist, so how can i make my own %change field and apply background color to it, that changes in real time along with the %change data? I very much need this idea to work in the premarket as well as the rest of the day. Any help greatly appreciated!

Marked as spam
Posted by (Questions: 6, Answers: 5)
Asked on November 29, 2020 6:56 am
235 views
0
Private answer

Pretty sure you already ran across the following posts when you searched the forum before posting your question. But the question you have posted has already been solved in numerous ways on this forum.

The following post shows how to display the percent change from previous close in real time including extended hours trading session:

https://www.hahn-tech.com/ans/percent-change-comparing-previous-day-close-to-premarket/

The following post shows how to display the percent change from previous close in real time for regular session only. But it does show how to dynamically set the background color based on positive or negative percent change:

https://www.hahn-tech.com/ans/percent-change-comparing-previous-day-close-to-premarket/

We can put those two elements together to solve your specific request:

def endTime = 1545;
def regularSessionEnd = SecondsTillTime(endTime) == 0;
rec dailyClose = if regularSessionEnd then close else dailyClose[1];
plot percentChange = 100 * (close / dailyClose - 1);
AssignBackgroundColor(if percentChange < 0 then Color.RED else if percentChange > 0 then Color.GREEN else Color.CURRENT);

IMPORTANT NOTE: You need to read the first post I linked above in order to understand how to properly set the custom column to the correct time frame and adjust the "endTime" variable to the appropriate time.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 29, 2020 9:43 am
0
Hi Pete, thanks for your help. The code appears to be giving a negative # for a positive %change and vise versa, for example if AAPL is up 0.50% the code returns " -0.50%
( at November 30, 2020 5:00 am)
0
Thanks for providing that feedback. For some reason this was missed in the previous solution I published so I have corrected both. You can copy the code from any answer to replace what you had before and use that to fix this issue. HOWEVER you must take the time to understand how the code reads the previous day's close. Last Friday was not a complete session. Markets closed early and most stocks do not have any trade data at 15:45 Eastern. For those that do, you would be reading trade data from the extended hours session. Holidays shortened sessions can really mess things up and you need to be aware of the limitations they present. Any code that relies on Friday's regular session close is producing pure garbage today. Tomorrow they will be back to normal.
( at November 30, 2020 9:51 am)