本策略是一个结合了Supertrend指标和考夫曼自适应移动平均线(KAMA)的趋势跟踪交易系统。该策略通过动态识别市场趋势变化,在上升趋势中寻找做多机会,并采用灵活的止损机制来控制风险。策略的核心思想是利用Supertrend指标的趋势方向判断能力,结合KAMA指标对市场波动的自适应特性,在市场上涨趋势中建立多头仓位。
策略采用了双重技术指标确认系统。首先,Supertrend指标通过ATR和自定义系数计算趋势方向,当指标线位于价格下方时表示上升趋势。其次,KAMA指标通过自适应机制调整移动平均线的敏感度,能够更好地适应不同市场环境。入场信号需同时满足两个条件:Supertrend指示上升趋势且价格位于KAMA线之上。同样,出场信号也需要双重确认:Supertrend转为下降趋势且价格跌破KAMA线。这种双重确认机制有效降低了虚假信号的影响。
该策略通过结合Supertrend和KAMA两个技术指标,构建了一个稳健的趋势跟踪交易系统。策略的主要优势在于其自适应性和风险控制能力,通过双重确认机制提高了交易信号的可靠性。虽然在震荡市场中可能面临一些挑战,但通过合理的参数设置和优化方向的实施,策略的整体表现可以得到进一步提升。该策略特别适合中长期趋势交易,在明确趋势的市场环境中表现较好。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Supertrend + KAMA Long Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)
// User-defined inputs for date range
startDate = input(timestamp("2018-01-01 00:00:00"), title="Start Date")
endDate = input(timestamp("2069-12-31 23:59:59"), title="End Date")
inDateRange = true
// Inputs for KAMA and Supertrend
kamaLength = input.int(21, title="KAMA Length", minval=1)
atrPeriod = input.int(10, title="Supertrend ATR Length", minval=1)
factor = input.float(3.0, title="Supertrend Factor", minval=0.01, step=0.01)
//------------------------- Kaufman Moving Average Adaptive (KAMA) -------------------------
xPrice = close
xvnoise = math.abs(xPrice - xPrice[1])
Length = kamaLength
nfastend = 0.666
nslowend = 0.0645
nsignal = math.abs(xPrice - xPrice[Length])
float nnoise = 0.0
for i = 0 to Length - 1
nnoise := nnoise + xvnoise[i]
nefratio = nnoise != 0.0 ? nsignal / nnoise : 0.0
nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
var float nAMA = na
nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
plot(nAMA, color=color.blue, linewidth=2, title="Kaufman KAMA")
//------------------------- Supertrend Calculation -------------------------
[stValue, dirValue] = ta.supertrend(factor, atrPeriod)
upTrend = dirValue < 0
downTrend = dirValue >= 0
plot(dirValue < 0 ? stValue : na, "Up Trend", color=color.green, style=plot.style_linebr)
plot(dirValue >= 0 ? stValue : na, "Down Trend", color=color.red, style=plot.style_linebr)
//------------------------- Strategy Logic -------------------------
// Entry condition: Supertrend is in uptrend AND price is above KAMA
canLong = inDateRange and upTrend and close > nAMA
// Exit condition (Take Profit): Supertrend switches to downtrend AND price is below KAMA
stopLoss = inDateRange and downTrend and close < nAMA
if canLong
strategy.entry("Long", strategy.long)
label.new(bar_index, low, "BUY", color=color.green, textcolor=color.white, style=label.style_label_down, size=size.normal)
if stopLoss
strategy.close("Long", comment="Stop Loss")
label.new(bar_index, high, "STOP LOSS", color=color.red, textcolor=color.white, style=label.style_label_up, size=size.normal)
//------------------------- Alerts -------------------------
alertcondition(canLong, title="Long Entry", message="Supertrend + KAMA Long Signal")
alertcondition(stopLoss, title="Stop Loss", message="Supertrend switched to Downtrend and Price below KAMA")