슈퍼 트렌드 전략에 기반


생성 날짜: 2024-02-02 11:11:48 마지막으로 수정됨: 2024-02-02 11:11:48
복사: 0 클릭수: 782
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

슈퍼 트렌드 전략에 기반

개요

이 전략은 가격 흐름을 판단하기 위해 초 트렌드 지표를 사용하며, 트렌드가 전환될 때 상위 또는 하위 입장에 들어갑니다. 이 전략은 ATR 주기를 조정하고 ATR 곱수를 최적화하여 변수를 최적화 할 수 있습니다. 또한 이 전략은 ATR 계산 방법을 변경하여 약간 다른 결과를 얻을 수있는 옵션을 제공합니다.

전략은 또한 재검토 날짜 범위 설정과 특정 시간 동안만 거래하는 기능을 내장했다. 이것은 특히 일간 거래되는 주식에 유용하다. 시간 범위 옵션을 활성화 할 때, 시간 기간의 시작에 즉시 현재 위치로 진입하거나 추세 전환 후에 첫 번째 목록으로 진입하는 것을 선택할 수 있다.

이 전략은 또한 비율을 기반으로 스톱로스 및 스톱을 설정할 수 있습니다. 대부분의 경우, 초고향이 자체적으로 제공하는 ATR 기반의 스톱로스 때문에 추가로 스톱을 설정할 필요가 없습니다. 따라서 종료 메커니즘을 최적화하기 위해 스톱로스만 사용할 수 있습니다.

마지막으로, 이 전략은 자동 거래 서비스에서 사용할 수 있는 사용자 정의 트레이드 입시 및 종료 경보 정보 기능을 가지고 있다.

전략 원칙

트렌드 전략은 다음과 같은 주요 원칙에 기초하여 작동합니다.

  1. ATR 값을 계산: SMA 계산을 선택할 수 있으며, 내장된 ATR 지표를 사용할 수도 있습니다. SMA 버전의 공식은 다음과 같습니다.
   atr2 = sma(tr, Periods) 
  1. 선로 상단과 선로 하단 계산: 선로 상단값은 ATR 곱하기 ATR의 곱셈을 빼고, 선로 하단값은 ATR 곱하기 ATR의 곱셈을 더한다.
   up = close - (Multiplier * atr)
   dn = close + (Multiplier * atr)
  1. 가격과 상하 궤도의 관계를 판단하고, 트렌드 방향을 계산한다. 가격이 상하 궤도를 통과할 때 트렌드는 다단계이며, 가격이 하하 궤도를 통과할 때 트렌드는 공백이다.
   trend := trend == -1 and close > dn ? 1 : trend == 1 and close < up ? -1 : trend 
  1. 트렌드 전환 시 거래 신호를 생성하는 것과 같이, 다중 헤드에서 공백으로 전환 시 판매 신호를 생성하는 것:
   sellSignal = trend == -1 and trend[1] == 1
  1. 트레이딩 신호 및 다른 조건에 따라 필터링을 통해 입시 여부를 선택하십시오.

  2. 이윤을 고정하거나 위험을 피하기 위해 스톱로스와 스톱을 설정한다.

이러한 요소들은 트렌드 외의 전략의 핵심 요소이며, 변수 최적화와 함께 더 나은 거래 결과를 얻을 수 있습니다.

전략적 이점

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 초트렌드 지표는 가격 동향을 직접적으로 파악하는 데 효과적이며, 흔히 쓰이는 스톱로스 추적 도구이다.

  2. ATR 매개 변수는 조정할 수 있으며, 다양한 품종에 최적의 매개 변수 조합을 얻을 수 있도록 최적화할 수 있다. SMA 계산 방식도 또 다른 옵션을 제공한다.

  3. 회수 및 실디 거래의 시간 범위를 설정하여 다른 거래 시간대의 요구에 적응 할 수 있습니다.

  4. 첫 번째 명단에 즉시 진입하거나 신호를 기다리는 옵션을 제공하며, 품종 특성에 따라 선택할 수 있다.

  5. 내장된 스톱로스 설정은 전략의 위험 저항력을 향상시키거나 더 많은 수익을 잠금할 수 있다.

  6. 사용자 정의 트레이드 힌트는 자동화 또는 로봇 트레이딩 시스템으로 통합되어 무인 경비를 구현할 수 있습니다.

전략적 위험

이 전략에는 몇 가지 위험도 있습니다.

  1. 초트렌드 지표는 거짓 신호를 더 많이 생성할 수 있으며, 다른 지표와 함께 필터링이 필요합니다.

  2. ATR 매개 변수가 잘못되면 거래가 빈번하거나 트렌드를 놓치게 될 수 있다. 최적의 균형을 얻기 위해 매개 변수를 최적화해야 한다.

  3. 정지점과 너무 가까운 것은 너무 빨리 이윤에서 벗어날 수 있고, 정지점과 너무 먼 것은 충분한 이익을 잠금 할 수 없습니다.

  4. 시간 범위가 잘못 설정되어 주요 거래 시간을 놓칠 수도 있고 보증금을 차지할 수도 있습니다.

위와 같은 위험에는 적절한 변수 조정이나 필터링 조건을 추가하여 전략의 안정성을 향상시킬 수 있습니다.

전략 최적화 방향

이 전략은 다음의 몇 가지 측면에서 더 개선될 수 있습니다.

  1. 다른 ATR 주기 변수를 시도하여 적절한 균형점을 찾습니다. 일반적으로 10-20 사이가 이상적입니다.

  2. 다른 ATR 곱하기 변수를 테스트하기 위해, 일반적으로 2-5가 가장 적합하며, 최적의 값을 찾기 위해 점진적으로 조정할 수 있다.

  3. 다른 지표들을 추가하여 MACD, KD 등과 같은 다공방향을 판단하여 가짜 신호를 필터링하십시오.

  4. 손해정지변수를 최적화하여 최적의 변수조합을 찾는다. 동적 손해정지손실을 도입할 수 있다.

  5. 다양한 거래 시간 범위 설정을 테스트하십시오. 일일 단선 품종은 짧은 시간 동안 적합합니다.

  6. 자동으로 계약을 선택하고, 유동성이 높거나 변동성이 높은 지표를 추적하는 것을 시도하십시오.

요약하다

이 초 트렌드 전략은 전체적으로 보다 일반적이고 실용적인 트렌드 추적 전략이다. 이 전략은 파라미터를 조정할 수 있고, 효율적인 트렌드 추적의 특징이 있으며, 또한 피해야 할 위험도 있다. 파라미터 최적화 및 CONDITIONS를 추가함으로써 이 전략을 신뢰할 수 있는 정량 거래 시스템으로 최적화하여 안정적인 알파를 얻을 수 있다.

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