Repaints Hull Turning Points & Concavity Questions For ThinkOrSwim

Repaints

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@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.

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.
 
Last edited:

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

Thank you @mashume and @MerryDay for your responses.
What would be a good indicator to go along with this to catch those buy signals and then swing it for a few days?
It is traditional to add a support & resistance and volume to swing trades.

Where Day trading is not about indicators, it is about being able to read price action
Swing trading is not about indicators, it is about picking the right stocks.
 
Last edited:
Thank you for clearing that up for me.

I would like to compare the lagging two-bar label against current strategies that I currently have going. Might you be able to point me in the proper direction? After fiddling, I still cannot get a responsive label. Do you know which historical bars would I need to change or adjust?
Without seeing your script, no one can guess where you went astray.

Post what is not working.
 
Hi all. I am new to this, I was wondering if someone could help me soften the Hull moving average (top code V4) and at the same time bring it closer to price.
My idea is to modify the code so that from time to time (user selectable) the HMA takes the exact value of the price, at that moment. After that it continues smoothing until the next moment it takes the price again and so on until the final.You experts will say if it is possible. Thanks.-
 
Hi all. I am new to this, I was wondering if someone could help me soften the Hull moving average (top code V4) and at the same time bring it closer to price.
My idea is to modify the code so that from time to time (user selectable) the HMA takes the exact value of the price, at that moment. After that it continues smoothing until the next moment it takes the price again and so on until the final.You experts will say if it is possible. Thanks.-
You could, I suppose do something like take the price at the hour (every hour) and 'shift' the HMA by the difference between the HMA and the HL2 (or whichever price you chose) for the next hour. It would probably be interesting to shift the HMA whenever an indicator registered a high/low support level rather than hour, but hours is easier (in some ways).

Perhaps someone will do this before I get to it, but I'll give it some thought after lunch if I am able.

-mashume
 
You could, I suppose do something like take the price at the hour (every hour) and 'shift' the HMA by the difference between the HMA and the HL2 (or whichever price you chose) for the next hour. It would probably be interesting to shift the HMA whenever an indicator registered a high/low support level rather than hour, but hours is easier (in some ways).

Perhaps someone will do this before I get to it, but I'll give it some thought after lunch if I am able.

-mashume
So I thought this was interesting enough to warrant looking at. Cool idea.

Code:
declare upper;

input HMA_Length = 55;
input minutes_between_adjustments = 30;

def trade_time_s = SecondsFromTime(0000);
def delta_t_s = trade_time_s - trade_time_s[1];

def thirty_min_blocks = trade_time_s % (60 * minutes_between_adjustments);

def HMA = MovingAverage(averageType = AverageType.HULL, data = HL2, length = HMA_Length);
def price_at_halfs =  if thirty_min_blocks < thirty_min_blocks[1] then  HL2 - HMA else price_at_halfs[1];

plot HMA_ADJ = HMA + price_at_halfs;
HMA_ADJ.AssignValueColor(if price_at_halfs > 0 then color.dark_green else if price_at_halfs < 0 then color.dark_red else color.black);

plot adjustment_point = if  thirty_min_blocks < thirty_min_blocks[1] then HMA_ADJ else double.nan;

adjustment_point.setPaintingStrategy(PaintingStrategy.POINTS);
adjustment_point.AssignValueColor(if price_at_halfs > 0 then color.dark_green else if price_at_halfs < 0 then color.dark_red else color.black);
adjustment_point.SetLineWeight(5);
Do with it as you will. :)
 
So I thought this was interesting enough to warrant looking at. Cool idea.

Code:
declare upper;

input HMA_Length = 55;
input minutes_between_adjustments = 30;

def trade_time_s = SecondsFromTime(0000);
def delta_t_s = trade_time_s - trade_time_s[1];

def thirty_min_blocks = trade_time_s % (60 * minutes_between_adjustments);

def HMA = MovingAverage(averageType = AverageType.HULL, data = HL2, length = HMA_Length);
def price_at_halfs =  if thirty_min_blocks < thirty_min_blocks[1] then  HL2 - HMA else price_at_halfs[1];

plot HMA_ADJ = HMA + price_at_halfs;
HMA_ADJ.AssignValueColor(if price_at_halfs > 0 then color.dark_green else if price_at_halfs < 0 then color.dark_red else color.black);

plot adjustment_point = if  thirty_min_blocks < thirty_min_blocks[1] then HMA_ADJ else double.nan;

adjustment_point.setPaintingStrategy(PaintingStrategy.POINTS);
adjustment_point.AssignValueColor(if price_at_halfs > 0 then color.dark_green else if price_at_halfs < 0 then color.dark_red else color.black);
adjustment_point.SetLineWeight(5);
Do with it as you will. :)
My trading is all about the HMA. I will pull, twist and bend this to see what happens .
 
Everyone here has been so amazing and so helpful I am ashamed I have not been able to add anything to the catalog of studies here. I am not to bashful to ask for help once again though.

I am trying to sum the value of the MA_max arrows and subtract the sum value of MA_min arrows and show them on a label. I thought it would be pretty simple and I might be able to do it .... but as you can guess, it is out of my league at the moment. Any help would be very much appreciated.
Code:
#
# Hull Moving Average Concavity and Turning Points
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mashume

declare upper;
input price = close;
input HMA_Length = 12;
input lookback = 2;

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_orange else color.green);

HMA.SetLineWeight(1);

turning_point.SetLineWeight(1);
turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.points);
turning_point.SetDefaultColor(color.black);

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

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

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

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

def divergence = HMA - next_bar;


def NetChg = Ma_max - MA_min;
def PctChg = (Ma_min / MA_max) - 1;

AddLabel(yes, "$/AVGDiff " + AsDollars(NetChg) + " " + AsPercent(PctChg), if MA_max < MA_min then Color.GREEN else if MA_min > MA_max then Color.LIGHT_RED else Color.LIGHT_RED);
 
Last edited by a moderator:
"plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;"

HMA[-1] is referencing the future value?

Easy way to troubleshoot is to output your variables and check them.

Example:
AddLabel(yes, HMA, color.white);
AddLabel(yes, "HMA_neg_one:" + HMA[-1], color.white);
AddLabel(yes, "HMA_plus_one:" + HMA[1], color.white)

Good luck
 
@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.
Hello Mashume!! I would like to ask if you can recommend any configuration for this strategy, to use in swing trading.-Thank you very much.-
 
Hello Mashume!! I would like to ask if you can recommend any configuration for this strategy, to use in swing trading.-Thank you very much.-
I just write code. ;-)

But seriously, I wouldn't know what timeframes / hold lengths / risk-on level / etc... you are comfortable with. Backtest and decide what works for the assets you're trading and the style you want to trade with.

Happy Trading,
mashume
 
Issues with Alert on HMA Indicator

Good Moring All,
Does anyone see an issue with this script? I cant get the Alert to announce....
I know the program settings are correct as I imported a quick SMA crossover and it sounded fine..
I tried

input price = close;
input Length = 5;

plot HMA = MovingAverage(AverageType.Weighted, price, Length);
HMA.DefineColor("Up", Color.GREEN);
HMA.DefineColor("Down", Color.RED);
HMA.AssignValueColor(if HMA > HMA[1] then HMA.Color("Up") else HMA.Color("Down"));
HMA.SetLineWeight(3);

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

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.POINTS);
MA_Min.SetLineWeight(5);

Alert(MA_MAX, "SELL, SELL, SELL", Alert.Bar, Sound.BELL);
Alert(MA_MIN, "BUY BUY BUY", Alert.Bar, Sound.BELL);
 
Last edited by a moderator:
Issues with Alert on HMA Indicator

Good Moring All,
Does anyone see an issue with this script? I cant get the Alert to announce....
I know the program settings are correct as I imported a quick SMA crossover and it sounded fine..
I tried

input price = close;
input Length = 5;

plot HMA = MovingAverage(AverageType.Weighted, price, Length);
HMA.DefineColor("Up", Color.GREEN);
HMA.DefineColor("Down", Color.RED);
HMA.AssignValueColor(if HMA > HMA[1] then HMA.Color("Up") else HMA.Color("Down"));
HMA.SetLineWeight(3);

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

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.POINTS);
MA_Min.SetLineWeight(5);

Alert(MA_MAX, "SELL, SELL, SELL", Alert.Bar, Sound.BELL);
Alert(MA_MIN, "BUY BUY BUY", Alert.Bar, Sound.BELL);
My understanding has always been that scripts which use forward-looking variables such as the Hull Turning Points cannot have alerts.
However, this member seems to have had some luck with using this script:
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-18#post-35731
No idea if it is viable or provides appropriate signals.
If you use it, come back and tell us the results.
 
Last edited:
Hello all…

I’m looking to see if the labels below can be somehow be converted to scannable conditions. I’ve been tooling around with it but my knowledge of thinkscript language isn’t quite good. The conditions in bold is what I’m looking to be able to scan for individually. Thanks in advance for any help provided. Credit goes to barbros / chuck at B4signals.com for the formula provided.

input HMA_Length = 55;
input HMA_Lookback = 2;

def HMA = HullMovingAvg(price = HL2, length = HMA_Length);
def HMA_delta = HMA[1] - HMA[HMA_Lookback + 1];
def HMA_delta_per_bar = HMA_delta / HMA_Lookback;
def HMA_next_bar = HMA[1] + HMA_delta_per_bar;
def HMA_concavity = if HMA > HMA_next_bar then 1 else -1;
def HMA_MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def HMA_MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;
def HMA_divergence = HMA - HMA_next_bar;

AddLabel(ShowHMALabel,
"Divergence " +
if HMA_concavity < 0 then
if HMA_divergence[1] > HMA_divergence then "Bearish"
else "Bearish (reversing)"
else
if HMA_divergence[1] < HMA_divergence then "Bullish"
else "Bullish (reversing)",
if HMA_concavity < 0 then
if HMA_divergence[1] > HMA_divergence then Color.RED
else Color.DARK_RED
else
if HMA_divergence[1] < HMA_divergence then Color.GREEN
else Color.DARK_GREEN);
 
Hello all…

I’m looking to see if the labels below can be somehow be converted to scannable conditions. I’ve been tooling around with it but my knowledge of thinkscript language isn’t quite good. The conditions in bold is what I’m looking to be able to scan for individually. Thanks in advance for any help provided. Credit goes to barbros / chuck at B4signals.com for the formula provided.

input HMA_Length = 55;
input HMA_Lookback = 2;

def HMA = HullMovingAvg(price = HL2, length = HMA_Length);
def HMA_delta = HMA[1] - HMA[HMA_Lookback + 1];
def HMA_delta_per_bar = HMA_delta / HMA_Lookback;
def HMA_next_bar = HMA[1] + HMA_delta_per_bar;
def HMA_concavity = if HMA > HMA_next_bar then 1 else -1;
def HMA_MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def HMA_MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;
def HMA_divergence = HMA - HMA_next_bar;

AddLabel(ShowHMALabel,
"Divergence " +
if HMA_concavity < 0 then
if HMA_divergence[1] > HMA_divergence then "Bearish"
else "Bearish (reversing)"
else
if HMA_divergence[1] < HMA_divergence then "Bullish"
else "Bullish (reversing)",
if HMA_concavity < 0 then
if HMA_divergence[1] > HMA_divergence then Color.RED
else Color.DARK_RED
else
if HMA_divergence[1] < HMA_divergence then Color.GREEN
else Color.DARK_GREEN);
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-22#post-70440
 
mod note:
Both this indicator and The Pam indicator repaint. It is not possible to get any reliable backtesting results with these indicators, as all the bad signals are erased and only the good trades show up in the backtesting data.

@QUIKTDR1 @_Merch_Man_
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
415 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