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

Repaints
Status
Not open for further replies.
@jay2, @Berezowsky,@mashume

Like Mashume said, You need to rename the study you downloaded or copy codes to Concavity study, then you can scan.

I have the Scan worked now. :). Let me know if you still have questions
 

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

Hello everybody! I’m very new to trading and TOS, and this is my first post here!

I have a very basic question about strategies.

In this strategy and others Buy/sell signals are calculated on the last known period, and the scripts also fills orders on that same period (buy to open/sell to close).

I’m unsure if this reflect real trading conditions. So to reflect better trading conditions, I was wondering if it was possible to change the way orders are filled. Orders should be filled at open and close prices on the next period (next period relative to the last know period exhibiting the buy/sell signal).

Is there something fundamental I don’t understand?
 
Hello everybody! I’m very new to trading and TOS, and this is my first post here!

I have a very basic question about strategies.

In this strategy and others Buy/sell signals are calculated on the last known period, and the scripts also fills orders on that same period (buy to open/sell to close).

I’m unsure if this reflect real trading conditions. So to reflect better trading conditions, I was wondering if it was possible to change the way orders are filled. Orders should be filled at open and close prices on the next period (next period relative to the last know period exhibiting the buy/sell signal).

Is there something fundamental I don’t understand?

I'm not sure about everyone else using this indicator, but personally I prefer to use the Ma_Min/Max as the buy sell signals. There are very few false signals this way. However rarely, they do disappear /repaint. I turned off the reg buy/sell signals.
 
Really surprised it hasn't been done yet (or maybe I missed it somewhere along inside this thread) but why not take the lower indicator format and throw a moving average on top? Purpose is to show change of momentum, not necessarily for entries, but decent for exits of trends. In the below code there are 2 moving averages: LegacyEMA and HMA2. HMA2 is currently just "def", change to "plot" and change LegacyEMA to "def" to switch if you wish. Current settings on 5min TF are: close, 200, 50, 100, 0.
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
#
# ----------------------

declare lower;

input price = CLOSE;

input HMA_length = 200;
input lookback = 50;

input length = 100;
input displace = 0;

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 = HMA - next_bar;

def HMA2 = MovingAverage(AverageType.HULL, divergence, length)[-displace];

divergence.setDefaultColor(Color.LIME);
divergence.SetLineweight(2);

assert(length > 0, "'length' must be positive: " + length);

def EMA = compoundValue(1, EMA[1] + 2 / (length + 1) * (divergence[-displace] - EMA[1]), divergence[-displace]);

plot LegacyEMA = EMA;
LegacyEMA.SetDefaultColor(GetColor(1));

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);

Important to note, change in momentum does not mean change in direction (for the newer traders out there)
 
Last edited:
Another, better example of trader/scalper with HULL and TMO for TSLA, made one small trade this am was n the 25 tick on main chart and 50 tick on bottom left, was a bit fast so dropped back to 50 and 100. Dark blue line in 50 EMA for trend guidance, HULL is 15 period, essentially TMO coming out of green bottom and 2 bricks thru yellow dash is buy, obviously buys work better with blue trend as shown with arrow at open, hope this makes sense and helps
EYUBW8AX0AA2sMC?format=jpg&name=large.jpg
trend working
 
Last edited:
@mashume
Hey again!

I noticed that sometimes the indicator (after popping up with the white triangle that initiates a light-green trend line) will delete the triangle or move it on to the next candlestick after roughly 30sec-1min of showing up initially.

Is there any way to turn this off or delete any line of code in the settings? I'm still running the initial release version because I've found it to be the most consistent with my strategy.

Thanks again for your persistent hard work!
 
@mashume
Hey again!

I noticed that sometimes the indicator (after popping up with the white triangle that initiates a light-green trend line) will delete the triangle or move it on to the next candlestick after roughly 30sec-1min of showing up initially.

Is there any way to turn this off or delete any line of code in the settings? I'm still running the initial release version because I've found it to be the most consistent with my strategy.

Thanks again for your persistent hard work!
That's the MA_MIN plot. You can un-check it in the indicator settings. No need to edit the code. You can, of course take the tinker-kit out and mod the source code if you really want.

-mashume
 
That's the MA_MIN plot. You can un-check it in the indicator settings. No need to edit the code. You can, of course take the tinker-kit out and mod the source code if you really want.

-mashume
Well I actually love that part of the indicator, as it's what I use as an entry. My true question is is there a way to make it stick and not move mid candlestick?

For example, I used it on the 3m chart for SPY today and it popped at 10:21EST so I entered. About 35seconds later I look back and I do not see the "white triangle" I spoke of earlier. That's where I was a bit confused. If there is no way to keep it once it's been placed regardless, I just thought I'd ask.

Thanks again
 
Well I actually love that part of the indicator, as it's what I use as an entry. My true question is is there a way to make it stick and not move mid candlestick?

For example, I used it on the 3m chart for SPY today and it popped at 10:21EST so I entered. About 35seconds later I look back and I do not see the "white triangle" I spoke of earlier. That's where I was a bit confused. If there is no way to keep it once it's been placed regardless, I just thought I'd ask.

Thanks again
Oh I see. Repainting is, unfortunately, a part of this indicator occasionally. Less so if you use CLOSE prices, but then it's not as reactive or timely necessarily.

-mashume
 
@tradebyday , that was very creative of you to plot the legacy EMA. I watched it today and on a 5 min chart of the /NQ. If it's not asking too much, can you please add the "adaptive moving average" to see how it compares alongside the legacy EMA. Thanks!
 
@madeinnyc here you go. On same value for the moving average there are subtle differences, but if you change the values I am sure you can get significantly different results, maybe making it better
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
#
# ----------------------

declare lower;

input price = CLOSE;

input HMA_length = 200;
input lookback = 50;

input length = 100;
input displace = 0;

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 = HMA - next_bar;

plot HMA2 = MovingAverage(AverageType.HULL, divergence, length)[-displace];

assert(length > 0, "'length' must be positive: " + length);

input highLowLength = 10;

def multiplier1 = 2 / (length + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (divergence - ma[1]), Average(divergence, length));

plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));

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);

divergence.DefineColor("Up", GetColor(1));
divergence.DefineColor("Down", GetColor(0));
divergence.AssignValueColor(if divergence > AEMA then divergence.color("Up") else divergence.color("Down"));
# END
 
@tradebyday , I was actually hoping to see both the legacy EMA and Adaptive MA together on the same study....along with the divergence line in lime color. As presented, the three lines above are a bit confusing. Sorry for not being clear in my first request :)

Update: I used a workaround.....I added the adaptive EMA to the top study and then dragged it down to the lower study together with the legacy EMA u created. But I'm thinking, if I keep it this way it may present scaling issues.....we'll see when I run it tomorrow. From what I see in the 5 minute, it shows potential.
 
Last edited:
@madeinnyc here is a rough generation of it having all 3 averages (hull, EMA, and AEMA). Simply uncheck the ones you don't want plotted and change their colors. I change the divergence line to dotted for easier visual of when it crosses.
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
#
# ----------------------

declare lower;

input price = CLOSE;

input Divergencelength = 200;
input lookback = 50;

input HMAlength = 200;
input displace = 0;
input EMAlength = 100;
input AEMAlength = 100;

def HMA = HullMovingAvg(length = Divergencelength, 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 = HMA - next_bar;

plot HMA2 = MovingAverage(AverageType.HULL, divergence, HMAlength)[-displace];

assert(HMAlength > 0, "'length' must be positive: " + HMAlength);

def EMA = compoundValue(1, EMA[1] + 2 / (EMAlength + 1) * (divergence[-displace] - EMA[1]), divergence[-displace]);

plot LegacyEMA = EMA;
LegacyEMA.SetDefaultColor(GetColor(1));

input highLowLength = 10;

def multiplier1 = 2 / (AEMAlength + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (divergence - ma[1]), Average(divergence, AEMAlength));

plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));

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);

divergence.DefineColor("Up", GetColor(1));
divergence.DefineColor("Down", GetColor(0));
divergence.AssignValueColor(if divergence > LegacyEMA then divergence.color("Up") else divergence.color("Down"));
# END
 
@tradebyday : Thank you! I modified the above code a little to show me the view format I needed for comparison purposes. I'll post the code below so u can view any changes.

What I'm interested to know pertains to the Adaptive EMA.....notice the first lower study....I had dragged down the AEMA vs. the second study where it's place right into the code. I'm almost sure the inputs are identical however, I think the first lower study AEMA may be affected by scaling issues. What are your thoughts? Do you see scaling issues between the AEMA's when comparing both?

With regards to the code, what MA does input length = 100 control? What does displace = 0 mean?

Watching the yellow divergence line cross the AEMA today was very insightful. It provided exit signals that were previously hard to see.

See Screenshot:

HhbK9IZ.png


Revised Code:

Code:
declare lower;

input price = CLOSE;

input HMA_length = 34;
input lookback = 2;

input length = 100;
input displace = 0;
input EMAlength = 100;
input AEMAlength = 20;

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 = HMA - next_bar;

def HMA2 = MovingAverage(AverageType.HULL, divergence, HMA_length)[-displace];

divergence.setDefaultColor(Color.LIME);
divergence.SetLineweight(2);

assert(HMA_length > 0, "'length' must be positive: " + HMA_length);

def EMA = compoundValue(1, EMA[1] + 2 / (EMAlength + 1) * (divergence[-displace] - EMA[1]), divergence[-displace]);

plot LegacyEMA = EMA;
LegacyEMA.SetDefaultColor(GetColor(1));

input highLowLength = 10;

def multiplier1 = 2 / (AEMAlength + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (divergence - ma[1]), Average(divergence, AEMAlength));

plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));

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);
# END
 
Last edited by a moderator:
@tradebyday .......looking at the last lower study with the code above, there is definitely an error. I'm new to thinkscript coding (just learning), and I can't figure out why the AEMA is tracing different than the higher lower study. Any thoughts are appreciated, thks!
 
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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