本策略基于Keltner通道指标设计了一个回抽交易策略。该策略通过比较价格与Keltner通道上下轨的关系,判断价格可能反转的时机,采取适当的做多做空操作。
本策略使用Keltner通道指标判断价格趋势。Keltner通道由均线和平均真实波幅(ATR)构成。通道上轨等于均线加上ATR的N倍;下轨等于均线减去ATR的N倍。当价格从下向上突破通道下轨时,认为多头力量增强,可以做多;当价格从上向下突破通道上轨时,认为空头力量增强,可以做空。
另外,本策略判断回抽机会的依据是价格重新触碰或突破通道边界。比如,价格上涨突破下轨后,在没有触碰上轨的情况下再次下跌触碰下轨,这就是一个做多回抽的机会。策略会在这个时候开仓做多。
这是一个利用价格回抽特性进行交易的策略。它的优势在于:
该策略的主要风险在于:
对策: 1. 优化参数,调整通道宽度,适应市场环境。 2. 加大仓位管理,降低单笔损失。
该策略可以从以下几个方面进行优化:
本策略整合了趋势判断和回抽交易的方法,在捕捉反转行情方面具有独特优势。通过参数调整和功能扩展,可以进一步增强策略的稳定性和盈利能力。
/*backtest
start: 2023-11-26 00:00:00
end: 2023-12-26 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("Keltner bounce from border. No repaint. (by Zelibobla)", shorttitle="Keltner border bounce", overlay=true)
price = close
// build Keltner
keltnerLength = input(defval=200, minval=1, title="Keltner EMA Period Length")
keltnerATRLength = input(defval=200, minval=1, title="Keltner ATR Period Length (the same as EMA length in classic Keltner Channels)")
keltnerDeviation = input(defval=8, minval=1, maxval=15, title="Keltner band width (in ATRs)")
closeOnEMATouch = input(type=bool, defval=false, title="Close trade on EMA touch? (less drawdown, but less profit and higher commissions impact)")
enterOnBorderTouchFromInside = input(type=bool, defval=false, title="Enter on border touch from inside? (by default from outside, which is less risky but less profitable)")
SL = input(defval=50, minval=0, maxval=10000, title="Stop loss in ticks (leave zero to skip)")
EMA = sma(price, keltnerLength)
ATR = atr(keltnerATRLength)
top = EMA + ATR * keltnerDeviation
bottom = EMA - ATR * keltnerDeviation
buyEntry = crossover(price, bottom)
sellEntry = crossunder(price, top)
plot(EMA, color=aqua,title="EMA")
p1 = plot(top, color=silver,title="Keltner top")
p2 = plot(bottom, color=silver,title="Keltner bottom")
fill(p1, p2)
tradeSize = input(defval=1, minval=1, title="Trade size")
if ( enterOnBorderTouchFromInside and crossunder(price, bottom) )
strategy.entry("BUY", strategy.long, qty=tradeSize, comment="BUY")
else
if( crossover(price, bottom) )
strategy.entry("BUY", strategy.long, qty=tradeSize, comment="BUY")
if( crossover(price,EMA) and closeOnEMATouch )
strategy.close("BUY")
if( 0 != SL )
strategy.exit("EXIT BUY", "BUY", qty=tradeSize, loss=SL)
strategy.exit("EXIT SELL", "SELL", qty=tradeSize, loss=SL)
if( enterOnBorderTouchFromInside and crossover(price, bottom) )
strategy.entry("SELL", strategy.long, qty=tradeSize, comment="SELL")
else
if ( crossunder(price, top) )
strategy.entry("SELL", strategy.short, qty=tradeSize, comment="SELL")
if( crossunder(price, EMA) and closeOnEMATouch )
strategy.close("SELL")