이동 평균 크로스오버에 기반한 BTC 거래 전략

저자:차오장, 날짜: 2023-12-07 14:56:50
태그:

img

전반적인 설명

이 전략은 BTC의 50일 이동 평균과 200일 이동 평균의 황금 십자 및 죽음의 십자 신호를 기반으로 하고 있으며, 구매 및 판매 신호를 생성하기 위한 추가 기술 지표와 결합되어 있습니다. 이 전략은 주로 BTC/USDT와 같은 명백한 트렌드 특성을 가진 통화 쌍에 적합합니다.

전략 원칙

50일 이동평균이 200일 이동평균을 넘어서 골든 크로스을 형성하면 BTC가 황소 시장에 진입하여 구매 신호를 생성한다는 것을 나타냅니다. 50일 이동평균이 200일 이동평균을 넘어서 죽음 크로스을 형성하면 BTC가 곰 시장에 진입하여 판매 신호를 생성한다는 것을 나타냅니다.

기본 이동 평균 골든 크로스죽음 크로스 신호 판단 외에도이 전략은 또한 판단에 도움이되는 몇 가지 추가 기술 지표를 포함합니다.

  1. EMA 지표: EMA 지표를 계산하면 길이 + 오프셋이 올라갈 때 현재 시장이 상승세를 나타냅니다.

  2. 이동 평균과 EMA 사이의 값 관계를 비교하십시오. EMA 값이 50 일 이동 평균보다 높으면 구매 신호가 생성됩니다.

  3. 가격이 이전 K 라인의 최저 수준과 비교하여 1% 이상 떨어졌는지 확인합니다. 그렇다면 판매 신호를 생성합니다.

위의 여러 지표의 사용을 결합함으로써 일부 잘못된 신호를 필터링하여 전략의 거래 결정이 더 신뢰할 수 있습니다.

이점 분석

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

  1. 이동 평균을 주요 거래 신호로 사용하면 시장 소음을 필터링하고 트렌드 방향을 식별 할 수 있습니다.

  2. 여러 보조 기술 지표와 결합하면 신호 신뢰성을 향상시키고 잘못된 신호를 필터링 할 수 있습니다.

  3. 적절한 스톱 로스 전략을 채택하면 단일 손실을 효과적으로 제어 할 수 있습니다.

  4. 비교적 간단한 거래 논리는 이해하기 쉽고 구현하기 쉽고 양적 거래의 초보자에게 적합합니다.

  5. 많은 구성 가능한 매개 변수가 있습니다.

위험 분석

이 전략은 또한 몇 가지 위험을 가지고 있습니다.

  1. 이동평균 자체는 강한 후퇴 특성을 가지고 있으며, 아마도 빠른 가격 반전을 위한 기회를 놓치고 있습니다.

  2. 보조 표시기를 추가하면 규칙의 수가 증가하고 잘못된 신호를 생성할 확률도 증가합니다.

  3. 부적절한 스톱 로스 설정으로 인해 손실이 커질 수 있습니다.

  4. 부적절한 매개 변수 설정 (동도 평균 길거리 등) 도 전략 결과에 영향을 줄 것입니다.

대응 해법은:

  1. 이동 평균 주기를 적절하게 단축하고 매개 변수 최적화 범위를 증가시킵니다.

  2. 신호 품질을 확인하기 위해 백테스트 데이터 양을 늘려

  3. 스톱 로스 범위를 적절히 풀고, 수익 스톱을 설정합니다.

  4. 가장 좋은 매개 변수 조합을 찾기 위해 매개 변수 최적화를 높여

최적화 방향

이 전략은 다음 방향으로도 최적화 될 수 있습니다.

  1. 자동 매개 변수 최적화를 위해 기계 학습 알고리즘을 강화합니다.

  2. 더 많은 보조 지표를 추가하여 여러 부전략을 구축하고 투표 메커니즘을 통해 결정을 내립니다.

  3. 가격의 돌파구를 파악하기 위해 브레이크업 전략을 시도해보세요.

  4. 가격 추세를 예측하기 위해 딥러닝을 사용하세요.

  5. 동적 추적 스톱 로스를 달성하기 위해 스톱 로스 메커니즘을 최적화합니다.

위의 최적화는 의사 결정의 정확성을 향상시키고 전략의 수익성과 안정성을 향상시킬 수 있습니다.

요약

이 전략은 주로 BTC의 이동 평균 크로스오버를 기반으로 거래 결정을 내리고, 신호를 필터하기 위해 EMA와 같은 기술적 지표에 의해 지원됩니다. 전략은 강한 트렌드 추적 능력과 높은 구성성을 가지고 있으며, 초보자의 양적 거래 전략으로 적합합니다. 그러나 보호해야 할 특정 후퇴 위험도 있습니다. 다음 최적화 방향은 기계 학습, 포트폴리오 전략, 스톱-손실 전략 등 여러 차원에서 발생할 수 있습니다.


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

//@version=5
strategy('JayJay BTC Signal', overlay=true, initial_capital=100, currency='USD', default_qty_value=100, default_qty_type=strategy.percent_of_equity, commission_value=0, calc_on_every_tick=true)

securityNoRepaint(sym, tf, src) => request.security(sym, tf, src[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]

//200 50 Moving Average
ma50Len = input.int(50, minval=1, title='MA50-Length')
ma50Src = input(close, title='MA50-Source')
ma50Show = input(true, title='Show SMA50 on chart')
ma50Close = ta.sma(ma50Src, ma50Len)
ma50CloseTimeframe = input.timeframe("240", "Ma50 Timeframe", group = "EMA Options")
ma50Open = ta.sma(open, ma50Len)
ma200Len = input.int(200, minval=1, title='MA200-Length')
ma200Src = input(close, title='MA200-Source')
ma200Show = input(true, title='Show SMA200 on chart')
ma200CloseTimeframe = input.timeframe("D", "Ma200 Timeframe", group = "EMA Options")
ma200Close = ta.sma(ma200Src, ma200Len)
ma200Open = ta.sma(open, ma200Len)
//plot(ma200Close, color=color.new(#0b6ce5, 0), title='MA200')
//plot(ma50Close, color=color.new(#00d8ff, 0), title='MA50')

sma50 = securityNoRepaint(syminfo.tickerid, ma50CloseTimeframe, ma50Close)
plot(sma50 and ma50Show ? sma50 : na, color=color.new(#00d8ff, 0), title='SMA50')
sma200 = securityNoRepaint(syminfo.tickerid, ma200CloseTimeframe, ma200Close)
plot(sma200 and ma200Show ? sma200 : na, color=color.new(#00d8ff, 0), title='SMA200')

// Short/Long EMA
// Define the offset value
EMAOffsetValue = input.int(2, title='EMA Offset', minval=0)
emaplot = input(true, title='Show EMA on chart')
len = input.int(20, minval=1, title='ema Length') + EMAOffsetValue
emaCloseTimeframe = input.timeframe("240", "EMA 1 Timeframe", group = "EMA Options")
emaOpen = ta.ema(open, len)
emaClose = ta.ema(close, len)

ema = securityNoRepaint(syminfo.tickerid, emaCloseTimeframe, emaClose)

up = emaClose > ema[1]
down = emaClose < ema[1]
mycolor = up ? color.green : down ? color.red : color.blue

plot(ema and emaplot ? ema : na, title='Signal EMA', color=mycolor, linewidth=3)
//plot(emaClose and emaplot ? emaClose : na, title='Signal 20 EMA', color=color.yellow, linewidth=3)

ma50GreaterThanMa200 = sma50 > sma200

last3BarUp = ema > ema[1]

startLong = up and ema > sma50 and ma50GreaterThanMa200 and (100 - (sma50 / ema * 100) > 1.0)

startFrom = input(timestamp("20 Jan 2000 00:00"), "StartFrom")

yearFilter = true

alertLongPositionMessage = "{\"direction:\": \"long\", \"action\": \"{{strategy.order.action}}\", \"price\": \"{{strategy.order.price}}\", \"qty\": \"{{strategy.position_size}}\", \"symbol\": \"{{ticker}}\", \"date\": \"{{time}}\"}"

if true and startLong and yearFilter
    strategy.entry('Long', strategy.long, comment = "Long", alert_message = alertLongPositionMessage)

longStopLossLevel = open * 0.05
strategy.exit('StopLoss', from_entry='Long',comment = "StopLoss!", loss=longStopLossLevel, profit=close * 0.3, alert_message = alertLongPositionMessage)
longPercentageChange = low / close[1] * 100 - 100
is1PercentLower = longPercentageChange < -0.1
closeLongPositionWhen = (down and is1PercentLower) or (emaClose < sma50)
if closeLongPositionWhen
    strategy.close('Long', comment = "Fuck It!", alert_message =  alertLongPositionMessage)

bgcolor(startLong ? color.green : na, transp=90)



더 많은