Display HMA Chart Label For Different Time Frame


Category:
0
0

Hi Pete!

Hope everything is going well for you and your family. I was wondering if you could help me create a chart bubble (on the top left corner of a chart in thinkorswim) to display the 100 hull moving average price. I want to have the HMA price from a different time frame displayed on my main chart. The HMA changes color depending on if it is in an upslope or downslope. Is it possible to have the upslope in a White colored bubble and downslope in a Gray colored bubble? Thank you so much for your help!

Marked as spam
Posted by (Questions: 9, Answers: 4)
Asked on June 6, 2020 10:34 am
149 views
0
Private answer

The solution is pretty simple. The following code provides user inputs for adjust the time frame,  the length and type of moving average.

input timeFrame = AggregationPeriod.DAY;
input maLengthOne = 100;
input maTypeOne = AverageType.HULL;
def maOne = MovingAverage(maTypeOne, close(period = timeFrame), maLengthOne);
rec trackDirection = if maOne > maOne[1] then 1 else -1;
AddLabel(yes, "HMA", if trackDirection > 0 then Color.WHITE else Color.GRAY);

Edit: The author of the post entered a new question asking for a modification that would display the value of the higher time frame HMA. Rather than post that to the new question I am provide it here.

You only need to make one very minor change to the last statement from the code above:

AddLabel(yes, maOne, if trackDirection > 0 then Color.WHITE else Color.GRAY);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 6, 2020 12:50 pm
0
I have updated my answer to provide the change you requested by posting a new question. The new question has been deleted.
( at June 6, 2020 3:51 pm)
0
Could I take the same Label concept from above but instead of using the HMA, use the Adaptive Moving Average? However in that case instead of looking for color changes (HMA) I would want to know if price is above or below the AMA.
( at November 10, 2023 10:09 am)
0
Yes, that is certainly possible. But it would require a much more complex solution than what you see on this page. That's because the "AMA" you mention is an entirely separate indicator named "MovAvgAdaptive". The source code itself would need to be copied into a new chart study and modified.
( at November 10, 2023 12:59 pm)