
이 전략은 QuantNomad에서 개발한 UT Bot 지표에 기반하고, 모바일 정지 (mobile stop loss) 의 사고를 결합한다. @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")