Optuma Forums › Optuma Scripting › Close Value Three Months Ago › Reply To: Close Value Three Months Ago
- Topics: 140
- Replies: 189
- Posts: 329
Hi,
I am coming back to my script issue again since I have updated to v2.1 with the new OFFSET() function.
My situation:
I calculate on a weekly chart the rolling 3-month percent change of the S&P 500.
Now I want use two “Chart Element” tools, one should display the date and the other one should display the closing value of the S&P 500 from which the calculation is made.
For example, today Wednesday 06/22/2022 the close is 3759.89. Optuma uses as the reference date Friday 03/18/2022 with the closing value of 4463.12. Optuma uses the Friday because my chart is a weekly chart.
Problem / Question:
How can I calculate the reference date and closing value?
I use the following script for the calculation of the rolling 3-month percent change:
1 2 3 4 5 6 7 8 |
// Get S&P 500 Data Line1 = GETDATA(CODE=SPX:WI, TIMEFRAME=1 Week) ; // Rolling 3-Month %-Change Line2 = CHANGE(Line1, INT_TYPE=Month, INT_COUNT=3) ; Line2 |
For the calculation of the reference date I use the following script:
1 2 3 4 5 6 7 8 9 10 |
// Get S&P 500 Data Line1 = GETDATA(CODE=SPX:WI, TIMEFRAME=1 Week) ; // Rolling 3-Month %-Change and displaying the reference date Line2 = CHANGE(Line1, INT_TYPE=Month, INT_COUNT=3) ; Line3 = BARDATE(Line2) ; Line4 = OFFSET(Line3, Month(PERIODAMOUNT=1), TYPE=Calendar Days, OFFSET=3) ; Line4 |
I have set the OFFSET() function to “Calendar Days” but I get as the result the number 44,736.00, using “Field Type – Date” I get the date 6/24/2022. That is the Friday this week BUT NOT the Friday 03/18/2022.
What did I made wrong?
Many thanks for any assistance,
Thomas