use “price for previous date” in calculations


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;  #

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
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:

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


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