슈퍼 트렌드 전략

저자:차오장, 날짜: 2023-10-13 17:03:55
태그:

전반적인 설명

슈퍼트렌드 전략은 평균 진정한 범위의 계산에 기반한 트렌드 다음 전략이다. ATR를 사용하여 스톱 로스 라인을 설정하고 가격이 스톱 로스 라인을 통과하는지 판단하여 트렌드 방향을 결정하여 거래 신호를 생성합니다.

전략 논리

이 전략은 먼저 일정 기간 동안의 평균 참 범위 (ATR) 를 계산한다. 그 다음에는 ATR 값을 스케일 인수로 곱하여 긴 스톱 로스 라인과 짧은 스톱 로스 라인을 계산한다. 구체적인 계산은 다음과 같다.

atr = mult * atr(length)

longStop = hl2 - atr 

shortStop = hl2 + atr

여기서 길이는 ATR를 계산하는 기간이고, mult은 ATR의 확장 요인입니다.

스톱 로스 라인을 계산한 후, 전략은 트렌드 방향을 결정하기 위해 가격이 이전 바의 스톱 로스 라인을 뚫었는지 여부를 판단합니다.

dir := dir == -1 and close > shortStopPrev ? 1 :  
         dir == 1 and close < longStopPrev ? -1 : dir

긴 스톱 로스 라인이 깨지면 추세는 상승 추세로 간주됩니다. 짧은 스톱 로스 라인이 깨지면 추세는 하락 추세로 간주됩니다.

트렌드 방향의 변화에 따라 구매 및 판매 신호가 생성됩니다.

buySignal = dir == 1 and dir[1] == -1

sellSignal = dir == -1 and dir[1] == 1 

마지막으로, 구매 또는 판매 신호가 나타나면 해당 거래 동작이 수행됩니다.

장점

  1. 스톱 로스 라인을 계산하기 위해 ATR을 사용하면 시장 소음을 효과적으로 필터링하고 더 신뢰할 수있는 트렌드 신호를 캡처 할 수 있습니다.

  2. 이 전략은 이해하기 쉽고 작동하기 쉬운 몇 가지 매개 변수를 가지고 있습니다. ATR 기간과 인수는 다른 시장 조건에 맞게 조정 될 수 있습니다.

  3. 트렌드 방향 변경을 결정하기 위해 스톱 로스 라인 브레이크오웃을 사용하면 위험을 효과적으로 제어하고 시간적으로 스톱 로스를 할 수 있습니다.

  4. 다른 거래 스타일에 맞게 단장 또는 쌍방향 거래를 구성할 수 있습니다.

  5. 모든 시간 프레임과 다양한 거래 도구에 사용할 수 있습니다.

위험성

  1. 범위에 있는 시장에서 ATR은 더 높게 당겨져 더 넓은 스톱 손실과 더 많은 잘못된 신호로 이어질 수 있습니다.

  2. 최적의 매개 변수 조합은 불확실합니다. ATR 기간과 곱셈은 시장 조건에 따라 최적화되어야합니다.

  3. 각 거래 수단에 대한 최적의 기간은 알려지지 않았으며 테스트가 필요합니다.

  4. 가장 좋은 출입 시기는 명확하지 않으며 약간의 지연이 있습니다.

  5. 추세가 약할 때 시장에 있지 않을 위험이 있습니다.

  6. 스톱 손실이 발생할 위험이 있습니다. 더 넓은 스톱 손실이 고려될 수 있습니다.

강화

  1. MACD, RSI와 같은 다른 지표는 필터링을 위해 포함 될 수 있습니다. 시장에서 잘못된 신호를 피하기 위해.

  2. 최적의 매개 변수 집합을 찾기 위해 기계 학습이나 유전 알고리즘을 사용할 수 있습니다.

  3. 각 기기에 대한 매개 변수 최적화는 최상의 ATR 기간과 곱셈을 찾기 위해 수행될 수 있습니다.

  4. 부피 지표는 더 나은 입시 시기를 결정하고 조기 입시를 피하기 위해 사용될 수 있습니다.

  5. 시장에 있지 않을 때 포지션을 유지하기 위해 잠금 전략을 사용하는 것을 고려하십시오.

  6. 스톱 로즈 폭은 트렌드 강도 지표로 느려지고 최적화 될 수 있습니다.

결론

슈퍼트렌드 전략은 가격 파격이 발생했을 때 트렌드 변화를 감지하기 위해 ATR에서 계산된 동적 스톱 로스 라인을 사용합니다. 그것은 비교적 신뢰할 수 있고 위험 통제 트렌드 다음 시스템입니다. 전략은 사용하기 쉽고 다양한 도구에 적용되지만 매개 변수 및 규칙은 다른 시장에서 더 나은 성능을 위해 최적화가 필요합니다. 다른 기술 지표 및 전략과 결합하면 거래 결과를 더욱 향상시킬 수 있습니다. 일반적으로 슈퍼트렌드는 과학적으로 건전한 개념에 기반하고 거래자들에 의해 추가 연구 및 응용 가치가 있습니다.


/*backtest
start: 2023-09-12 00:00:00
end: 2023-10-12 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy("SuperTrend Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000)

LongOnly = input(title="Long Only ?", type=input.bool, defval=true)
length = input(title="ATR Period", type=input.integer, defval=22)
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)

////////////////////////////////////////////////////////////////////////////////
// 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=2020, 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

////////////////////////////////////////////////////////////////////////////////


atr = mult * atr(length)

longStop = hl2 - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = hl2 + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop

dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and close > shortStopPrev ? 1 : 
   dir == 1 and close < longStopPrev ? -1 : dir

longColor = color.green
shortColor = color.red


plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)

plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)

if LongOnly
    if buySignal and time_cond
        strategy.entry("Long", strategy.long, comment="Long")
    
    if(sellSignal and time_cond)
        strategy.close("Long")
else
    if buySignal and time_cond
        strategy.entry("Long", strategy.long, comment="Long")
    else
        strategy.cancel("Long")
    
    
    if sellSignal and time_cond
        strategy.entry("Short", strategy.short, comment="Short")
    else
        strategy.cancel("Short")

if not time_cond
    strategy.close_all()


더 많은