이중 이동 평균 채널 거래 전략

저자:차오장, 날짜: 2024-02-29 14:54:25
태그:

img

전반적인 설명

이중 이동 평균 채널 거래 전략은 이중 이동 평균 사이의 교차점을 추적하는 트렌드 거래 전략이다. 이 전략은 지수 이동 평균 (EMA) 과 가중 이동 평균 (WMA) 을 거래 신호 지표로 사용합니다. 단기 EMA가 장기 WMA를 넘을 때 전략은 길게 간다. 단기 EMA가 장기 WMA를 넘을 때 전략은 짧게 간다.

전략 논리

이 전략의 거래 신호는 10 기간 단기 EMA와 20 기간 장기 WMA 사이의 황금 십자와 죽음의 십자에서 온다. 단기 EMA가 장기 WMA를 넘을 때, 시장이 상향을 거슬러 올라가고 있음을 나타냅니다. 단기 EMA가 장기 WMA를 넘을 때, 시장이 하향을 거슬러 올라가고 있음을 나타냅니다.

거래 방향을 결정 한 후 전략은 입상 가격보다 1 ATR 기간 이하 또는 그 이상의 스톱 로스를 설정하고, 두 가지 수익을 취합니다. 첫 번째 스톱 로프는 입상 가격보다 1 ATR 이상 또는 그 이하로 설정되고, 두 번째 스톱 로프는 입상 가격보다 2 ATR 이상 또는 그 이하로 설정됩니다. 첫 번째 스톱 로프트가 활성화되면 포지션의 50%가 폐쇄됩니다. 나머지 포지션은 두 번째 스톱 로프트 또는 트레일링 스톱 로프트로 진행됩니다.

트레일링 스톱 로스 로직 - 가장 높은 가격 또는 가장 낮은 가격이 첫 번째 수익 수준에 도달하면 활성화됩니다. 실시간 바 업데이트에 따르면 최대 수익 포인트와 엔트리 가격 사이의 스톱 로스는 손실을 피하고 수익을 차단하기 위해 보호로 추적됩니다.

장점

이 전략은 움직이는 평균의 이중 평형 잡음 감소 기능을 활용하여 시장의 무작위 변동을 효과적으로 필터링하고 중장기 트렌드 신호를 식별하여 화프사에 걸리지 않도록합니다. 또한 두 단계의 수익은 전략의 수익 구역을 증가시키고 이익을 극대화합니다. 후속 중지 메커니즘은 또한 전략이 이익을 잠금하고 손실을 줄일 수 있습니다.

위험성

이동 평균 자체는 더 큰 지연을 가지고 있으며, 이는 신호가 사라지는 위험을 초래합니다. 이중 이동 평균 사이의 교차 또한 특정 시장에서 과도한 잘못된 신호를 생성하여 손실을 초래할 수 있습니다.

스톱 로스 설정은 전략의 중요한 구성 요소입니다. 스톱 로스가 너무 작으면 시장 소음에 영향을 받을 가능성이 있습니다. 스톱 로스가 너무 크면 위험을 효과적으로 제어하지 못할 수 있습니다.

또한 시장이 격렬하게 변동할 때, 후속 정지는 보호에 잘 작동하지 않을 수 있습니다.

최적화 방향

  1. 최적의 매개 변수 조합을 찾기 위해 다른 매개 변수와 WMA를 테스트하십시오. 너무 짧은 EMA 또는 너무 긴 WMA는 모두 전략 성능에 영향을 줄 수 있습니다.

  2. 고정점 또는 ATR 다중 스톱 로스를 선택하여 다른 제품 특성 및 거래 스타일을 기준으로 합니다.

  3. 부분 위치 후속 정지 및 전체 위치 후속 정지 효과를 테스트합니다.

  4. 신호 품질을 향상시키기 위해 EMA와 WMA를 돕기 위해 신호 필터링을 위한 다른 지표를 도입합니다.

요약

일반적으로 이중 이동 평균 채널 거래 전략은 상대적으로 견고하며 트렌딩 시장에서 잘 수행됩니다. 매개 변수, 스톱 손실 메커니즘을 최적화하고 신호 품질을 향상시킴으로써이 전략의 실제 거래 성능을 더욱 향상시킬 수 있습니다. 이것은 실제 거래에서 심층 연구 및 응용 가치가있는 유망한 전략 아이디어입니다.


/*backtest
start: 2024-01-29 00:00:00
end: 2024-02-28 00:00:00
period: 3h
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/
// © gpadihar

//@version=4
strategy("SL1 Pips after TP1 (MA)", commission_type=strategy.commission.cash_per_order, overlay=true)

// Strategy
Buy  = input(true)
Sell = input(true)

// Date Range
start_year    = input(title='Start year'   ,defval=2020)
start_month   = input(title='Start month'  ,defval=1)
start_day     = input(title='Start day'    ,defval=1)
start_hour    = input(title='Start hour'   ,defval=0)
start_minute  = input(title='Start minute' ,defval=0)
end_time      = input(title='set end time?',defval=false)
end_year      = input(title='end year'     ,defval=3019)
end_month     = input(title='end month'    ,defval=12)
end_day       = input(title='end day'      ,defval=31)
end_hour      = input(title='end hour'     ,defval=23)
end_minute    = input(title='end minute'   ,defval=59)

// MA
ema_period = input(title='EMA period',defval=10)
wma_period = input(title='WMA period',defval=20)
ema        = ema(close,ema_period)
wma        = wma(close,wma_period)

// Entry Condition
buy =
 crossover(ema,wma) and
 nz(strategy.position_size) == 0 and Buy and
 time > timestamp(start_year, start_month, start_day, start_hour, start_minute) and
 (end_time?(time < timestamp(end_year, end_month, end_day, end_hour, end_minute)):true)
 
sell =
 crossunder(ema,wma) and
 nz(strategy.position_size) == 0 and Sell and
 time > timestamp(start_year, start_month, start_day, start_hour, start_minute) and
 (end_time?(time < timestamp(end_year, end_month, end_day, end_hour, end_minute)):true)

// Pips
pip = input(20)*10*syminfo.mintick

// Trading parameters //
var bool  LS  = na
var bool  SS  = na
var float EP  = na
var float TVL = na
var float TVS = na
var float TSL = na
var float TSS = na
var float TP1 = na
var float TP2 = na
var float SL1 = na
var float SL2 = na

if buy or sell and strategy.position_size == 0
    EP  := close
    SL1 := EP - pip     * (sell?-1:1)
    SL2 := EP - pip     * (sell?-1:1)
    TP1 := EP + pip     * (sell?-1:1)
    TP2 := EP + pip * 2 * (sell?-1:1) 
   
// current trade direction    
LS := buy  or strategy.position_size > 0
SS := sell or strategy.position_size < 0

// adjust trade parameters and trailing stop calculations
TVL := max(TP1,open) - pip[1]
TVS := min(TP1,open) + pip[1]
TSL := open[1] > TSL[1] ? max(TVL,TSL[1]):TVL 
TSS := open[1] < TSS[1] ? min(TVS,TSS[1]):TVS

if LS and high > TP1
    if open <= TP1
        SL2:=min(EP,TSL)
    
if SS and low < TP1
    if open >= TP1
        SL2:=max(EP,TSS)

// Closing conditions
close_long  = LS and open < SL2
close_short = SS and open > SL2

// Buy
strategy.entry("buy"  , strategy.long, when=buy and not SS)
strategy.exit ("exit1", from_entry="buy", stop=SL1, limit=TP1, qty_percent=50)
strategy.exit ("exit2", from_entry="buy", stop=SL2, limit=TP2)

// Sell
strategy.entry("sell" , strategy.short, when=sell and not LS)
strategy.exit ("exit3", from_entry="sell", stop=SL1, limit=TP1, qty_percent=50)
strategy.exit ("exit4", from_entry="sell", stop=SL2, limit=TP2)

// Plots
a=plot(strategy.position_size >  0 ? SL1 : na, color=#dc143c, style=plot.style_linebr)
b=plot(strategy.position_size <  0 ? SL1 : na, color=#dc143c, style=plot.style_linebr) 
c=plot(strategy.position_size >  0 ? TP1 : na, color=#00ced1, style=plot.style_linebr) 
d=plot(strategy.position_size <  0 ? TP1 : na, color=#00ced1, style=plot.style_linebr) 
e=plot(strategy.position_size >  0 ? TP2 : na, color=#00ced1, style=plot.style_linebr) 
f=plot(strategy.position_size <  0 ? TP2 : na, color=#00ced1, style=plot.style_linebr) 
g=plot(strategy.position_size >= 0 ? na  : EP, color=#ffffff, style=plot.style_linebr) 
h=plot(strategy.position_size <= 0 ? na  : EP, color=#ffffff, style=plot.style_linebr) 

plot(ema,title="ema",color=#fff176)
plot(wma,title="wma",color=#00ced1)



더 많은