Unable to crease strategy for HMA color change

tlee404

Member
I have been trying to create a buy (red to green) or sell ( green to red) strategy based on the change in color of the HMA average. Tried using buy = HMA > HMA[1] and HMA[1] < HMA[2]; Sell = HMA < HMA[1] and HMA[1] > HMA[2]; but it buy and sell signal does not match the color change. Would appreciate help on this if it can be done. Tried for several hours but can't figure it out. I can create arrows at the color change but can't create correct Strategy for Buy and Sell trades. It appears that using the HMA values do not follow the smooth curve of the average line.
 
@tlee404 Note that your buy/sell condition as described is that of a state rather than an event
I have whipped up a HMA Strategy and color coded the candles on the chart as well.

Code:
# HMA Strategy
# tomsk
# 12.3.2019

input price = close;
input length = 21;
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"));

AssignPriceColor(if HMA > HMA[1] 
                 then HMA.color("Up") 
                 else HMA.color("Down"));

AddOrder(OrderType.BUY_AUTO, HMA crosses above HMA[1], low[-1], tickcolor = Color.YELLOW, arrowcolor = Color.YELLOW, name = "HMA Bull");
AddOrder(OrderType.Sell_AUTO, HMA crosses below HMA[1], low[-1], tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "HMA Bear");
# End HMA Strategy
 

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

@tomsk I know that you just whipped that up. Incredible! I'd like to be that fast but at my age, speed is declining.
To all, Alan Hull doesn't advocate using two HMA as cross overs for signals. The way @tomsk created the above is correct; one HullMA that gives the signal when polarity changes.
 
@tomsk I know that you just whipped that up. Incredible! I'd like to be that fast but at my age, speed is declining.
To all, Alan Hull doesn't advocate using two HMA as cross overs for signals. The way @tomsk created the above is correct; one HullMA that gives the signal when polarity changes.

@markos You're too kind. The methodology is similar across most studies and so after doing a few iterations, tacking on additional studies is pretty much a cookie cutter
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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