Hey all,
My name is Phil and I've been trading for a little over a year now. I trade futures on the S&P500 e-mini using a prop firm. I've been using a Hull MA indicator and I find it quite useful in my trading. I'm trying to convert it to a strategy but can't get the buy and sell conditions to work. Script is below and any help would be apricated.
//@version=5
strategy(title='Hull MA & Warning Zones & Buy/Sell Arrows', overlay=true)
//inputs
n = input(title='MA period', defval=9) //period
el = input(true, title='Show 1st MA - entry line') //show 1nd HMA entry line
trl = input(false, title='Show 2nd MA - trendline') //show 2nd HMA trendline
pld = input(true, title='Show Downtrend - red line') //Show Downtrend
plu = input(true, title='Show Uptrend - green line') //Show Uptrend
plr = input(true, title='Show Reversing trend - yellow line') //Show trend change
plb = input(true, title='Show Line background - black line') //Show Line background
pla = input(false, title='Show buy/sell arrows') //Show buy/sell arrows
useCurrentRes = input(false, title='Use Current Chart Resolution for 2nd MA') //use custom resolution
resCustom = input.timeframe(title='Timeframe for 2nd MA, Standart - 4h', defval='240') //resolution for 2nd HMA
res = useCurrentRes ? timeframe.period : resCustom
//functions
n2ma = 2 * ta.wma(close, math.round(n / 2))
nma = ta.wma(close, n)
diff = n2ma - nma
sqn = math.round(math.sqrt(n))
n2ma1 = 2 * ta.wma(close[1], math.round(n / 2))
nma1 = ta.wma(close[1], n)
diff1 = n2ma1 - nma1
sqn1 = math.round(math.sqrt(n))
n1 = ta.wma(diff, sqn)
n2 = ta.wma(diff1, sqn)
n3 = n1 - n1 * -1
n4 = n1 + n1
//colors
dif = n1[1] - n3
dif1 = dif > dif[1] and dif[1] > dif[2] ? na : color.lime //uptrend - green
dif3 = n4 - n1[1]
dif2 = dif3 > dif3[1] and dif3[1] > dif3[2] ? na : color.red //downtrend - red
dif4 = (dif > dif[1] and dif[1] > dif[2]) == (dif3 > dif3[1] and dif3[1] > dif3[2]) ? color.yellow : na //trend change - yellow
c = n1 > n2 ? color.lime : color.red //fill red/lime
//periods
outn1 = request.security(syminfo.tickerid, res, n1) //MA custom res
outc = request.security(syminfo.tickerid, res, c) //fill red/lime custom res
outdif = request.security(syminfo.tickerid, res, dif)
outdif1 = request.security(syminfo.tickerid, res, dif1) //uptrend green custom res
outdif2 = request.security(syminfo.tickerid, res, dif2) //downtrend red custom res
outdif3 = request.security(syminfo.tickerid, res, dif3)
outdif4 = request.security(syminfo.tickerid, res, dif4) //trend change yellow custom res
//plots - 2nd line
sma = plot(trl and outn1 ? outn1 : na, color=outdif1, linewidth=25, transp=80) //2nd green
sma2 = plot(trl and outn1 ? outn1 : na, color=outdif2, linewidth=25, transp=80) //2nd red
sma3 = plot(trl and outn1 ? outn1 : na, color=outdif4, linewidth=25, transp=90) //2nd yellow
//plots - 1st line
mab = plot(el and n1 and plb ? n1 : na, color=color.new(color.black, 0), linewidth=4, title='Background line') //black
ma = plot(el and n1 and plu ? n1 : na, color=dif1, linewidth=2, transp=10) //green
ma2 = plot(el and n1 and pld ? n1 : na, color=dif2, linewidth=2, transp=20) //red
ma3 = plot(el and n1 and plr ? n1 : na, color=dif4, linewidth=2, transp=10) //yellow
long = dif < dif[1] and dif[1] >= dif[2] //long condition
short = dif3 < dif3[1] and dif3[1] >= dif3[2] //short condition
//plots - arrows and alerts
longarrow = long == 1 ? 1 : na
shortarrow = short == 1 ? -1 : na
plotarrow(pla and longarrow ? longarrow : na, colorup=color.new(color.aqua, 50))
plotarrow(pla and shortarrow ? shortarrow : na, colordown=color.new(color.red, 50))
// Buy condition
if (c[1] == color.lime)
strategy.entry("Long", strategy.long)
// Sell condition
if (c[1] == color.red)
strategy.close("Long", "Long")