이 전략은 주로 적응적 인 스톱 메커니즘을 구현하며, 가격 변동에 따라 자동으로 스톱 위치를 조정하여 더 나은 스톱 효과를 달성 할 수 있습니다. 전략은 ATR 지표를 사용하여 합리적인 스톱 범위를 계산하고, EMA 평행선과 결합하여 거래 신호를 생성합니다. EMA 평행선을 돌파 할 때 포지션을 열고 더 많은 공백을 만들며, 동시에 적응적 인 스톱 알고리즘을 사용하여 스톱 위치를 추적합니다.
이 전략의 전체적인 아이디어는 명확하고 이해하기 쉽다. ATR 지표를 이용하여 자율적으로 손해를 줄 수 있는 범위를 설정하고, EMA와 협력하여 거래 신호를 생성하여 손실을 효과적으로 제어할 수 있다. 그러나 전략 자체는 수동적이며, 최적화 공간은 넓으며, 트렌드 판단을 포함하는 것을 고려할 수 있으며, 시장상황에 따라 조정 파라미터와 같은 방법으로 전략을 더 적극적으로 만들 수 있다.
/*backtest
start: 2023-09-07 00:00:00
end: 2023-10-07 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="UT Bot Strategy", overlay = true)
//CREDITS to HPotter for the orginal code. The guy trying to sell this as his own is a scammer lol.
// Inputs
a = input(1, title = "Key Vaule. 'This changes the sensitivity'")
c = input(10, title = "ATR Period")
h = input(false, title = "Signals from Heikin Ashi Candles")
////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE
// From Date Inputs
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2019, title = "From Year", minval = 1970)
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2100, title = "To Year", minval = 1970)
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true
////////////////////////////////////////////////////////////////////////////////
xATR = atr(c)
nLoss = a * xATR
src = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : close
xATRTrailingStop = 0.0
xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))
pos = 0
pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue
ema = ema(src,1)
above = crossover(ema, xATRTrailingStop)
below = crossover(xATRTrailingStop, ema)
buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below
barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop
plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)
barcolor(barbuy ? color.green : na)
barcolor(barsell ? color.red : na)
strategy.entry("long", true, when = buy and time_cond)
strategy.entry("short", false, when = sell and time_cond)