三均线交叉动量策略是一种典型的跟踪市场趋势的技术指标策略。它结合了16周期、36周期和72周期的三条简单移动平均线,通过它们的多头交叉和空头交叉来判断市场趋势,并结合考夫曼自适应移动平均线作为过滤器,在趋势方向比较明确时,采取做多或做空的操作。
该策略的核心指标是16周期、36周期和72周期三条简单移动平均线。当短周期均线上穿较长周期的均线时,表明市场进入多头趋势;当短周期均线下穿较长周期均线时,表明市场进入空头趋势。例如,16均线上穿36均线和72均线时,为多头信号;16均线下穿36均线和72均线时,为空头信号。
考夫曼自适应移动平均线(KAMA)被用作过滤器,来避免在趋势不明确的情况下出现错误信号。只有在KAMA处于非加速或非减速模式下(即线性段落),均线交叉信号才会被激活执行。
策略通过跟踪均线的交叉情况,在趋势较为明朗时,采取做多或做空的操作。做多条件是16均线上穿36均线和72均线,且KAMA线性(非加速);做空条件是16均线下穿36均线和72均线,且KAMA线性(非减速)。
该策略具有如下优势:
该策略也存在一些风险:
可以通过适当调整均线参数,设置止损约束,或只在波动较大的市场使用该策略来降低风险。
该策略可以通过以下方式进行优化:
三均线交叉动量策略整体来说是一个较为经典和实用的跟踪趋势型策略。它通过多时间段均线的交叉来判断市场中长线走势,并有效过滤了部分噪音。可以作为选时交易的参考指标之一。但该策略也存在一定弱点,需要进一步扩展和优化,才能在更广泛的市场中立足。
/*backtest
start: 2023-11-24 00:00:00
end: 2023-12-24 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Wielkieef
//@version=5
strategy(title='Three SMA-crossover strategy [30min] ', overlay=true, pyramiding=1, initial_capital=10000, default_qty_type=strategy.cash, default_qty_value=10000, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.03)
src = close
Length1 = input.int(16, title=' 1-SMA Lenght', minval=1, group='SMA')
Length2 = input.int(36, title=' 2-SMA Lenght', minval=1, group='SMA')
Length3 = input.int(72, title=' 3-SMA Lenght', minval=1, group='SMA')
SMA1 = ta.sma(close, Length1)
SMA2 = ta.sma(close, Length2)
SMA3 = ta.sma(close, Length3)
Long_ma = SMA1 > SMA2 and SMA2 > SMA3
Short_ma = SMA1 < SMA2 and SMA2 < SMA3
LengthMainSMA = input.int(100, title=' Trend SMA ', minval=1)
SMAas = ta.sma(src, LengthMainSMA)
// Powered Kaufman Adaptive Moving Average by alexgrover (modificated by Wielkieef)
lengthas = input.int(50, title=' KAMA Lenght')
sp = input.bool(true, title=' Self Powered')
er = math.abs(ta.change(close, lengthas)) / math.sum(math.abs(ta.change(close)), lengthas)
pow = sp ? 1 / er : 2
per = math.pow(math.abs(ta.change(close, lengthas)) / math.sum(math.abs(ta.change(close)), lengthas), pow)
a = 0.
a := per * src + (1 - per) * nz(a[1], src)
mad4h = 0.
a_f = a / a[1] > .999 and a / a[1] < 1.001
///.
Bar_color = close > SMAas ? color.green : Long_ma ? color.blue : Short_ma ? color.maroon : color.gray
barcolor(color=Bar_color)
long_cond = Long_ma and SMAas < close and not a_f and close > a
short_cond = Short_ma and SMAas > close and not a_f and close < a
long_stop = Short_ma and SMAas < close
short_stop = Long_ma and SMAas > close
SMA1plot = plot(SMA1, color=Bar_color, linewidth=2)
SMA2plot = plot(SMA2, color=Bar_color, linewidth=4)
SMA3plot = plot(SMA3, color=Bar_color, linewidth=2)
fill(SMA1plot,SMA3plot,title="RANGE " ,color = color.new(Bar_color, 50))
if long_cond
strategy.entry('Long', strategy.long)
if short_cond
strategy.entry('Short', strategy.short)
strategy.close_all(when=long_stop or short_stop)
//by wielkieef