该策略基于QuantNomad开发的UT Bot指标,结合了移动止损的思路。原始代码由@Yo_adriiiiaan编写,@HPotter进行了修改。该策略将与LuxAlgo的Smart Money Concepts配合使用。目前该策略处于测试阶段。
该策略的主要原理如下:
该策略在UT Bot指标的基础上,加入了移动止损的逻辑,能够在趋势行情中起到保护利润的作用。同时,策略对多头和空头仓位分别设置止损,适应性较强。使用ATR作为移动止损的参考依据,可以动态调整止损位置,提高灵活性。但是,该策略在震荡行情中可能面临频繁止损带来的高交易成本风险,且缺乏移动止盈的设置,有错失盈利的可能。此外,参数的选择对策略表现有较大影响。
未来,可以从优化进场条件、探索更复杂的移动止损方式、加入移动止盈机制、针对不同品种和周期进行参数优化等方面对策略进行完善,以期获得更稳健的收益。总的来说,该策略思路简单明了,易于理解和实现,但还有进一步优化的空间,值得继续探索和改进。
/*backtest start: 2023-03-05 00:00:00 end: 2024-03-10 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy("Trailingstop", overlay=true) if close > sma(close, 50) strategy.entry("long", strategy.long) // Trailing stop loss for long positions Trailperc = 0.20 price_stop_long = 0.0 if (strategy.position_size > 0) stopValue = close * (1 - Trailperc) price_stop_long := max(stopValue, price_stop_long[1]) else price_stop_long := 0 if (strategy.position_size > 0) strategy.exit(id="stoploss_long", stop=price_stop_long) // Trailing stop loss for short positions Trailperc_short = 0.20 price_stop_short = 0.0 if (strategy.position_size < 0) stopValue_short = close * (1 + Trailperc_short) price_stop_short := min(stopValue_short, price_stop_short[1]) else price_stop_short := 0 if (strategy.position_size < 0) strategy.exit(id="stoploss_short", stop=price_stop_short) // ATR Trailing Stop for visualization keyvalue = input(3, title="Key Value. 'This changes the sensitivity'", step=0.5) atrperiod = input(10, title="ATR Period") xATR = atr(atrperiod) nLoss = keyvalue * xATR xATRTrailingStop = 0.0 xATRTrailingStop := iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss))) pos = 0 pos := iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1, iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue plot(xATRTrailingStop, color = xcolor, title = "Trailing Stop")