Return from a specific date


Category:
0
0

Is there a study that will either show a label on a chart or a column in the Watchlist with the following:

((Close[today]- Close[at a specific date to be input by user])/ Close[at the specific date])*100)  ?

Marked as spam
Posted by (Questions: 2, Answers: 4)
Asked on April 29, 2021 12:14 pm
53 views
0
Private answer

The following code will work when assign as a custom chart study or as a custom watchlist column. Note than when applied to a custom watchlist column it will not sort correctly because the value is displayed as text. The very first line contains the user input for the date. The date you enter must be a day the markets were open for regular trade or else the code will fail.

input targetDate = 20210104;
rec targetPrice = if DaysFromDate(targetDate) == 0 then close else targetPrice[1];
def percentChange = Round(100 * (close / targetPrice - 1), 2);
AddLabel(yes, Concat("Percent Change: ", percentChange), if percentChange > 0 then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 29, 2021 1:50 pm
0
Thank you, it works great.
( at April 29, 2021 2:27 pm)