이중 이동 평균 교차 거래 전략을 기반으로 함


생성 날짜: 2023-12-27 16:07:49 마지막으로 수정됨: 2023-12-27 16:07:49
복사: 2 클릭수: 681
avatar of ChaoZhang ChaoZhang
1
집중하다
1623
수행원

이중 이동 평균 교차 거래 전략을 기반으로 함

개요

이 전략은 이동 평균의 황금 교차와 죽음의 교차를 기반으로 구매 및 판매 신호를 생성한다. 구체적으로, 이 전략은 5 일 지수 이동 평균 ((EMA) 와 34 일 쌍 지수 이동 평균 ((DEMA) 을 동시에 사용합니다. 단기 5 일 EMA가 아래에서 34 일 DEMA를 가로지르면 구매 신호가 생성되며 단기 5 일 EMA가 위에서 34 일 DEMA를 가로지르면 판매 신호가 생성됩니다.

전략 원칙

  1. 5일 EMA와 34일 DEMA 계산
  2. 단기 5일 EMA가 34일 DEMA를 아래에서 넘어가면 구매 신호가 발생한다.
  3. 단기 5일 EMA가 34일 DEMA를 상단에서 아래로 넘어가면 팔기 신호가 발생한다.
  4. 특정 거래 시간 동안만 거래할 수 있습니다.
  5. 트래킹 중지 사용 여부를 선택할 수 있습니다

이 전략은 동시적으로 트렌드 추적과 평행선 교차의 두 가지 요소를 결합하여 안정적인 효과를 낸다. 이동 평균은 트렌드 추적 지표로서 시장의 흐름을 효과적으로 식별 할 수 있습니다. EMA와 DEMA의 조합은 거래 신호를 생성하기 위해 가격 데이터를 효과적으로 평행 할 수 있습니다. 단기 및 장기 평행선의 교차는 큰 추세 변화 시 거래 신호를 미리 줄 수 있습니다.

우위 분석

  1. 전략은 간단하고 명확하며, 실행에 옮기는 것은 쉽다.
  2. 이동 평균의 조합은 트렌드 판단과 가격 데이터의 부드러운 처리를 고려합니다.
  3. 단기 및 장기 평행선이 교차하여 큰 시장 전환점에 거래 신호를 미리 줄 수 있습니다.
  4. 매개 변수를 통해 최적화, 평균 선의 길이를 조정하여 다른 품종과 주기에 맞게 조정할 수 있습니다.
  5. 두 가지 요소를 통합하면 전략의 안정성을 높일 수 있습니다.

위험 분석

  1. 지진이 발생했을 때 더 많은 잘못된 신호가 발생할 수 있습니다.
  2. 평균선 길이가 잘못되면 신호 지연이 발생할 수 있다.
  3. 잘못된 거래 시간 및 중지 설정으로 전략적 수익에 영향을 미칠 수 있습니다.

평균선 길이를 조정하여 거래 시간을 최적화하고 합리적인 스톱로드를 설정하여 이러한 위험을 줄일 수 있습니다.

최적화 방향

  1. 거래의 종류와 주기에 따라 평균선 길이 변수를 조정합니다
  2. 거래 시간 변수를 최적화하여 주요 활동 시간 동안 거래
  3. 고정 스톱과 추적 스톱의 장단점 비교
  4. 다양한 가격대책이 전략에 미치는 영향에 대한 테스트

요약하다

이 전략은 쌍평선 교차로 거래 신호를 생성하고, 동시에 트렌드 추적과 데이터 부드러운 처리를 결합하여, 간단한 실용적인 트렌드 추적 전략이다. 매개 변수 조정과 규칙 최적화를 통해, 다른 품종과 거래 주기에 적응할 수 있으며, 큰 트렌드 변화가 있을 때 미리 거래 신호를 주고, 잘못된 신호를 피한다. 추천하고 적용할 가치가 있다.

전략 소스 코드
/*backtest
start: 2023-11-01 00:00:00
end: 2023-11-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
args: [["v_input_1",false]]
*/

//@version=2
strategy(title='[STRATEGY][RS]MicuRobert EMA cross V2', shorttitle='S', overlay=true)
USE_TRADESESSION = input(title='Use Trading Session?', type=bool, defval=true)
USE_TRAILINGSTOP = input(title='Use Trailing Stop?', type=bool, defval=true)
trade_session = input(title='Trade Session:',  defval='0400-1500', confirm=false)
istradingsession = not USE_TRADESESSION ? false : not na(time('1', trade_session))
bgcolor(istradingsession?gray:na)
trade_size = input(title='Trade Size:', type=float, defval=1)
tp = input(title='Take profit in pips:', type=float, defval=55.0) * (syminfo.mintick*10)
sl = input(title='Stop loss in pips:', type=float, defval=22.0) * (syminfo.mintick*10)
ma_length00 = input(title='EMA length:', defval=5)
ma_length01 = input(title='DEMA length:',  defval=34)
price = input(title='Price source:', defval=open)

//  ||--- NO LAG EMA, Credit LazyBear:  ---||
f_LB_zlema(_src, _length)=>
    _ema1=ema(_src, _length)
    _ema2=ema(_ema1, _length)
    _d=_ema1-_ema2
    _zlema=_ema1+_d
//  ||-------------------------------------||

ma00 = f_LB_zlema(price, ma_length00)
ma01 = f_LB_zlema(price, ma_length01)
plot(title='M0', series=ma00, color=black)
plot(title='M1', series=ma01, color=black)

isnewbuy = change(strategy.position_size)>0 and change(strategy.opentrades)>0
isnewsel = change(strategy.position_size)<0 and change(strategy.opentrades)>0

buy_entry_price = isnewbuy ? price : buy_entry_price[1]
sel_entry_price = isnewsel ? price : sel_entry_price[1]
plot(title='BE', series=buy_entry_price, style=circles, color=strategy.position_size <= 0 ? na : aqua)
plot(title='SE', series=sel_entry_price, style=circles, color=strategy.position_size >= 0 ? na : aqua)
buy_appex = na(buy_appex[1]) ? price : isnewbuy ? high : high >= buy_appex[1] ? high : buy_appex[1]
sel_appex = na(sel_appex[1]) ? price : isnewsel ? low : low <= sel_appex[1] ? low : sel_appex[1]
plot(title='BA', series=buy_appex, style=circles, color=strategy.position_size <= 0 ? na : teal)
plot(title='SA', series=sel_appex, style=circles, color=strategy.position_size >= 0 ? na : teal)
buy_ts = buy_appex - sl
sel_ts = sel_appex + sl
plot(title='Bts', series=buy_ts, style=circles, color=strategy.position_size <= 0 ? na : red)
plot(title='Sts', series=sel_ts, style=circles, color=strategy.position_size >= 0 ? na : red)

buy_cond1 = crossover(ma00, ma01) and (USE_TRADESESSION ? istradingsession : true)
buy_cond0 = crossover(price, ma00) and ma00 > ma01 and (USE_TRADESESSION ? istradingsession : true)
buy_entry = buy_cond1 or buy_cond0
buy_close = (not USE_TRAILINGSTOP ? low <= buy_entry_price - sl: low <= buy_ts) or high>=buy_entry_price+tp//high>=last_traded_price + tp or low<=last_traded_price - sl //high >= hh or 
sel_cond1 = crossunder(ma00, ma01) and (USE_TRADESESSION ? istradingsession : true)
sel_cond0 = crossunder(price, ma00) and ma00 < ma01 and (USE_TRADESESSION ? istradingsession : true)
sel_entry = sel_cond1 or sel_cond0
sel_close = (not USE_TRAILINGSTOP ? high >= sel_entry_price + sl : high >= sel_ts) or low<=sel_entry_price-tp//low<=last_traded_price - tp or high>=last_traded_price + sl //low <= ll or 

strategy.entry('buy', long=strategy.long, qty=trade_size, comment='buy', when=buy_entry)
strategy.close('buy', when=buy_close)
strategy.entry('sell', long=strategy.short, qty=trade_size, comment='sell', when=sel_entry)
strategy.close('sell', when=sel_close)