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:
I've been testing the Hull concavity indicator found at https://usethinkscript.com/threads/...ng-points-and-concavity-2nd-derivatives.1803/ and it's a wonderful tool. Thank you @mashume. I like faster and slower periods (each has its advantages, early entry vs. longer moves), and I applied both to see what happens. For example, I used the 9 and 20 periods by applying two instances of the study (and slightly altering code to allow the 20 arrows room to appear above/below the 9 arrows). What I noticed is that sometimes when both fire together (when they "stack"), sometimes it signals a powerful longer term move to come but also allows a trader the ability to enter early into the move. It also allows you to ignore the many other signals the indicator provides, some good and some bad). Here's an example from a few days ago on the ES 2m chart (grey is 9, white is 20):

1FMS7sG.jpg


I was practicing on sim and actually took the short on the second example, which is about a 25 point move. Of course, I cherry picked instances where it worked to demonstrate what I'm trying to accomplish, but it doesn't always work and I have not backtested it yet.

I have limited knowledge of coding, so I'm looking to this community with help altering the current latest version of @mashume 's indicator to create the following: an indicator that signals only when both chosen periods signal on the same bar. The indicator should allow the trader to choose the periods for the slow and fast options (there very well may be better combinations than 9 and 20). There should be an option to allow a secondary signal (different color or whatever) that shows when the slow and fast periods signal on bars next to each other rather than the same bar, which is perhaps a weaker signal (again, I don't know because I have not backtested properly). Such an indicator could, imo, have advantage over the the author's original because (at least, it's my theory) it would provide fewer, more meaningful signals with less clutter on the chart.

Here is the RTY on the same day to show some signals that failed or didn't provide big moves, 1 big move, and some instances where signals on 2 bars next to each other provided some nice moves:

STyc64N.jpg


I would appreciate it if @mashume @BenTen and anyone else could assist with this idea. I'm still trying to form a framework/system/rules and experimenting, but the concept seems promising. I hope this is the right place to post this thread and I apologize if it's not. Thank you all in advance for your interest and help with this.
 

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

I noticed that good signals happen when the colors go in sequence. A long signal is when the colors go from Red -> Dark Green -> Green. A short signal is when colors go from Green -> Orange -> Red. I added coded alerts at the bottom of the script to catch these scenarios. This is used in coordination with other indicators.

Ruby:
#
# Hull Moving Average Concavity and Turning Points
#  or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mashume)
# Version: 2020-05-01 V4
#
# https://usethinkscript.com/threads/hull-moving-average-turning-points-and-concavity-2nd-derivatives.1803/
#

declare upper;

input price = HL2;
input HMA_Length = 55;
input lookback = 2;
input show_labels = Yes;
input stddev_len = 21;

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_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 Double.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 Double.Nan;
MA_Min.SetDefaultColor(Color.WHITE);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(3);

plot sell = if turning_point and concavity == -1 then high else double.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 double.nan;
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(3);

def divergence = HMA - next_bar;

addLabel(show_labels, concat("DIVERGENCE: " , divergence * 10000), color = if concavity < 0 then if divergence[1] > divergence then Color.dark_RED else color.PINK else if divergence[1] < divergence then color.dark_green else color.dark_orange);

def divergence_stddev = StandardDeviation(price = divergence, length = stddev_len);
addLabel(show_labels, concat("STDDEV: " , divergence_stddev * 10000), color = if absValue(divergence) > absValue(divergence_stddev) then color.blue else color.dark_gray);

# 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 double.nan;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(3);

plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else double.nan;
CCD_I.SetDefaultColor(Color.DARK_ORANGE);
CCD_I.SetLineWeight(3);

plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else double.nan;
CCU_D.SetDefaultColor(COLOR.DARK_GREEN);
CCU_D.SetLineWeight(3);

plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else double.nan;
CCU_I.SetDefaultColor(COLOR.GREEN);
CCU_I.SetLineWeight(3);

######################################################
# New Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################

# GO back through the bars, find when the last Dark Green section
# started then see if the color before that was Red

Def RedToDarkGreen = fold idx5 = 1 to 100 with p5 = 0 do if !isNaN(GetValue(CCU_D,idx5)) && !isNaN(GetValue(CCD_D,idx5+1)) && p5 == 0 then idx5 else if !isNaN(GetValue(CCU_D,idx5)) && isNaN(GetValue(CCU_D,idx5+1)) && p5 == 0 then Double.NaN else p5;

# GO back through the bars, find when the last Orage section
# started then see if the color before that was Green

Def GreenToOrange = fold idx6= 1 to 100 with p6 = 0 do if !isNaN(GetValue(CCD_I,idx6)) && !isNaN(GetValue(CCU_I,idx6+1)) && p6 == 0 then idx6 else if !isNaN(GetValue(CCD_I,idx6)) && isNaN(GetValue(CCD_I,idx6+1)) && p6 == 0 then Double.NaN else p6;

# Long signal when last bar line color is Green, line color of the bar
# before that was Dark Green and the color before that was Red

Def RedToDarkGreenToGreen = CCU_I[1]&& CCU_D[2] && !isNaN(RedToDarkGreen);
alert(RedToDarkGreenToGreen, "RED TO DARK GREEN TO GREEN - GO LONG", alert.bar, sound.chimes);

# Short signal when last bar line color is Red, line color of the bar
# before that was Red and the color before that was Orange

Def GreenToOrangeToRed = CCD_D[1] && CCD_I[2] && !isNaN(GreenToOrange);
alert(GreenToOrangeToRed, "GREEN TO ORANGE TO RED - GO SHORT", alert.bar, sound.chimes);

######################################################
# END Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################
/CODE]
 
@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 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.
I am trying to put conditional order ie almost autotrade, to put buy order should I put condition as Ma_min true within 1 bar, as this seems nto to work, even Buy is true does not work correctly
I tried to copy and paste from Mashume strategy itself but when I put in Pine editer It is not accepted
 
I am trying to put conditional order ie almost autotrade, to put buy order should I put condition as Ma_min true within 1 bar, as this seems nto to work, even Buy is true does not work correctly
I tried to copy and paste from Mashume strategy itself but when I put in Pine editer It is not accepted
It's not Pinescript, it's thinkscript. So unless you have a pine version somewhere, it won't work. I've worked on a version for python somewhere but can't find the code anymore. Others may have converted it to pinescript.

-mashume
 
I am trying to put conditional order ie almost autotrade, to put buy order should I put condition as Ma_min true within 1 bar, as this seems nto to work, even Buy is true does not work correctly
I tried to copy and paste from Mashume strategy itself but when I put in Pine editer It is not accepted
Ditto everything that @mashume stated, and the scan needs to be set to: Ma_min true within 2 bars to get accurate results.
 
Hello,
Im new here but been trading for quite some time now. I ran into this indicator http://tos.mx/wKuLZAc on here and i noticed that its quite useful on the daily charts if you catch it ahead of time a day prior. I needed help with building a scan that is able to help me scan for when the green dot appears on the daily chart when i run my scan end of day for the next day. Please help i would highly appreciate it.

If you look at the chart of $PPSI for example recently it showed green dots a day prior to it spiking on the daily chart.
 
Last edited by a moderator:
Hello,
Im new here but been trading for quite some time now. I ran into this indicator http://tos.mx/wKuLZAc on here and i noticed that its quite useful on the daily charts if you catch it ahead of time a day prior. I needed help with building a scan that is able to help me scan for when the green dot appears on the daily chart when i run my scan end of day for the next day. Please help i would highly appreciate it.
See the 1st post
 
I am reaching out for help with this wonderful indicator by @mashume

In an attempt to create a color changing label based on the defined buy/sell signals from the script, the labels appear black, but I cannot figure out what data is missing.

From script:

def buy = if turning_point and concavity == 1 then low else Double.NaN;

def sell = if turning_point and concavity == -1 then high else Double.NaN;

Both Turning_point and concavity reference previous bars and compare them to the current bar.

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 HMA else Double.NaN;

I am currently trying:

def LongEntry = if ((turning_point and concavity == 1) then 1 else 0;

AddLabel(yes,
if LongEntry == 1 then "LE "
else "LE ",

if LongEntry == 1 then Color.GREEN
else Color.GRAY);

I suppose my question is, will the label turn green only once the current bar closes, or am I trying to predict a future event?
Also, what impact might once_per_bar have on the label in this context?

I was unable to watch the labels today due to work, and this will likely keep me up at night.
 
I am reaching out for help with this wonderful indicator by @mashume

In an attempt to create a color changing label based on the defined buy/sell signals from the script, the labels appear black, but I cannot figure out what data is missing.

I suppose my question is, will the label turn green only once the current bar closes, or am I trying to predict a future event?
Also, what impact might once_per_bar have on the label in this context?

I was unable to watch the labels today due to work, and this will likely keep me up at night.
Because of the future-looking calculations, labels are problematic. Some members have reported positive results in using
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-18#post-35731 for alerts.
Maybe it can be modified to provide labels.
 
Last edited:
I've been testing the Hull concavity indicator found at https://usethinkscript.com/threads/...ng-points-and-concavity-2nd-derivatives.1803/ and it's a wonderful tool. Thank you @mashume. I like faster and slower periods (each has its advantages, early entry vs. longer moves), and I applied both to see what happens. For example, I used the 9 and 20 periods by applying two instances of the study (and slightly altering code to allow the 20 arrows room to appear above/below the 9 arrows). What I noticed is that sometimes when both fire together (when they "stack"), sometimes it signals a powerful longer term move to come but also allows a trader the ability to enter early into the move. It also allows you to ignore the many other signals the indicator provides, some good and some bad). Here's an example from a few days ago on the ES 2m chart (grey is 9, white is 20):

1FMS7sG.jpg


I was practicing on sim and actually took the short on the second example, which is about a 25 point move. Of course, I cherry picked instances where it worked to demonstrate what I'm trying to accomplish, but it doesn't always work and I have not backtested it yet.

I have limited knowledge of coding, so I'm looking to this community with help altering the current latest version of @mashume 's indicator to create the following: an indicator that signals only when both chosen periods signal on the same bar. The indicator should allow the trader to choose the periods for the slow and fast options (there very well may be better combinations than 9 and 20). There should be an option to allow a secondary signal (different color or whatever) that shows when the slow and fast periods signal on bars next to each other rather than the same bar, which is perhaps a weaker signal (again, I don't know because I have not backtested properly). Such an indicator could, imo, have advantage over the the author's original because (at least, it's my theory) it would provide fewer, more meaningful signals with less clutter on the chart.

Here is the RTY on the same day to show some signals that failed or didn't provide big moves, 1 big move, and some instances where signals on 2 bars next to each other provided some nice moves:

STyc64N.jpg


I would appreciate it if @mashume @BenTen and anyone else could assist with this idea. I'm still trying to form a framework/system/rules and experimenting, but the concept seems promising. I hope this is the right place to post this thread and I apologize if it's not. Thank you all in advance for your interest and help with this.
@iAskQs I took a stab at what you asked for; to generate a signal when two HMA time frames agree. Note the following:
  • offset/offset2 - set individual arrow offset
  • show hma - show/hide HMA average lines and indicators
  • show arrows - show/hide all individual arrows
  • show bubbles - show/hide all MTF agreement bubbles
  • show mtf arrow - show/hide MTF agreement arrows
  • mtf offset - set mtf arrow/bubble offset
  • ha in use - calculate low and high correctly for visuals if you're using Heikin Ashi candles
I make no promises on the code and offer it "as is". ;)

Code link: http://tos.mx/cTj98mo
Ruby:
#
# Hull Moving Average Concavity and Turning Points
#  or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mashume)
# Version: 2020-05-01 V4
#
# Modified: Greg James (Hunt4Life)
# Version: 2021-12-06 v2
# Changes: Added 2nd time frame and bubbles when both TMs are in agreement
#
# https://usethinkscript.com/threads/hull-moving-average-turning-points-and-concavity-2nd-derivatives.1803/
#

declare upper;

### 1st time frame
input price = HL2;
input HMA_Length = 9;
input lookback = 2;
input offset = .05;

### 2nd time frame
input price2 = HL2;
input HMA_Length2 = 20;
input lookback2 = 2;
input offset2 = .05;

### visual displays
input show_labels = yes;
input show_arrows = no;
input show_bubbles = yes;
input HA_inUse = no;

def o = open;
def h = high;
def l = low;
def c = close;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
HAhigh = Max(Max(h, HAopen), HAclose[1]);
HAlow = Min(Min(l, HAopen), HAclose[1]);
HAclose = (open + high + low + close) / 4;
def low_value = if HA_inUse then HAlow else low;
def high_value = if HA_inUse then HAhigh else high;


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_GREEN else Color.GREEN);

HMA.SetLineWeight(2);

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 Double.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 Double.NaN;
MA_Min.SetDefaultColor(Color.WHITE);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(3);


plot sell = if turning_point and concavity == -1 then high_value + offset else Double.NaN;
sell.SetHiding(!show_arrows);
sell.SetDefaultColor(Color.DARK_ORANGE);
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetLineWeight(2);

plot buy = if turning_point and concavity == 1 then low_value - offset else Double.NaN;
buy.SetHiding(!show_arrows);
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(2);

def divergence = HMA - next_bar;

AddLabel(show_labels, Concat("DIVERGENCE: " , divergence * 10000), color = if concavity < 0 then if divergence[1] > divergence then Color.DARK_RED else Color.PINK else if divergence[1] < divergence then Color.DARK_GREEN else Color.DARK_ORANGE);

# 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 Double.NaN;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(2);

plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
CCD_I.SetDefaultColor(Color.DARK_ORANGE);
CCD_I.SetLineWeight(2);

plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
CCU_D.SetDefaultColor(Color.DARK_GREEN);
CCU_D.SetLineWeight(2);

plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
CCU_I.SetDefaultColor(Color.GREEN);
CCU_I.SetLineWeight(2);

###
### 2nd time frame
###

plot HMA2 = HullMovingAvg(price = price2, length = HMA_Length2);

def delta2 = HMA2[1] - HMA2[lookback2 + 1];
def delta_per_bar2 = delta2 / lookback2;

def next_bar2 = HMA2[1] + delta_per_bar2;

def concavity2 = if HMA2 > next_bar2 then 1 else -1;

plot turning_point2 = if concavity2[1] != concavity2 then HMA2 else Double.NaN;

HMA2.AssignValueColor(color = if concavity2[1] == -1 then
    if HMA2 > HMA2[1] then Color.DARK_ORANGE else Color.RED else
    if HMA2 < HMA2[1] then Color.DARK_GREEN else Color.GREEN);

HMA2.SetLineWeight(2);

turning_point2.SetLineWeight(4);
turning_point2.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
turning_point2.SetDefaultColor(Color.WHITE);

plot MA_Max2 = if HMA2[-1] < HMA2 and HMA2 > HMA2[1] then HMA2 else Double.NaN;
MA_Max2.SetDefaultColor(Color.WHITE);
MA_Max2.SetPaintingStrategy(PaintingStrategy.SQUARES);
MA_Max2.SetLineWeight(3);

plot MA_Min2 = if HMA2[-1] > HMA2 and HMA2 < HMA2[1] then HMA2 else Double.NaN;
MA_Min2.SetDefaultColor(Color.WHITE);
MA_Min2.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min2.SetLineWeight(3);


plot sell2 = if turning_point2 and concavity2 == -1 then high_value + offset2 else Double.NaN;
sell2.SetHiding(!show_arrows);
sell2.SetDefaultColor(Color.YELLOW);
sell2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell2.SetLineWeight(2);

plot buy2 = if turning_point2 and concavity2 == 1 then low_value - offset2 else Double.NaN;
buy2.SetHiding(!show_arrows);
buy2.SetDefaultColor(Color.BLUE);
buy2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy2.SetLineWeight(2);

def divergence2 = HMA2 - next_bar2;

AddLabel(show_labels, Concat("DIVERGENCE2: " , divergence2 * 10000), color = if concavity2 < 0 then if divergence2[1] > divergence2 then Color.DARK_RED else Color.PINK else if divergence2[1] < divergence2 then Color.DARK_GREEN else Color.DARK_ORANGE);

# 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_D2 = if concavity2 == -1 and HMA2 < HMA2[1] then HMA2 else Double.NaN;
CCD_D2.SetDefaultColor(Color.RED);
CCD_D2.SetLineWeight(2);

plot CCD_I2 = if concavity2 == -1 and HMA2 >= HMA2[1] then HMA2 else Double.NaN;
CCD_I2.SetDefaultColor(Color.DARK_ORANGE);
CCD_I2.SetLineWeight(2);

plot CCU_D2 = if concavity2 == 1 and HMA2 <= HMA2[1] then HMA2 else Double.NaN;
CCU_D2.SetDefaultColor(Color.DARK_GREEN);
CCU_D2.SetLineWeight(2);

plot CCU_I2 = if concavity2 == 1 and HMA2 > HMA2[1] then HMA2 else Double.NaN;
CCU_I2.SetDefaultColor(Color.GREEN);
CCU_I2.SetLineWeight(2);

AddChartBubble(show_bubbles && sell && sell2, high, "sell", Color.DOWNTICK, yes);
AddChartBubble(show_bubbles && buy && buy2, low, "buy", Color.UPTICK, no);

#AddChartBubble((barnumber and D1), if isUp then low else high, if D1 then "DRV" else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK, yes);
 
Last edited by a moderator:
When i tried to scan for "buy" signals via this code "Concavity("hma length" = 55, price = CLOSE)."buy" is true within 2 bars", I noticed that the results have the buy signals a few bars behind. Is this expected?
 
When i tried to scan for "buy" signals via this code "Concavity("hma length" = 55, price = CLOSE)."buy" is true within 2 bars", I noticed that the results have the buy signals a few bars behind. Is this expected?
Yes, it's one of the known complications with this study. There is good discussion of it in the main thread, though I couldn't point to a particular post anywhere, nor remember when in the chain of things it happened.

-mashume
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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