Hull Moving Avg does not match results when compared with pine and think script

serendipity2020

Member
Plus
Hello

I've a pine script in which I'm using below command to get hull moving avg for 55 length.

Code:
hma55  = ta.hma(close, 55 )

Now, when I try the same equivalent in ToS and compare the value, it does not match.

def hma55 = HullMovingAvg(close, 55); OR
def hma = MovingAverage(AverageType.HULL, close, 55);

I tried both above but they both give same results, however does not match with result from pine script and miss by a large difference.

Does anyone know why this happens and whats the correct way to convert pine script hma to ToS?

Thanks!
 
Solution
@serendipity2020

Neither ThinkOrSwim nor pine script give away the internals of how they calculate the Hull Moving Average. There are many resources on the net which do give the formula for calculation, and you could take that and code it up for a 'third opinion' on which of them is most "accurate". However, given that there is no code available for how Pine Script does it's thing, and without knowing in what way the discrepancy you see is being manifest (you didn't specify what was different, only that they are different) it will be very difficult to impossible to sort out why you see those differences.

-mashume
@serendipity2020

Neither ThinkOrSwim nor pine script give away the internals of how they calculate the Hull Moving Average. There are many resources on the net which do give the formula for calculation, and you could take that and code it up for a 'third opinion' on which of them is most "accurate". However, given that there is no code available for how Pine Script does it's thing, and without knowing in what way the discrepancy you see is being manifest (you didn't specify what was different, only that they are different) it will be very difficult to impossible to sort out why you see those differences.

-mashume
 
Solution
@serendipity2020

Neither ThinkOrSwim nor pine script give away the internals of how they calculate the Hull Moving Average. There are many resources on the net which do give the formula for calculation, and you could take that and code it up for a 'third opinion' on which of them is most "accurate". However, given that there is no code available for how Pine Script does it's thing, and without knowing in what way the discrepancy you see is being manifest (you didn't specify what was different, only that they are different) it will be very difficult to impossible to sort out why you see those differences.

-mashume
Thanks for the reply. Today, I tried it on OXY symbol and the difference was not that big. Pine script was showing 62.56 whereas think script was showing as 61.10

I believe that is acceptable but let me know if its not.
 
So I was curious.

Here's my hand-coded reference HMA from formulas available online:
Code:
declare upper;

input length = 55;
input src = close;
plot hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
This is then plotted in blue against the ToS built in HMA (which changes color) on the OXY daily chart.
bksbOhr.png


This is interesting, but I have no explanation for it whatsoever.

EDIT
So even when I change the built-in length to match the reference (eyeballing, not actual statistical closeness here) it still doesn't overlap perfectly.

This is reference at 55 and built-in at 52:
yvQYgzz.png



-mashume

I once read that a man with one watch always knows what time it is but a man with two is never quite sure.
 
Last edited:
So I was curious.

Here's my hand-coded reference HMA from formulas available online:
Code:
declare upper;

input length = 55;
input src = close;
plot hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
This is then plotted in blue against the ToS built in HMA (which changes color) on the OXY daily chart.
bksbOhr.png


This is interesting, but I have no explanation for it whatsoever.

-mashume
Wow...interesting...Thanks for the efforts anyways. I believe little bit of offset is ok I guess.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
388 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top