FiatExIntl

HA Moving Ave with MACD and BB

Long
KRAKEN:XMRUSD   Monero
Using a HA moving average that you'll see below, with a BB and MACD crossover as a trigger. Created one for a Long and Short strategy to be used on a Daily chart only after the trend had been confirmed in the weekly.

//@version=3
strategy("HA & BB Long Strategy", overlay = true)

// === BACKTEST RANGE === //
FromMonth = input(defval = 1, title = "From Month", minval = 1)
FromDay = input(defval = 1, title = "From Day", minval = 1)
FromYear = input(defval = 2020, title = "From Year", minval = 2014)
ToMonth = input(defval = 1, title = "To Month", minval = 1)
ToDay = input(defval = 1, title = "To Day", minval = 1)
ToYear = input(defval = 9999, title = "To Year", minval = 2014)

//// === MACD Settings === ////
MacdSrc = input(close, title="Source")

macdfastLength = input(24, minval=1)
macdslowLength=input(26, minval=1)
macdsignalLength = input(9, minval=1)

fastMA = ema(MacdSrc, macdfastLength)
slowMA = ema(MacdSrc, macdslowLength)
macd = fastMA - slowMA
macdsignal = sma(macd, macdsignalLength)

buyMACD = macd >= macdsignal
sellMACD = macd <= macdsignal

// === Bollinger Band === //
BBsrc = input(open, title = "source")

len = input(4, title = "timeframe / # of period's")
bbbase = ema(BBsrc,len)
evar = (BBsrc - bbbase)*(BBsrc - bbbase)
evar2 = (sum(evar,len))/len
std = sqrt(evar2)
Multiplier = input(1, minval = 0.01, title = "# of STDEV's")
bbupper = bbbase + (Multiplier * std)
bblower = bbbase - (Multiplier * std)


//// ==== Calculation HA Values ==== ////
haopen = 0.0
haclose = ((open + high + low + close)/4)
haopen := na(haopen) ? (open + close)/2 : (haopen + haclose) / 2
hahigh = max(high, max(haopen, haclose))
halow = min(low, min(haopen, haclose))

//// === HA MA Variables === ////
haChart1 = ((haclose+haopen+hahigh+halow)/4)
haChart2 = ((haclose+haopen+hahigh+halow)/4)
haChart3 = ((haclose+haopen+hahigh+halow)/4)
haChart4 = ((haclose+haopen+hahigh+halow)/4)
haChart5 = ((haclose+haopen+hahigh+halow)/4)
haChart6 = ((haclose+haopen+hahigh+halow)/4)
haChart7 = ((haclose+haopen+hahigh+halow)/4)
haChart8 = ((haclose+haopen+hahigh+halow)/4)

//// === HA MA === ////
haCloseChart = ((haChart1+haChart2+haChart3+haChart4+haChart5+haChart6+haChart7+haChart8)/8)

//// === HA & MACD Triggers === ////

long = crossunder(haCloseChart, bblower) and bblower < haCloseChart and buyMACD and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))

short = sellMACD and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))


if (long)
strategy.entry("BUY",strategy.long)

if (short)
strategy.close_all(when=short)

plot(haCloseChart, color=red, linewidth=2)
plot(bbupper, color = blue, linewidth = 1, title = "BB Upper band")
plot(bblower, color = blue, linewidth = 1, title = "BB Down band")
Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.