Inconsistent calculation of values in incomplete periods

This post is sort of related to this post but is slightly different.

It is about the calculation of values in incomplete periods.

For example, take closing price. What should the weekly timeframe closing price be showing on Monday, Tuesday, Wednesday or Thursday on a daily chart? Should it be static and show last week’s (last Friday’s) closing value on every day, or should it be dynamic and change with each day’s new closing price?

It seems that Optuma does it both ways. Some observations:

  1. A weekly chart does not wait until the end of the week before it gives the week's closing price. The most recent bar will show the most recent closing price, even thought the week is incomplete from Monday-Thursday. In other words, the last bar on a weekly chart will show Monday's closing price on Monday, Tuesday's closing price on Tuesday, and so on. It keeps changing until the week is complete. The same occurs with other indicators too (e.g. Bollinger Bands, etc.)
  2. If a weekly closing price formula is plotted on a daily chart, it follows the daily closing price on Monday-Thursday, then settles to a final closing value on the Friday. See the attached screenshot where the thick green line (weekly closing price) is the same as the closing price on a Monday. This is the same behaviour as a weekly chart (see first observation).
  3. If the weekly closing price formula is shown as a cursor custom label, it remains at last week's closing price from Monday to Thursday (see screen shot again, look for the label WeeklyClose at 2990.4 in the cursor labels). It is not dynamic in the same way as the weekly closing price is in observations 1 & 2.
  4. Using the weekly closing price formula in scripts gives the same outcome as observation 3. It is not dynamic in the same way as the weekly closing price is in observations 1 & 2.
It seems that Optuma handles timeframes in different ways depending on the context you are operating in. I would prefer that a consistent approach is applied in all contexts. I'm sure that most would prefer that too.

My view is that observations 1 & 2 above should be the standard way values are calculated in incomplete periods, in all contexts. That is, values are dynamic until the period is finished, at which time they become fixed in history.

Please reply with your own views or experiences on this matter. Perhaps I’m missing something and I’d really appreciate some good advice or insight. Otherwise, it would be great if the Optuma scripting community was able to gain some consensus and provide feedback to Optuma.

Many thanks, Dean

Hey Dean, I believe I’ve run into similar issues as you when running a script with daily parameters with a “weekly” override. I have spoken with Optuma and it seems this is a known warning as I have been pointed to the following post which may also help you.

In my case, I only want to make trades on Friday’s close, but as you note, this can become an issue given the dynamicism of the weekly data.

https://www.optuma.com/the-danger-of-weekly-scripting/

 

Hope this helps.

Thanks Chad.

The Optuma team have thought about this issue deeply as Mathew explained in the article. So we can all be confident that since the release of Optuma 1.3 we will never be exposed to inadvertently using future data in developing our testing and trading strategies. A huge thank you to Optuma for that.

With that issue resolved though, in my view, there still seems to be a lack of consistent behaviour across timeframes. For example:

  1. On a weekly chart, the close of the last bar will reflect the close of the last trading day
  2. On a daily chart, the value of a close with a weekly timeframe override on the last bar will reflect the close of last week
I'm sure that if point #2 behaved in the same way as point #1 the risks explained in the article would not be re-introduced. That is, a close with a weekly timeframe override can very safely reflect the daily close as we go day-by-day, just like the weekly chart does.

Even more confusing, with respect to point #2, Mon, Tues, Wed and Thurs take the closing value of the previous week, but Friday takes the daily close. I guess the logic here is that the week is closed, so the closing value of the Friday can be taken immediately.<i> But that means that there are actually not one but two closing values per week if you use a weekly timeframe override on a daily chart - one value for Mon-Thu and then a second value on Friday.</i>

<i></i>It has to be said that the Optuma team has vastly more experience than me in this game so I have to refer to their wisdom and experience. I just don’t have the depth of knowledge to grasp why Optuma behaves in this way.

These different behaviours are all little ‘gotchas’ though that you’ve got to be alert to when you are scripting.

What’s the upshot of all of this? Don’t mix weekly and daily timeframes when you are scripting! :slight_smile:

Cheers, Dean