I
ikpllc
New member
@mashume Sorry to bother, one more question. How can I make this not repaint?
The repainting issue has been discussed at length earlier in this thread.Sorry to bother, one more question. How can I make this not repaint?
Again, thanks much.The repainting issue has been discussed at length earlier in this thread.
TL;DR
It will repaint.
You can, perhaps, minimize the repainting by using HL2 and not CLOSE or HLC3 (or even OHLC4) because it doesn't need to wait for a close and highs and lows are often (but not always) set before the end of a bar's time window.
-mashume
I prefer Candle Trend, personally.@mashume are you using this study with Heiken Ashi candles?
input price = HL2;
input HMA_Length = 55;
input lookback = 2;
def 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;
Def turning_point = if concavity[1] != concavity then 1 else 0;
Def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then 1 else 0; # white squares
Def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then 1 else 0; # white triangles
Def sell = if turning_point and concavity == -1 then 1 else 0; # orange arrow down
Def buy = if turning_point and concavity == 1 then 1 else 0; # blue - cyan arrow up
def divergence = HMA - next_bar;
def scan = if
turning_point and concavity == 1
then 1 else 0 ;
plot sc = scan within 1 bars ;
then 1 else double.nan;
as the then clause in def scanplot sc = scan == 1 within 1 bars;
and explicitly define sc as only when scan is 1Try this: https://usethinkscript.com/threads/...and-concavity-2nd-derivatives.1803/post-26455Hi @mashume, excellent study. I've been using it extensively the past week. I have one question - is there a way to also plot a higher timeframe HMA so as to be able to make a judgement on a lower timeframe on whether to stay in a trade longer? Even as a lower study with a series of dots with the same colours so as to be able to quickly view the state without having to switch the chart. What do you think?
I've been overlaying a higher timeframe HMA on my chart using a higher aggregationPeriod on the price but it's very choppy and very difficult to follow.
#
# 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
#
# ----------------------
# TheBewb - Added Standard Deviation bars for divergence amounts.
declare lower;
input price = OPEN;
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 diffave = HMA - next_bar;
diffave.setdefaultColor(getColor(5));
diffave.SetPaintingStrategy(PaintingStrategy.line);
diffave.SetLineWeight(3);
diffave.DefineColor("Positive and Up", Color.green);
diffave.DefineColor("Positive and Down", Color.dark_green);
diffave.DefineColor("Negative and Down", Color.dark_red);
diffave.DefineColor("Negative and Up", Color.red);
diffave.AssignValueColor(if diffave >= 0 then if diffave > diffave[1] then diffave.Color("Positive and Up") else diffave.Color("Positive and Down") else if diffave < diffave[1] then diffave.Color("Negative and Down") else diffave.Color("Negative and Up"));
plot cx_up = if diffave 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 diffave crosses below zero then 0 else double.nan;
cx_down.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_down.SetDefaultColor(Color.RED);
cx_down.SetLineWeight(4);
input stddev_len = 21;
def divergence_stddev = StandardDeviation(price = diffave, length = stddev_len);
plot div_StdDev = divergence_stddev;
plot div_StdDevNeg = -divergence_stddev;
plot div_StdDev2 = divergence_stddev*2;
plot div_StdDevNeg2 = -divergence_stddev*2;
#
# Hull Moving Average Concavity and Turning Points
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------
declare upper;
input price = HL2;
input HMA_Length = 55;
input lookback = 2;
# I read somewhere that it's faster to define nan's and then use the def'd var rather than call double.nan every time.
def nan = double.nan;
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 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 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 Nan;
MA_Min.SetDefaultColor(Color.WHITE);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(3);
# NOTE: I PREFER TO TURN OFF UP ARROWS WHEN IN DOWN TREND. IF IN DOWNTRENDING SWINGARM, THE TURN ON ONLY DOWN SELL ARROWS. YOU CAN DO THIS USING THE INPUT SETTINGS SCREEN.
plot sell = if turning_point and concavity == -1 then high else 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 nan;
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(3);
def divergence = HMA - next_bar;
addLabel(yes, concat("DIVERGENCE: " , divergence), color = if concavity < 0 then if divergence[1] > divergence then Color.RED else color.PINK else if divergence[1] < divergence then color.green else color.yellow);
###################
#
# ALERTS
#
###################
Alert(condition = MA_Min, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Bell);
Alert(condition = MA_Max, text = "Sell", "alert type" = Alert.BAR, sound = Sound.Chimes);
###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# 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 nan;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(3);
plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else nan;
CCD_I.SetDefaultColor(Color.DARK_ORANGE);
CCD_I.SetLineWeight(3);
plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else nan;
CCU_D.SetDefaultColor(COLOR.DARK_GREEN);
CCU_D.SetLineWeight(3);
plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else nan;
CCU_I.SetDefaultColor(COLOR.GREEN);
CCU_I.SetLineWeight(3);
@mashume Seth, broski... can you help me out on the in depth math required to make this indicator more accurate? Just point me in the right direction as to what you were inferring. Thanks!@mashume excellent work on this. Very intriguing to me and something I have been imitating just by checking one bar back for MAs... which obviously has its issues. I added the following code to the lower Divergence study... very basic no frills that shows two standard deviation bands. It is interesting to look at as a lower study. It seems to offer the best clues of a turning point when the Std Dev bands are not compressed and the divergence is close to its historical highs (obvious), but still I wonder if it could be used to fine tune this study. This is going to be my main focus going forward.
Also, you mentioned a mathematically intensive way to make the original Hull Concavity script faster by solving for the unknown variable using the source math equation for the Hull MA. Could you expand on that a bit? Much appreciated.
I am trying to figure out a way to add it and/or the Hull script to my proprietary algo script to get better entrances... will keep everyone updated on it. See below:
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 # # ---------------------- # TheBewb - Added Standard Deviation bars for divergence amounts. declare lower; input price = OPEN; 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 diffave = HMA - next_bar; diffave.setdefaultColor(getColor(5)); diffave.SetPaintingStrategy(PaintingStrategy.line); diffave.SetLineWeight(3); diffave.DefineColor("Positive and Up", Color.green); diffave.DefineColor("Positive and Down", Color.dark_green); diffave.DefineColor("Negative and Down", Color.dark_red); diffave.DefineColor("Negative and Up", Color.red); diffave.AssignValueColor(if diffave >= 0 then if diffave > diffave[1] then diffave.Color("Positive and Up") else diffave.Color("Positive and Down") else if diffave < diffave[1] then diffave.Color("Negative and Down") else diffave.Color("Negative and Up")); plot cx_up = if diffave 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 diffave crosses below zero then 0 else double.nan; cx_down.SetPaintingStrategy(PaintingStrategy.POINTS); cx_down.SetDefaultColor(Color.RED); cx_down.SetLineWeight(4); input stddev_len = 21; def divergence_stddev = StandardDeviation(price = diffave, length = stddev_len); plot div_StdDev = divergence_stddev; plot div_StdDevNeg = -divergence_stddev; plot div_StdDev2 = divergence_stddev*2; plot div_StdDevNeg2 = -divergence_stddev*2;
I've got a conference all week this week... presenter Thursday. I may be able to get back to this stuff at the weekend or so.@mashume Seth, broski... can you help me out on the in depth math required to make this indicator more accurate? Just point me in the right direction as to what you were inferring. Thanks!
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
B | Hull moving average scan when crossing | Questions | 1 | |
A | Create a custom strategy from Hull moving average | Questions | 3 | |
C | Hull Moving Average Scan? | Questions | 10 | |
S | RSI with Hull Moving Average > 100 or < 0? | Questions | 1 | |
Hull moving average using data created with 9 period exponential MACD line ? | Questions | 11 |