use “price for previous date” in calculations


Category:
0
0

https://www.hahn-tech.com/ans/price-for-a-specified-date/

discusses how to define a price for a previous date using the code

def priceAtDate = if GetYYYYMMDD() == 20170103 then close else Double.NaN;

That code gives a value only for the single day 20170103 and doesn’t have a value for other days.

 

How can I use the priceAtDate value for calculations on other days

For example

def priceAtDate = if GetYYYYMMDD() == 20211101 then close else Double.NaN;  #https://www.hahn-tech.com/ans/price-for-a-specified-date/

plot scan = priceAtDate;

plot close – scan;     <-   TOS says this line is invalid

Marked as spam
Posted by (Questions: 5, Answers: 3)
Asked on December 3, 2021 10:45 pm
25 views
0
Private answer

The only part  you are missing the name of the plot variable. This is what you last line should look like:

plot myVariableName = close – scan;

I used a rather ridiculous name for the variable name of the plot statement so that you can see where it needs to be placed. And you must have the equal sign immediately following the name of the plot variable.

Want to learn more? Here is a link to the Thinkorswim language reference that covers the plot statement:

https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/plot

Thinkorswim also provides an only tutorial that explains how to begin writing custom trading tools:

https://tlc.thinkorswim.com/center/reference/thinkScript/tutorials/Overview

 

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on December 5, 2021 8:57 am