Hull Turning Points & Concavity Questions

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
mod note:
@mashume's Hull has a lag because it waits for future bars to close before it REPAINTS the perfect signal. For us, longer-term swing traders, the lag is not a barrier to using @mashume's excellent study. But for scalpers, day traders, and short-swingers, @mashume's Hull might not be an optimal choice.


@Mashume's Hull Moving Average Turning Points and Concavity (2nd Derivatives)
The upper study plots Hull Moving Average with the addition of colored segments representing concavity and turning points: maxima, minima and inflection.​
The lower study 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.​
######################################################
https://usethinkscript.com/threads/hull-turning-points-concavity-questions.7847/#post-80172
# New Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################



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 Study:
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.
The lower can give you a preview of when things might be approaching a concavity shift, and how quickly or perhaps decisively they are crossing.
 
Last edited:

iAskQs

Member
I've been testing the Hull concavity indicator found at https://usethinkscript.com/threads/...ng-points-and-concavity-2nd-derivatives.1803/ and it's a wonderful tool. Thank you @mashume. I like faster and slower periods (each has its advantages, early entry vs. longer moves), and I applied both to see what happens. For example, I used the 9 and 20 periods by applying two instances of the study (and slightly altering code to allow the 20 arrows room to appear above/below the 9 arrows). What I noticed is that sometimes when both fire together (when they "stack"), sometimes it signals a powerful longer term move to come but also allows a trader the ability to enter early into the move. It also allows you to ignore the many other signals the indicator provides, some good and some bad). Here's an example from a few days ago on the ES 2m chart (grey is 9, white is 20):

1FMS7sG.jpg


I was practicing on sim and actually took the short on the second example, which is about a 25 point move. Of course, I cherry picked instances where it worked to demonstrate what I'm trying to accomplish, but it doesn't always work and I have not backtested it yet.

I have limited knowledge of coding, so I'm looking to this community with help altering the current latest version of @mashume 's indicator to create the following: an indicator that signals only when both chosen periods signal on the same bar. The indicator should allow the trader to choose the periods for the slow and fast options (there very well may be better combinations than 9 and 20). There should be an option to allow a secondary signal (different color or whatever) that shows when the slow and fast periods signal on bars next to each other rather than the same bar, which is perhaps a weaker signal (again, I don't know because I have not backtested properly). Such an indicator could, imo, have advantage over the the author's original because (at least, it's my theory) it would provide fewer, more meaningful signals with less clutter on the chart.

Here is the RTY on the same day to show some signals that failed or didn't provide big moves, 1 big move, and some instances where signals on 2 bars next to each other provided some nice moves:

STyc64N.jpg


I would appreciate it if @mashume @BenTen and anyone else could assist with this idea. I'm still trying to form a framework/system/rules and experimenting, but the concept seems promising. I hope this is the right place to post this thread and I apologize if it's not. Thank you all in advance for your interest and help with this.
 

iAskQs

Member

_Merch_Man_

Active member
I noticed that good signals happen when the colors go in sequence. A long signal is when the colors go from Red -> Dark Green -> Green. A short signal is when colors go from Green -> Orange -> Red. I added coded alerts at the bottom of the script to catch these scenarios. This is used in coordination with other indicators.

Ruby:
#
# Hull Moving Average Concavity and Turning Points
#  or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mashume)
# Version: 2020-05-01 V4
#
# https://usethinkscript.com/threads/hull-moving-average-turning-points-and-concavity-2nd-derivatives.1803/
#

declare upper;

input price = HL2;
input HMA_Length = 55;
input lookback = 2;
input show_labels = Yes;
input stddev_len = 21;

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

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);
MA_Max.SetLineWeight(3);

plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;
MA_Min.SetDefaultColor(Color.WHITE);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(3);

plot sell = if turning_point and concavity == -1 then high else double.nan;
sell.SetDefaultColor(Color.DARK_ORANGE);
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetLineWeight(3);

plot buy = if turning_point and concavity == 1 then low else double.nan;
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(3);

def divergence = HMA - next_bar;

addLabel(show_labels, concat("DIVERGENCE: " , divergence * 10000), color = if concavity < 0 then if divergence[1] > divergence then Color.dark_RED else color.PINK else if divergence[1] < divergence then color.dark_green else color.dark_orange);

def divergence_stddev = StandardDeviation(price = divergence, length = stddev_len);
addLabel(show_labels, concat("STDDEV: " , divergence_stddev * 10000), color = if absValue(divergence) > absValue(divergence_stddev) then color.blue else color.dark_gray);

# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing

plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else double.nan;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(3);

plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else double.nan;
CCD_I.SetDefaultColor(Color.DARK_ORANGE);
CCD_I.SetLineWeight(3);

plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else double.nan;
CCU_D.SetDefaultColor(COLOR.DARK_GREEN);
CCU_D.SetLineWeight(3);

plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else double.nan;
CCU_I.SetDefaultColor(COLOR.GREEN);
CCU_I.SetLineWeight(3);

######################################################
# New Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################

# GO back through the bars, find when the last Dark Green section
# started then see if the color before that was Red

Def RedToDarkGreen = fold idx5 = 1 to 100 with p5 = 0 do if !isNaN(GetValue(CCU_D,idx5)) && !isNaN(GetValue(CCD_D,idx5+1)) && p5 == 0 then idx5 else if !isNaN(GetValue(CCU_D,idx5)) && isNaN(GetValue(CCU_D,idx5+1)) && p5 == 0 then Double.NaN else p5;

# GO back through the bars, find when the last Orage section
# started then see if the color before that was Green

Def GreenToOrange = fold idx6= 1 to 100 with p6 = 0 do if !isNaN(GetValue(CCD_I,idx6)) && !isNaN(GetValue(CCU_I,idx6+1)) && p6 == 0 then idx6 else if !isNaN(GetValue(CCD_I,idx6)) && isNaN(GetValue(CCD_I,idx6+1)) && p6 == 0 then Double.NaN else p6;

# Long signal when last bar line color is Green, line color of the bar
# before that was Dark Green and the color before that was Red

Def RedToDarkGreenToGreen = CCU_I[1]&& CCU_D[2] && !isNaN(RedToDarkGreen);
alert(RedToDarkGreenToGreen, "RED TO DARK GREEN TO GREEN - GO LONG", alert.bar, sound.chimes);

# Short signal when last bar line color is Red, line color of the bar
# before that was Red and the color before that was Orange

Def GreenToOrangeToRed = CCD_D[1] && CCD_I[2] && !isNaN(GreenToOrange);
alert(GreenToOrangeToRed, "GREEN TO ORANGE TO RED - GO SHORT", alert.bar, sound.chimes);

######################################################
# END Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################
/CODE]
 

jaynaf

New member
@Mashume's Hull Moving Average Turning Points and Concavity (2nd Derivatives)
The upper study plots Hull Moving Average with the addition of colored segments representing concavity and turning points: maxima, minima and inflection.​
The lower study 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.​



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 Study:
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.
The lower can give you a preview of when things might be approaching a concavity shift, and how quickly or perhaps decisively they are crossing.
I am trying to put conditional order ie almost autotrade, to put buy order should I put condition as Ma_min true within 1 bar, as this seems nto to work, even Buy is true does not work correctly
I tried to copy and paste from Mashume strategy itself but when I put in Pine editer It is not accepted
 

mashume

Well-known member
VIP
Lifetime
I am trying to put conditional order ie almost autotrade, to put buy order should I put condition as Ma_min true within 1 bar, as this seems nto to work, even Buy is true does not work correctly
I tried to copy and paste from Mashume strategy itself but when I put in Pine editer It is not accepted
It's not Pinescript, it's thinkscript. So unless you have a pine version somewhere, it won't work. I've worked on a version for python somewhere but can't find the code anymore. Others may have converted it to pinescript.

-mashume
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
I am trying to put conditional order ie almost autotrade, to put buy order should I put condition as Ma_min true within 1 bar, as this seems nto to work, even Buy is true does not work correctly
I tried to copy and paste from Mashume strategy itself but when I put in Pine editer It is not accepted
Ditto everything that @mashume stated, and the scan needs to be set to: Ma_min true within 2 bars to get accurate results.
 

tgomes27

New member
VIP
Hello,
Im new here but been trading for quite some time now. I ran into this indicator http://tos.mx/wKuLZAc on here and i noticed that its quite useful on the daily charts if you catch it ahead of time a day prior. I needed help with building a scan that is able to help me scan for when the green dot appears on the daily chart when i run my scan end of day for the next day. Please help i would highly appreciate it.

If you look at the chart of $PPSI for example recently it showed green dots a day prior to it spiking on the daily chart.
 
Last edited by a moderator:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
Hello,
Im new here but been trading for quite some time now. I ran into this indicator http://tos.mx/wKuLZAc on here and i noticed that its quite useful on the daily charts if you catch it ahead of time a day prior. I needed help with building a scan that is able to help me scan for when the green dot appears on the daily chart when i run my scan end of day for the next day. Please help i would highly appreciate it.
See the 1st post
 

Jonessw1

New member
I am reaching out for help with this wonderful indicator by @mashume

In an attempt to create a color changing label based on the defined buy/sell signals from the script, the labels appear black, but I cannot figure out what data is missing.

From script:

def buy = if turning_point and concavity == 1 then low else Double.NaN;

def sell = if turning_point and concavity == -1 then high else Double.NaN;

Both Turning_point and concavity reference previous bars and compare them to the current bar.

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;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

I am currently trying:

def LongEntry = if ((turning_point and concavity == 1) then 1 else 0;

AddLabel(yes,
if LongEntry == 1 then "LE "
else "LE ",

if LongEntry == 1 then Color.GREEN
else Color.GRAY);

I suppose my question is, will the label turn green only once the current bar closes, or am I trying to predict a future event?
Also, what impact might once_per_bar have on the label in this context?

I was unable to watch the labels today due to work, and this will likely keep me up at night.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
I am reaching out for help with this wonderful indicator by @mashume

In an attempt to create a color changing label based on the defined buy/sell signals from the script, the labels appear black, but I cannot figure out what data is missing.

I suppose my question is, will the label turn green only once the current bar closes, or am I trying to predict a future event?
Also, what impact might once_per_bar have on the label in this context?

I was unable to watch the labels today due to work, and this will likely keep me up at night.
Because of the future-looking calculations, labels are problematic. Some members have reported positive results in using
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-18#post-35731 for alerts.
Maybe it can be modified to provide labels.
 
Last edited:

Climb4Life

New member
VIP
I've been testing the Hull concavity indicator found at https://usethinkscript.com/threads/...ng-points-and-concavity-2nd-derivatives.1803/ and it's a wonderful tool. Thank you @mashume. I like faster and slower periods (each has its advantages, early entry vs. longer moves), and I applied both to see what happens. For example, I used the 9 and 20 periods by applying two instances of the study (and slightly altering code to allow the 20 arrows room to appear above/below the 9 arrows). What I noticed is that sometimes when both fire together (when they "stack"), sometimes it signals a powerful longer term move to come but also allows a trader the ability to enter early into the move. It also allows you to ignore the many other signals the indicator provides, some good and some bad). Here's an example from a few days ago on the ES 2m chart (grey is 9, white is 20):

1FMS7sG.jpg


I was practicing on sim and actually took the short on the second example, which is about a 25 point move. Of course, I cherry picked instances where it worked to demonstrate what I'm trying to accomplish, but it doesn't always work and I have not backtested it yet.

I have limited knowledge of coding, so I'm looking to this community with help altering the current latest version of @mashume 's indicator to create the following: an indicator that signals only when both chosen periods signal on the same bar. The indicator should allow the trader to choose the periods for the slow and fast options (there very well may be better combinations than 9 and 20). There should be an option to allow a secondary signal (different color or whatever) that shows when the slow and fast periods signal on bars next to each other rather than the same bar, which is perhaps a weaker signal (again, I don't know because I have not backtested properly). Such an indicator could, imo, have advantage over the the author's original because (at least, it's my theory) it would provide fewer, more meaningful signals with less clutter on the chart.

Here is the RTY on the same day to show some signals that failed or didn't provide big moves, 1 big move, and some instances where signals on 2 bars next to each other provided some nice moves:

STyc64N.jpg


I would appreciate it if @mashume @BenTen and anyone else could assist with this idea. I'm still trying to form a framework/system/rules and experimenting, but the concept seems promising. I hope this is the right place to post this thread and I apologize if it's not. Thank you all in advance for your interest and help with this.
@iAskQs I took a stab at what you asked for; to generate a signal when two HMA time frames agree. Note the following:
  • offset/offset2 - set individual arrow offset
  • show hma - show/hide HMA average lines and indicators
  • show arrows - show/hide all individual arrows
  • show bubbles - show/hide all MTF agreement bubbles
  • show mtf arrow - show/hide MTF agreement arrows
  • mtf offset - set mtf arrow/bubble offset
  • ha in use - calculate low and high correctly for visuals if you're using Heikin Ashi candles
I make no promises on the code and offer it "as is". ;)

Code link: http://tos.mx/cTj98mo
 
Last edited:

karmic

New member
VIP
When i tried to scan for "buy" signals via this code "Concavity("hma length" = 55, price = CLOSE)."buy" is true within 2 bars", I noticed that the results have the buy signals a few bars behind. Is this expected?
 

mashume

Well-known member
VIP
Lifetime
When i tried to scan for "buy" signals via this code "Concavity("hma length" = 55, price = CLOSE)."buy" is true within 2 bars", I noticed that the results have the buy signals a few bars behind. Is this expected?
Yes, it's one of the known complications with this study. There is good discussion of it in the main thread, though I couldn't point to a particular post anywhere, nor remember when in the chain of things it happened.

-mashume
 

Similar threads

Top