슈퍼 트렌드 전략

저자:차오장, 날짜: 2024-02-02 11:11:48
태그:

img

전반적인 설명

이 전략은 가격 트렌드를 결정하기 위해 슈퍼트렌드 지표를 사용하며 트렌드가 변경되면 긴 또는 짧은 포지션을 입력합니다. 이 전략은 매개 변수를 최적화하기 위해 ATR 기간과 멀티플리커를 조정할 수 있습니다. 또한 약간 다른 결과를 위해 ATR 계산 방법을 변경할 수 있는 옵션을 제공합니다.

이 전략은 백테스팅 날짜 범위를 내장하고 하루의 특정 시간 내에만 거래하고 그 시간 프레임의 끝에서 모든 거래를 닫을 수 있습니다. 이것은 특히 일 거래 주식에서 유용합니다. 시간 프레임 옵션이 활성화되면 시간 프레임이 시작되면 즉시 현재 위치에 진입하거나 트렌드 변경이 첫 번째 위치에 진입하는 것을 기다릴 수 있습니다.

이 전략은 또한 비율에 기반한 스톱 손실을 지정하고 수익 수준을 취하도록 허용합니다. 대부분의 경우, 슈퍼트렌드 자체에서 제공하는 ATR 기반 스톱은 추가 스톱 손실을 불필요하게 만듭니다. 따라서 출구 메커니즘을 최적화하기 위해 수익을 취하는 것만을 활성화 할 수 있습니다.

마지막으로, 자동 거래 서비스와 함께 사용할 입력 및 출력 메시지에 대한 사용자 지정 경고 필드가 있습니다.

전략 논리

슈퍼트렌드 전략은 다음의 핵심 원칙에 기초합니다.

  1. ATR 값을 계산: SMA 계산 또는 내장 ATR 지표 중 하나를 선택할 수 있습니다. SMA 공식:

    atr2 = sma(tr, Periods)
    
  2. 상부와 하부 대역을 계산해 보세요. 상부 대역은 ATR 곱하기 ATR 곱하기 ATR입니다. 하부 대역은 ATR 곱하기 ATR 곱하기 ATR입니다.

    up = close - (Multiplier * atr) 
    dn = close + (Multiplier * atr)
    
  3. 가격과 대역을 비교하여 트렌드 방향을 결정합니다. 가격이 하위 대역을 넘을 때 상승 트렌드. 가격이 상위 대역을 넘을 때 하락 트렌드

    trend := trend == -1 and close > dn ? 1 : trend == 1 and close < up ? -1 : trend
    
  4. 트렌드 변경에 대한 거래 신호를 생성합니다. 예를 들어 상승 추세에서 하락 추세로 변경할 때 판매 신호:

    sellSignal = trend == -1 and trend[1] == 1 
    
  5. 신호와 추가 조건에 기초한 입력 필터

  6. 스톱 로스를 사용해서 수익을 확보하거나 위험을 제한합니다.

이것은 슈퍼트렌드 전략의 핵심 작동 원칙입니다. 매개 변수 최적화와 결합하면 좋은 거래 결과를 얻을 수 있습니다.

장점

슈퍼트렌드 전략은 몇 가지 장점이 있습니다.

  1. 슈퍼트렌드 자체는 트렌드를 효과적으로 식별하고 일반적으로 트레일링 스톱에 사용됩니다.

  2. 커스터마이징 가능한 ATR 매개 변수는 제품을 통해 최적화하여 최적화 할 수 있습니다. SMA 계산은 또 다른 옵션을 제공합니다.

  3. 설정 가능한 백테스트 및 라이브 거래 시간 범위는 다른 거래 세션에 적합합니다.

  4. 첫 번째 거래를 즉시 시작하거나 신호를 기다리는 옵션은 다른 제품을 제공합니다.

  5. 내장된 스톱 로스 및 영업 영업은 리스크 관리를 개선하거나 더 많은 수익을 올리는 데 도움이 됩니다.

  6. 자동 거래 시스템과 봇과의 통합을 위해 사용자 정의 가능한 거래 알림.

위험성

또한 고려해야 할 몇 가지 위험이 있습니다.

  1. 슈퍼트렌드는 잘못된 신호를 만들어 추가 조건으로 필터링해야 합니다.

  2. 부적절한 ATR 매개 변수는 과도한 거래 또는 트렌드를 놓치는 결과를 초래할 수 있습니다. 최상의 균형을 위해 최적화가 필요합니다.

  3. 너무 가까운 스톱 로스는 수익성 있는 거래에서 조기 종료 할 수 있습니다. 너무 느슨한 이익은 테이블에 돈을 남길 수 있습니다.

  4. 잘못된 시간 프레임 구성은 거래 세션을 놓칠 수도 있고 마진을 불필요하게 묶을 수도 있습니다.

이러한 위험은 견고성을 향상시키기 위해 매개 변수 또는 추가 필터를 적절히 조정하여 해결할 수 있습니다.

최적화 기회

이 전략이 더 이상 최적화 될 수 있는 몇 가지 방법:

  1. 올바른 균형을 찾기 위해 다른 ATR 기간을 테스트하십시오. 일반적으로 10-20은 잘 작동합니다.

  2. 다른 ATR 곱셈값을 시도해보세요. 일반적으로 2-5가 적합합니다. 최적을 찾기 위해 조정하세요.

  3. MACD, RSI 등과 같은 필터를 추가하여 잘못된 신호를 줄이십시오.

  4. 최대의 결과를 위해 손해를 멈추고 수익 수준을 최적화하십시오. 동적 후속 메커니즘을 고려하십시오.

  5. 다른 거래 시간 범위를 테스트합니다. 짧은 기간은 내일 및 고 빈도 전략에 적합합니다.

  6. 높은 운동량이나 변동성을 추적하기 위해 자동 기호 선택을 구현합니다.

결론

전체적으로 이것은 상당히 일반적이고 실용적인 트렌드 다음 전략입니다. 사용자 정의 가능한 매개 변수로 트렌드를 효율적으로 추적하지만 관리해야 할 고유한 위험이 있습니다. 최적화 및 추가 조건으로 일관성있는 알파와 함께 강력한 양 거래 시스템으로 정제 될 수 있습니다.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © REV0LUTI0N

//@version=4

// Strategy
strategy("Supertrend Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)
Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
enableentry = input(true, title="Enter First Trade ASAP")
waitentry = input(false, title="Wait To Enter First Trade")

atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
Long = (trend == 1 ? up : na)
buySignal = trend == 1 and trend[1] == -1

dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
Short = (trend == 1 ? na : dn)
sellSignal = trend == -1 and trend[1] == 1

// Strategy Backtesting
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true

//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = (time(timeframe.period, startendtime))
timetoclose = na(time(timeframe.period, startendtime))

// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100

longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)

plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")

// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")

// Strategy Execution
if Long and time_cond and timetobuy and enableentry
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
    
if Short and time_cond and timetobuy and enableentry
    strategy.entry("Short", strategy.short, alert_message = message_entershort)
    
if buySignal and time_cond and timetobuy and waitentry
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
    
if sellSignal and time_cond and timetobuy and waitentry
    strategy.entry("Short", strategy.short, alert_message = message_entershort)
    
if strategy.position_size > 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closeshort)
    
if strategy.position_size > 0 and enablesl and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
    
if strategy.position_size > 0 and enabletp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)






더 많은