TradingView
SeaSide420
Nov 12, 2016 8:27 PM

HullMA cross Strategy 

U.S. Dollar/Japanese YenFXCM

Description

From Indicator420 by SeaSide420 HULL MOVING AVERAGE CROSS & CANDLE CROSS

Hull Moving Average (HMA) formula
Integer(SquareRoot(Period)) WMA (2 x Integer(Period/2) WMA(Price) - Period WMA(Price))

Solving the problem of lag requires an explanation with numbers rather than charts. Consider a series of 10 numbers from '0' to '9' inclusive and imagine that they are successive price points on a chart with 9 being the most recent price point at the right hand leading edge.
If we take the 10 period simple average of these numbers then, not surprisingly, we will determine the midpoint of 4.5 which significantly lags behind the most recent price point of 9. Here's the clever bit, first let's halve the period of the average to 5 and apply it to the most recent numbers of 5, 6, 7, 8 and 9, the result being the midpoint of 7.
To remove the lag we take the midpoint of 7 and add the difference between the two averages which equals 2.5 (7 - 4.5). This gives a final answer of 9.5 (7 + 2.5) which is a slight overcompensation. But this overcompensation is very handy because it offsets the lagging effect of the nested averaging.
Hence the result of combining these 2 techniques is a near perfect balance between lag reduction and curve smoothing. The HMA manages to keep up with rapid changes in price activity whilst having superior smoothing over an SMA of the same period.
The HMA employs weighted moving averages and dampens the smoothing effect (and resulting lag) by using the square root of the period instead of the actual period itself.
There are 3 HullMAs in the script, one runs on current price, and others on previous candle prices, when they cross over, is the entry signal.
The strategy also includes a candle cross condition for entry:
(if current price greater than previous candle value (Open+High+Low+Close)/4) then BUY
(if current price less than previous candle value (Open+High+Low+Close)/4) then SELL
in total 4 crossover conditions must be met to initiate a signal.

Release Notes

put in the Backteser History data settings
Comments
SeaSide420
//@version=2
//From Indicator420 by SeaSide420 HULL MOVING AVERAGE CROSS & CANDLE CROSS
strategy("Indicator420 Strategy", shorttitle="HMA_X", overlay=true, default_qty_type=strategy.percent_of_equity, max_bars_back=420, default_qty_value=100, calc_on_order_fills= true, calc_on_every_tick=true, pyramiding=0)
z=input(type=integer,defval=26,title="HullMA cross")
p=input(ohlc4,type=source,title="Price data")
n2ma=2*wma(p,round(z/2))
nma=wma(p,z)
diff=n2ma-nma
sqn=round(sqrt(z))
n2ma1=2*wma(p[1],round(z/2))
nma1=wma(p[1],z)
diff1=n2ma1-nma1
sqn1=round(sqrt(z))
n2ma2=2*wma(p[2],round(z/2))
nma2=wma(p[2],z)
diff2=n2ma2-nma2
sqn2=round(sqrt(z))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
n3=wma(diff2,sqn)
c=n1>n2?green:red
n1e=plot(n1, color=c, linewidth=1, offset=2)
n2e=plot(n2, color=c, linewidth=1, offset=2)
fill(n1e, n2e, color=c, transp=75)
plot(cross(n1, n2) ? n1 : na, style = circles,color=c, linewidth = 4)
closelong = p<p[1] and n1<n3
if (closelong)
strategy.close("BUY")
closeshort = p>p[1] and n1>n3
if (closeshort)
strategy.close("SELL")
longCondition = strategy.opentrades<1 and n1>n2 and p>p[1] and n1>n3
if (longCondition)
strategy.entry("BUY",strategy.long)
shortCondition = strategy.opentrades<1 and n1<n2 and p<p[1] and n1<n3
if (shortCondition)
strategy.entry("SELL",strategy.short)
ajay1984
@SeaSide420, excellent
SeaSide420
//@version=3
//From Indicator420 by SeaSide420 HULL MOVING AVERAGE CROSS & CANDLE CROSS
strategy("Indicator420 Strategy", shorttitle="HMA_X", overlay=true, default_qty_type=strategy.percent_of_equity, max_bars_back=200, commission_type=strategy.commission.percent, commission_value=0.2, default_qty_value=100, calc_on_order_fills= true, calc_on_every_tick=true, pyramiding=0)
z=input(type=integer,defval=26,title="HullMA cross")
p=input(ohlc4,type=source,title="Price data")
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2017, title = "From Year", minval = 2017)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 2017)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
n2ma=2*wma(p,round(z/2))
nma=wma(p,z)
diff=n2ma-nma
sqn=round(sqrt(z))
n2ma1=2*wma(p[1],round(z/2))
nma1=wma(p[1],z)
diff1=n2ma1-nma1
sqn1=round(sqrt(z))
n2ma2=2*wma(p[2],round(z/2))
nma2=wma(p[2],z)
diff2=n2ma2-nma2
sqn2=round(sqrt(z))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
n3=wma(diff2,sqn)
c=n1>n2?green:red
n1e=plot(n1, color=c, linewidth=1, offset=2)
n2e=plot(n2, color=c, linewidth=1, offset=2)
fill(n1e, n2e, color=c, transp=75)
plot(cross(n1, n2) ? n1 : na, style = circles,color=c, linewidth = 4)
closelong = p<p[1] and n1<n3
if (closelong)
strategy.close("BUY", when=window())
closeshort = p>p[1] and n1>n3
if (closeshort)
strategy.close("SELL", when=window())
longCondition = strategy.opentrades<1 and n1>n2 and p>p[1] and n1>n3
if (longCondition)
strategy.entry("BUY",strategy.long, when=window())
shortCondition = strategy.opentrades<1 and n1<n2 and p<p[1] and n1<n3
if (shortCondition)
strategy.entry("SELL",strategy.short, when=window())
N0S41NT
@SeaSide420, Hey man. Does this have repainting issues?
SeaSide420
@N0S41NT, maybe, maybe not, im not sure. please test then comment with result.
i only trading with MT4 bot
SeaSide420
SeaSide420
please if want code just private message me i give it no problem
ReapBtC
@SeaSide420, hi can i have access please looks nice
aahoffert
@SeaSide420, can I have access to the code please?
SeaSide420
justpaste.it/477kj <---- script
More