This strategy is based on the UT Bot indicator developed by QuantNomad and incorporates the idea of a trailing stop loss. The original code was written by @Yo_adriiiiaan and modified by @HPotter. The strategy will be used in conjunction with LuxAlgo’s Smart Money Concepts. Currently, the strategy is in the testing phase.
The main principles of this strategy are as follows:
Based on the UT Bot indicator, this strategy incorporates trailing stop logic, which can protect profits in trend markets. At the same time, the strategy sets stop losses separately for long and short positions, making it highly adaptable. Using ATR as a reference for the trailing stop allows for dynamic adjustment of the stop loss position, improving flexibility. However, this strategy may face the risk of high transaction costs due to frequent stop-outs in choppy markets, and it lacks a trailing profit target setting, which may miss profit opportunities. In addition, the choice of parameters has a significant impact on strategy performance.
In the future, the strategy can be improved by optimizing entry conditions, exploring more complex trailing stop methods, adding a trailing profit target mechanism, and optimizing parameters for different varieties and cycles, in order to obtain more stable returns. Overall, the strategy idea is simple and straightforward, easy to understand and implement, but there is room for further optimization and it is worth continuing to explore and improve.
/*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")template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6