本策略基于KPL波动指标进行交易,是一种简单的趋势跟踪机械交易系统。当价格收盘突破20天高点时做多,收盘跌破20天低点时做空,以捕捉中长线的价格波动。
具体来说,该策略首先计算过去20天的最高价和最低价,以此构建出震荡范围。当收盘价从下方突破20天高点时,做多入场;从上方跌破20天低点时,做空入场。同时在突破方向计算止损位,入场后立即设置止损单,以控制单笔亏损。
可通过调整观察突破周期,引入趋势判断,优化止损策略等方式来管理风险。
本策略基于KPL波动指标进行趋势跟踪。优点是简单易操作,有止损;缺点是存在滞后和潜在收益有限。可通过参数优化、策略组合等方式在保持优势的同时改进缺点。该策略可助交易者掌握基于指标的机械交易方法。
/*backtest
start: 2022-09-20 00:00:00
end: 2023-09-20 00:00:00
period: 2d
basePeriod: 1d
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/
// © ceyhun
//@version=4
strategy("KPL Swing Strategy", overlay=true)
no = input(20)
res = highest(high, no)
sup = lowest(low, no)
avd = iff(close > res[1], 1, iff(close < sup[1], -1, 0))
avn = valuewhen(avd != 0, avd, 1)
tsl = iff(avn == 1, sup, res)
sl = iff(close > tsl, highest(lowest(low, no / 2), no / 2), lowest(highest(high, no / 2), no / 2))
plot(tsl, color=#0000FF,title="KPL Swing")
plot(sl, color=color.white,title="Stoploss")
bgcolor(abs(close - tsl[1]) > close ? color.white : close < tsl ? color.red : color.green, 90, offset=0)
if crossover(close, tsl)
strategy.entry("Long", strategy.long, comment="Long")
if crossunder(close,tsl)
strategy.entry("Short", strategy.short, comment="Short")