Thinkscript – Cannot Plot Calculated Value of Secondary Symbol


Category:
0
0

Hi Pete,
Was finally able to create account, thanks much for your help 🙂
Following is the problem I am encountering and would much appreciate if you could please let me know if its something that can or cannot be done in thinkscript.
1) I am on “AMD” 2D:15m chart.
2) I can plot the following no problem –
plot x = close(period = AggregationPeriod.DAY)[1] + close
3) But secondary symbol in the following did not work –
plot y = close(“INTC”period = AggregationPeriod.DAY)[1] + close(“INTC”);
Broke up the two time frames per ts manual instruction still does’nt work as shown below –
def a = close(“INTC”period = AggregationPeriod.DAY)[1];
def b = close(“INTC”);
(I even tried close(“INTC”period = AggregationPeriod.FIFTEEN_MIN);)
plot y = a + b;
this only calculates and plots for the first bar of the day and then a horizontal line for the rest of the bars for the day
If I plot a & b separately it works just fine.
Really baffled, is there a completely different process or is it ts limitation? Perhaps you may know some trick 🙂
Thanks much in advance

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on February 17, 2020 12:36 pm
190 views
0
Amazing! Thanks so much for your prompt and kind help! Sorry for those comma typos etc... Have a good one!
( at February 17, 2020 4:23 pm)
0
Private answer

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.

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on February 17, 2020 2:20 pm