How to script the 2020 performance

Hello I’m trying to script the 2020 performance using the following script:

D1 = BARDATE()==STRDATE(DATE=2020-01-01);
D2 = BARDATE()==STRDATE(DATE=2020-12-31);
(VALUEWHEN(D2)/VALUEWHEN(D1))-1

The result gives me -1
I would appreciate it if you would help me to know where I am wrong.

Hi Alfonso,

It’s because the market was closed on January 1st so the value for D1 cannot be found. If you change it to 2019-12-31 then the formula will be able to be calculated:

Capture

[postquote quote=66801]

It keeps giving me -1.

Is the script ok? Any other suggestions?

Optuma Scritp

Hi,

The script looks ok, i’ve tested it here and it works ok. One thing to note, when posting scripts please do not post a screen shot, rather copy and paste the script directly into the post, it makes it easier for us to test the code.

D1 = BARDATE() == STRDATE(DATE=2019-12-31) ;
D2 = BARDATE() == STRDATE(DATE=2020-12-31) ;
(VALUEWHEN(D2) / VALUEWHEN(D1)) - 1

First thing to check is when you open a chart you have historical data going back that far. If you do not, run through Option 3 here.

If the data is going back far enough for the script to work, try adjusting the Date Range property in the Watchlist to Everything.

Ex4