Repaints Hull Moving Average Turning Points and Concavity (2nd Derivatives)

Repaints
Status
Not open for further replies.
imo, if any of the "gurus" try to sell you their stuff, and say how rich they are from using any indicator, I'd ask for their 1040, signed by a reputable CPA firm. And same for me, I may think I know what I'm doing or I may be Bozo's first cousin - you simply don't know - so massive grain of salt with my comments and never forget its your money.
Those are important points, @codydog! When I was a newb, I got caught up in the hype of making big money and listening to "gurus." What I learned (after losing a lot of money, LOL) was that there is no substitute for learning market basics, price action, etc. Maybe other newbs are smarter than I was and can make money applying someone else's trading system. I couldn't do it. I had to study price action and then watch charts for months and months to build a trading plan around aspects of price movement that I could see and understand.
 
@JB7 I use it quite a bit to confirm my other signals. It's usually spot on. I like it a lot. I concur with what was mentioned above. We're all different so we're gonna pull the trigger differently so I use it in my own personal way. It doesn't work well in channels, but I don't know what indicator does. I paid dearly for my trading education having lost quite a bit in my early years, but I survived and now I'm consistently profitable. It was more about learning who I was rather than the market. I can highly recommend this indicator in parallel with a confirming signal or good 'ol price action if you have the experience.
 
It was more about learning who I was rather than the market.

Well said! Boy, did I have to learn about myself too! I was impulsive and not waiting for a good entry. Greed prompted me to overtrade and lose. Arrogance made me revenge trade and lose even more. Laziness kept me from holding myself accountable with a trade journal. For me, the hardest part of trading has been self-discipline. Maybe others don't find it an issue, but I have been my own worst enemy.
 
@codydog If you don't mind sharing, how did you switch from the HMA to the EHMA in the code?

@mashume has the best advice, but if you can't find it-

script EHMA {
input Price = close;
input Length = 3;

plot ehma = ExpAverage(2 * ExpAverage(Price, Round(Length / 2, 0)) - ExpAverage(Price, Length), Round(Sqrt(Length), 0));

}

then find the "plot hma" line and replace with-

plot HMA = ehma(price,hma_length);

mashume's code is very forgiving for this type of change
 
As I was looking at the Hull Moving Average, it occurred to me that taking the local minimums and maximums might not be the most effective use of it's smooth nature. Nor did it seem that a moving average cross over would provide timely signals.

And then I remembered that I used to teach physics and calculus and decided to look at rates of change and that lead me to...

CONCAVITY

which is nothing but the second derivative of the function (if you remember or not) :) and so this indicator was born.

It is in two parts -- the upper which is the Hull Moving Average with the addition of colored segments representing concavity and turning points: maxima, minima and inflection. The last of these are of the greatest interest. The second part is a plot of the calculation used in finding the turning points (which is roughly the second derivative of the HMA function, where zero crosses are the inflection points.

SDcVypw.png


UPPER INDICATOR

Upper HMA colors:
  • Green: Concave Up but HMA decreasing. The 'mood' has changed and the declining trend of the HMA is slowing. Long trades were entered at the turning point
  • Light Green: Concave up and HMA increasing. Price is increasing, and since the curve is still concave up, it is accelerating upward.
  • Orange: Concavity is now downward, and though price is still increasing, the rate has slowed, perhaps the mood has become less enthusiastic. We EXIT the trade (long) when this phase starts. Very little additional upward price movement is likely.
  • Red: Concave down and HMA decreasing. Not good for long trades, but get ready for a turning point to enter long on again.

Upper Label Colors:
these are useful for getting ready to enter a trade, or exit a trade and serve as warnings that a turning point may be reached soon
  • Green: Concave up and divergence (the distance from the expected HMA value to the actual HMA value is increasing). That is, we're moving away from a 2nd derivative zero crossover.
  • Yellow: Concave up but the divergence is decreasing (heading toward a 2nd derivative zero crossover); it may soon be time to exit the trade.
  • Red: Concave down and the absolute value of the divergence is increasing (moving away from crossover)
  • Pink: Concave down but approaching a zero crossover from below (remember that that is the entry signal, so pink means 'get ready').
Arrows are provided as Buy and Sell and could perhaps be scanned against.

LOWER INDICATOR

For those who prefer less cluttered uppers, I offer the plot of the divergence from expected HMA values; analogous to the second derivative in that the zero crossovers are of interest, as is the slope of the line. The further from zero, the stronger the curve of the concavity, and the more likely to reach a local minima or maxima in short order.


Miscelaneous

If you find that there are too many buy and sell signals, you can change the length of the HMA (I find 34 a happy medium, though 55 and sometimes 89 can be appropriate). You can also play with the value of the lookback, though that will slow down signals.

This works well on Daily timeframes as well as intraday candles.

I set it up with High + Low / 2 as the default so that it shouldn't wait for close prices. That may not be appropriate to how you wish to trade.

Comments welcome. Let me know how you use it, how it works for your trades, and whether it made your head hurt trying to remember your calculus.

Happy Trading,
Mashume

UPPER:
https://tos.mx/cgKFdmm

LOWER:
https://tos.mx/p0k7ims

UPPER CODE

Code:
#
# Hull Moving Average Concavity and Turning Points
#  or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
# Faster, but not necessarily mathematically as good as the first
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------


declare upper;

input price = HL2;
input HMA_Length = 21;
input lookback = 2;

plot HMA = HullMovingAvg(price = price, length = HMA_Length);

# def delta_per_bar =
# (fold n = 0 to lookback with s do s + getValue(HMA, n, lookback - 1)) / lookback;

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;

def concavity = if HMA > next_bar then 1 else -1;

plot turning_point = if concavity[1] != concavity then HMA else double.nan;

HMA.AssignValueColor(color = if concavity[1] == -1 then
    if HMA > HMA[1] then color.dark_orange else color.red else
    if HMA < HMA[1] then color.dark_green else color.green);

HMA.SetLineWeight(3);

turning_point.SetLineWeight(4);
turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
turning_point.SetDefaultColor(color.white);

plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
MA_Max.SetDefaultColor(Color.WHITE);
MA_Max.SetPaintingStrategy(PaintingStrategy.SQUARES);

#####
# Added Alerts 2020-02-23
Alert(condition = buy, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Chimes);
Alert(condition = sell, text = "Sell", "alert type" = Alert.BAR, sound = Sound.Chimes);

LOWER CODE

Code:
#
# Hull Moving Average Concavity Divergence
#  or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------

declare lower;

input price = OPEN;

input HMA_length = 55;
input lookback = 2;

def HMA = HullMovingAvg(length = HMA_length, price = price);

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;

def concavity = if HMA > next_bar then 1 else -1;

plot zero = 0;
zero.setdefaultcolor(color.gray);
zero.setpaintingstrategy(PaintingStrategy.DASHES);

plot divergence = HMA - next_bar;
divergence.setDefaultColor(Color.LIME);
divergence.SetLineweight(2);

plot cx_up = if divergence crosses above zero then 0 else double.nan;
cx_up.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_up.SetDefaultColor(Color.LIGHT_GREEN);
cx_up.SetLineWeight(4);

plot cx_down = if divergence crosses below zero then 0 else double.nan;
cx_down.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_down.SetDefaultColor(Color.RED);
cx_down.SetLineWeight(4);


Hello
You mentioned above for Upper Label Colors, Green, Yellow, Red and Pink. These are just after you say about concavities. (upper HMA colors)
Where are these colors? I only see orange and blue arrows that paint when dots are painted.
I'm looking at your indicator and seems pretty nice; I'm testing in at 1 min chart.
Appreciate your work
chris
 
@mashume curious what time frame you are using the 34 HMA setting on? I notice that the default is 21 with 2 look back

you find that there are too many buy and sell signals, you can change the length of the HMA (I find 34 a happy medium, though 55 and sometimes 89 can be appropriate). You can also play with the value of the lookback, though that will slow down signals.
 
@kshires4

I think I keep it at 55 most of the time. I have two scans set up, one at 55 and one at 34 (both daily agg) and sometimes symbols from the 34 daily scan make it onto a watchlist and become more interesting purchase signals when the 55 flips. I don't usually trade on much faster than 10 minutes. I did 5 once upon a time, but I find I trade better on 20 min. I may miss out on some early trades, but the combination of 20min and 55 length seems a sweet spot for me personally.

Since I first wrote this, I've taken a bit slower approach to it, really trying to take the smoothness of the HMA for all it can give. Fewer, better signals. Slower, but then I don't, personally, like to flip trades every three candles. :)


@codydog

Thanks for the vote of confidence in my code being easily modifiable. I've worked in software long enough to know the value of easy to read code that does obvious things. Glad some of that comes through in thinkscript. I worry every now and then.


@Chris77

The colors of the label are related to whether the divergence is approaching a turning point -- kind of an advanced warning. The colors are explained in the first post, I think. It's been a while. Essentially, if the indicator is showing red, and you'd want to enter a long position when it turns green, the a plot of the change in concavity should cross the zero -- the colors of the label help you know (without the lower study) when it might be coming. No guarantees, of course.

If you want a more concrete way to think about this, imagine being in a car traveling down a straight road, except that the rack-and-pinion steering is old and wobbles. You are the passenger, and can not look out the window to know where the road is going, but you can see the steering wheel. Now, imagine an 's' curve ahead. the road bends left, then right and continues (for this example) on in a straight line. As the car travels toward the curve, the driver may turn the wheel slightly right or left to compensate for the wobbly steering. However, when the driver turns the wheel left, you can see that the car is about to turn. You can't tell how far left the car will turn, because you only see the wheel turn. But you do know when the corner is coming to an end, because the driver starts turning the wheel back to the center. You can also tell when the car is going to start to turn right (for the second part of the 's' curve, because the wheel passes the center point.

The turning of the wheel is what is indicated in the colored label for the indicator. if the wheel is turning away from center to the left, imagine it to be red. as it turns back toward center, but the car is turning left (approaching straight again) the indicator would be pink. Green is turning right and turning the wheel to make a tighter corner, and yellow is turning right, but turning the wheel back toward straight.

That's a long winded explanation, but hopefully gives you a better idea.



Happy trading
-mashume
 
@mashume

@JB7 - I use it in conjunction with zscore and it works well. Its not a stand alone tool though.

My style is much more short term, higher trade volume than many others. I also consider break even trades important versus the traditional win/loss many folks go on and on about. I refer you to Greg Laughlin's comment "Insights into high frequency trading...", esp page 3 table for more background.

I use it on a 1 day, 2 min chart, with -
hma length = 13, lookback =1,

I also switched from HMA to EHMA.

imo, if any of the "gurus" try to sell you their stuff, and say how rich they are from using any indicator, I'd ask for their 1040, signed by a reputable CPA firm. And same for me, I may think I know what I'm doing or I may be Bozo's first cousin - you simply don't know - so massive grain of salt with my comments and never forget its your money.

Happy trading!

Thank you this is really helpful
 
@mashume

By any chance you're also versed in Ninjascript? TOS lags terribly for me. I want to see about having the same indicator for Ninjatrader.
 
@mashume

By any chance you're also versed in Ninjascript? TOS lags terribly for me. I want to see about having the same indicator for Ninjatrader.

Not terribly versed, no. I do lots of Python, SQL, XSL-T, a bit of Nim, some Julia, don't like C / C++ but can hack, BASIC from way back when and Fortran before that, and some bash. But not Ninjascript. :cool:
 
@kshires4

I think I keep it at 55 most of the time. I have two scans set up, one at 55 and one at 34 (both daily agg) and sometimes symbols from the 34 daily scan make it onto a watchlist and become more interesting purchase signals when the 55 flips. I don't usually trade on much faster than 10 minutes. I did 5 once upon a time, but I find I trade better on 20 min. I may miss out on some early trades, but the combination of 20min and 55 length seems a sweet spot for me personally.

Since I first wrote this, I've taken a bit slower approach to it, really trying to take the smoothness of the HMA for all it can give. Fewer, better signals. Slower, but then I don't, personally, like to flip trades every three candles. :)


@codydog

Thanks for the vote of confidence in my code being easily modifiable. I've worked in software long enough to know the value of easy to read code that does obvious things. Glad some of that comes through in thinkscript. I worry every now and then.


@Chris77

The colors of the label are related to whether the divergence is approaching a turning point -- kind of an advanced warning. The colors are explained in the first post, I think. It's been a while. Essentially, if the indicator is showing red, and you'd want to enter a long position when it turns green, the a plot of the change in concavity should cross the zero -- the colors of the label help you know (without the lower study) when it might be coming. No guarantees, of course.

If you want a more concrete way to think about this, imagine being in a car traveling down a straight road, except that the rack-and-pinion steering is old and wobbles. You are the passenger, and can not look out the window to know where the road is going, but you can see the steering wheel. Now, imagine an 's' curve ahead. the road bends left, then right and continues (for this example) on in a straight line. As the car travels toward the curve, the driver may turn the wheel slightly right or left to compensate for the wobbly steering. However, when the driver turns the wheel left, you can see that the car is about to turn. You can't tell how far left the car will turn, because you only see the wheel turn. But you do know when the corner is coming to an end, because the driver starts turning the wheel back to the center. You can also tell when the car is going to start to turn right (for the second part of the 's' curve, because the wheel passes the center point.

The turning of the wheel is what is indicated in the colored label for the indicator. if the wheel is turning away from center to the left, imagine it to be red. as it turns back toward center, but the car is turning left (approaching straight again) the indicator would be pink. Green is turning right and turning the wheel to make a tighter corner, and yellow is turning right, but turning the wheel back toward straight.

That's a long winded explanation, but hopefully gives you a better idea.



Happy trading
-mashume
I ran the P/L for 21 day, 34 day and 55day. On both a 20 min chart and daily chart. 21 day gives me the best P/L of the 3. But to each his own. Use what works for you.
 
@kshires4

I think I keep it at 55 most of the time. I have two scans set up, one at 55 and one at 34 (both daily agg) and sometimes symbols from the 34 daily scan make it onto a watchlist and become more interesting purchase signals when the 55 flips. I don't usually trade on much faster than 10 minutes. I did 5 once upon a time, but I find I trade better on 20 min. I may miss out on some early trades, but the combination of 20min and 55 length seems a sweet spot for me personally.

Since I first wrote this, I've taken a bit slower approach to it, really trying to take the smoothness of the HMA for all it can give. Fewer, better signals. Slower, but then I don't, personally, like to flip trades every three candles. :)


@codydog

Thanks for the vote of confidence in my code being easily modifiable. I've worked in software long enough to know the value of easy to read code that does obvious things. Glad some of that comes through in thinkscript. I worry every now and then.


@Chris77

The colors of the label are related to whether the divergence is approaching a turning point -- kind of an advanced warning. The colors are explained in the first post, I think. It's been a while. Essentially, if the indicator is showing red, and you'd want to enter a long position when it turns green, the a plot of the change in concavity should cross the zero -- the colors of the label help you know (without the lower study) when it might be coming. No guarantees, of course.

If you want a more concrete way to think about this, imagine being in a car traveling down a straight road, except that the rack-and-pinion steering is old and wobbles. You are the passenger, and can not look out the window to know where the road is going, but you can see the steering wheel. Now, imagine an 's' curve ahead. the road bends left, then right and continues (for this example) on in a straight line. As the car travels toward the curve, the driver may turn the wheel slightly right or left to compensate for the wobbly steering. However, when the driver turns the wheel left, you can see that the car is about to turn. You can't tell how far left the car will turn, because you only see the wheel turn. But you do know when the corner is coming to an end, because the driver starts turning the wheel back to the center. You can also tell when the car is going to start to turn right (for the second part of the 's' curve, because the wheel passes the center point.

The turning of the wheel is what is indicated in the colored label for the indicator. if the wheel is turning away from center to the left, imagine it to be red. as it turns back toward center, but the car is turning left (approaching straight again) the indicator would be pink. Green is turning right and turning the wheel to make a tighter corner, and yellow is turning right, but turning the wheel back toward straight.

That's a long winded explanation, but hopefully gives you a better idea.



Happy trading
-mashume
@mashume
Are you finding better signals using a close candle instead of the (H+L)/2? I also trade on higher time frames. 30M 1H and some 4H. I have seen most of my winners when I trade only on bright green and red with matching Heiken Ashi candles.
I ran the P/L for 21 day, 34 day and 55day. On both a 20 min chart and daily chart. 21 day gives me the best P/L of the 3. But to each his own. Use what works for you.
I agree, after reading your last reply I also did some back testing and found the 21/2 the best setting across the board. Trading only on light green and red HMA.
I have found some good set ups on the 1H and 30M charts using the ironrod SMI and TMO
https://tos.mx/pLXvTov
 
Is there a way to display the divergence label and color in tos mobile app?

Not that I've ever found. The same idea can be found in the Concaviry Lower study, which is essentially a plot of whether the price action is moving toward or away from a concavity flip. Zero crossings are concavity changes.
 
Hello Mashume,

Thank you for working on this indicator, do you suggest to club this with any others like Moving Averages or MFI ..Please let us know what works best with this to avoid fake outs.
 
Hi @mashume would love to get your thoughts with the new studies available out of the box in the April release of TOS; compare it against the custom studies and innovations in this post.

LeavittConvolutionAcceleration

The Leavitt Convolution Acceleration study is a technical indicator designed by Jay A. Leavitt, PhD. Based on linear regression, this indicator estimates the momentum of the projected price change.

LeavittConvolution

The Leavitt Convolution study is a technical indicator designed by Jay A. Leavitt, PhD. It calculates the extrapolation of the extrapolated price value for the upcoming bars.
 
Status
Not open for further replies.

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
324 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