Track performance from a track date in a watchlist


Category:
0
0

Hi Pete,  Looking to add a date to a watchlist for all the stocks in the watchlist. Show the performance of the stocks in the watchlist from that date forward (I call it a track date and track price which is close of stock on track date). In addition provide a percentage move of the stock from the track date. Here is an example of the watchlist.

Watchlist header

Symbol………track date………….. Track price….. Track percentage …..Last price……………………………………………….. SPY………….. 10/25/2020………..Ex. $100 ……      3.00 % ………………..103.00

QQQQ. ………10/25/2020. ………ex. 200.00…….. 1.50% …………………202.50

Hope this is clarifies what I was looking for. I’m new to coding. Appreciate your help. Thank you Paul

 

Marked as spam
Posted by (Questions: 1, Answers: 2)
Asked on October 27, 2020 1:25 pm
7 views
0
Private answer

The solution requires the custom column of the watchlist be set to daily time frame.

The date is adjusted through a user input named "targetDate". This date is applied to every stock in the watchlist. There is no way to apply different dates to different tickers within the watchlist.

There is no way for columns within a watchlist to read data from other columns. (only the ticker symbol is read by the code in a custom column). What does that mean? It means there is no need to display the target date as a separate column. However if you really want to display that you need to keep in mind that whatever value is displayed there cannot be read by any other columns in the watchlist AND the date will need to be kept up to date by manually adjusting it in each of the custom columns in your watchlist. Here is the signal line of code to display the date (or any other text) in a custom column:

AddLabel(yes, "9/1/2020");

Here is the code to display your two values. Notice that there are two plot statements and only one is permitted within a custom column. You will need to add two custom columns to the watchlist and copy this code into each. You will then move the "#" symbol to display the one value that you want to display for each. The first displays the net change and the last line displays the percent change:

input targetDate = 20200901;
def targetBar = DaysFromDate(targetDate) == 0;
rec targetClose = if targetBar then close else targetClose[1];
#plot data = close - targetClose;
plot data = 100 * (close / targetClose - 1);

Final note and VERY important. The date you enter for the user input named "targetDate" must be a date the markets were open for regular trade. If you select a date that markets were closed the code will fail.

Marked as spam
Posted by (Questions: 38, Answers: 3345)
Answered on October 27, 2020 4:01 pm