Unable to crease strategy for HMA color change

T

tlee404

New 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.
 
T

tomsk

Well-known member
VIP
Warehouse
@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
 
markos

markos

Well-known member
VIP
Warehouse
@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.
 
T

tomsk

Well-known member
VIP
Warehouse
@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
 
Thread starter Similar threads Forum Replies Date
2 Questions 8
Z Questions 0

Top