ATR 및 RSI 트렌드를 따라 트래일링 스톱 로스로 전략

저자:차오장, 날짜: 2024-01-23 11:31:14
태그:

img

전반적인 설명

이 전략은 적응 트렌드 다음을 달성하기 위해 평균 진정한 범위 (ATR), 상대적 강도 지수 (RSI) 및 트레일링 스톱 손실을 결합합니다. 동적 스톱 손실은 시장 변동성을 반영하기 위해 ATR에 의해 계산되며, RSI는 트렌드 방향을 식별하고, 트레일링 스톱 손실은 수익을 극대화하기 위해 가격 변동을 추적합니다. 그것은 매우 전형적인 트렌드 다음 전략입니다.

원칙

  1. ATR을 계산하십시오. ATR은 시장 변동성과 위험 수준을 보여줍니다. 이 전략은 적응적 위험 통제를 위해 동적 스톱 손실을 계산하기 위해 ATR을 사용합니다.

  2. RSI를 계산한다. RSI는 과반 구매/ 과반 판매 상태를 판단한다. RSI가 50보다 높을 때 상승 전망, 50보다 낮을 때 하락 전망을 신호한다. 이 전략은 트렌드 방향을 결정하기 위해 RSI를 이용한다.

  3. 트래킹 스톱 로스 추적. ATR에 의해 계산된 스톱 로스 수준과 RSI에 의해 트렌드 방향에 따라 이 전략은 효과적인 스톱 로스를 보장하면서 수익을 극대화하기 위해 가격 변동을 추적하기 위해 스톱 로스를 계속 움직입니다.

  4. 특히, RSI가 50을 넘으면 긴, 50을 넘으면 짧은, 그리고 ATR에 기반한 스톱 로스를 이동하여 트렌드를 따라 수익을 확보합니다.

이점 분석

  1. ATR 적응 스톱 로스는 시장 변동성을 고려하고 너무 넓거나 너무 좁은 스톱 로스를 피합니다.

  2. RSI는 트렌드를 신뢰성 있게 파악하고, 위프사를 피합니다.

  3. 스톱 로스 트렌드는 수익 목표를 확대하는 경향을 보이고 있습니다.

위험 분석

  1. ATR와 RSI 매개 변수는 백테스트 최적화가 필요해 그렇지 않으면 전략 성능에 영향을 미칩니다.

  2. 스톱 로스 보호로도, 스톱 로스를 침투하기 위해 급격한 가격 상승 위험이 여전히 존재합니다. 위험을 제어하기 위해 포지션 사이징을 고려할 수 있습니다.

  3. 전략 성능은 다른 제품에 대한 매개 변수 조정에 많이 의존합니다.

강화

  1. 적응적 매개 변수 최적화를 위한 기계 학습 알고리즘을 고려해 봅시다.

  2. 시장 조건에 따라 동적 조정을 위해 위치 사이즈 컨트롤을 추가하여 스톱 로스 침투 가능성을 줄이십시오.

  3. 더 많은 트렌드 지표를 추가하여 주요 트렌드 반전 지점을 놓치지 않도록 합니다.

결론

이 전략은 전형적인 적응 트렌드 다음 시스템을 위해 ATR, RSI 및 트레일링 스톱 로스를 통합합니다. 매개 변수 조정을 통해 다양한 거래 제품에 유연하게 적응 할 수 있으며 권장되는 보편적 트렌드 다음 전략입니다. 더 많은 판단과 기계 학습 최적화로 더 나은 성능을 달성 할 수 있습니다.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-19 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title="UTBot Strategy", overlay = true )
   
// CREDITS to @HPotter for the orginal code. 
// CREDITS to @Yo_adriiiiaan for recently publishing the UT Bot study based on the original code -
// CREDITS to @TradersAITradingPlans for making this Strategy. 
// Strategy fixed with Time period by Kirk65.
// I am using this UT bot with 2 hours time frame with god resultss. Alert with "Once per bar" and stoploss 1.5%. If Alerts triggered and price goes against Alert. Stoploss will catch it. Wait until next Alert.
// While @Yo_adriiiiaan mentions it works best on a 4-hour timeframe or above, witch is a lot less risky, but less profitable. 

testStartYear = input(2019, "BACKTEST START YEAR", minval = 1980, maxval = 2222) 
testStartMonth = input(01, "BACKTEST START MONTH", minval = 1, maxval = 12)
testStartDay = input(01, "BACKTEST START DAY", minval = 1, maxval = 31)
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2222, "BACKTEST STOP YEAR", minval=1980, maxval = 2222)
testStopMonth = input(12, "BACKTEST STOP MONTH", minval=1, maxval=12)
testStopDay = input(31, "BACKTEST STOP DAY", minval=1, maxval=31)
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

testPeriod = true

SOURCE = input(hlc3)
RSILENGTH = input(14, title = "RSI LENGTH")
RSICENTERLINE = input(52, title = "RSI CENTER LINE")
MACDFASTLENGTH = input(7, title = "MACD FAST LENGTH")
MACDSLOWLENGTH = input(12, title = "MACD SLOW LENGTH")
MACDSIGNALSMOOTHING = input(12, title = "MACD SIGNAL SMOOTHING")
a = input(10, title = "Key Vaule. 'This changes the sensitivity'") 
SmoothK = input(3)
SmoothD = input(3)
LengthRSI = input(14)
LengthStoch = input(14)
RSISource = input(close) 
c = input(10, title="ATR Period")
xATR = atr(c)
nLoss = a * xATR
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 =	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))) 
color = pos == -1 ? red: pos == 1 ? green : blue 
ema= ema(close,1)
above = crossover(ema,xATRTrailingStop )
below = crossover(xATRTrailingStop,ema)
buy = close > xATRTrailingStop and above 
sell = close < xATRTrailingStop and below
barbuy = close > xATRTrailingStop 
barsell = close < xATRTrailingStop 
plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= green,textcolor = white, transp = 0, size = size.tiny)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= red,textcolor = white, transp = 0, size = size.tiny)
barcolor(barbuy? green:na)
barcolor(barsell? red:na)
//alertcondition(buy, title='Buy', message='Buy')
//alertcondition(sell, title='Sell', message='Sell')

if (buy)
    strategy.entry("UTBotBuy",strategy.long, when=testPeriod)
if (sell)
    strategy.entry("UTBotSell",strategy.short, when=testPeriod)

더 많은