MACD를 기반으로 하는 암호화 거래 전략

저자:차오장, 날짜: 2023-09-19 11:21:42
태그:

전반적인 설명

이 전략은 암호화폐에 대한 거래 신호를 식별하기 위해 이동 평균 컨버전스 디버전스 (MACD) 및 상대 강도 지수 (RSI) 지표를 사용합니다. 거래 결정을 내리기 위해 시장 추세와 과잉 구매 / 과잉 판매 수준을 판단하기 위해 RSI와 함께 단기 및 장기 이동 평균의 차이를 계산합니다.

전략 논리

  1. 12일 EMA와 26일 EMA를 단기 및 장기 이동 평균으로 계산합니다.

  2. MACD 히스토그램으로 짧은 EMA와 긴 EMA의 차이를 계산합니다.

  3. MACD의 9일 EMA를 신호선으로 계산합니다.

  4. 14일 RSI를 계산해서 과잉 구매/ 과잉 판매 수준을 판단합니다.

  5. MACD가 신호선을 넘어서고 RSI가 81보다 높을 때 구매 신호를 표시합니다.

  6. MACD가 신호선 아래로 넘어가고 RSI가 27보다 작을 때 판매 신호를 표시합니다.

  7. 입구와 출구에 내장된 전략 모듈을 사용하세요.

이점 분석

  1. MACD는 트렌드와 변화를 식별할 수 있고, RSI는 과잉 구매/ 과잉 판매 수준을 보여줍니다. 이 둘을 결합하면 신호 정확도가 향상됩니다.

  2. MACD는 0선 이상/하위에서 단기 트렌드와 장기 트렌드의 방향/강도를 나타냅니다.

  3. RSI는 높은/저한 수준에서 가능한 과열/ 과판을 나타냅니다. 거래 신호를 찾는 데 도움이 됩니다.

  4. 명확하고 간단한 거래 신호, 체계적으로 거래를 실행하기 쉽습니다.

  5. 최적화 및 다른 시장 조건에 적응하기 위해 사용자 정의 가능한 매개 변수.

위험 분석

  1. MACD 및 RSI 데이터는 잘못된 파업 및 이상으로 인해 잘못된 신호를 생성 할 수 있습니다.

  2. 고정된 매개 변수는 변화하는 시장에 적응하지 못할 수도 있고 최적화가 필요합니다.

  3. 신호가 지연되어 전환점에 거래할 수 없게 될 수 있습니다.

  4. 단기/장기만, 다양한 시장에서 수익을 낼 수 없습니다.

최적화 방향

  1. 최적의 설정을 찾기 위해 다른 매개 변수 조합을 테스트합니다.

  2. 가짜 브레이크 트레이드를 피하기 위해 필터를 추가합니다.

  3. 한쪽 시장에서 손실을 제한하기 위해 Stop Loss를 추가합니다.

  4. 포지션 크기와 트렌드 증가 및 범위 감소를 관리합니다.

  5. 더 정확한 신호를 얻기 위해 다른 지표와 결합합니다.

  6. 다른 기기와 시간 프레임에서 테스트합니다.

요약

이 전략은 트렌드와 거래 신호를 식별하기 위해 MACD와 RSI의 보완적인 강점을 활용합니다. 미세한 조정 매개 변수 및 필터를 추가하면 안정성과 수익성을 향상시킬 수 있습니다. 정지 및 위치 사이징 조정 또한 이익을 극대화하고 위험을 최소화하는 데 도움이됩니다. MACD와 RSI의 장단점은 이 전략을 단기 거래보다는 중장기 트렌드를 잡기 위해 더 적합하게 만듭니다. 전반적으로 개선된 백테스트 및 라이브 결과를 달성하기 위해 추가 테스트 및 최적화를 가치가있는 간단하고 실용적인 전략입니다.


/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-12 04:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Revision:        5
// Author:          @Hugo_Moriceau
//study("Thesis_EMLYON_Withdate-strategies-Daily_Crypto_Moriceau_indicator",overlay=true)

// Pyramide 10 order size 100, every tick

strategy("Daily_Crypto_Moriceau_indicator",overlay=true)

// === GENERAL INPUTS ===

fast = 12, slow = 26
fastMA = ema(close, fast)
slowMA = ema(close, slow)

macd = fastMA - slowMA
signal = sma(macd, 9)
rsi = rsi(close,14)



tradeInvert     = input(defval = false, title = "Invert Trade Direction?")

// === LOGIC ===

// is fast ma above slow ma?
aboveBelow = fastMA >= slowMA ? true : false

// are we inverting our trade direction?
tradeDirection = tradeInvert ? aboveBelow ? false : true : aboveBelow ? true : false

// === Plot Setting ===

//plot(fastMA,color=red)
//plot(slowMA,color=blue)
//barcolor(color=iff(fastMA > slowMA, yellow, na))
//barcolor(color=iff(fastMA < slowMA, black, na))
barcolor(color=iff(macd > 0.12*close , fuchsia, na))
barcolor(color=iff(macd < -0.1*close , lime, na))
dataS= macd > 0.125 and rsi>81 and fastMA > slowMA
dataB= macd < -0.1  and rsi<27 and fastMA< slowMA


plotchar(dataB, char='B',color=black,size = size.tiny,location = location.belowbar,transp= 0)  
plotchar(dataS, char='S',color=black,size = size.tiny,location = location.abovebar,transp= 0)


// === BACKTEST RANGE ===
FromMonth = input(defval = 01, title = "From Month", minval = 1)
FromDay   = input(defval = 01, title = "From Day", minval = 1)
FromYear  = input(defval = 2017, title = "From Year", minval = 2014)
ToMonth   = input(defval = 2, title = "To Month", minval = 1)
ToDay     = input(defval = 10, title = "To Day", minval = 1)
ToYear    = input(defval = 2019, title = "To Year", minval = 2018)


// === STRATEGY RELATED INPUTS ===+
// the risk management inputs
inpTakeProfit   = input(defval = 20000, title = "Take Profit", minval = 0)
inpStopLoss     = input(defval = 1500, title = "Stop Loss", minval = 0)
inpTrailStop    = input(defval = 100, title = "Trailing Stop Loss", minval = 0)
inpTrailOffset  = input(defval = 0, title = "Trailing Stop Loss Offset", minval = 0)

// === RISK MANAGEMENT VALUE PREP ===

// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.

useTakeProfit   = inpTakeProfit  >= 1 ? inpTakeProfit  : na
useStopLoss     = inpStopLoss    >= 1 ? inpStopLoss    : na
useTrailStop    = inpTrailStop   >= 1 ? inpTrailStop   : na
useTrailOffset  = inpTrailOffset >= 1 ? inpTrailOffset : na


// === STRATEGY - LONG POSITION EXECUTION ===

enterLong() => not tradeDirection[1] and tradeDirection 
exitLong() => tradeDirection[1] and not tradeDirection
strategy.entry(id = "Long", long = true, when = enterLong()) // use function or simple condition to decide when to get in
strategy.close(id = "Long", when = exitLong()) // ...and when to get out

// === STRATEGY - SHORT POSITION EXECUTION ===

enterShort() => tradeDirection[1] and not tradeDirection
exitShort() => not tradeDirection[1] and tradeDirection
strategy.entry(id = "Short", long = false, when = enterShort())
strategy.close(id = "Short", when = exitShort())

// === STRATEGY RISK MANAGEMENT EXECUTION ===

// finally, make use of all the earlier values we got prepped
strategy.exit("Exit Long", from_entry = "Long", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Exit Short", from_entry = "Short", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)

더 많은