Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Add to the bottom of your studyIm 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
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);
The ToS platform does not allow for the use of MTF (multi-timeframe) indicators in scans or watchlists.I want to look for up (Hull ascending) at a certain aggregation and going up from down (hull descending) at a certain aggregation.
# 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);
#
# 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.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"));
# 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);
You’re welcome, happy trading. Remember nothing is perfect as market can change directions any time.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!!!
https://usethinkscript.com/threads/...ist-scan-for-thinkorswim.947/page-2#post-7685Does someone have the Hull Shuite Indicator from Trading View to ThinkorSwim?
https://www.tradingview.com/script/hg92pFwS-Hull-Suite/
#
# 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);
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
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?
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);
great job! thank you! will be possible to paint the bars with this system? thank you in advance!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.
Start a new thread and receive assistance from our community.
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.
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.