슈퍼 트렌드 전략


생성 날짜: 2023-10-13 17:03:55 마지막으로 수정됨: 2023-10-13 17:03:55
복사: 0 클릭수: 718
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

슈퍼 트렌드 전략은 평균 실제 파장을 계산하는 트렌드 추적 전략이다. 그것은 평균 실제 파장을 사용하여 스톱 로드를 설정하고, 가격이 스톱 로드를 뚫었는지 판단하여 트렌드 방향을 판단하여 거래 신호를 발생시킨다.

전략 원칙

이 전략은 먼저 일정 주기 동안의 평균 실제 파도 ATR을 계산한다. 그리고 ATR 값을 따라 축소 계수로 곱하여 긴 선의 스톱 라인과 짧은 선의 스톱 라인을 계산한다. 구체적인 계산 방법은 다음과 같다:

atr = mult * atr(length) 

longStop = hl2 - atr

shortStop = hl2 + atr

여기서 length는 계산된 ATR의 주기 길이를 나타내고, mult은 ATR의 축소 계수를 나타낸다.

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

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. 평균 실제 파장을 사용하여 스톱 라인을 계산하여 시장 소음을 효과적으로 제거하고 더 신뢰할 수있는 트렌드 신호를 잡을 수 있습니다.

  2. 전략의 매개 변수가 적고 이해하기 쉽고 동작하기 쉽다. ATR 주기와 곱하기 계수는 다른 시장 환경에 적응할 수 있도록 조정할 수 있다.

  3. 브레이크 스톱 라인을 사용하여 트렌드 방향의 변화를 판단하여 위험을 효과적으로 제어하고 적시에 스톱 할 수 있습니다.

  4. 다중 또는 양방향 거래로 구성할 수 있으며, 다양한 거래 스타일을 만족시킬 수 있다.

  5. 어떤 시간 주기에도 사용할 수 있으며, 여러 거래 품종에 적용된다.

전략적 위험

  1. 진동상태에서 ATR 값이 높게 당겨져 스톱라인이 너무 넓어지고 더 많은 가짜 신호를 생성할 수 있다.

  2. 최적의 변수 조합을 결정할 수 없으며, ATR 주기 및 곱수는 시장 상황에 따라 최적화해야 한다.

  3. 거래 품종에 대한 최적의 거래 주기를 결정할 수 없기 때문에 각 거래 품종에 대한 테스트가 필요합니다.

  4. 가장 좋은 출입시간을 파악할 수 없고, 다소 늦어졌기 때문이다.

  5. 어떤 빈 위치 위험도 존재하며, 추세가 약할 때 빈 위치 상태가 될 수 있다.

  6. 스톱 손실이 뚫릴 위험이 있으므로 스톱 손실 경계를 적절히 완화하십시오.

전략 최적화 방향

  1. 다른 지표와 결합하여 필터링을 고려할 수 있습니다. MACD, RSI 등과 같은 흔들리는 상황에서 잘못된 신호를 피하기 위해.

  2. 기계 학습이나 유전 알고리즘을 사용하여 최적의 변수 조합을 찾을 수 있다.

  3. 다양한 품종에 대해 파라미터를 최적화하여 최적의 ATR 주기 및 곱하기 계수를 결정할 수 있다.

  4. 입학 시기를 판단하기 위해 양적 지표를 조합할 수 있습니다. 예를 들어, 입학 시기를 판단하기 위해 입학 시기를 결정하는 방법 중 하나는, 입학 시기를 결정하기 위해 입학 시기를 결정하는 방법이다.

  5. 잠금 포지션 전략을 고려할 수 있으며, 빈 포지션이 있을 때 포지션을 유지할 수 있다.

  6. 적절히 느슨한 스톱 레인지가 가능하며, 트렌드 강도 지표와 결합하여 스톱 레인지 위치를 최적화한다.

요약하다

슈퍼 트렌드 전략은 평균 실제 파장을 계산하여 동적 스톱 라인을 계산하고 가격 돌파구를 판단하여 트렌드 변화를 발견하는 것으로, 더 신뢰할 수 있고 위험을 제어할 수 있는 트렌드 추적 전략 중 하나입니다. 이 전략은 간단하고 사용하기 쉽고, 여러 가지 거래 품종에 적합하지만, 다양한 시장에서 더 나은 효과를 얻기 위해 파라미터와 전략 규칙을 최적화해야합니다. 다른 기술 지표와 전략 조합을 사용하면 더 나은 거래 성과를 얻을 수 있습니다.

전략 소스 코드
/*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()