이중 EMA 크로스오버 트렌드 전략

저자:차오장, 날짜: 2023-12-29 15:46:15
태그:

img

전반적인 설명

이 전략은 현재 트렌드 방향을 결정하기 위해 이중 EMA 지표의 황금 십자가와 죽음의 십자가를 사용하고, 구매 및 판매 기회를 놓치지 않도록 RSI 지표를 결합합니다. 이것은 전형적인 트렌드 추적 전략입니다.

전략 원칙

  1. 각각 ma00 및 ma01로 지명된 10개 기간 및 20개 기간 EMA 라인을 계산합니다.
  2. 매00이 마01을 넘을 때 구매 신호가 생성됩니다.
  3. ma00이 ma01보다 낮을 때 판매 신호가 생성됩니다.
  4. 동시에, 가격이 ma00을 넘으면, ma00이 ma01을 넘으면 구매 신호가 생성됩니다.
  5. 마찬가지로, 가격이 ma00 아래로 넘어가면, ma00이 ma01 아래로 넘어가면, 판매 신호도 생성됩니다.
  6. 이러한 이중 검증을 통해 일부 구매 및 판매 포인트가 빠지는 것을 피할 수 있습니다.
  7. 위험 통제를 위해 스톱 로스를 설정하고 이윤을 취합니다.

이점 분석

  1. 이중 EMA를 사용하여 잘못된 브레이크오웃을 효과적으로 필터링할 수 있습니다.
  2. 이중 조건 검증으로 주문을 놓치지 않습니다.
  3. 스톱 로스 및 수익 설정은 리스크 관리에 유용합니다.

위험 분석

  1. 이중 EMA 전략은 트렌드 추적 전략에 속합니다. 옆 시장에서 자주 구매 및 판매하면 쉽게 스톱 로스를 얻을 수 있습니다.
  2. 트렌드 반전 지점을 정확하게 결정할 수 없습니다. 손실로 이어질 수 있습니다.
  3. 부적절한 중지 손실 포인트 설정은 손실을 증폭시킬 수 있습니다.

최적화 방향

  1. EMA 사이클은 가장 좋은 매개 변수 조합을 찾기 위해 적절하게 최적화 될 수 있습니다.
  2. 전략의 안정성을 높이기 위해 다른 지표를 추가할 수 있습니다.
  3. 동적 스톱은 시장 변동에 따라 실시간으로 스톱 손실 지점을 조정할 수 있습니다.

/*backtest
start: 2023-12-21 00:00:00
end: 2023-12-28 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy(title='[STRATEGY][RS]MicuRobert EMA cross V1', shorttitle='S', overlay=true, pyramiding=0, initial_capital=100000)
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?color.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=11.0) * (syminfo.mintick*10)
ma_length00 = input(title='EMA length:',  defval=10)
ma_length01 = input(title='DEMA length:',  defval=20)
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 ? false : 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 ? false : 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)

//What i add .!
pos = iff(ma01 < ma00 , 1,
	    iff(ma01 > ma00 , -1, nz(pos[1], 0))) 
barcolor(pos == -1 ? red: pos == 1 ? green : blue)
plot(ma00, color=red, title="MA")
plot(ma01, color=blue, title="EMA")

더 많은