Hull Format, Label, Watchlist, Scan for ThinkorSwim

BAlIARf.png

Any scripts for candle color change above or below Hull Moving Averages?
this kind of appearance
 
Last edited by a moderator:
I'd like to know if there is a custom thinkScript for the HMA that alerts when a color change is detected within ToS. I tried using this on the default HMA code:

alert(uptrend,"Up", Alert.Bar, Sound.Chimes);
alert(downtrend,"Down", Alert.Bar, Sound.Bell);


It doesn't quite give me the results I want with a particular time frame, like a 5 or 3 min chart. It seems to go off randomly.

Can anyone help?
 
declare lower;

input length = 10;
input colorNormLength = 10;
input price = close;


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

plot ROC = if price[length] != 0 then (price / price[length] - 1) * 100 else 0;
plot ZeroLine = 0;


ROC.DefineColor("Highest", Color.YELLOW);
ROC.DefineColor("Lowest", Color.LIGHT_RED);
ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));



Input AvgType = averageType.HULL;
input AvgLength = 14;
input offset = -1;


def HMA = MovingAverage(AvgType, ROC, AvgLength)[offset];
Plot Hull = HMA;

Im looking to add alert when value of Hull changes directions up or down when above zero to alert when the hull changes directions upwards or below to downwards
 
Last edited by a moderator:
Im looking to add alert when value of Hull changes directions up or down when above zero to alert when the hull changes directions upwards or below to downwards
Add to the bottom of your study
Ruby:
def AboveZero = Hull > 0 and Hull < Hull[1] and Hull[1] > Hull[2]  #above zero and changes direction down
                            Hull > 0 and Hull > Hull[1] and Hull[1] < Hull[2]  #above zero and changes direction up

# Alert AboveZero  change in direction
Alert(AboveZero , "AboveZero  change in direction", Alert.Bar, Sound.Chimes);



def BelowZero = Hull < 0 and  Hull < Hull[1] and Hull[1] > Hull[2]  #below zero and changes direction down

# Alert BelowZero  change to downward direction
Alert(BelowZero  , "BelowZero  change in direction", Alert.Bar, Sound.Chimes);
 
Not sure if this is what you are looking for but this might help.

Code:
#MACD based on Hull Moving Average W/peak/ebb arrows

#TOS title = MACD_via_Hull_MA_fav



declare lower;



input fastLength = 12;

input slowLength = 26;

input MACDLength = 9;

input AverageType = {SMA, EMA, default HULL};



plot Value;

plot Avg;

switch (AverageType) {

  case SMA:

    Value = Average(close, fastLength) - Average(close, slowLength);

    Avg = Average(Value, MACDLength);

  case EMA:

    Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);

    Avg = ExpAverage(Value, MACDLength);

  case HULL:

    Value =  MovingAverage(AverageType.HULL, close, fastLength) -  MovingAverage(AverageType.HULL, close, slowLength);

    Avg = Average(Value, MACDLength);

}



plot Diff = Value - Avg;

plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));

Avg.SetDefaultColor(GetColor(8));

Diff.SetDefaultColor(GetColor(5));

Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

Diff.SetLineWeight(3);

Diff.DefineColor("Positive and Up", Color.GREEN);

Diff.DefineColor("Positive and Down", Color.DARK_GREEN);

Diff.DefineColor("Negative and Down", Color.RED);

Diff.DefineColor("Negative and Up", Color.DARK_RED);

Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

ZeroLine.SetDefaultColor(GetColor(0));



#plot Min arrows*

def MinArrow = if (Value < Value[1] and value[1] < Value[2] and value[2] < Value[3] and value[-1] > Value and value < 0)

  then 0

  else if (Value > Value[1])

  then double.nan

  else double.nan;



plot UpArrow = if(MinArrow == 0, value, double.nan);

UpArrow.AssignValueColor(Color.Green);

UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

UpArrow.SetLineWeight(1);

UpArrow.HideBubble();



#plot Max arrows*

def MaxArrow = if (Value > Value[1] and value[1] > Value[2] and value[2] > Value[3] and value[-1] < Value and value > 0)

  then 0

  else if (Value > Value[1])

  then double.nan

  else double.nan;



plot DwnArrow = if(MaxArrow == 0, value, double.nan);

DwnArrow.AssignValueColor(Color.cyan);

DwnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_Down);

DwnArrow.SetLineWeight(1);

DwnArrow.HideBubble();



#plot Max signal(Avg) arrows*

def SignalArrow = if (Avg > Avg[1] and Avg[1] > Avg[2] and Avg[2] > Avg[3] and Avg[-1] < Avg and Avg > 0)

  then 0

  else if (Avg > Avg[1])

  then double.nan

  else double.nan;



plot downSignalArrow = if(SignalArrow == 0, avg, double.nan);

downSignalArrow.AssignValueColor(Color.yellow);

downSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_Down);

downSignalArrow.SetLineWeight(1);

downSignalArrow.HideBubble();



AddCloud(ZeroLine, Value, color.RED, color.GREEN);

# end

This is the source I found it from.

https://github.com/jshingler/TOS-an...llection.md#MACD_BASED_ON_HULL_MOVING_AVERAGE
A VERY GOOD SYSTEM, CAN SOMEONE HELP TO LOCATE THE ARROW SIGNAL FROM THE LOWER INDICATOR AND PLOT IT INTO THE UPPER CHART? THANK YOU VERY MUCH IN ADVANCE..
 
Hi,

From the study in Price Performance, I located the Hull_Average_Change search. It is useful to find Hull change from up to down or down to up.
Below is the Thinkscript for the scan. I need some guidance to modify the code to look for Hull in up or down.


#Hull_Average_Change from scan
input price = close;
input length = 20;
input choice1 = {default Up, Down};
input choice2 = {default Down, Up};
def avg = hullMovingAvg(price, length);

def condition1;
switch (choice1) {
case Up:
condition1 = avg[1] > avg[2];
case Down:
condition1 = avg[1] < avg[2];
}

def condition2;
switch (choice2) {
case Up:
condition2 = avg > avg[1];
case Down:
condition2 = avg < avg[1];
}

plot scan = condition1 and condition2;

I want to look for up (Hull ascending) at a certain aggregation and going up from down (hull descending) at a certain aggregation.
 
Last edited by a moderator:
I want to look for up (Hull ascending) at a certain aggregation and going up from down (hull descending) at a certain aggregation.
The ToS platform does not allow for the use of MTF (multi-timeframe) indicators in scans or watchlists.
The ToS platform allows MTF (multi-timeframe) indicators to be plotted on a chart.
Ruby:
# Hull_Average_Change from scan
# @DataDriven 5/19/2022
input agg2 = AggregationPeriod.FOUR_HOURS;
input agg1 = AggregationPeriod.FIVE_MIN ;
def price1 = Close(Period =agg1);
def price2 = Close(Period =agg2);
input length = 20;
input displace = 0;

input choice1 = {default Up, Down};
input choice2 = {default Down, Up};
plot HMA1 = MovingAverage(AverageType.HULL, price1, length)[-displace];
def  HMA2 = MovingAverage(AverageType.HULL, price2, length)[-displace];


def condition1;
switch (choice1) {
case Up:
condition1 = HMA1[1] > HMA1[2];
case Down:
condition1 = HMA1[1] < HMA1[2];
}

def condition2;
switch (choice2) {
case Up:
condition2 = HMA2 > HMA2[1];
case Down:
condition2 = HMA2 < HMA2[1];
}

def scan = condition1 and condition2;

HMA1.AssignValueColor(if  scan then color.blue else color.pink);

plot ConditionsBegin = if scan and !scan[1] then HMA1 else double.NaN ;
     ConditionsBegin.SetPaintingStrategy(PaintingStrategy.ARROW_up);
     ConditionsBegin.SetDefaultColor(color.blue) ;
     ConditionsBegin.SetLineWeight(1);

plot ConditionsEnd = if !scan and scan[1] then HMA1 else double.NaN ;
     ConditionsEnd.SetPaintingStrategy(PaintingStrategy.ARROw_DOWN);
     ConditionsEnd.SetDefaultColor(color.blue) ;
     ConditionsEnd.SetLineWeight(1);
H2nMuQa.png

In order to scan. It is necessary to input each aggregation filter separately:
Shared Scan Link: http://tos.mx/phi2pN3 Click here for --> Easiest way to load shared links
hvpopZv.png


Here is the tutorial for creating MTF studies:
https://usethinkscript.com/threads/converting-indicator-to-multi-timeframe-mtf-in-thinkorswim.8050/
 
Last edited:
Hi, would anyone be able to modify the ToS 'HullMovingAvg' and add a syntax to color the price bars based on the HMA Down/Up trend?

Would be indebted if so.

Original code below.

Thanks.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
 
Last edited:
Hi, would anyone be able to modify the ToS 'HullMovingAvg' and add a syntax to color the price bars based on the HMA Down/Up trend?

Would be indebted if so.

Original code below.

Thanks.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
Here you go. Give it a try. I added a color price bar and alert.

Code:
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));

def bullish = HMA > HMA[1];
def bearish = HMA < HMA[1];

# Alerts
Alert(bullish, "UP arrow alert", Alert.BAR, Sound.Chimes);
Alert(bearish, "DOWN arrow alert", Alert.BAR, Sound.Ring);


AssignPriceColor(if bullish then color.Green else color.Red);
 
Here you go. Give it a try. I added a color price bar and alert.

Code:
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));

def bullish = HMA > HMA[1];
def bearish = HMA < HMA[1];

# Alerts
Alert(bullish, "UP arrow alert", Alert.BAR, Sound.Chimes);
Alert(bearish, "DOWN arrow alert", Alert.BAR, Sound.Ring);


AssignPriceColor(if bullish then color.Green else color.Red);

Wow, @s1111 - totally flawless. Can't thank you enough, you're friggin' ace. And what a cheetah fast turn-around!

And the alerts, a nice ancillary bonus!! Thank you!!!
 
Wow, @s1111 - totally flawless. Can't thank you enough, you're friggin' ace. And what a cheetah fast turn-around!

And the alerts, a nice ancillary bonus!! Thank you!!!
You’re welcome, happy trading. Remember nothing is perfect as market can change directions any time.
 
Hull Moving Average
Is it possible to code a study for think or swim mobile so you can see hull moving average change color when the momentum changes but on your mobile device.
 
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2019

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));


#I added these arrows:
plot U1 = HMA > HMA[1];
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);

plot D1 = HMA < HMA[1];
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);

How would I change my code to where it only plots an up or down arrow on only the 1st candle that changes trend
instead of ALL the candles that are the same direction? Thanks
 
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2019

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));


#I added these arrows:
plot U1 = HMA > HMA[1];
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);

plot D1 = HMA < HMA[1];
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);

How would I change my code to where it only plots an up or down arrow on only the 1st candle that changes trend
instead of ALL the candles that are the same direction? Thanks

One way is to look at the prior bars and ensure that it is going the opposite direction.

Ruby:
input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.Color("Up") else HMA.Color("Down"));


#I added these arrows:
plot U1 =  HMA > HMA[1] and  HMA[1] < HMA[2];
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);

plot D1 = HMA < HMA[1] and HMA[1] > HMA[2] ;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);
 
Thats perfect. Exactly what I wanted.

I noticed my arrows come a bar after the HMA color has changed.
Is there a way to make it bar[0] immediate?
 
Thats perfect. Exactly what I wanted.

I noticed my arrows come a bar after the HMA color has changed.
Is there a way to make it bar[0] immediate?

Yes, but it relies on the next future bar, '[-1]', which may not actually close to cause the HMA to change. The arrow may disappear (repaint] as a result. The plot of the arrow will look how you want only if the future bar closes to change the HMA.

You can test it with the following code to see which version you feel comfortable with using.

Ruby:
input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.Color("Up") else HMA.Color("Down"));


#I added these arrows:
plot U1 =  HMA < HMA[-1] and  HMA < HMA[1];
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);

plot D1 = HMA > HMA[-1] and HMA > HMA[1] ;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);
 

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