I want to be able to do calculations on variables assigned to imported scripts using a different timeframe to the chart that the host script is being applied to.
Case study:
Script_A has the following formula to calculate the weekly value of the Bollinger Upper Band:
BB(Week(PERIODAMOUNT=1), BARS=9, DEFAULT=UpperLine, CALC=Close, STDDEV=2.000000);
When Script_A is plotted on a daily chart it behaves as expected. (It has a sort of ‘stepped’ look because it is only plotting the end-of-week value, which doesn’t change from Monday-Thursday).Let’s now import Script_A into Script_B. Script_B looks like this:
BBWeeklyUpperLine = SCRIPT(SCRIPTNAME=Script_A);
BBWeeklyUpperLine
What happens on a daily chart with Script_B is that we get a huge sawtooth pattern because Script_B outputs 0 (zero) for Monday, Tuesday, Wednesday, Thursday and then outputs the expected end-of-week value on Friday. (If you take SPX for example, in the last few weeks you’ll see Script_B jump from zero to over 3,000 every Friday).This makes it rather difficult to do comparisons of variables assigned to imported scripts using different timeframes to the chart. For example, what is the difference between this week’s weekly Upper Bollinger Band and last week’s weekly Upper Bollinger Band on a daily chart? When on a weekly chart the formula is simple and returns the expected results:
BBWeeklyUpperLine = SCRIPT(SCRIPTNAME=Script_A);
BBWeeklyUpperLine[0] – BBWeeklyUpperLine[1]
But if you use that same formula on a daily chart it compares today’s value to yesterday’s value, not this week’s end-of-week-value to last week’s end-of-week-value, even though the imported script was explicitly set to a weekly timeframe.Rather than the shorthand notation above (using [0] and [1]), I’ve tried using OFFSET with a weekly timeframe override as follows:
BBWeeklyUpperLine = SCRIPT(SCRIPTNAME=Script_A);
OFFSET(Week(PERIODAMOUNT=1), BBWeeklyUpperLine, OFFSET=0) – OFFSET(Week(PERIODAMOUNT=1), BBWeeklyUpperLine, OFFSET=1)
but get the same output as the shorthand notation. Optuma seems determined to use a chart's default timeframe for any offset applied to an imported script.Has anyone had a similar experience or have any suggestions on how to overcome this?
Many thanks, Dean