이중 이동 평균 역전 전략

저자:차오장, 날짜: 2023-11-03 16:51:18
태그:

img

전반적인 설명

이 전략은 거래 신호를 생성하기 위해 2 개의 지표를 사용합니다: 2/20 기하급수적 이동 평균 및 평균 진정한 범위 반전. 반전 기회를 포착하는 것을 목표로 트렌드 다음과 단기 반전의 아이디어를 결합합니다.

원칙

이 전략은 두 부분으로 구성되어 있습니다.

  1. 2/20 기하급수적 이동 평균. 20일 EMA를 계산하고 가격이 EMA를 상향 또는 하향으로 넘을 때 신호를 생성합니다.

  2. 평균 True Range Reversal Indicator. ATR를 기반으로 스톱 로스 레벨을 계산하고, 가격이 스톱 로스 레벨을 넘을 때 신호를 생성합니다. 여기 3.5 x ATR가 스톱 레벨로 사용됩니다.

이 전략은 양쪽의 신호를 결합합니다. 2/20 EMA가 긴 신호를 줄 때 짧습니다. ATR 역전이 짧은 신호를 줄 때 길습니다.

이점 분석

이 전략은 트렌드 추종과 반전 아이디어를 결합하여 반전을 포착하는 것을 목표로합니다. 이점은 다음과 같습니다.

  1. 2/20 EMA는 중장기 동향을 파악하고 시장 소음을 피합니다.

  2. ATR 역행은 단기적 역행과 기회를 포착합니다.

  3. 신호를 결합하면 트렌드 전환이 더 빨리 파악되고 수익성이 향상됩니다.

  4. 합리적인 ATR 스톱 손실은 특정 위험 통제를 제공합니다.

  5. 맞춤형 ATR 곱셈은 다양한 제품에 적응합니다.

  6. 회환 옵션은 다른 시장 환경에 적응합니다.

위험 분석

위험은 다음과 같습니다.

  1. 2/20 EMA는 느리고 단기적인 기회를 놓칠 수 있습니다.

  2. ATR 스톱 손실은 쉽게 침투 할 수 있습니다. 더 넓은 스톱 손실이 필요합니다.

  3. 단 하나의 신호는 신뢰할 수 없습니다. 더 많은 필터가 필요합니다.

  4. 과잉 거래 하는 것 을 조심 하십시오.

  5. 파라미터 튜닝과 백테스트가 필요한 제품입니다.

  6. 거래별 리스크를 통제하기 위해 엄격한 자본 관리가 필요합니다.

최적화 방향

이 전략은 다음과 같이 개선될 수 있습니다.

  1. 가장 좋은 조합을 위해 EMA 매개 변수를 조정합니다.

  2. 더 나은 스톱 손실을 위해 ATR 곱셈을 최적화합니다.

  3. 부피와 휘발성 같은 필터 조건을 추가합니다.

  4. 동적 위치 크기를 위한 자본 관리 모델을 추가합니다.

  5. 다른 스톱 로스 전략을 추가합니다.

  6. 다른 제품에서 테스트 파라미터

  7. 더 나은 성능을 위해 기계 학습 모델을 추가합니다.

  8. 더 많은 알파를 위해 여러 가지 하위 전략을 결합합니다.

결론

이 전략은 두 가지 주요 아이디어를 결합하고 반전을 포착하는 특정 이점을 가지고 있습니다. 그러나 부적절한 매개 변수 선택은 또한 위험을 가져올 수 있습니다. 중지 손실 전략에 대한 추가 개선 및 필터를 추가하면 안정성과 수익성이 향상 될 수 있습니다.


/*backtest
start: 2022-10-27 00:00:00
end: 2023-11-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 05/04/2022
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This indicator plots 2/20 exponential moving average. For the Mov 
// Avg X 2/20 Indicator, the EMA bar will be painted when the Alert criteria is met.
//
// Second strategy
// Average True Range Trailing Stops Strategy, by Sylvain Vervoort 
// The related article is copyrighted material from Stocks & Commodities Jun 2009 
// Please, use it only for learning or paper trading. Do not for real trading.
//
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
EMA20(Length) =>
    pos = 0.0
    xPrice = close
    xXA = ta.ema(xPrice, Length)
    nHH = math.max(high, high[1])
    nLL = math.min(low, low[1])
    nXS = nLL > xXA or nHH < xXA ? nLL : nHH
    iff_1 = nXS < close[1] ? 1 : nz(pos[1], 0)
    pos := nXS > close[1] ? -1 : iff_1
    pos


ATRR(nATRPeriod,nATRMultip) =>
    pos = 0.0
    xATR = ta.atr(nATRPeriod)
    nLoss = nATRMultip * xATR
    xATRTrailingStop = 0.0
    xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) :
                          close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : 
                          close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss
    pos:= close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0) ? 1 :
    	     close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0) 
    pos

strategy(title='Combo 2/20 EMA & Average True Range Reversed', shorttitle='Combo', overlay=true)
var I1 = '●═════ 2/20 EMA ═════●'
Length = input.int(14, minval=1, group=I1)
var I2 = '●═════ Average True Range Reversed  ═════●'
nATRPeriod = input.int(5, group=I2)
nATRMultip = input.float(3.5, group=I2)
var misc = '●═════ MISC ═════●'
reverse = input.bool(false, title='Trade reverse', group=misc)
var timePeriodHeader = '●═════ Time Start ═════●'
d = input.int(1, title='From Day', minval=1, maxval=31, group=timePeriodHeader)
m = input.int(1, title='From Month', minval=1, maxval=12, group=timePeriodHeader)
y = input.int(2005, title='From Year', minval=0, group=timePeriodHeader)
StartTrade = time > timestamp(y, m, d, 00, 00) ? true : false
posEMA20 = EMA20(Length)
prePosATRR = ATRR(nATRPeriod,nATRMultip)
iff_1 = posEMA20 == -1 and prePosATRR == -1 and StartTrade ? -1 : 0
pos = posEMA20 == 1 and prePosATRR == 1 and StartTrade ? 1 : iff_1
iff_2 = reverse and pos == -1 ? 1 : pos
possig = reverse and pos == 1 ? -1 : iff_2
if possig == 1
    strategy.entry('Long', strategy.long)
if possig == -1
    strategy.entry('Short', strategy.short)
if possig == 0
    strategy.close_all()
barcolor(possig == -1 ? #b50404 : possig == 1 ? #079605 : #0536b3)

더 많은