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:
Hi,
I love this study. I having trouble trying to figure out how to get the value of the turning points.

I would like to get the value of the last 3 bullish and 3 bearish turning points is that possible?

Bullish turning point = DarkGreen to LightGreen
Bearish Turning Point = Orange to DarkRed

- StrategyNode
One way to carry data forward in ThinkScript is to use recursion.
def CarryForwardCalc = if YourConditionIsMet then Variable else KeepLooking If YourConditionIsNotMet then KeepPreviousCarryForwardCalc

Recursion is a resource-intensive. Doing three recursions on a repainting variable that uses future bars would not be recommended, as the script would be too complex to be used anywhere other than for plots on a chart.

Here are the top 50 posts that discuss recursion. Perhaps they will help you along on your quest.
 
One way to carry data forward in ThinkScript is to use recursion.
def CarryForwardCalc = if YourConditionIsMet then Variable else KeepLooking If YourConditionIsNotMet then KeepPreviousCarryForwardCalc

Recursion is a resource-intensive. Doing three recursions on a repainting variable that uses future bars would not be recommended, as the script would be too complex to be used anywhere other than for plots on a chart.

Here are the top 50 posts that discuss recursion. Perhaps they will help you along on your quest.
Hi MerryDay,
Thank You for the prompt reply I think I understand the first step but

How do I get the previous Turning Point Value after I get the first one?
Here is what I have till now (Once I understand the bullish then I can figure out the Bearish)

######### Labels for test
def DarkGreeN = if concavity == 1 and HMA <= HMA[1] then HMA else 0;
def LightGreeN = if concavity == 1 and HMA > HMA[1] then HMA else 0;

def DarkRed = if concavity == -1 and HMA < HMA[1] then HMA else 0;
def Orange = if concavity == -1 and HMA >= HMA[1] then HMA else 0;

def BullishTurningPoint = DarkGreen[1] and Lightgreen;

#BTP = BullishTurningPoint
def RecentBTP = if BullishTurningPoint == 1 then HMA[1] else RecentBTP[1];

AddLabel (Yes,RecentBTP);
 
mod note:
Both this indicator and The Pam indicator repaint. It is not possible to get any reliable backtesting results with these indicators, as all the bad signals are erased and only the good trades show up in the backtesting data.

@QUIKTDR1 @_Merch_Man_
 
Issue: Conditional study-based OCO order is not executing at all (let alone at desired entry point) and just sits unfilled riding along with market.
 
Last edited by a moderator:
@halcyonguy @MerryDay thanks, both, appreciate the feedback
i haven't used OCO code, but i'm guessing it is similar to a scan code.
i think tos expects the code to have a true or false plot value, not a number.


problems,
..you are trying to use a study to determine a true/false situation, but don't have any true/false outputs (plots)
..this study is set up to be an upper chart study.
..has 4 plots. there should be just 1 plot
..all the plots have number values, not true/false (not 0 or 1)


fix
..disable all outputs , plots, AssignPriceColor() , labels, bubbles, ...
..change all the plots to def. then create 1 plot formula that will be true or false
..figure out what condition you want this oco thing to trigger on and make a new plot formula for it.

--------------------------

i made a lower chart study for you to experiment with.

it plots a spike at 1 when plot z is true, when concavity is different from the previous bar.
..i copied a formula and replaced data with 1 and double.nan with 0.
..(true is the same as 1, false is 0)

plot z = if concavity[1] != concavity then 1 else 0;

Code:
# OCO_code_not_working_00_lower

#https://usethinkscript.com/threads/study-based-oco-trouble.14592/
#Study-based OCO trouble
#Issue: Conditional study-based OCO order is not executing at all

declare lower;

input Quantity = 2;
input numberOfBars = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

def Point = (Quantity / TickSize()) * TickValue();
def day = GetDay();
def PMfirstBar = day != day[1];
def PMOpen = if PMfirstBar then open else PMOpen[1];
def currentDay = GetLastDay() == GetDay() and GetLastYear() == GetYear();
def PMO = if currentDay then PMOpen else Double.NaN;
def okToPlot = IsNaN(close[-numberOfBars]);

input average_type = AverageType.HULL;
input length1 = 55;
input price = close;
input signalSource = {default concavity, direction};
input paintbars = no;

def data = MovingAverage(average_type, price, length1);
#plot data = MovingAverage(average_type, price, length1);
#data.SetPaintingStrategy(PaintingStrategy.LINE);
#data.SetDefaultColor(Color.CYAN);
#data.SetLineWeight(3);
#data.HideTitle();
#data.HideBubble();

def direction = if data[1] < data then 1 else -1;
#def slope = reference LinearRegressionSlope(data, Max(RoundDown(length / 10,0), 2));
def slope = reference LinearRegressionSlope(data, Sqrt(length1));
def concavity = if slope  > slope [1] then 1 else -1;

#data.AssignValueColor(if concavity > 0 and direction > 0 then Color.GREEN else
#                      if concavity > 0 and direction < 0 then Color.DARK_GREEN else
#                      if concavity < 0 and direction < 0 then Color.RED else
#                      Color.DARK_ORANGE);

def ss = if signalSource == signalSource.concavity then concavity else direction;

#AssignPriceColor(if !paintbars then Color.CURRENT else if ss > 0 then Color.GREEN else Color.RED);

def MA_Max = if data[-1] < data and data > data[1] then data else Double.NaN;
#plot MA_Max = if data[-1] < data and data > data[1] then data else Double.NaN;
#MA_Max.SetDefaultColor(Color.WHITE);
#MA_Max.SetPaintingStrategy(PaintingStrategy.SQUARES);
#MA_Max.SetLineWeight(5);
#MA_Max.HideBubble();
#MA_Max.HideTitle();

def MA_Min = if data[-1] > data and data < data[1] then data else Double.NaN;
#plot MA_Min = if data[-1] > data and data < data[1] then data else Double.NaN;
#MA_Min.SetDefaultColor(Color.WHITE);
#MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
#MA_Min.SetLineWeight(5);
#MA_Min.HideBubble();
#MA_Min.HideTitle();

#def turning_point = if concavity[1] != concavity then data else Double.NaN;
#plot turning_point = if concavity[1] != concavity then data else Double.NaN;
#turning_point.SetLineWeight(3);
#turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
#turning_point.SetDefaultColor(Color.WHITE);
#turning_point.HideBubble();
#turning_point.HideTitle();

plot z = if concavity[1] != concavity then 1 else 0;

#

uJSfmqJ.jpg
@halcyonguy

apologies, I'm trying to learn what I'm still doing wrong. Regardless of the code needing to be worked through, I am just still struggling getting the OCO to execute using the updated lower study that you provided. When setting up the conditional order, I have it set up with the same market order rules and then the condition being that when the study plots z as true within 1 bar, but its not executing. I have tried setting it up also as the plot z equal to Value 1 within 1 bar but also fails. Would you mind please letting me know what I could be doing wrong? Again, not even considering having to work on the code, just trying to learn conceptually what I'm doing wrong to not have the OCO execute at all. Thank you for your help.
 
@halcyonguy

apologies, I'm trying to learn what I'm still doing wrong. Regardless of the code needing to be worked through, I am just still struggling getting the OCO to execute using the updated lower study that you provided. When setting up the conditional order, I have it set up with the same market order rules and then the condition being that when the study plots z as true within 1 bar, but its not executing. I have tried setting it up also as the plot z equal to Value 1 within 1 bar but also fails. Would you mind please letting me know what I could be doing wrong? Again, not even considering having to work on the code, just trying to learn conceptually what I'm doing wrong to not have the OCO execute at all. Thank you for your help.

You seem to be having difficulty following the instructions provided here:
https://usethinkscript.com/threads/...avity-for-thinkorswim.7847/page-3#post-120489

So to start, we have deleted @halcyonguy's post as it may have added to the confusion.
Let's go over a couple of important points to keep in mind:
  1. As it was explained before, using the signal within 1 bar is not allowed since the signal did not occur within 1 bar. Change to: within 2 bars.
  2. Before you start writing an OCO, it's important to make sure that you are getting valid results in both the scanner test and the chart alert test. You can find more details on this in the instructions here: https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-80482
We hope this clears things up a bit and helps you move forward on your quest.
 
Last edited:
is that math correct on the Divergence display in AddLabel??

Ruby:
addLabel(yes, 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(yes, concat("STDDEV: " , divergence_stddev * 10000), color = if absValue(divergence) > absValue(divergence_stddev) then color.blue else color.dark_gray);
 
This is a repainting indicator. It uses future bars. Meaning, it waits until the future happens and then goes back and paints the triggers that you see on your charts.

Scripts that repaint should NOT be used in Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies.
a. It will falsely show up in your Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies, but the signal will not be painted on your chart. You will think the script is broken.
b. Or the opposite. It will be painted on your chart but NOT show up in your Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies. This is because it wasn't there in real time! It was painted on afterward.
You will think the script is broken.

As stated above: this should NOT be used in Scans, Labels, Watchlists, Alerts, Conditional Orders
But if you insist, this future bar repainter can be made to work, however be aware there will be a lag which has shown to result in unprofitable trades.
The workaround: requires that you add the "within 2 bars" syntax to your statement.

Here is a scan to test for your concavities. You can use it as a basis for your Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies.
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-21#post-66454


@dannyboi11 @halcyonguy @bakktrader
 
Last edited:
I really like this code I tried to add a label with buy and sell signal using and have not been able to get it to work you have any ideas. I posted the code below
AddLabel(yes, " BUY ", if turning_point and concavity ==1 then CreateColor(153, 255, 153) else Color.WHITE);
 
Last edited by a moderator:
Hi!
I have had this particular convergence indication on my phone's TOS for a long time, and I really like it. I haven't figured out if I can get alerts for a watchlist based on this or not. I FEEL like i should be able to.

I just wanna know when a ticker crosses it on the daily. am I missing something?
Thank you!

http://tos.mx/Ghvc1KV
original code is from: https://usethinkscript.com/threads/...ng-points-and-concavity-2nd-derivatives.1803/
Ruby:
#
# 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
#
# Faster, but not necessarily mathematically as good as the first
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------


declare upper;

input price = HL2;
input HMA_Length = 55;
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_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(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 = buy, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Bell);

Alert(condition = sell, 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 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);
 
Last edited by a moderator:
Hi!
I have had this particular convergence indication on my phone's TOS for a long time, and I really like it. I haven't figured out if I can get alerts for a watchlist based on this or not. I FEEL like i should be able to.

I just wanna know when a ticker crosses it on the daily. am I missing something?
Thank you!

http://tos.mx/Ghvc1KV
original code is from: https://usethinkscript.com/threads/...ng-points-and-concavity-2nd-derivatives.1803/
Ruby:
#
# 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
#
# Faster, but not necessarily mathematically as good as the first
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------


declare upper;

input price = HL2;
input HMA_Length = 55;
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_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(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 = buy, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Bell);

Alert(condition = sell, 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 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);


This uses future bars. Meaning it waits until the future and then goes back in time to repaint the perfect signal.

Alerts work in real time on the current bar. But this signal is repainted on a past bar so the standard default alerts will not work.

However, you can search past bars for signals by adding 'within 3 bars' to your alert criteria. This works well for swing traders who are not looking to get in on a very beginning of a trend. But does not work as well for daytraders and not at all well for scalpers and traders on timeframes of 5min and less because the alert arrives too late for optimal profits.
Here is a script with the alerts:
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-18#post-35731
 
Last edited:
Hi,
Can anybody help me to add MTF to the following HMA indicator?
Thank you so much in advance.




#Hull Moving Average Concavity and Turning Points
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
# Faster, but not necessarily mathematically as good as the first
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------


declare upper;


input price = HL2;
input HMA_Length = 21;
input lookback = 2;
input MovingAverage = {default "HMA", "EMA", "SMA", "WMA", "ALMA","TEMA"};

plot HMA = HullMovingAvg(price = price, length = HMA_Length);

# def delta_per_bar =
# (fold n = 0 to lookback with s do s + getValue(HMA, n, lookback - 1)) / lookback;

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.mageNTA else color.yellow else
if HMA < HMA[1] then color.Lime else color.mageNTA);

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.MAGENTA);
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(yes, concat("DIVERGENCE: " , divergence), color = if concavity < 0 then if divergence[1] > divergence then Color.yellow else color.PINK else if divergence[1] < divergence then color.mageNTA else color.yellow);

Alert(MA_Min, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Chimes);

Alert(MA_Max, text = "Sell", "alert type" = Alert.BAR, sound = Sound.Chimes);
 
Hi,
Can anybody help me to add MTF to the following HMA indicator?
Thank you so much in advance.




#Hull Moving Average Concavity and Turning Points
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
# Faster, but not necessarily mathematically as good as the first
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------


declare upper;


input price = HL2;
input HMA_Length = 21;
input lookback = 2;
input MovingAverage = {default "HMA", "EMA", "SMA", "WMA", "ALMA","TEMA"};

plot HMA = HullMovingAvg(price = price, length = HMA_Length);

# def delta_per_bar =
# (fold n = 0 to lookback with s do s + getValue(HMA, n, lookback - 1)) / lookback;

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.mageNTA else color.yellow else
if HMA < HMA[1] then color.Lime else color.mageNTA);

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.MAGENTA);
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(yes, concat("DIVERGENCE: " , divergence), color = if concavity < 0 then if divergence[1] > divergence then Color.yellow else color.PINK else if divergence[1] < divergence then color.mageNTA else color.yellow);

Alert(MA_Min, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Chimes);

Alert(MA_Max, text = "Sell", "alert type" = Alert.BAR, sound = Sound.Chimes);
This is a repainting indicator. MTF are repainting indicators.
No, putting a repainter on a repainter is not a thing.

However, it is possible to "mimic" a higher aggregation by changing the lengths of the moving averages
Here is someone that made the attempt of plotting different lengths:
https://usethinkscript.com/threads/...ty-questions-for-thinkorswim.7847/#post-83801
 
So I thought this was interesting enough to warrant looking at. Cool idea.

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);
Do with it as you will. :)
Hello.Masume.-
I would like to ask you again about this wonderful script. I am using 1H timeframe. The maximum interval that I can achieve, between two points that take the value of the price, is one day. I would like to ask you if it can be adapted to be able to take intervals greater than one day (between two consecutive points).-Thank you very much.-
 
Hello.Masume.-
I would like to ask you again about this wonderful script. I am using 1H timeframe. The maximum interval that I can achieve, between two points that take the value of the price, is one day. I would like to ask you if it can be adapted to be able to take intervals greater than one day (between two consecutive points).-Thank you very much.-

The concavity script does not have a time component, so the phenomenon that you are observing is mostly likely due to market conditions.

You did not provide enough information to determine what 'interval' you are discussing.
In order to continue this conversation; please provide a chart image with the confluence that you see as well as annotating what you are trying to make it appear as.
 

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
460 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