빠르게 움직이는 평균 이중 지표 교차 롱 앤 숏 전략


생성 날짜: 2023-11-22 17:29:04 마지막으로 수정됨: 2023-11-22 17:29:04
복사: 0 클릭수: 615
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

빠르게 움직이는 평균 이중 지표 교차 롱 앤 숏 전략

개요

빠른 이동 평균 이중 지표 교차 다공지 전략 (Dual Moving Average Crossover Trend Strategy) 은 빠른 이동 평균과 느린 이동 평균의 교차를 이용하여 구매 신호를 형성하는 트렌드 추적 전략이다. 이 전략은 동시에 MACD, RSI 등 여러 지표를 결합하여 트렌드 방향을 결정하는데, 강한 트렌드 추적 능력을 가지고 있다.

전략 원칙

이 전략은 다음과 같은 몇 가지 지표에 따라 판단됩니다.

  1. 빠른 이동 평균과 느린 이동 평균: 빠른 라인 상의 느린 라인을 가로질러 구매 신호를, 빠른 라인 아래의 느린 라인을 가로질러 판매 신호를 낸다.

  2. MACD: MACD 라인이 Signal 라인보다 높고 MACD 최저가 상승할 때 다중선 신호이다.

  3. RSI: RSI가 50보다 높으면 멀티 헤드 신호이며, 50보다 낮으면 공백 신호이다.

  4. 측정 오실레이터 (AO): AO 위 0축을 통과하면 구매 신호이며, AO 아래 0축을 통과하면 판매 신호이다.

  5. 일선 레벨의 세 개의 이동 평균: 일선 레벨의 짧은 주기 이동 평균 위에 더 긴 주기 이동 평균을 뚫고 구매 신호를 다.

이 전략은 여러 시간 주기와 여러 지표를 통합하여 구매 및 판매 판단 논리를 형성한다. 여러 지표가 동시에 구매 신호가 발생하면 구매 지시가 발생하고, 여러 지표가 동시에 판매 신호가 발생하면 판매 지시가 발생하여 트렌드를 추적한다.

우위 분석

이 전략에는 다음과 같은 장점이 있습니다.

  1. 다중 지표 조합 판단, 잘못된 신호를 방지, 판단 정확도를 높여라.

  2. 여러 시기를 통한 판단을 통해 더 큰 차원의 트렌드 방향을 파악할 수 있다.

  3. 지표 매개 변수가 최적화되고, Parameters tuning, 더 좋은 수익률을 가지고 있다.

  4. 이동적 손실을 사용하여 위험을 통제하고 손실을 막습니다.

  5. 자동 트렌드 추적 운영, 인적 개입 없이, 운영 비용 절감.

위험 분석

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

  1. 불안정한 상황에서 더 많은 무효 거래 신호가 발생할 수 있다. 지표 매개 변수를 최적화하여 무효 신호를 줄일 수 있다.

  2. 급격한 사건으로 인해 급격한 철수할 수 있다. 손해를 제어하기 위해 이동식 스톱을 설정할 수 있다.

  3. 다공간 신호 결정 규칙은 더 복잡하고, 변수 최적화는 많은 역사 데이터의 지원을 필요로 한다.

  4. 추적 중지 설정이 부적절하면 조기 종료가 발생할 수 있습니다. 최적의 매개 변수를 결정하기 위해 반복 테스트가 필요합니다.

최적화 방향

이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.

  1. 더 안정적이고 정확한 거래 신호를 찾기 위해 더 많은 지표의 조합을 테스트하십시오. 예를 들어 변동률 지표, OBV 지표 등이 있습니다.

  2. 지표 파라미터를 최적화하여 유효하지 않은 거래의 수를 줄인다. 기계 학습과 유전 알고리즘을 사용하여 최적화 파라미터를 자동으로 찾는다.

  3. 모델 통합 기술을 추가하고, 더 많은 독립적인 전략 모델 판단 결과를 통합한다. 안정성을 높인다.

  4. 높은 주파수 레벨에서 입력하고 낮은 주파수 레벨에서 종료한다.

  5. 정량화된 풍력 제어 모듈을 추가하고, 단발 손실 비율, 최대 회수 비율 등을 엄격하게 제어한다.

요약하다

빠른 평균 쌍 지표 크로스 다공간 전략은 빠른 이동 평균선과 느린 이동 평균선의 교차로 거래 신호를 형성하고 MACD, RSI 등의 여러 지표와 결합하여 트렌드 방향을 판단하여 자동화된 트렌드 추적을 구현한다. 이 전략의 최적화 공간은 넓고, 더 많은 지표를 도입하고, 매개 변수를 조정하고, 모델 통합과 같은 수단을 통해 더 나은 전략 효과를 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-10-22 00:00:00
end: 2023-11-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('SteffVans', shorttitle='SteffVans strategy', overlay=true, process_orders_on_close = true)

// Input settings
macd_fast_length = input(12)
macd_slow_length = input(26)
macd_signal_length = input(9)

// Calculate MACD values
[macd_line, signal_line, _] = ta.macd(close, macd_fast_length, macd_slow_length, macd_signal_length)
mg = ta.lowest(signal_line, 30) >= -0

// RSI
ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1)
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
RSI = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))


//  AO
AO = ta.sma((high + low) / 2, 5) - ta.sma((high + low) / 2, 34)
crossaosell = AO < AO[1] and AO[1] < AO[2] and AO[2] > AO[3]  and ta.lowest(low,3)

// Uptrend sma
len1 = input.int(5, minval=1)
len2 = input.int(10, minval=1)
len3 = input.int(20, minval=1)
src = input(close)

out1 = ta.sma(src, len1)
out2 = ta.sma(src, len2)
out3 = ta.sma(src, len3)



// Timeframe 
macdl60 = request.security(syminfo.tickerid, "60", signal_line,lookahead = barmerge.lookahead_on)
ao = request.security(syminfo.tickerid, "60", AO,lookahead = barmerge.lookahead_on)
rsi = request.security(syminfo.tickerid, "60", RSI,lookahead = barmerge.lookahead_on)
good = request.security(syminfo.tickerid, "60", mg,lookahead = barmerge.lookahead_on)
bad = request.security(syminfo.tickerid, "60", crossaosell,lookahead = barmerge.lookahead_on)

ma1 = request.security(syminfo.tickerid, "D", out1,lookahead = barmerge.lookahead_on)
ma2 = request.security(syminfo.tickerid, "D", out2, lookahead = barmerge.lookahead_on)
ma3 = request.security(syminfo.tickerid, "D", out3, lookahead = barmerge.lookahead_on)






// Kriteria BUY and SELL
uptrend1 =  request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) > ma1 and ma1 > ma3 and ma2 > ma3
uptrend2 = ta.lowest(ma1,12) > ta.lowest(ma3,12) and ta.lowest(ma2,12) > ta.lowest(ma3,12) 


 

// Triger BUY and SELL 
cross1 = ao > ao[1] and ao[1] < ao[2] and ao > 0 and good and rsi >= 60 and uptrend1
cross2 = ao > 0 and ao[1] < 0 and good and rsi >=50 and uptrend1
cross3 =  ao > 0 and ao[1] < 0 and not good and uptrend2 and uptrend1
cross4 =  ao > ao[1] and ao[1] > ao[2] and ao[2] < ao[3] and ao[3] < ao[4]  and not good and uptrend2 and uptrend1

s1 = ao < ao[1] and ao[1] < ao[2] and ao[2] < ao[3] and ao > 0 and rsi < 50 and request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) < ma1
s2 =  ao < 0 and ao < ao[2] and rsi < 50 and request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) < ma1 

// Variabel Buy dan Sell
buySignal = false
sellSignal = false

// Syarat masuk Buy
buyCondition =  cross1 or cross2 or cross3 or cross4
if buyCondition
    buySignal := true

// Syarat masuk Sell
sellCondition = s1 or s2
if sellCondition
    sellSignal := true

// Reset sinyal jika ada sinyal berulang
if buySignal and sellSignal
    sellSignal := false
if sellSignal and buySignal
    buySignal := false

// Logika perdagangan
if buySignal
    strategy.entry("Buy", strategy.long, comment = "BUY")
if sellSignal
    strategy.close("Buy")


plotshape(cross1,title = "Stefkuy1", style = shape.labelup, location = location.belowbar, color = color.green,text = "1", textcolor = color.white,size = size.small)
plotshape(cross2,title = "Stefkuy2", style = shape.labelup, location = location.belowbar, color = color.green, text = "2", textcolor= color.white, size = size.small)
plotshape(cross3,title = "StefVan1", style = shape.labelup, location = location.belowbar, color = color.rgb(0, 153, 255), text = "3", textcolor= color.white,size = size.small)
plotshape(cross4,title = "StefVan2", style = shape.labelup, location = location.belowbar, color = color.rgb(0, 153, 255), text = "4", textcolor= color.white,size = size.small)