Hi, I’ve been playing around with a simple trend-following code using TEMA but would prefer to have it work with the HULL MA, which is what I use for manual trading. I understand that v11 supports HullAverage[period](price) but I’m still working with v10.3 and it doesn’t recognise that syntax. How would I go about modifying the code below for Hull instead of Tema?
Hugely grateful for any help!
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = TEMA[21](typicalPrice)
indicator2 = TEMA[21](typicalPrice)
c1 = (indicator1 > indicator2[1])
IF c1 AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = TEMA[21](typicalPrice)
indicator4 = TEMA[21](typicalPrice)
c2 = (indicator3 < indicator4[1])
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator5 = TEMA[21](typicalPrice)
indicator6 = TEMA[21](typicalPrice)
c3 = (indicator5 < indicator6[1])
IF c3 AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
indicator7 = TEMA[21](typicalPrice)
indicator8 = TEMA[21](typicalPrice)
c4 = (indicator7 > indicator8[1])
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
indicator1 = Average[21,8](typicalPrice)
Try above, I’ve had a few of my Systems use above successfully, but others say v10.3 doesn’t recognise Hull??
Let us know how you go on?
You can hard code the Hull average calculation into your strategy. Try this which has 21 period hull average based on typical price (not tested).
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Period=21
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
hull = weightedaverage[round(sqrt(Period))](inner)
// Conditions to enter long positions
c1 = hull > hull[1])
c2 = hull < hull[1])
IF c1 AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
IF c2 AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
IF c1 THEN
EXITSHORT AT MARKET
ENDIF
If GraHal’s suggestion doesn’t work you can use the HULL indicator in the library https://www.prorealcode.com/prorealtime-indicators/hull-moving-average/.
Hey, thanks for that, I’ll try it as an option. What I was really looking for though is how to hardcode a definition of the Hull MA, which I believe is something like this. I just don’t know how to make it work!
Period=20
inner = 2*weightedaverage[ round( Period/2 ) ](close)-weightedaverage[Period](close)
MMHULL=weightedaverage[ round( sqrt(Period) ) ]( inner )
return MMHULL
Vonasi, you are a megastar – thanks, exactly what I wanted!
Thanks too to all others, very much appreciated!