Join useThinkScript to post your question to a community of 21,000+ developers and traders.
It is traditional to add a support & resistance and volume to swing trades.
Without seeing your script, no one can guess where you went astray.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?
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).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.-
So I thought this was interesting enough to warrant looking at. Cool idea.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
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);
My trading is all about the HMA. I will pull, twist and bend this to see what happens .So I thought this was interesting enough to warrant looking at. Cool idea.
Do with it as you will.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);
![]()
#
# 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);
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.-@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 Study (version 4): https://usethinkscript.com/threads/...nd-concavity-2nd-derivatives.1803/#post-16566Scan For Turning Points (upper study): https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-21#post-66454Scan For Divergences (lower study): https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-22#post-70440######################################################
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
Arrows are provided as Buy and Sell and could perhaps be scanned against.
- 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').
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 just write code. ;-)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.-
My understanding has always been that scripts which use forward-looking variables such as the Hull Turning Points cannot have alerts.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);
Because this indicator repaints:wondering how the script could be modified under strategies to use floatingpl and other backtesting
https://usethinkscript.com/threads/hull-turning-points-concavity-questions.7847/#post-75223Is there a watchlist for this wonderful indicator?
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-22#post-70440Hello 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);
Start a new thread and receive assistance from our community.
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.
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.