동적 SMA 크로스 트렌드 전략

저자:차오장, 날짜: 2024-02-05 12:14:12
태그:

img

전반적인 설명

이 전략은 암호화폐 시장에 적합한 간단한 이동 평균 (SMA) 크로스오버 전략이다. 빠른, 중간 및 느린 SMA를 사용하여 잠재적 진입 및 출구 신호를 식별합니다. 빠른 SMA가 중간 SMA를 넘을 때 구매 신호가 생성됩니다. 빠른 SMA가 중간 SMA를 넘을 때 판매 신호가 생성됩니다.

전략 논리

매개 변수 설정

이 전략은 거래자가 다음의 주요 매개 변수를 설정할 수 있도록 합니다.

  • 가격 소스: 폐쇄 가격 또는 다른 가격
  • 불완전한 바를 고려하거나
  • SMA 예측 방법: 변동 예측 또는 선형 회귀 예측
  • 빠른 SMA 길이: 기본 7
  • 중간 SMA 길이는 기본 30
  • 느린 SMA 길이: 기본 50
  • 계좌 자금
  • 거래당 위험 비율

SMA 계산

빠른 SMA, 중간 SMA 및 느린 SMA는 사용자가 설정한 SMA 길이를 기반으로 계산됩니다.

거래 신호

빠른 SMA가 중간 SMA를 넘을 때 구매 신호가 생성됩니다. 빠른 SMA가 중간 SMA를 넘을 때 판매 신호가 생성됩니다.

리스크 및 포지션 크기

이 전략은 거래당 명목 원금과 거래당 수용 가능한 위험 비율을 기준으로 거래당 명목 원금을 계산합니다. 그 다음 ATR을 사용하여 스톱 로스 범위를 계산하고 최종적으로 각 거래에 대한 포지션 크기를 결정합니다.

이점 분석

  • 더 확실한 트렌드를 식별하기 위해 여러 SMA를 사용합니다.
  • 더 나은 적응력을 위한 선택적인 SMA 예측 방법
  • 간단하고 명확한 거래 신호
  • 과학적인 위험 및 위치 관리

위험 분석

  • SMA의 지연 성격은 가격 반전 지점을 놓칠 수 있습니다
  • 기하급수적 지표만 고려하고 기본 지표를 결합하지 않습니다.
  • 갑작스러운 사건의 영향을 고려하지 않습니다.

SMA 기간을 단축하고 다른 지표를 추가하여 최적화 할 수 있습니다.

최적화 방향

  • 거짓 신호를 필터링하기 위해 다른 표시기를 추가합니다.
  • 기본 분석을 포함
  • SMA 기간 매개 변수를 최적화
  • 리스크 및 포지션 사이즈 매개 변수를 최적화

결론

이 전략은 암호화 시장에 적합한 강력한 트렌드 다음 시스템을 위해 SMA 크로스오버 규칙, 리스크 관리 및 포지션 사이징을 통합합니다. 거래자는 거래 스타일, 시장 조건 등과 같은 매개 변수를 조정하여 사용자 정의하고 최적화 할 수 있습니다.


/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Onchain Edge Trend SMA Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Configuration Parameters
priceSource = input(close, title="Price Source")
includeIncompleteBars = input(true, title="Consider Incomplete Bars")
maForecastMethod = input(defval="flat", options=["flat", "linreg"], title="Moving Average Prediction Method")
linearRegressionLength = input(3, title="Linear Regression Length")
fastMALength = input(7, title="Fast Moving Average Length")
mediumMALength = input(30, title="Medium Moving Average Length")
slowMALength = input(50, title="Slow Moving Average Length")
tradingCapital = input(100000, title="Trading Capital")
tradeRisk = input(1, title="Trade Risk (%)")

// Calculation of Moving Averages
calculateMA(source, period) => sma(source, period)
predictMA(source, forecastLength, regressionLength) => 
    maForecastMethod == "flat" ? source : linreg(source, regressionLength, forecastLength)

offset = includeIncompleteBars ? 0 : 1
actualSource = priceSource[offset]

fastMA = calculateMA(actualSource, fastMALength)
mediumMA = calculateMA(actualSource, mediumMALength)
slowMA = calculateMA(actualSource, slowMALength)

// Trading Logic
enterLong = crossover(fastMA, mediumMA)
exitLong = crossunder(fastMA, mediumMA)

// Risk and Position Sizing
riskCapital = tradingCapital * tradeRisk / 100
lossThreshold = atr(14) * 2
tradeSize = riskCapital / lossThreshold

if (enterLong)
    strategy.entry("Enter Long", strategy.long, qty=tradeSize)

if (exitLong)
    strategy.close("Enter Long")

// Display Moving Averages
plot(fastMA, color=color.blue, linewidth=2, title="Fast Moving Average")
plot(mediumMA, color=color.purple, linewidth=2, title="Medium Moving Average")
plot(slowMA, color=color.red, linewidth=2, title="Slow Moving Average")


더 많은