동적 이동 평균 크로스오버 컴보 전략

저자:차오장, 날짜: 2024-02-05 10:23:10
태그:

img

전반적인 설명

동적 이동 평균 크로스오버 콤보 전략은 여러 기술적 지표와 시장 상태 검출을 통합하는 복합 거래 전략이다. 동적으로 시장 변동성을 계산하고 장기 이동 평균과 변동성: 변동성, 트렌딩 및 통합의 가격 거리에 따라 세 가지 시장 단계를 결정합니다. 다른 시장 조건 하에서 전략은 다른 입출 규칙을 채택하고 EMA/SMA 크로스오버, MACD 및 볼링거 밴드와 같은 지표의 조합으로 구매 및 판매 신호를 생성합니다.

전략 논리

시장 변동성 계산

ATR 지표를 사용하여 최근 14 일 동안의 시장 변동성을 측정합니다. 100 일 SMA 필터를 적용하여 평균 변동성을 얻습니다.

시장 단계 를 결정

가격과 200일 SMA 사이의 거리를 계산합니다. 절대 거리가 명확한 방향의 평균 변동의 1.5배를 초과하면 트렌딩 시장으로 결정됩니다. 현재 변동이 평균의 1.5배를 초과하면 변동 시장입니다.

EMA/SMA 크로스오버

빠른 EMA 기간은 10일이다. 느린 SMA 기간은 30일이다. 빠른 EMA가 느린 SMA를 넘을 때 구매 신호가 생성된다.

MACD

MACD를 12, 26, 9 매개 변수로 계산합니다. 긍정적 MACD 히스토그램은 구매 신호를 제공합니다.

볼링거 밴드

20일 표준편차 채널을 계산합니다. 채널 폭이 20일 SMA보다 작으면 통합됩니다.

입국 규칙

변동성: 크로스오버 또는 MACD가 양성하면 가격 범위 내에서 장면을 입력합니다.

트렌딩: 크로스오버 또는 MACD가 긍정적일 때 장면을 입력합니다.

통합: 크로스오버가 하위 범위를 넘어서면 장면을 입력합니다.

출입규칙

일반: MACD가 마이너스 2 바로 떨어지고 가격이 2 일 떨어지면 출입합니다.

변동성: 주식RSI가 과잉 매입되면 출출을 더합니다.

통합: 상위 지대 이하의 가격에 출입을 더합니다.

장점

이 전략은 다음과 같은 강점을 가지고 있습니다.

  1. 주관적 개입이 적은 체계적인 작업.

  2. 시장 조건에 따라 조정된 적응 파라미터

  3. 더 높은 신호 정확성

  4. 볼링거 밴드에서 자동 스톱 손실을 줄이는 위험.

  5. 거짓 신호를 피하기 위해 모든 상태 필터링을 둥글게

  6. 동적 스톱 로스 및 트렌드를 따라 수익을 취합니다.

위험성

주요 위험은 다음과 같습니다.

  1. 잘못된 파라미터 튜닝이 있으면 전략이 유효하지 않습니다. 최적화가 제안됩니다.

  2. 갑작스러운 사건으로 인해 모델 고장이 발생했습니다. 논리 업데이트가 좋습니다.

  3. 거래비용에서 압축된 이익 마진 낮은 수수료 브로커 추천

  4. 복수의 모듈이 더 복잡해서 핵심 지표가 좋습니다.

강화

최적화의 잠재적인 방향:

  1. 시장 환경 판단 기준을 개선

  2. 자동 매개 변수 적응을 위한 기계 학습을 도입합니다.

  3. 이벤트를 감지하기 위해 텍스트 분석을 추가합니다.

  4. 가장 좋은 매개 변수를 찾기 위해 여러 시장에서 백테스팅을 합니다.

  5. 더 나은 수익을 위해 트레일링 스톱 전략을 실행하십시오.

결론

동적 이동 평균 크로스오버 컴보 전략은 지능적인 다중 지표 양적 거래 시스템입니다. 체계적인 규칙 기반 거래를 구현하기 위해 시장 조건에 따라 매개 변수를 동적으로 조정합니다. 전략은 매우 적응적이고 결정적입니다. 그러나 매개 변수 및 추가 모듈은 과도한 복잡성을 피하기 위해 신중하게 도입해야합니다. 전반적으로 이것은 실행 가능한 양적 전략 아이디어입니다.


/*backtest
start: 2024-01-28 00:00:00
end: 2024-02-04 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Improved Custom Strategy", shorttitle="ICS", overlay=true)

// Volatility
volatility = ta.atr(14)
avg_volatility_sma = ta.sma(volatility, 100)
avg_volatility = na(avg_volatility_sma) ? 0 : avg_volatility_sma

// Market Phase detection
long_term_ma = ta.sma(close, 200)
distance_from_long_term_ma = close - long_term_ma
var bool isTrending = math.abs(distance_from_long_term_ma) > 1.5 * avg_volatility and not na(distance_from_long_term_ma)
var bool isVolatile = volatility > 1.5 * avg_volatility

// EMA/MA Crossover
fast_length = 10
slow_length = 30
fast_ma = ta.ema(close, fast_length)
slow_ma = ta.sma(close, slow_length)
crossover_signal = ta.crossover(fast_ma, slow_ma)

// MACD
[macdLine, signalLine, macdHistogram] = ta.macd(close, 12, 26, 9)
macd_signal = crossover_signal or (macdHistogram > 0)

// Bollinger Bands
source = close
basis = ta.sma(source, 20)
upper = basis + 2 * ta.stdev(source, 20)
lower = basis - 2 * ta.stdev(source, 20)
isConsolidating = (upper - lower) < ta.sma(upper - lower, 20)

// StockRSI
length = 14
K = 100 * (close - ta.lowest(close, length)) / (ta.highest(close, length) - ta.lowest(close, length))
D = ta.sma(K, 3)
overbought = 75
oversold = 25

var float potential_SL = na
var float potential_TP = na
var bool buy_condition = na
var bool sell_condition = na

// Buy and Sell Control Variables
var bool hasBought = false
var bool hasSold = true

// Previous values tracking
prev_macdHistogram = macdHistogram[1]
prev_close = close[1]

// Modify sell_condition with the new criteria
if isVolatile
    buy_condition := not hasBought and crossover_signal or macd_signal and (close > lower) and (close < upper)
    sell_condition := hasBought and (macdHistogram < 0 and prev_macdHistogram < 0) and (close < prev_close and prev_close < close[2])
    potential_SL := close - 0.5 * volatility
    potential_TP := close + volatility

if isTrending
    buy_condition := not hasBought and crossover_signal or macd_signal
    sell_condition := hasBought and (macdHistogram < 0 and prev_macdHistogram < 0) and (close < prev_close and prev_close < close[2])
    potential_SL := close - volatility
    potential_TP := close + 2 * volatility

if isConsolidating
    buy_condition := not hasBought and crossover_signal and (close > lower)
    sell_condition := hasBought and (close < upper) and (macdHistogram < 0 and prev_macdHistogram < 0) and (close < prev_close and prev_close < close[2])
    potential_SL := close - 0.5 * volatility
    potential_TP := close + volatility

// Update the hasBought and hasSold flags
if buy_condition
    hasBought := true
    hasSold := false

if sell_condition
    hasBought := false
    hasSold := true

// Strategy Entry and Exit
if buy_condition
    strategy.entry("BUY", strategy.long, stop=potential_SL, limit=potential_TP)
    strategy.exit("SELL_TS", from_entry="BUY", trail_price=close, trail_offset=close * 0.05)

if sell_condition
    strategy.close("BUY")
    
// Visualization
plotshape(series=buy_condition, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=sell_condition, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)

plot(long_term_ma, color=color.gray, title="200-Day MA", linewidth=1)
plot(potential_SL, title="SL Level", color=color.red, linewidth=1, style=plot.style_linebr)
plot(potential_TP, title="TP Level", color=color.green, linewidth=1, style=plot.style_linebr)

bgcolor(isVolatile ? color.new(color.purple, 90) : isTrending ? color.new(color.blue, 90) : isConsolidating ? color.new(color.orange, 90) : na)


더 많은