MTF with Hull MA

Cliff

New member
VIP
All I'm trying to do is determine the slope of the Hull Moving Average for different time frames, but my code doesn't generate any labels. I understand I have to set the chart period to something shorter than the periods I'm calculating.

Code:
#INPUTS
input malength = 9;
input averageType = AverageType.HULL;
input showlabels = yes; #show labels
input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label

#CORE
DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("TurnBullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.DARK_RED);
DefineGlobalColor("TurnBearish", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);

# AGGREGATION 1 - ONE MINUTE

def aM1 = AggregationPeriod.MIN;
def closem1 = close(period = aM1);

def MaM1 = MovingAverage(averageType = averageType, closem1, malength);

def bullishM1 = MaM1[0] > MaM1[aM1];
def bearishM1 = MaM1[0] < MaM1[aM1];

AddLabel(showlabels and show1MIN, "1MIN",
    if bullishM1[0] and bullishM1[1] then GlobalColor("Bullish")
    else if bullishM1[0] and bearishM1[1] then GlobalColor("TurnBullish")
    else if bearishM1[0] and bearishM1[1] then GlobalColor("Bearish")
    else if bearishM1[0] and bullishM1[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 2 - TWO MINUTES

def am2 = AggregationPeriod.TWO_MIN;
def closem2 = close(period = am2);

def MaM2 = MovingAverage(averageType = averageType, closem2, malength);

def bullishM2 = MaM2[0] > MaM2[am2];
def bearishM2 = MaM2[0] < MaM2[am2];

AddLabel(showlabels and show2MIN, "2MIN",
    if bullishM2[0] and bullishM2[1] then GlobalColor("Bullish")
    else if bullishM2[0] and bearishM2[1] then GlobalColor("TurnBullish")
    else if bearishM2[0] and bearishM2[1] then GlobalColor("Bearish")
    else if bearishM2[0] and bullishM2[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 3 - THREE MINUTES

def am3 = AggregationPeriod.THREE_MIN;
def closem3 = close(period = am3);

def MaM3 = MovingAverage(averageType = averageType, closem3, malength);

def bullishM3 = MaM3[0] > MaM3[am3];
def bearishM3 = MaM3[0] < MaM3[am3];

AddLabel(showlabels and show3MIN, "3MIN",
    if bullishM3[0] and bullishM3[1] then GlobalColor("Bullish")
    else if bullishM3[0] and bearishM3[1] then GlobalColor("TurnBullish")
    else if bearishM3[0] and bearishM3[1] then GlobalColor("Bearish")
    else if bearishM3[0] and bullishM3[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));
 
All I'm trying to do is determine the slope of the Hull Moving Average for different time frames, but my code doesn't generate any labels. I understand I have to set the chart period to something shorter than the periods I'm calculating.

Code:
#INPUTS
input malength = 9;
input averageType = AverageType.HULL;
input showlabels = yes; #show labels
input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label

#CORE
DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("TurnBullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.DARK_RED);
DefineGlobalColor("TurnBearish", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);

# AGGREGATION 1 - ONE MINUTE

def aM1 = AggregationPeriod.MIN;
def closem1 = close(period = aM1);

def MaM1 = MovingAverage(averageType = averageType, closem1, malength);

def bullishM1 = MaM1[0] > MaM1[aM1];
def bearishM1 = MaM1[0] < MaM1[aM1];

AddLabel(showlabels and show1MIN, "1MIN",
    if bullishM1[0] and bullishM1[1] then GlobalColor("Bullish")
    else if bullishM1[0] and bearishM1[1] then GlobalColor("TurnBullish")
    else if bearishM1[0] and bearishM1[1] then GlobalColor("Bearish")
    else if bearishM1[0] and bullishM1[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 2 - TWO MINUTES

def am2 = AggregationPeriod.TWO_MIN;
def closem2 = close(period = am2);

def MaM2 = MovingAverage(averageType = averageType, closem2, malength);

def bullishM2 = MaM2[0] > MaM2[am2];
def bearishM2 = MaM2[0] < MaM2[am2];

AddLabel(showlabels and show2MIN, "2MIN",
    if bullishM2[0] and bullishM2[1] then GlobalColor("Bullish")
    else if bullishM2[0] and bearishM2[1] then GlobalColor("TurnBullish")
    else if bearishM2[0] and bearishM2[1] then GlobalColor("Bearish")
    else if bearishM2[0] and bullishM2[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 3 - THREE MINUTES

def am3 = AggregationPeriod.THREE_MIN;
def closem3 = close(period = am3);

def MaM3 = MovingAverage(averageType = averageType, closem3, malength);

def bullishM3 = MaM3[0] > MaM3[am3];
def bearishM3 = MaM3[0] < MaM3[am3];

AddLabel(showlabels and show3MIN, "3MIN",
    if bullishM3[0] and bullishM3[1] then GlobalColor("Bullish")
    else if bullishM3[0] and bearishM3[1] then GlobalColor("TurnBullish")
    else if bearishM3[0] and bearishM3[1] then GlobalColor("Bearish")
    else if bearishM3[0] and bullishM3[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

look in the top left corner of the chart. is there a white circle with an exclamation mark?
click on it. it shows an error message.
trying to process 60,000 historical bars, when the limit is 2000.

you are using labels, i'm guessing you want to see slopes from just the last 2 bars.
i think you should add some code to only calculate a slope , between the last 2 bars on the chart.

this will be true on the last bar
def lastbar = !isnan(close[0]) and isnan(close[-1]);
 

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

look in the top left corner of the chart. is there a white circle with an exclamation mark?
click on it. it shows an error message.
trying to process 60,000 historical bars, when the limit is 2000.

you are using labels, i'm guessing you want to see slopes from just the last 2 bars.
i think you should add some code to only calculate a slope , between the last 2 bars on the chart.

this will be true on the last bar
def lastbar = !isnan(close[0]) and isnan(close[-1]);
Thank you for the help. I did not see that error code. Your guess is right.
 
Last edited:
I added the last bar requirement to the label and to the slope, but that didn't help. The only thing left is the moving average, and I haven't been able to figure out a way to do that. Can you give me another hint?

Code:
#INPUTS
input malength = 9;
input averageType = AverageType.HULL;
input showlabels = yes; #show labels
input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label

#CORE
DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("TurnBullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.DARK_RED);
DefineGlobalColor("TurnBearish", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);
def LastBar = !isnan(close[0]) and isnan(close[-1]);

# AGGREGATION 1 - ONE MINUTE

def aM1 = AggregationPeriod.MIN;
def closem1 = close(period = aM1);
def MaM1 = MovingAverage(averageType = averageType, closem1, malength);
def bullishM1 = MaM1[0] > MaM1[aM1] and LastBar;
def bearishM1 = MaM1[0] < MaM1[aM1] and LastBar;

AddLabel(showlabels and show1MIN and LastBar, "1MIN",
    if bullishM1[0] and bullishM1[1] then GlobalColor("Bullish")
    else if bullishM1[0] and bearishM1[1] then GlobalColor("TurnBullish")
    else if bearishM1[0] and bearishM1[1] then GlobalColor("Bearish")
    else if bearishM1[0] and bullishM1[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 2 - TWO MINUTES

def am2 = AggregationPeriod.TWO_MIN;
def closem2 = close(period = am2);
def MaM2 = MovingAverage(averageType = averageType, closem2, malength);
def bullishM2 = MaM2[0] > MaM2[am2] and LastBar;
def bearishM2 = MaM2[0] < MaM2[am2] and LastBar;

AddLabel(showlabels and show2MIN and LastBar, "2MIN",
    if bullishM2[0] and bullishM2[1] then GlobalColor("Bullish")
    else if bullishM2[0] and bearishM2[1] then GlobalColor("TurnBullish")
    else if bearishM2[0] and bearishM2[1] then GlobalColor("Bearish")
    else if bearishM2[0] and bullishM2[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 3 - THREE MINUTES

def am3 = AggregationPeriod.THREE_MIN;
def closem3 = close(period = am3);
def MaM3 = MovingAverage(averageType = averageType, closem3, malength);
def bullishM3 = MaM3[0] > MaM3[am3] and LastBar;
def bearishM3 = MaM3[0] < MaM3[am3] and LastBar;

AddLabel(showlabels and show3MIN and LastBar, "3MIN",
    if bullishM3[0] and bullishM3[1] then GlobalColor("Bullish")
    else if bullishM3[0] and bearishM3[1] then GlobalColor("TurnBullish")
    else if bearishM3[0] and bearishM3[1] then GlobalColor("Bearish")
    else if bearishM3[0] and bullishM3[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));
 
All I'm trying to do is determine the slope of the Hull Moving Average for different time frames, but my code doesn't generate any labels. I understand I have to set the chart period to something shorter than the periods I'm calculating.

Code:
#INPUTS
input malength = 9;
input averageType = AverageType.HULL;
input showlabels = yes; #show labels
input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label

#CORE
DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("TurnBullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.DARK_RED);
DefineGlobalColor("TurnBearish", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);

# AGGREGATION 1 - ONE MINUTE

def aM1 = AggregationPeriod.MIN;
def closem1 = close(period = aM1);

def MaM1 = MovingAverage(averageType = averageType, closem1, malength);

def bullishM1 = MaM1[0] > MaM1[aM1];
def bearishM1 = MaM1[0] < MaM1[aM1];

AddLabel(showlabels and show1MIN, "1MIN",
    if bullishM1[0] and bullishM1[1] then GlobalColor("Bullish")
    else if bullishM1[0] and bearishM1[1] then GlobalColor("TurnBullish")
    else if bearishM1[0] and bearishM1[1] then GlobalColor("Bearish")
    else if bearishM1[0] and bullishM1[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 2 - TWO MINUTES

def am2 = AggregationPeriod.TWO_MIN;
def closem2 = close(period = am2);

def MaM2 = MovingAverage(averageType = averageType, closem2, malength);

def bullishM2 = MaM2[0] > MaM2[am2];
def bearishM2 = MaM2[0] < MaM2[am2];

AddLabel(showlabels and show2MIN, "2MIN",
    if bullishM2[0] and bullishM2[1] then GlobalColor("Bullish")
    else if bullishM2[0] and bearishM2[1] then GlobalColor("TurnBullish")
    else if bearishM2[0] and bearishM2[1] then GlobalColor("Bearish")
    else if bearishM2[0] and bullishM2[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 3 - THREE MINUTES

def am3 = AggregationPeriod.THREE_MIN;
def closem3 = close(period = am3);

def MaM3 = MovingAverage(averageType = averageType, closem3, malength);

def bullishM3 = MaM3[0] > MaM3[am3];
def bearishM3 = MaM3[0] < MaM3[am3];

AddLabel(showlabels and show3MIN, "3MIN",
    if bullishM3[0] and bullishM3[1] then GlobalColor("Bullish")
    else if bullishM3[0] and bearishM3[1] then GlobalColor("TurnBullish")
    else if bearishM3[0] and bearishM3[1] then GlobalColor("Bearish")
    else if bearishM3[0] and bullishM3[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

i admit, i was looking at the wrong thing, trying to fix this...

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

error,
in the top left corner of the chart, there is a white circle with an exclamation mark.
click on it. it shows an error message.
trying to process 60,000 historical bars, when the limit is 2000.

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

error cause,
bad offset in 6 formulas , should be 1 , not am1,....

def bullishM1 = MaM1[0] > MaM1[aM1];
def bearishM1 = MaM1[0] < MaM1[aM1];

am1 is an aggregation number.
for 1 minute, it is evaluated to be 60000.

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

this had me confused at first.

to debug a problem, i try to disable extra codes, until i get to a point that the code works. then figure out the code that caused the change.

i disabled the second and third set of formulas.

then i replaced the long if-then in the label for picking the color, with color.yellow.
that removed the the error.

i reenabled the color formula, so the error came back.
then changed 1 minute agg to 2 minute... and the error changed to 120,000 bars...
then i remembered that 1 minute aggregation is 60,000 milliseconds...
and looked at the code again and saw the wrong offset.

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


fixed study

change offsets in 6 formulas , from am1 to 1
ie,..
def bullishM1 = MaM1[0] > MaM1[aM1];


Code:
#mtf_hull_slopes_00d

#https://usethinkscript.com/threads/mtf-with-hull-ma.15366/
#MTF with Hull MA

#INPUTS
input malength = 9;
input averageType = AverageType.HULL;
input showlabels = yes; #show labels
input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label

#CORE
DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("TurnBullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.DARK_RED);
DefineGlobalColor("TurnBearish", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);

# AGGREGATION 1 - ONE MINUTE
def aM1 = AggregationPeriod.MIN;
def closem1 = close(period = aM1);
def MaM1 = MovingAverage(averageType = averageType, closem1, malength);
def bullishM1 = MaM1[0] > MaM1[1];
def bearishM1 = MaM1[0] < MaM1[1];

AddLabel(showlabels and show1MIN, "1MIN",
    if bullishM1[0] and bullishM1[1] then GlobalColor("Bullish")
    else if bullishM1[0] and bearishM1[1] then GlobalColor("TurnBullish")
    else if bearishM1[0] and bearishM1[1] then GlobalColor("Bearish")
    else if bearishM1[0] and bullishM1[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 2 - TWO MINUTES
def am2 = AggregationPeriod.TWO_MIN;
def closem2 = close(period = am2);
def MaM2 = MovingAverage(averageType = averageType, closem2, malength);
def bullishM2 = MaM2[0] > MaM2[1];
def bearishM2 = MaM2[0] < MaM2[1];

AddLabel(showlabels and show2MIN, "2MIN",
    if bullishM2[0] and bullishM2[1] then GlobalColor("Bullish")
    else if bullishM2[0] and bearishM2[1] then GlobalColor("TurnBullish")
    else if bearishM2[0] and bearishM2[1] then GlobalColor("Bearish")
    else if bearishM2[0] and bullishM2[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));

# AGGREGATION 3 - THREE MINUTES
def am3 = AggregationPeriod.THREE_MIN;
def closem3 = close(period = am3);
def MaM3 = MovingAverage(averageType = averageType, closem3, malength);
def bullishM3 = MaM3[0] > MaM3[1];
def bearishM3 = MaM3[0] < MaM3[1];

AddLabel(showlabels and show3MIN, "3MIN",
    if bullishM3[0] and bullishM3[1] then GlobalColor("Bullish")
    else if bullishM3[0] and bearishM3[1] then GlobalColor("TurnBullish")
    else if bearishM3[0] and bearishM3[1] then GlobalColor("Bearish")
    else if bearishM3[0] and bullishM3[1] then GlobalColor("TurnBearish")
    else GlobalColor("Neutral"));
#

https://tlc.thinkorswim.com/center/...tants/AggregationPeriod/AggregationPeriod-MIN
AggregationPeriod.MIN
Defines aggregation period equal to one minute (60,000 milliseconds).
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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