EMA RSI MACD 동적 손절매 및 손절매 거래 전략

EMA RSI MACD
생성 날짜: 2024-06-14 15:38:17 마지막으로 수정됨: 2024-06-14 15:38:17
복사: 4 클릭수: 767
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

EMA RSI MACD 동적 손절매 및 손절매 거래 전략

개요

이 거래 전략은 지수 이동 평균 (EMA), 상대적으로 약한 지수 (RSI) 및 이동 평균 수렴 분산 (MACD) 의 세 가지 기술 지표를 결합하여, 가격의 특정 조건을 충족하면 구매 및 판매 신호를 생성하기 위해 그들의 교차와 수학적 관계를 분석합니다. 동시에, 이 전략은 거래 위험을 관리하기 위해 동적 정지 및 중단을 설정합니다.

전략 원칙

  1. 전략의 기본 데이터로 HLCC4) 를 계산한다.
  2. HLCC4를 기반으로 세 개의 다른 주기에서 계산된 EMA와 RSI 지표.
  3. MACD 기둥 도표의 값을 계산한다.
  4. EMA1과 EMA2의 교차 상황을 판단하기 위해:
    • EMA1에 EMA2를 착용하면, 보 신호가 발생한다.
    • EMA1이 EMA2을 통과하면 하향 신호가 발생한다.
  5. EMA, RSI, MACD의 수치를 종합적으로 고려하여 구매 또는 판매 조건을 충족하는지 판단합니다.
    • 구매 조건: EMA1에 EMA2, HLCC4가 EMA3보다 높고, RSI가 하락보다 높고, 종결 가격이 개시 가격보다 높고, MACD 기둥은 긍정적이다.
    • 판매 조건: EMA1 아래 EMA2를 통과, HLCC4는 EMA3보다 낮고, RSI는 하락보다 낮고, 종결 가격은 개시 가격보다 낮고, MACD 기둥은 부정적이다.
  6. 지분을 보유할 때 반대의 신호가 발생하면, 먼저 기존의 지점을 청산하고, 새로운 지점을 개설한다.
  7. 구매 또는 판매 할 때, 설정 된 점수 ((pips) 에 따라 스톱 스톱 및 스톱 손실 가격을 설정하십시오.

전략적 이점

  1. 여러 기술 지표와 결합하여 종합적으로 판단하여 신호의 신뢰도를 높였습니다.
  2. 다이내믹 스티프 스톱 손실 메커니즘을 도입하여 위험을 효과적으로 제어 할 수 있습니다.
  3. 반대의 신호가 발생했을 때 원래의 포지션을 평평하게 하고, 반복적인 포지션 보유 문제를 피한다.
  4. 매개 변수는 조정 가능하고, 적응력이 강하며, 다른 시장 환경에 따라 최적화할 수 있다.

전략적 위험

  1. 위기 상황에서는, 자주 교차하는 것이 과도한 거래로 이어져 수수료 비용이 증가할 수 있습니다.
  2. 고정된 점수의 스톱 스톱 손실은 시장의 변동에 적응하지 못할 수 있으며, 이로 인해 손실이 너무 일찍 또는 스톱 스톱이 너무 늦게 중단됩니다.
  3. 전략은 역사적 데이터에 의존하고, 갑작스러운 사건이나 비정상적인 행동에 대한 반응이 늦어질 수 있다.

전략 최적화 방향

  1. 신호의 정확성을 높이기 위해 더 많은 기술 지표 또는 시장 정서 지표, 예를 들어 브린 띠, ATR 등을 도입하는 것을 고려할 수 있습니다.
  2. 정지 손실을 위해, 정지 손실을 추적하거나 변동률에 따라 정지 손실 거리를 조정하는 것과 같은 더 역동적인 방법을 사용할 수 있습니다.
  3. 주요 뉴스 사건, 경제 데이터 발표 등과 같은 기초적인 분석과 결합하여 거래 신호를 필터링하여 특별한 시기에 거래를 피할 수 있습니다.
  4. 매개 변수 설정에 대해, 최적의 매개 변수 조합을 찾기 위해 기계 학습 또는 최적화 알고리즘을 사용할 수 있다.

요약하다

이 전략은 EMA, RSI 및 MACD와 같은 여러 기술 지표를 결합하여 전체적인 거래 시스템을 형성한다. 트렌드 상황에서 전략은 트렌드를 효과적으로 포착하고 동적 스톱 로즈로 위험을 제어 할 수 있다. 그러나, 충격적인 상황에서, 자주 거래하는 것은 수익에 영향을 미칠 수 있다.

전략 소스 코드
/*backtest
start: 2023-06-08 00:00:00
end: 2024-06-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("[BUY/SELL]EMA RSI MACD with TP and SL", overlay=true)

// Input parameters
ema1Length = input.int(9, title="EMA 1 Length")
ema2Length = input.int(21, title="EMA 2 Length")
ema3Length = input.int(34, title="EMA 3 Length")
rsiLength = input.int(14, title="RSI Length")
rsiThreshold = input.int(50, title="RSI Threshold")
macdFastLength = input.int(12, title="MACD Fast Length")
macdSlowLength = input.int(26, title="MACD Slow Length")
macdSignalSmoothing = input.int(9, title="MACD Signal Smoothing")
tpPips = input.int(10, title="Take Profit (pips)")
slPips = input.int(10, title="Stop Loss (pips)")

// HLCC4 calculation
hlcc4_custom = (high + low + close + close) / 4

// Calculate EMA and RSI based on HLCC4
ema1 = ta.ema(hlcc4_custom, ema1Length)
ema2 = ta.ema(hlcc4_custom, ema2Length)
ema3 = ta.ema(hlcc4_custom, ema3Length)
rsi = ta.rsi(hlcc4_custom, rsiLength)

// Calculate MACD Histogram
[a, b, histogram] = ta.macd(hlcc4_custom, macdFastLength, macdSlowLength, macdSignalSmoothing)

// EMA1 and EMA2 crossover conditions
emaCrossUp = ta.crossover(ema1, ema2)
emaCrossDown = ta.crossunder(ema1, ema2)

// BUY signal conditions
buySignal = emaCrossUp and hlcc4_custom > ema3 and rsi > rsiThreshold and close > open and histogram > 0

// SELL signal conditions
sellSignal = emaCrossDown and hlcc4_custom < ema3 and rsi < rsiThreshold and close < open and histogram < 0

var float entryPrice = na
var float tpPrice = na
var float slPrice = na

// Check if there is an open position and a contrary signal appears, then close all old orders first
if strategy.opentrades > 0
    if sellSignal and strategy.position_size > 0
        strategy.close("Buy", comment="Close Buy Order")
    if buySignal and strategy.position_size < 0
        strategy.close("Sell", comment="Close Sell Order")

// Place a BUY order when there is a BUY signal and set TP and SL based on pips
if buySignal and strategy.position_size == 0
    entryPrice := close
    tpPrice := entryPrice + tpPips * syminfo.mintick
    slPrice := entryPrice - slPips * syminfo.mintick
    strategy.entry("Buy", strategy.long)
    strategy.exit("Take Profit/Stop Loss", "Buy", limit=tpPrice, stop=slPrice)

// Place a SELL order when there is a SELL signal and set TP and SL based on pips
if sellSignal and strategy.position_size == 0
    entryPrice := close
    tpPrice := entryPrice - tpPips * syminfo.mintick
    slPrice := entryPrice + slPips * syminfo.mintick
    strategy.entry("Sell", strategy.short)
    strategy.exit("Take Profit/Stop Loss", "Sell", limit=tpPrice, stop=slPrice)

// Plot the crossover points of EMA1 and EMA2
plotshape(series=emaCrossUp, location=location.belowbar, color=color.aqua, style=shape.triangleup, title="EMA Cross Up", size=size.small)
plotshape(series=emaCrossDown, location=location.abovebar, color=color.red, style=shape.triangledown, title="EMA Cross Down", size=size.small)

// Plot the EMA lines on the chart
plot(ema1, title="EMA 1", color=color.aqua)
plot(ema2, title="EMA 2", color=color.red)
plot(ema3, title="EMA 3", color=color.yellow, linewidth=2)