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[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2
hahigh = max(high, max(haopen, haclose))
halow = min(low, min(haopen, haclose))
//// === HA MA Variables === ////
haChart1 = ((haclose+haopen+hahigh+halow)/4)[1]
haChart2 = ((haclose+haopen+hahigh+halow)/4)[2]
haChart3 = ((haclose+haopen+hahigh+halow)/4)[3]
haChart4 = ((haclose+haopen+hahigh+halow)/4)[4]
haChart5 = ((haclose+haopen+hahigh+halow)/4)[5]
haChart6 = ((haclose+haopen+hahigh+halow)/4)[6]
haChart7 = ((haclose+haopen+hahigh+halow)/4)[7]
haChart8 = ((haclose+haopen+hahigh+halow)/4)[8]
//// === HA MA === ////
haCloseChart = ((haChart1+haChart2+haChart3+haChart4+haChart5+haChart6+haChart7+haChart8)/8)[1]
//// === HA & MACD Triggers === ////
long = crossunder(haCloseChart, bblower) and bblower[1] < haCloseChart[1] 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")
//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[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2
hahigh = max(high, max(haopen, haclose))
halow = min(low, min(haopen, haclose))
//// === HA MA Variables === ////
haChart1 = ((haclose+haopen+hahigh+halow)/4)[1]
haChart2 = ((haclose+haopen+hahigh+halow)/4)[2]
haChart3 = ((haclose+haopen+hahigh+halow)/4)[3]
haChart4 = ((haclose+haopen+hahigh+halow)/4)[4]
haChart5 = ((haclose+haopen+hahigh+halow)/4)[5]
haChart6 = ((haclose+haopen+hahigh+halow)/4)[6]
haChart7 = ((haclose+haopen+hahigh+halow)/4)[7]
haChart8 = ((haclose+haopen+hahigh+halow)/4)[8]
//// === HA MA === ////
haCloseChart = ((haChart1+haChart2+haChart3+haChart4+haChart5+haChart6+haChart7+haChart8)/8)[1]
//// === HA & MACD Triggers === ////
long = crossunder(haCloseChart, bblower) and bblower[1] < haCloseChart[1] 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")
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.