The following plot statement is missing a comma:
plot y = close(“INTC”period = AggregationPeriod.DAY)[1] + close(“INTC”);
The corrected line follows:
plot y = close(“INTC”, period = AggregationPeriod.DAY)[1] + close(“INTC”);
However even after fixing the error we find the study throws an exception. Which can be found by clicking the icon in the upper left corner of the chart. Is is a circle with an exclamation mark inside. Click that icon and the message states: "Two different secondary periods cannot be used with a single variable".
So you are correct. We cannot do that, period.
Next we try your technique of separating them:
def a = close(“INTC”period = AggregationPeriod.DAY)[1];
def b = close(“INTC”);
Which we find produces an error because the first line is missing a comma just like the example above. So we correct that like so:
def a = close(“INTC”, period = AggregationPeriod.DAY)[1];
def b = close(“INTC”);
At this point the only error we get is "At least one plot should be defined. Which is easily corrected by adding a plot statement:
plot y = a + b;
This compiles without error and plots the line you described in your question. So I see what you mean, in that you would expect the plot to be changing throughout the entire span of the chart. But instead the value is the same for each day.
I did find one trick to get this to work correctly. We simply add an equation that incorporates at least one of the data points from the symbol that is plotted on the chart. This somehow breaks the stranglehold of whatever unseen forces are preventing this from working. This is how I did it:
plot testA = (a + b) + (close - close);
All I did there was to add (close - close) to the equation. The result is zero, so that it does not change the computation at all. But it does break this loose from whatever glitch is preventing this from working as expected.