Joanne on Crypto - MACD 스칼핑 전략과 함께 두 개의 이동 평균

저자:차오장, 날짜: 2023-11-02 16:09:08
태그:

img

전반적인 설명

이 전략의 핵심 아이디어는 트렌드를 따라 트렌드 방향을 결정하기 위해 이중 이동 평균과 MACD 지표를 결합하는 것입니다. 빠른 MA가 느린 MA보다 높을 때 상승 추세 기회를 신호합니다. 빠른 MA가 느린 MA보다 낮을 때 하락 추세 기회를 신호합니다. MACD 히스토그램은 0을 넘을 때 길고 0을 넘을 때 짧게 이동하여 특정 입문 및 출구 지점을 결정하는 데 사용됩니다.

전략 논리

  1. MACD의 빠른 EMA (12일), 느린 EMA (26일), 신호 EMA (9일) 를 계산합니다.

  2. MACD 히스토그램 (빠른 EMA - 느린 EMA) 및 MACD 신호 라인 (MACD 히스토그램의 9일 EMA) 을 계산합니다.

  3. 50일 및 200일 MAs를 트렌드로 계산합니다.

  4. MACD 히스토그램이 0을 넘으면 상승 신호이고 0을 넘으면 하락 신호입니다.

  5. 느린 EMA 위에 빠른 EMA를 넘어서고 긴 MA 위에 짧은 MA를 넘어서면 상승 신호가 나옵니다.

  6. 느린 EMA 아래로 빠른 EMA를 넘어가고 긴 MA 아래로 짧은 MA를 넘어가면 하향 신호가 나옵니다.

  7. EMA 크로스 파라미터 이후의 최대 트레이드를 사용하여 각 MA 크로스오버 이후 거래 제한 수

  8. 손해를 멈추고 수익을 취해서 거래를 종료하세요.

장점

  1. 이중 MAs는 역동적인 트렌드를 피하기 위해 전체 트렌드를 결정합니다.

  2. MACD는 트렌드 변동을 파악하기 위해 입점과 출구점을 식별합니다.

  3. 조합은 트렌드 방향으로 진입을 위한 좋은 타이밍을 제공합니다.

  4. 크로스오버 이후 트레이드 수를 제한하여 트렌드를 추구하고 있지 않도록 합니다.

  5. 손실을 멈추고 수익을 통제하는 위험을 감수하십시오.

  6. 더 나은 성능을 위해 매개 변수를 최적화 할 수 있습니다.

위험성

  1. 잘못된 트렌드 결정은 역 트렌드 손실로 이어집니다. 트렌드를 확고하게 설정하기 위해 MA 차이 요구 사항을 넓혀주세요.

  2. MACD 신호가 가격 동작을 지연시켜 조기 또는 늦은 엔트리를 초래합니다. MACD 매개 변수를 조정하거나 필터를 추가하십시오.

  3. 부적절한 스톱 로스 및 취리 레벨은 과도한 스톱 또는 불충분한 수익으로 이어집니다. 각 도구에 대한 매개 변수 최적화를 요구합니다.

  4. 매개 변수 최적화는 어렵다. 다른 제품과 시간 프레임에 따라 다른 매개 변수 조합이 필요합니다. 광범위한 사전 테스트가 필요합니다.

더 나은 기회

  1. 트렌드를 결정하기 위해 KD와 같은 다른 지표를 테스트하십시오.

  2. 다른 지표를 추가하여 MACD 신호를 필터링합니다. 볼링거 밴드, ATR 스톱과 같이요.

  3. 매 상품에 대한 스톱 로스를 최적화하고 수익을 취합니다.

  4. 더 나은 매개 변수를 찾기 위해 워크포워드 및 무작위 최적화를 활용합니다.

  5. 거래 빈도를 줄이기 위한 메커니즘을 추가합니다. MACD 영역과 같은 0 주위.

  6. 여러 제품에서 자동 매개 변수 및 조합 최적화

요약

이 전략은 트렌드 방향과 입점 타이밍에 대한 이중 MAs의 강점을 결합하여 견고한 트렌드 다음 시스템을 만듭니다. 매개 변수 최적화 및 지표 조합을 통해 추가 성능 이득이 가능합니다. 전반적으로 라이브 거래에 고려해야 할 강력한 리스크 관리 및 수익 잠재력이 있습니다. 그러나 매개 변수 테스트는 여전히 각 제품에 대한 견고성 확보가 필요합니다.


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

//@version=5
strategy(title="ComiCo - Joel on Crypto - MACD Scalping", shorttitle="ComiCo - Joel on Crypto - MACD Scalping")
// Getting inputs
slow_length1 = input(title="EMA Trend 1", defval=50)
slow_length2 = input(title="EMA Trend 2 ", defval=200)
fast_length = input(title="MACD Fast Length", defval=12)
slow_length = input(title="MACD Slow Length", defval=26)
signal_length = input.int(title="MACD Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
src = input(title="MACD Source", defval=close)

i_switch = input.string(title="Tick Highlight", defval="Moving average" ,options=["Moving average","Fixed value" ])
i_switch2 = input.string(title="Tick Source", defval="Highest bar" ,options=["Highest bar","Average","Last bar"])

signal_lengthup = input.int(title="Upticks Avg. Length",  minval = 1, maxval = 5000, defval = 72)
signal_lengthdown = input.int(title="Downticks Avg. Length",  minval = 1, maxval = 5000, defval = 72)

signal_lengthMA = input.float(title="Ticks Avg. Multiplier",  minval = 0, maxval = 5000, defval = 2, step = 0.1)

sma_source = "EMA"
sma_signal = "EMA"
// Plot colors

col_grow_above = #26A69A
col_fall_above =#B2DFDB
col_grow_below = #FFCDD2
col_fall_below = #FF5252
// Calculating

fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)

time_macd=timeframe.period=="1"?"1": timeframe.period=="3"?"1": timeframe.period=="5"?"1": timeframe.period=="15"?"3":timeframe.period=="30"?"5":timeframe.period=="60"?"15":timeframe.period=="120"?"30":timeframe.period=="240"?"60":timeframe.period=="D"?"240":timeframe.period=="W"?"D":timeframe.period=="M"?"W":timeframe.period=="12M"?"M":timeframe.period



macd = fast_ma - slow_ma
macd1=request.security(syminfo.tickerid, time_macd, macd)
signal = sma_signal == "SMA" ? ta.sma(macd1, signal_length) : ta.ema(macd1, signal_length)

ema50=ta.ema(close,slow_length1)
ema200=ta.ema(close ,slow_length2)

var TradeCounter = 0
MaxCount = input.int(title = "Max trades after EMA cross", minval = 0, maxval = 1000, defval = 3)
bull = ema50>ema200
if bull != bull[1]
    TradeCounter := 0


hist = request.security(syminfo.tickerid, time_macd, macd1 - signal)


f() => [hist[4],hist[3],hist[2],hist[1], hist]
ss=request.security(syminfo.tickerid, time_macd, hist, barmerge.gaps_on,barmerge.lookahead_off)



[ss5,ss4,ss3,ss2,ss1]=request.security(syminfo.tickerid, time_macd, f(), barmerge.gaps_on,barmerge.lookahead_off)



a = array.from(ss5,ss4,ss3,ss2,ss1)

s3=i_switch2=="Highest bar"?(ss>0? array.max(a, 0) : array.min(a, 0)):i_switch2=="Average"?array.avg(a):i_switch2=="Last bar"?ss1:0

saa=timeframe.period == '1'? ss:s3

saa2=timeframe.period == '1'? ss:s3*signal_lengthMA


colorss=(s3>=0 ? (s3[1] < s3 ? col_grow_above : col_fall_above) : (s3[1] < s3 ? col_grow_below : col_fall_below))


saadown = saa2
saaup = saa2

saadown:=saa>=0? saa2:saadown[1]

saaup:=saa<0? saa2:saaup[1]



verr=ta.ema(saadown,signal_lengthup)
dowww=ta.ema(saaup,signal_lengthdown)

ss22=plot(verr, title="Avg. Cloud Upper 1", color=color.new(color.white, 100))
ss33=plot(dowww, title="Avg. Cloud Lower 1", color=color.new(color.white, 100))

fill(ss22, ss33, color.new(color.white, 93), title="Avg. Cloud Background")

fixeduptick = input(title="Fixed Uptick Value", defval=30)
fixeddowntick = input(title="Fixed Downtick Value", defval=-30)
minl = i_switch=="Fixed value"? fixeduptick  :  verr
maxl = i_switch=="Fixed value"? fixeddowntick : dowww 

plot(minl, title="Avg. Cloud Upper 2", color=color.new(color.white, 81))
plot(maxl, title="Avg. Cloud Lower 2", color=color.new(color.white, 81))


colors2= s3<=minl and s3>=maxl ? #2a2e39 : colorss

coro2=s3>0? ema50>ema200 ? #2a2e39 :  colors2 : ema50<ema200 ? #2a2e39: colors2
plot(saa, title="Histogram", style=plot.style_columns, color=coro2)

LimitDiff = input.float(title="Limit Price Difference",  minval = 0, maxval = 0.1, defval = 0.005, step = 0.0005)
TP = input.float(title="Take Profit",  minval = 0, maxval = 0.1, defval = 0.005, step = 0.0005)
SL = input.float(title="Stop Loss",  minval = 0, maxval = 0.1, defval = 0.004, step = 0.0005)

minEMAdiff = input.float(title = "Min EMA difference", defval = 100, step = 10)

if #2a2e39 != coro2
    a22 = 0
    if ema50<ema200 and TradeCounter < MaxCount and math.abs(ema50-ema200) > minEMAdiff
        LimitPrice = close * (1 + LimitDiff)
        strategy.entry("enter short", strategy.short, limit = LimitPrice)
        strategy.exit("exit short", "enter short", limit = LimitPrice * (1 - TP), stop = LimitPrice * (1 + SL))
        TradeCounter := TradeCounter + 1
    if ema50>ema200 and TradeCounter < MaxCount and math.abs(ema50-ema200) > minEMAdiff
        LimitPrice = close * (1 - LimitDiff)
        strategy.entry("enter long", strategy.long, limit = LimitPrice)
        strategy.exit("exit long", "enter long", limit = LimitPrice * (1 + TP), stop = LimitPrice * (1 - SL))
        TradeCounter := TradeCounter + 1

//alertcondition(#2a2e39 != coro2 , title='MACD Tick Alert', message='Joel on Crypto - MACD Tick Alert')



더 많은