패턴 반전과 MACD 지표를 기반으로 한 복합 트레이딩 전략


생성 날짜: 2023-09-19 17:17:30 마지막으로 수정됨: 2023-09-19 17:17:30
복사: 0 클릭수: 715
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 123 형태 반전과 MACD 지표를 조합하여 강력한 거래 신호 필터링을 구현합니다. 123 형태 반전은 단기 반전 기회를 포착하고 MACD는 중기 및 장기 동향 판단을 제공합니다. 조합 신호는 높은 확률의 거래 지점을 효과적으로 발견 할 수 있습니다.

전략 원칙

  1. 123 형태 역전 전략, 판단 전 이틀 하락하고 오늘 종결 가격 상승, 그리고 스토카스틱 지표가 하락 하락 할 때 구매; 이틀 하락 하락 하락, 스토카스틱 상하 하락 할 때 판매.

  2. MACD 지표 전략, 빠른 선이 낮은 선에 공백을 할 때, 빠른 선이 낮은 선보다 높을 때 더 많이 할 것.

  3. 두 전략 신호가 일치할 때만 거래한다. 그렇지 않으면 거래하지 않는다. 정면 반면 거래로 전환할 수 있다.

우위 분석

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

  1. 조합 신호는 가짜 돌파구를 효과적으로 필터링하여 승률을 높인다.

  2. 123 형태는 단기 반전 기회를 잡을 수 있으며, MACD는 중장선 트렌드 방향을 판단한다.

  3. 스토카스틱 지표는 123 형태와 결합하여 트렌드 반전 후 과도한 거래를 피할 수 있습니다.

  4. 두 전략은 서로 다른 거래 임무를 공유하고, 상호 검증할 수 있으며, 단일 전략의 과잉 최적화 위험을 줄일 수 있다.

  5. 다양한 시장 환경에 적응할 수 있는 여러 방향의 공백을 편리하게 전환할 수 있다.

위험 분석

이 전략의 주요 위험은:

  1. 콤비네이션 신호는 너무 보수적이어서 더 좋은 기회를 놓칠 수 있습니다.

  2. 반전형은 갑작스러운 사건의 영향을 받기 쉽고, 무효가 발생한다.

  3. 손해배상 장치가 고려되지 않아 큰 손실 위험이 있습니다.

  4. 이중 필터링 신호는 트렌드 기회를 놓칠 수 있습니다.

  5. 매개 변수 최적화를 고려하지 않고, 기본 매개 변수는 모든 품종에 적합하지 않다.

최적화 방향

다음의 관점에서 최적화할 수 있습니다.

  1. 다양한 변수 조합을 테스트하여 최적의 변수를 찾습니다.

  2. 단편적 손실을 통제하기 위한 손실을 막는 전략을 강화한다.

  3. 더 많은 필터링 지표를 추가하여 신호 품질을 향상시킵니다.

  4. 기계 학습 모델을 추가하여 파라미터를 자동으로 최적화합니다.

  5. 더 많은 종류의 거래에서 전략의 안정성을 평가하기 위해 테스트합니다.

  6. 시장 환경에 따라 전환 매개 변수 콤비

요약하다

이 전략은 전체적으로, 복수 신호를 조합하여 단일 전략의 과잉 최적화 문제를 효과적으로 방지할 수 있습니다. 더 많은 필터링 지표, 손실 중지 장치 등의 개선 사항을 추가하면, 더 안정적이고 실용적인 양적 거래 전략이 될 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-14 02:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 24/07/2020
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// This is one of the techniques described by William Blau in his book
// "Momentum, Direction and Divergence" (1995). If you like to learn more,
// we advise you to read this book. His book focuses on three key aspects
// of trading: momentum, direction and divergence. Blau, who was an electrical
// engineer before becoming a trader, thoroughly examines the relationship 
// between price and momentum in step-by-step examples. From this grounding,
// he then looks at the deficiencies in other oscillators and introduces some
// innovative techniques, including a fresh twist on Stochastics. On directional 
// issues, he analyzes the intricacies of ADX and offers a unique approach to help 
// define trending and non-trending periods.
// Blau`s indicator is like usual MACD, but it plots opposite of meaningof
// stndard MACD indicator.  
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos

fADX(Len) =>
    up = change(high)
    down = -change(low)
    trur = rma(tr, Len)
    plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, Len) / trur)
    minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, Len) / trur)
    sum = plus + minus 
    100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), Len)

EMACD(r,SmthLen,LengthMACD) =>
    pos = 0
    source = close
    fastMA = ema(source, r)
    slowMA = ema(source, LengthMACD)
    xmacd = fastMA - slowMA
    xMA_MACD = ema(xmacd, SmthLen)
    pos := iff(xmacd < xMA_MACD, -1,
    	     iff(xmacd > xMA_MACD, 1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Ergodic MACD", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
r = input(14, minval=1)
LengthMACD = input(21, minval=1)
SmthLen = input(5, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posEMACD = EMACD(r,SmthLen,LengthMACD)
pos = iff(posReversal123 == 1 and posEMACD == 1 , 1,
	   iff(posReversal123 == -1 and posEMACD == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
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 )