
이 전략은 ATR (Average True Range) 지표와 SMA (Simple Moving Average) 지표를 결합하여 동적 스톱 손실 추적 거래 시스템을 구현한다. 가격이 SMA보다 높을 때 다중 주문을 하고, 동시에 ATR 기반의 동적 스톱 손실을 설정하면, 스톱 가격이 가격 상승에 따라 계속 상승한다. 가격이 동적 스톱 손실 가격을 깨면 평지한다. 이 전략의 주요 아이디어는 트렌드 상황에서 동적 스톱 손실을 사용하여 수익을 고정하고, 철수를 감소시키는 것이다.
이 전략은 ATR 및 SMA 지표를 기반으로 동적 스톱 손실 추적 거래 시스템을 구현하여 트렌드 상황에서 자동으로 스톱 손실 위치를 조정하여 수익을 보호하고 위험을 제어하는 역할을합니다. 전략 논리는 명확하고 장점은 분명하지만 제한과 위험점이 있습니다. 공백 논리, 최적 포지션 관리, 최대 손실 설정 등과 같은 합리적인 최적화 및 개선을 통해 전략의 안정성과 수익성을 더욱 향상시킬 수 있습니다. 실제 응용에서는 다양한 거래 종류와 주기에 따라 전략 매개 변수를 유연하게 조정하고 위험을 엄격하게 제어해야합니다.
/*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")