SMA 오프셋 변동 거래 전략

저자:차오장, 날짜: 2023-12-19 10:52:10
태그:

img

전략 개요

이 전략은 간단한 이동 평균 (SMA) 과 몇 가지 수학 계산을 사용하여 구매/판매 포인트를 결정합니다. 우리는 100일 SMA 라인을 기본으로 유지합니다. 닫기 가격이 이 라인 아래에 있다면, 우리는 가격이 라인 아래에 있는 비율 (낮은 오프셋) 을 기반으로 개막 포지션을 결정합니다. 마찬가지로, 우리는 긴 포지션을 닫기 전에 100일 SMA 위에 높은 오프셋 퍼센트를 설정합니다. 가격이 여전히 상승하는 동안 너무 일찍 닫으려고 하면, 후속 스톱 손실이 유발됩니다.

전략 논리

이 전략은 세 개의 SMA 라인을 사용합니다: 빠른 라인 (저수 14 일), 느린 라인 (저수 100 일), 참조 라인 (저수 30 일).

닫기 가격이 기준선 아래, 느린 선 아래의 비율 (낮은 오프셋) 이 구성된 값보다 높을 때 길어집니다. 빠른 선이 상승하고 느린 선이 떨어집니다. 이 조건이 충족되면 빠른 선과 느린 선이 곧 교차 할 가능성이 높으므로 좋은 입구 지점입니다.

닫기 가격이 참조 라인 이상, 느린 라인 위의 비율 (높은 오프셋) 이 구성 된 값보다 크면 닫기 가격이 3 개의 촛불을 연속으로 올랐을 때 긴 것을 닫습니다. 우리는 오픈 이윤을 가지고 있으며 빠른 라인이 느린 라인 위에 있습니다. 가격이 긴 폐쇄 후 계속 상승하면 후속 스톱 손실이 유발됩니다.

오더 크기는 전체 자금의 비율에 기반합니다. 이것은 우리의 포지션 크기를 제어합니다.

이점 분석

  1. SMA가 가격 변동을 완화하고 시장 소음을 필터링할 수 있다는 장점을 활용합니다.
  2. SMA 크로스오버는 트렌드 변화를 예측할 수 있습니다.
  3. 오프셋을 설정하면 SMA 라인의 거짓 파열이 피할 수 있습니다.
  4. 트렌드와 크로스오버 지표를 결합하면 거래 신호의 정확도가 향상됩니다.
  5. 후속 스톱 손실은 수익을 차단하고 인출을 방지합니다.

위험 분석

  1. SMA 자체는 지연을 가지고 있으며 가격 전환점을 놓칠 수 있습니다.
  2. 잘못된 오프셋 설정은 전략을 너무 공격적이거나 너무 보수적으로 만들 수 있습니다.
  3. 부적절한 스톱 손실 매개 변수는 너무 일찍 멈추거나 스톱 손실 비율이 너무 커질 수 있습니다.
  4. 급격한 가격 변동에 대처할 수 없습니다.

그에 따른 개선:

  1. 필터 항목에 다른 주요 지표를 추가합니다.
  2. 역 테스트하고 오프셋을 최적화합니다.
  3. 백테스트하고 최적의 스톱 로스 매개 변수를 찾습니다.
  4. 높은 변동성 기간 동안 포지션 크기를 줄이세요.

최적화 방향

  1. 최적의 매개 변수를 찾기 위해 다른 기간의 SMA를 테스트합니다.
  2. 시장 구조와 동향을 결정하기 위해 다른 지표를 추가하십시오.
  3. 더 많은 수익을 얻기 위해 후속 스톱 로스 매개 변수를 최적화합니다.
  4. 시장의 변동성에 따라 포지션 크기를 조정합니다.
  5. 다양한 상품에 동시에 전략을 적용해 다양성을 높여야 합니다.

결론

SMA 오프셋 변동 거래 전략은 다른 SMA 라인을 기반으로 오프셋을 설정하여 최적의 입구 지점을 식별합니다. 출구 메커니즘은 이익을 잠금하기 위해 후속 스톱 손실을 설정합니다. 이 전략은 이해하기 쉽고 구현하기 쉽습니다. SMA 기간, 오프셋, 스톱 손실 수준과 같은 매개 변수를 최적화함으로써 더 나은 결과를 얻을 수 있습니다. 안정적인 이익을 추구하는 중장기 투자자에게 적합합니다.


/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4
// Author: Sonny Parlin (highschool dropout)
strategy(shorttitle="SMA+Strategy", title="SMA Offset Strategy",
                                      overlay=true,  currency=currency.USD,
                                      initial_capital=10000)

// Inputs and variables
ss = input(14, minval=10, maxval=50, title="SMA Fast (days)")
ff = input(100, minval=55, maxval=200, title="SMA Slow (days)")
ref = input(30, minval=20, maxval=50, title="SMA Reference (days)")
lowOffset = input(0.001, "Low Offset (%)", minval=0, step=0.001)
highOffset = input(0.0164, "High Offset (%)", minval=0, step=0.0001)
orderStake = input(0.96, "Order Stake (%)", minval=0, step=0.01)

// SMA
smaFast = sma(close, ss)
smaSlow = sma(close, ff)
smaRef = sma(close, ref)
distanceLow = (close - smaSlow) / close
distanceHigh = (close - smaSlow) / close

// Set up SMA plot but don't show by default
plot(smaFast, "smaFast", color=#00ff00, display = 0)
plot(smaSlow, "smaSlow", color=#ff0000, display = 0)
plot(smaRef, "smaRef", color=#ffffff, display = 0)

// The buy stratey:
// guard that the low is under our sma low reference line by our lowOffset %, 
// default is 0.001. (low < smaRef) and (distanceLow > lowOffset)
// SMA fast is on the rise and SMA slow is falling and they are very likely
// to cross. (rising(smaFast,1)) and (falling(smaSlow, 1)) 
enterLong = (low < smaRef) and (distanceLow > lowOffset) and (rising(smaFast,1)) and (falling(smaSlow, 1)) 

// The sell Strategy:
// Guard that close is higher than our sma high reference line by our 
// highOffset %, default is 0.0164. (close > smaRef) and (distanceHigh > highOffset)
// Guard that close has risen by 3 candles in a row (rising(close,3)) 
// Guard that we currently have profit (strategy.openprofit > 0)
// Guard that SMA fast is higher than smaSlow (smaFast > smaSlow)
// If it keeps going up past our close position the trailing stoploss will kick in!
enterShort = (close > smaRef) and (distanceHigh > highOffset) and (rising(close,3)) and (strategy.openprofit > 0) and (smaFast > smaSlow)

// Order size is based on total equity
// Example 1:
// startingEquity = 2000
// close = 47434.93
// orderStake = 0.45
// (2,000 × orderStake) / close = orderSize = 0.0189733599 = approx $900

// Example 2:
// startingEquity = 2000
// close = 1.272
// orderStake = 0.45
// (startingEquity × orderStake) / close = orderSize = 707.5471698113 = approx $900
orderSize = (strategy.equity * orderStake) / close

// Trailing Stoploss
// I'm using 1.35 as my default value, play with this for different results.
longTrailPerc = input(title="Trailing Stoploss (%)",
     type=input.float, minval=0.0, step=0.1, defval=1.35) * 0.01
     
longStopPrice = 0.0

longStopPrice := if (strategy.position_size > 0)
    stopValue = close * (1 - longTrailPerc)
    max(stopValue, longStopPrice[1])
else
    0

if (enterLong)
    strategy.entry("Open Long Position", strategy.long, orderSize, when=strategy.position_size <= 0)
    
if (enterShort)
    strategy.exit(id="Close Long Position", stop=longStopPrice)


//plot(strategy.equity)

더 많은