Apply Hull MA to secondary chart symbol


Category:
0
0

Hi Peter, this code combination merely plots the the upper symbols 21 day HMA on the lower plot. What am I doing wrong?

 

declare lower;
plot data = close(“VIX”);
plot maOne = MovingAverage(AverageType.HULL, data, 21);

 

input price = close;

input length = 21;

input displace = 0;

 

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

 

HMA.DefineColor(“Up”, GetColor(1));

HMA.DefineColor(“Down”, GetColor(0));

HMA.AssignValueColor(if HMA > HMA[1] then HMA.color(“Up”) else HMA.color(“Down”));

Marked as spam
Posted by (Questions: 3, Answers: 8)
Asked on March 15, 2020 12:42 pm
126 views
0
I can add this back to my previous inquiry, but I mistakenly marked it resolved (didn't notice it was plotting the upper symbol's HMA until looking more closely). Thank you for any assistance.
( at March 15, 2020 12:44 pm)
0
Private answer

In the code you provided, the line of code that computes the Hull moving average is:

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

The MovingAverage() function takes three parameters. Details here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage

The first parameter is the average type, the second is the price used to compute the moving average and the third is for the length of the moving average. In your code the second parameter is an input variable named "price". And this is the line of code that holds that user input:

input price = close;

So we can see why your Hull moving average is plotting based on the chart ticker symbol instead of the alternate ticker symbol. So simply delete everything except the first three lines. The first three lines are all that is needed to plot the Hull moving average along with the closing prices of the alternate ticker symbol.

declare lower;
plot data = close(“VIX”);
plot maOne = MovingAverage(AverageType.HULL, data, 21);

There you go. That's all you need. However because this is the second post on this topic I understand from the previous post that you are actually trying to dynamically set the color of the Hull moving average just as it is in the original version provided with Thinkorswim. You did not include that in this current request, but somehow I managed to remember this small detail. The dynamic color assignment is found in the last three of the lines in the code I just told you to delete.

So here they are again. This time I have replaced the reference to the HMA plot (which was deleted as per my instructions) , and in it's place I am going to use the plot named "maOne":

maOne.DefineColor(“Up”, GetColor(1));
maOne.DefineColor(“Down”, GetColor(0));
maOne.AssignValueColor(if maOne > maOne[1] then maOne.color(“Up”) else maOne.color(“Down”));

Let's make sure we don't leave this incomplete, or else we will have many viewers fail to put all these pieces together correctly:

declare lower;
plot data = close(“VIX”);
plot maOne = MovingAverage(AverageType.HULL, data, 21);
maOne.DefineColor(“Up”, GetColor(1));
maOne.DefineColor(“Down”, GetColor(0));
maOne.AssignValueColor(if maOne > maOne[1] then maOne.color(“Up”) else maOne.color(“Down”));

For those who are wondering how on earth I knew how to do this.... it's just magic. No, I'm totally kidding. Everything you need to know to learn how to do this yourself is contained in the following links to the Thinkorswim Language Reference:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/DefineColor

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AssignValueColor

 

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on March 15, 2020 1:15 pm
0
Thank you, Peter.
( at March 15, 2020 1:37 pm)