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

Repaints
Status
Not open for further replies.
@tradebyday....it's the code I posted above that may have an error. It's applied to the 2nd lower study. If u compare the AEMA traces between both lower studies, there is something not right with the 2nd lower study AEMA. It may just be a scaling issue.
 
Code posted above seems fine to me, I think your settings are too low for use of the 2line cross aspect. Try putting HMA above 100 and AEMA anything above 50 and it should look better, just for a visual reference
 
I had the same issue. Make sure your script matches the same time frame as watchlist. I found some of my watchlist were calculating close and not H/L 2. I believe the backrest showed results of daily with close.
I have personally found good signals using 21/2 on all time frames.
kshires4: Can you please provide the script for a Thinkorswim Watchlist for your Hull Moving Avg Turning Points which shows the different colors of light green, dark green, red and orange? Of particular interest to me is the orange arrows sell/buy arrows (as a suggestion, change these colors to red and green). Need and example? Look no further than Welkin's example at this link... https://usethinkscript.com/threads/obv-histogram-with-paintbars-for-thinkorswim.1668/#post-24293
 
Hi Mashume, I am trying to modify script as below to get the stocks of which buy signal is triggered within last 10 bar, however I am not able to get any item, even if I change the within last bar limit from 10 to 100. May be I made mistake somewhere. Can you please review & advise?

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

    declare lower;

    input price = HL2;

    input HMA_length = 34;
    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 = Displacer(-1, 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);

plot turning_point = if concavity[-1] != concavity then HMA else double.nan;
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 signal = ConcavityDivergence("hma length" = 55)."concavity";
def HMA = ConcavityDivergence("hma length" = 55)."HMA";
def next = ConcavityDivergence("hma length" = 55)."next_bar";

#plot buy = signal < 0 and (HMA - next) > (HMA[1] - next[1]);

plot data = Sum("data" =ConcavityDivergence("hma length" = 55)."buy" != Double.NaN, "length" = 10) > 0;
 
Replace the everything after the closing curly bracket with this:

Code:
plot signal = ConcavityDivergence("hma length" = 55).divergence crosses above 0 within 10 bars;

Explanation:
There must be a plot. We call it signal.
Then you call the function, and specifically the divergence plot of it
Then we ask to find any ticker that shows a cross above zero
Then we specify the when of the crossover with the "within [the last] 10 bars" bit.
Then We buy truckloads and make money hand over fist. *

* That last step is debatable and dependant on lots and lots of variables not in the script. ;-)

Should work. On my install, I don't even need the script above... but I haven't figured out when that works and when it doesn't.

happy trading,
Mashume
 
Thanks Mashume! I tried as you suggested & was expecting results but I couldn't get single result in the scan. I have commented your original scan condition in this shared version (https://tos.mx/G5Kprzp) & added your sugested line at the end. Can you please run it for yourself & check what could be wrong?
 
Thanks Mashume! I tried as you suggested & was expecting results but I couldn't get single result in the scan. I have commented your original scan condition in this shared version (https://tos.mx/G5Kprzp) & added your sugested line at the end. Can you please run it for yourself & check what could be wrong?

Check the timeframe you're running the scanner on, and whether you have extended hours turned on or not.

-mashume
 
Check the timeframe you're running the scanner on, and whether you have extended hours turned on or not.

-mashume
Timeframme is Daily. No extended hours option. If I coment last line & uncomment your original scan script, then scan will give results. However if I switch to last line scan after commenting original scan code, then no result for the same daily timeframe.
 
Is there anyway this could include a multi-time frame option? So have a 15 minute aggregation of this appear on a 3 minute chart? Thanks in advance.
 
Is there anyway this could include a multi-time frame option? So have a 15 minute aggregation of this appear on a 3 minute chart? Thanks in advance.

It looks a bit odd to my eye, and the signals will be off but you can start with something like this:
add the input statement and change the definition (plot) of HMA to the code below
Code:
input HMA_Aggregation = AggregationPeriod.FIFTEEN_MIN;

plot HMA = HullMovingAvg(price = HL2(period = HMA_Aggregation), length = HMA_Length);

Have fun
Mashume
 
hi everyone, i brought up the V3 Upper and Lower study onto my chart but dont get the Divergence Label and any arrow plot on my chart.. The alert gives an error too, am i doing something wrong here. Please advise.
 
Last edited:
How do I scan for "Buy Confirmed" signal only ? I used the code here to scan for uptrend, but I would like to get in when "Buy confirmed" has been triggered
 
How do you address that this indicator looks forward in time to determine it's inflection points? If a strategy is based on the inflection, one would need to wait an extra bar.

See how the turning point variable looks at tomorrows concavity?

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

I would tend to write this as such (and do similar for all variables):

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

Obviously this will shift everything by a day, but it reflects what happens on the right edge of the chart.

It will also affect performance results

Thoughts?
 
@RmS59 It is certainly attempting to be forward looking, and to a great degree hinges on looking at the next bar, whether day or minute. There is some attempt to mitigate the effect of needing to wait by using the high and low and not waiting for the close to take place, on the assumption (correct or not) that the top and bottom of the range for a candle are less volatile than the close.

I put some effort into solving the equations for the HMA of a given length for a price that would make the turning point happen, but the math is laborious and must be hard coded for a single length and price. It's still on a back burner, but in theory would show the price point required for a turning point to manifest before it did. What to do with that information would, of course, be up to the individual -- and there's no guarantee that the price, once met would stick.

Thanks for your thoughts, questions, and comments.

-mashume
 
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
484 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