이중 이동 평균 및 MACD 조합 단기 거래 전략

저자:차오장, 날짜: 2023-10-09 16:47:42
태그:

전반적인 설명

이 전략은 이중 이동 평균, 스토카스틱 지표 및 MACD를 결합하여 비교적 고전적인 단기 거래 전략인 단기 거래 기회를 식별합니다.

원칙

이 전략은 주로 다음과 같은 원칙에 기초합니다.

  1. 트렌드 방향을 결정하기 위해 50주기 및 100주기 EMA를 사용한다. 짧은 기간이 있는 EMA는 가격 변화에 빠르게 반응할 수 있다. 50주기 EMA를 100주기 EMA 위에 넘기는 것은 긴 포지션을 설정하는 것을 나타내고, 아래로 넘기는 것은 짧은 포지션을 설정하는 것을 나타낸다.

  2. 입점과 출구 지점을 결정하기 위해 MACD 사이의 차이를 사용하십시오. 차이가 0을 넘으면 황소 힘의 강화를 나타내고 긴 진입으로 이어집니다. 0을 넘으면 곰 힘의 강화를 나타내고 짧은 진입으로 이어집니다.

  3. 과반 구매 및 과반 판매 상황을 판단하기 위해 스토카스틱 RSI 지표를 결합하십시오. 이 지표는 KDJ 및 RSI의 장점을 결합하고 과반 구매 및 과반 판매 조건을 잘 보여줄 수 있습니다. 20보다 낮으면 시장이 과반 판매되고 긴 진입은 다른 지표를 결합하는 것으로 간주 될 수 있습니다. 80보다 높으면 시장이 과반 구매되고 짧은 진입을 고려 할 수 있습니다.

  4. 진입 방향을 결정한 후, 가장 최근 5개의 촛불 가운데 4개의 닫기 가격이 이동평균에 닿는 경우, 이동평균 주변에 지원/저항이 있음을 보여줍니다. 그리고 포지션은 열 수 있습니다.

  5. 스톱 로스를 사용하고 리스크를 관리하기 위해 이윤을 취합니다.

장점

이 전략의 장점은 다음과 같습니다.

  1. 여러 지표의 조합은 이동 평균, 과잉 구매/ 과잉 판매 지표 및 동력 지표를 함께 사용하여 승률을 향상시킵니다.

  2. 짧은 기간 이동 평균은 트렌드와 반전을 빠르게 파악 할 수 있습니다. MACD 매개 변수는 정확한 입시 신호를 생성하도록 최적화되었습니다.

  3. 스토카스틱 RSI 매개 변수는 과잉 구매/ 과잉 판매 상황을 잘 식별하기 위해 최적화됩니다.

  4. 타이밍 컨트롤을 위해 이동 평균에 대한 지원/ 저항을 사용하면 가짜 브레이크에 갇히지 않습니다.

  5. 합리적인 스톱 로스 및 영업이익은 각 거래의 위험을 효과적으로 제어합니다.

위험성

이 전략에는 몇 가지 위험도 있습니다.

  1. 가짜 탈출으로 인한 손실을 완전히 피할 수 없습니다.

  2. 지표들 사이에 오차가 발생할 수 있어 거래 신호가 불일치할 수 있습니다.

  3. 일정한 스톱 로즈와 영업이익은 시장 변화에 적응하지 못할 수 있습니다.

  4. 많은 매개 변수를 가진 복잡한 코드는 최적화하기가 어렵습니다.

해결책은 다음과 같습니다.

  1. 신호 품질을 높이고 가짜 탈출 가능성을 낮추기 위해 매개 변수를 최적화합니다.

  2. 충돌을 피하기 위해 지표들 사이에서 우선 순위를 설정합니다.

  3. 동적 스톱 로스를 채택하고 ATR 범위를 기반으로 수익을 취합니다.

  4. 논리를 단순화하고 테스트와 최적화를 위해 핵심 매개 변수를 추출합니다.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 이동 평균 기간과 MACD 매개 변수들의 최적의 조합을 테스트하고 찾아내십시오.

  2. 스토카스틱 RSI를 대체하기 위해 다른 과잉 구매/ 과잉 판매 지표를 테스트합니다.

  3. 역동적인 스톱 로스를 시도하고, 수익을 취하고, 리스크 관리를 더 지능적으로 만들기 위해 트레일링 스톱을 시도하세요.

  4. 신호 품질을 향상시키기 위해 볼륨을 높이는 것과 같은 필터링 조건을 추가합니다.

  5. 트렌드를 결정하기 위해 더 많은 지표를 사용하여 비효율적인 브레이크오웃을 피하기 위해 엔트리 로직을 최적화하십시오.

  6. 전체 위험을 통제하기 위해 계좌 크기와 하루 거래 수에 따라 스톱 로스 제한을 설정합니다.

요약

이 전략은 여러 지표의 장점을 통합하고 단기 거래에 매우 실용적입니다. 파라미터 최적화, 엄격한 엔트리 로직 및 향상된 리스크 관리로 안정성과 수익성이 더욱 향상 될 수 있습니다. 일부 경험을 가진 단기 거래자에게 적합하지만 큰 손실을 피하기 위해 위험을 통제해야합니다.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-10-08 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy(title="Forex scalper 2xEMA + SRSI + MACD", shorttitle="Forex scalper 5-15min", overlay=true)
src = input(title="Source", type=input.source, defval=close)

src_0 = src[0]
src_1 = src[1]
src_2 = src[2]
src_3 = src[3]
src_4 = src[4]

len50 = input(50, minval=1, title="Length")
src50 = input(close, title="Source")
out50 = ema(src50, len50)
len100 = input(100)
src100 = input(close, title="Source")
out100 = ema(src100, len100)

len1 = input(1, minval=1, title="Length")
src1 = input(close, title="Source")
out1 = sma(src1, len1)

length = input(4, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3

k = sma(stoch(close, high, low, length), smoothK)
d = sma(k, smoothD)
cu = crossover(k,OverSold)
co = crossunder(k,OverBought)

sma_down = crossunder(out1, out50)
sma_up = crossover(out1,out50)

//if (not na(k) and not na(d))
  //  if (co and k < OverSold)
    //    strategy.entry("StochLE", strategy.long, comment="StochLE")
    //if (cu and k > OverBought)
     //   strategy.entry("StochSE", strategy.short, comment="StochSE")

crossCandle_4 = crossover(src[4],out50)
crossCandleUnder_4= cross(src[4],out50)
crossCandle_3 = crossover(src[3],out50)
crossCandleUnder_3= crossunder(src[3],out50)
crossCandle_2 = crossover(src[2],out50)
crossCandleUnder_2= crossunder(src[2],out50)
crossCandle_1 = crossover(src[1],out50)
crossCandleUnder_1= crossunder(src[1],out50)
crossCandle_0 = crossover(src[0],out50)
crossCandleUnder_0= crossunder(src[0],out50)

conditionOver = (crossCandle_4 or crossCandle_3 or crossCandle_2 or crossCandle_1 or crossCandle_0)
conditionUnder =(crossCandleUnder_4 or crossCandleUnder_3 or crossCandleUnder_2 or crossCandleUnder_1 or crossCandleUnder_0)

touch4 = (cross(low[4],out50) or cross(high[4],out50))
touch3 = (cross(low[3],out50) or cross(high[3],out50))
touch2 = (cross(low[2],out50) or cross(high[2],out50))
touch1 = (cross(low[1],out50) or cross(high[1],out50))

touch = touch1 or touch2 or touch3 or touch4

//and sma_up
//and sma_down

// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src_macd = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 10)
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00

// Calculating
fast_ma = sma_source ? sma(src_macd, fast_length) : ema(src_macd, fast_length)
slow_ma = sma_source ? sma(src_macd, slow_length) : ema(src_macd, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal

//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
//plot(macd, title="MACD", color=col_macd, transp=0)
//plot(signal, title="Signal", color=col_signal, transp=0)


// plot((conditionOver or conditionUnder or touch)  and src[0] >= out50 and close >= out50 and  (cu) and out50 > out100 and hist>=0 , title="Buy", style=columns, color=lime)
// plot((conditionOver or conditionUnder or touch)  and src[0] <= out50 and close <= out50 and  (co) and out50< out100 and hist<=0 , title="sell", style=columns, color=red)


long_cond = ((conditionOver or conditionUnder or touch)  and src[0] >= out50 and close > out50 and  (cu) and out50 > out100 and hist>=0)
short_cond = ((conditionOver or conditionUnder or touch)  and src[0] <= out50 and close < out50 and  (co) and out50< out100 and hist<=0)

tp=input(200)
sl=input(200)

strategy.entry("long",strategy.long, when=long_cond)
strategy.entry("short",strategy.short, when=short_cond)

strategy.exit("X_long", "long", profit=tp,  loss=sl, when=touch  )
strategy.exit("x_short", "short",profit=tp, loss=sl,when = touch )

더 많은