渐变追踪止损策略通过动态调整止损线,实现风险控制和止盈截取的有机结合。它使用平均真实波动范围计算止损线,可有效跟踪股价趋势,在保护利润的同时减少不必要的止损。该策略适用于趋势较强的股票,可获得稳定收益。
该策略使用计算平均真实波动范围(ATR)作为动态止损的基础。ATR可以有效反映股票的波动性。策略先输入ATR周期参数,典型为10天。然后计算出ATR值。股价上涨时,止损线也会随之上移,是动态追踪的;当股价下跌时,止损线保持不变,可锁定利润。同时,策略允许通过“因子”参数微调止损线与股价的距离。
具体来说,策略计算当前K线的ATR值,然后乘以“因子”参数,得到止损距离。如果股价高于止损价格,则开多仓;如果股价低于止损价格,则开空仓。这样,止损线就会紧貼股价运行,实现止损线的渐变追踪效果。
渐变追踪止损策略通过动态调整止损距离,实现了风险控制与止盈截取的有效平衡。该策略操作简单,可自定义度高,适用于机器人自动交易。当然,合理的参数选择和指标组合仍需人工经验。通过进一步优化,该策略可望获取更加稳定的投资回报。
/*backtest
start: 2023-10-17 00:00:00
end: 2023-10-24 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Supertrend Strategy, by Ho.J.", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=15)
// 백테스팅 시작일과 종료일 입력
startYear = input(2020, title="Start Year")
startMonth = input(1, title="Start Month")
startDay = input(1, title="Start Day")
endYear = input(9999, title="End Year")
endMonth = input(12, title="End Month")
endDay = input(31, title="End Day")
// 백테스팅 시간 범위 확인
backtestingTimeBool = (year >= startYear and month >= startMonth and dayofmonth >= startDay) and (year <= endYear and month <= endMonth and dayofmonth <= endDay)
atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)
[_, direction] = ta.supertrend(factor, atrPeriod)
var bool longCondition = false
var bool shortCondition = false
if backtestingTimeBool
prevDirection = direction[1]
if direction < 0
longCondition := false
shortCondition := true
else if direction > 0
longCondition := true
shortCondition := false
if longCondition
strategy.entry("My Long Entry Id", strategy.long)
if shortCondition
strategy.entry("My Short Entry Id", strategy.short)
plot(strategy.equity, title="equity", color=color.rgb(255, 255, 255), linewidth=2, style=plot.style_area)