
이 전략은 평균 실제 파장 (ATR) 을 사용하여 스톱로스 (TS) 를 추적합니다. 동적으로 스톱로스 위치를 조정하여 트렌드를 추적합니다. 가격이 유리한 방향으로 움직일 때, 스톱로스 위치도 그에 따라 조정되어 얻은 이익을 잠금합니다. 가격이 불리한 방향으로 움직일 때, 스톱로스는 변하지 않으며, 가격이 스톱로스 가격에 도달하면 평평한 스톱로스가됩니다. 이 전략의 핵심은 스톱로스의 동적인 조정입니다.
ATR 추적 스톱 전략은 가격 변동의 폭에 따라 스톱 위치를 동적으로 조정할 수 있으며, 트렌드 상황에서 좋은 효과를 얻을 수 있습니다. 그러나, 이 전략은 불안한 시장, 너무 자주 스톱 및 도약 틈을 피할 수 없는 위험을 감당할 수 없습니다. 위의 결함에 대해, 트렌드 판단, 스톱 전략, 최대 스톱 제한 등 측면에서 전략에 최적화 및 개선이 가능합니다. 이러한 조정으로 전략의 적응성과 수익성을 향상시킬 수 있습니다.
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Long TAP", overlay=true)
// Constants
keyValueDefault = 3.0
keyValueStep = 0.5
atrPeriodDefault = 10
// Inputs
keyValue = input.float(keyValueDefault, title="Key Value")
atrPeriod = input.int(atrPeriodDefault, title="ATR Period")
// Calculations
xATR = ta.atr(atrPeriod)
nLoss = keyValue * xATR
// Trailing Stop Calculation
var float xATRTrailingStop = 0.0
xATRTrailingStop := ta.highest(math.max(nz(xATRTrailingStop[1], 0), close - nLoss), 1)
xATRTrailingStop := ta.lowest(math.min(nz(xATRTrailingStop, 0), close + nLoss), 1)
// Position Calculation
var int pos = 0
pos := nz(pos[1], 0)
if (close[1] < nz(xATRTrailingStop, 0) and close > nz(xATRTrailingStop, 0))
pos := 1
else if (close[1] > nz(xATRTrailingStop, 0) and close < nz(xATRTrailingStop, 0))
pos := -1
// Plotting Trailing Stop
var color xcolor = na
if (pos == -1)
xcolor := color.red
else if (pos == 1)
xcolor := color.green
plot(xATRTrailingStop, color=xcolor, title="Trailing Stop")
// Buy/Sell Signals
buySignal = ta.crossover(close, xATRTrailingStop)
sellSignal = ta.crossunder(close, xATRTrailingStop)
// Strategy
if (buySignal)
strategy.entry("Long", strategy.long)
label.new(bar_index, xATRTrailingStop, text="Buy Signal", color=color.green, style=label.style_label_up, yloc=yloc.belowbar)
if (sellSignal)
strategy.entry("Short", strategy.short)
label.new(bar_index, xATRTrailingStop, text="Sell Signal", color=color.red, style=label.style_label_down, yloc=yloc.abovebar)
// Alerts
alertcondition(buySignal, title='UT BOT Buy', message='UT BOT Buy')
alertcondition(sellSignal, title='UT BOT Sell', message='UT BOT Sell')