이동평균에 기초한 평균 회전 거래 전략

저자:차오장, 날짜: 2023-10-26 15:38:14
태그:

img

전반적인 설명

평균 회전 거래 전략은 거래 결정을 내리기 위해 이동 평균에서 가격 오차를 기반으로합니다. 가격이 이동 평균보다 크게 낮거나 높을 때 포지션을 설정하여 가격의 단기 오차와 장기 회전 패턴을 활용하여 가격의 회전 후 포지션을 닫습니다.

전략 논리

전략은 먼저 일정 기간 동안 이동 평균을 계산하여 장기 가격 추세를 나타냅니다. 그 다음 이동 평균에서 가격의 오차를 기반으로 포지션의 타이밍과 크기를 결정합니다.

가격이 이동 평균보다 일정 비율로 낮아지면 가격이 장기 트렌드에서 벗어나는 신호입니다. 이 경우, 오차가 넓어짐에 따라 크기가 증가함에 따라 긴 포지션이 점차적으로 구축됩니다. 가격이 이동 평균 이상으로 다시 반등하면 평균으로 회귀하는 것을 암시하며, 긴 포지션은 수익을 얻기 위해 닫습니다.

마찬가지로, 가격이 이동 평균보다 한계치로 상승하면, 짧은 포지션이 만들어집니다. 가격이 이동 평균으로 다시 떨어지면, 짧은 포지션은 수익으로 닫습니다.

이점 분석

  1. 이동평균의 트렌드 식별 능력을 활용하여 주식 가격의 장기 균형 트렌드를 추적하고 주요 트렌드 방향을 파악합니다.

  2. 평균 비용을 낮춰서 포지션을 확장하여 더 나은 입시 가격을 얻을 수 있습니다.

  3. 단계적 이윤 취득을 채택하여 평균 회귀의 다른 수준에서 이윤을 확보하고 위험을 줄이십시오.

  4. 단일 거래 손실 크기를 제한하기 위해 고정 비율로 제어 위치 크기를 조정합니다.

  5. 다양한 제품에 따라 이동 평균 기간 및 위치 크기 설정과 같은 유연한 매개 변수 설정.

위험 분석

  1. 가격이 변동할 때 빈번한 스톱 손실. 스톱 손실 범위를 넓히거나 다른 필터를 추가 할 수 있습니다.

  2. 강한 트렌드는 이동 평균을 깨고 평균 반전에서 닫을 수 없습니다. 트렌드 강도 지표에 의해 식별 된 포지션 크기를 줄일 수 있습니다.

  3. 부적절한 매개 변수 설정으로 인해 과도한 공격적인 입출 또는 정지 될 수 있습니다. 시장 조건에 따라 신중한 역 테스트 및 조정이 필요합니다.

  4. 높은 거래 빈도는 상당한 거래 비용을 초래합니다. 매개 변수 최적화에서 비용 요소가 고려되어야합니다.

개선 방향

  1. 이동 평균 기간을 최적화하여 제품 특성에 맞게 조정합니다.

  2. 리스크와 수익을 균형을 맞추기 위해 포지션 크기를 최적화하십시오.

  3. 불필요한 거래를 피하기 위해 다른 기술적 필터를 추가합니다.

  4. 시장 변동 수준에 따라 포지션 크기를 조정하기 위한 변동성 척도를 포함합니다.

  5. 수익 목표 스케일링을 도입하여 위험을 줄이고 수익을 높여

결론

평균회전 전략은 주식들의 평형회전 경향을 활용하여 이동평균의 오차를 입력하고 회전에서 이윤을 취한다. 적절한 매개 변수 조정 및 필터로 시장 변화에 적응하고 위험 통제 하에서 좋은 수익을 얻을 수 있다. 전략은 트렌드 추적과 위험 관리 모두를 통합하여 투자자들에게 연구하고 적용할 가치가 있다.


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

//@version=4
strategy("YJ Mean Reversion", overlay=true)
//Was designed firstly to work on an index like the S&P 500 , which over time tends to go up in value. 
//Avoid trading too frequently (e.g. Daily, Weekly), to avoid getting eaten by fees. 
//If you change the underlying asset, or time frame, tweaking the moving average may be necessary. 
//Can work with a starting capital of just $1000, optimise the settings as necessary. 
//Accepts floating point values for the amount of units to purchase (e.g. Bitcoin ). 
//If price of units exceeds available capital, script will cancel the buy. 
//Adjusted the input parameters to be more intuitive.

//input variables
movingAverage = input(title="Moving Average (bars)", type=input.integer, defval=28, minval=1, maxval=1000)
//riskPercentage = input(title="Amount to Risk (%)", type=input.integer, defval=1, minval=1, maxval=50)
deviation = input(title="Deviation Increment (%)", type=input.float, defval=5, minval=0.01, maxval=100) / 100
unitsLevel1 = input(title="Level 1 (units)", type=input.float, defval=1, minval=0.0001, maxval=10000)
unitsLevel2 = input(title="Level 2 (units)", type=input.float, defval=2, minval=0.0001, maxval=10000)
unitsLevel3 = input(title="Level 3 (units)", type=input.float, defval=4, minval=0.0001, maxval=10000)
unitsLevel4 = input(title="Level 4 (units)", type=input.float, defval=8, minval=0.0001, maxval=10000)
unitsLevel5 = input(title="Level 5 (units)", type=input.float, defval=16, minval=0.0001, maxval=10000)

//moving average and ma slope (use on weekly chart)
ma = sma(close, movingAverage)
//sl = ma > ma[4]

//units to buy
//amount = riskPercentage / 100 * (strategy.initial_capital + strategy.netprofit)
//units = floor(amount / close)

//mode 1
//strategy.order("buy", true, 1, when = (close < 0.95 * ma) and (strategy.position_size < 10))
//strategy.order("sell", false, strategy.position_size, when = (close > 1.05 * ma) and (strategy.position_size > 0))

//mode 2
//strategy.order("buy", true, 1, when = close < 0.8 * ma)
//strategy.order("sell", false, strategy.position_size, when = (close > 310) and (strategy.position_size > 0))

//mode 3
//strategy.order("buy", true, 1, when = (close < 0.95 * ma) and (close > 0.9 * ma))
//strategy.order("buy", true, 2, when = (close < 0.9 * ma) and (close > 0.85 * ma))
//strategy.order("buy", true, 4, when = (close < 0.85 * ma) and (close > 0.8 * ma))
//strategy.order("buy", true, 8, when = (close < 0.8 * ma) and (close > 0.75 * ma))
//strategy.order("buy", true, 16, when = (close < 0.75 * ma))
//strategy.order("sell", false, strategy.position_size, when = (close > 310) and (strategy.position_size > 0))

//mode 4
//strategy.order("buy", true, 1, when = (close < 0.98 * ma) and (close > 0.96 * ma) and (sl))
//strategy.order("buy", true, 2, when = (close < 0.96 * ma) and (close > 0.94 * ma) and (sl))
//strategy.order("buy", true, 4, when = (close < 0.94 * ma) and (close > 0.92 * ma) and (sl))
//strategy.order("buy", true, 8, when = (close < 0.92 * ma) and (close > 0.90 * ma) and (sl))
//strategy.order("buy", true, 16, when = (close < 0.90 * ma) and (sl))
//strategy.order("sell", false, strategy.position_size, when = (close > 310) and (strategy.position_size > 0))

//mode 5
//strategy.order("buy", true, 1, when = (close < 0.95 * ma) and (close > 0.9 * ma))
//strategy.order("buy", true, 2, when = (close < 0.9 * ma) and (close > 0.85 * ma))
//strategy.order("buy", true, 4, when = (close < 0.85 * ma) and (close > 0.8 * ma))
//strategy.order("buy", true, 8, when = (close < 0.8 * ma) and (close > 0.75 * ma))
//strategy.order("buy", true, 16, when = (close < 0.75 * ma))

//strategy.order("sell", false, 1, when = (close > 1.05 * ma) and (close < 1.1 * ma) and (strategy.position_size > 0))
//strategy.order("sell", false, 2, when = (close > 1.1 * ma) and (close < 1.15 * ma) and (strategy.position_size > 0))
//strategy.order("sell", false, 4, when = (close > 1.15 * ma) and (close < 1.2 * ma) and (strategy.position_size > 0))
//strategy.order("sell", false, 8, when = (close > 1.2 * ma) and (close < 1.25 * ma) and (strategy.position_size > 0))
//strategy.order("sell", false, 16, when = (close > 1.25 * ma) and (close < 1.3 * ma) and (strategy.position_size > 0))

//mode 6
//strategy.order("B1", true, unitsLevel1 * units, when = (close < 0.95 * ma) and (close > 0.9 * ma))
//strategy.order("B2", true, unitsLevel2 * units, when = (close < 0.9 * ma) and (close > 0.85 * ma))
//strategy.order("B3", true, unitsLevel3 * units, when = (close < 0.85 * ma) and (close > 0.8 * ma))
//strategy.order("B4", true, unitsLevel4 * units, when = (close < 0.8 * ma) and (close > 0.75 * ma))
//strategy.order("B5", true, unitsLevel5 * units, when = (close < 0.75 * ma))

//strategy.order("S1", false, unitsLevel1 * units, when = (close > 1.05 * ma) and (close < 1.1 * ma) and (strategy.position_size > 0))
//strategy.order("S2", false, unitsLevel2 * units, when = (close > 1.1 * ma) and (close < 1.15 * ma) and (strategy.position_size > 0))
//strategy.order("S3", false, unitsLevel3 * units, when = (close > 1.15 * ma) and (close < 1.2 * ma) and (strategy.position_size > 0))
//strategy.order("S4", false, unitsLevel4 * units, when = (close > 1.2 * ma) and (close < 1.25 * ma) and (strategy.position_size > 0))
//strategy.order("S5", false, unitsLevel5 * units, when = (close > 1.25 * ma) and (close < 1.3 * ma) and (strategy.position_size > 0))

//mode 7
//strategy.order("B1", true, units, when = (close < 0.95 * ma) and (close > 0.9 * ma))
//strategy.order("B2", true, units, when = (close < 0.9 * ma) and (close > 0.85 * ma))
//strategy.order("B3", true, units, when = (close < 0.85 * ma) and (close > 0.8 * ma))
//strategy.order("B4", true, units, when = (close < 0.8 * ma) and (close > 0.75 * ma))
//strategy.order("B5", true, units, when = (close < 0.75 * ma))

//strategy.order("S1", false, units, when = (close > 1.05 * ma) and (close < 1.1 * ma) and (strategy.position_size > 0))
//strategy.order("S2", false, units, when = (close > 1.1 * ma) and (close < 1.15 * ma) and (strategy.position_size > 0))
//strategy.order("S3", false, units, when = (close > 1.15 * ma) and (close < 1.2 * ma) and (strategy.position_size > 0))
//strategy.order("S4", false, units, when = (close > 1.2 * ma) and (close < 1.25 * ma) and (strategy.position_size > 0))
//strategy.order("S5", false, units, when = (close > 1.25 * ma) and (close < 1.3 * ma) and (strategy.position_size > 0))

//banding calculations
aH = 1.0 - deviation
aL = aH - deviation
bH = aL
bL = bH - deviation
cH = bL
cL = cH - deviation
dH = cL
dL = dH - deviation
eH = dL
strategy.initial_capital = 50000
//mode 8
strategy.order("B1", true, unitsLevel1, when = (close < aH * ma) and (close > aL * ma) and (unitsLevel1 * close < (strategy.initial_capital + strategy.netprofit)))
strategy.order("B2", true, unitsLevel2, when = (close < bH * ma) and (close > bL * ma) and (unitsLevel2 * close < (strategy.initial_capital + strategy.netprofit)))
strategy.order("B3", true, unitsLevel3, when = (close < cH * ma) and (close > cL * ma) and (unitsLevel3 * close < (strategy.initial_capital + strategy.netprofit)))
strategy.order("B4", true, unitsLevel4, when = (close < dH * ma) and (close > dL * ma) and (unitsLevel4 * close < (strategy.initial_capital + strategy.netprofit)))
strategy.order("B5", true, unitsLevel5, when = (close < eH * ma) and (unitsLevel5 * close < (strategy.initial_capital + strategy.netprofit)))

//banding calculations
fL = 1.0 + deviation
fH = fL + deviation
gL = fH
gH = gL + deviation
hL = gH
hH = hL + deviation
iL = hH
iH = iL + deviation
jL = iH

strategy.order("S1", false, unitsLevel1, when = (close > fL * ma) and (close < fH * ma) and (strategy.position_size > 0))
strategy.order("S2", false, unitsLevel2, when = (close > gL * ma) and (close < gH * ma) and (strategy.position_size > 0))
strategy.order("S3", false, unitsLevel3, when = (close > hL * ma) and (close < hH * ma) and (strategy.position_size > 0))
strategy.order("S4", false, unitsLevel4, when = (close > iL * ma) and (close < iH * ma) and (strategy.position_size > 0))
strategy.order("S5", false, unitsLevel5, when = (close > jL * ma) and (strategy.position_size > 0))

plot(ma, color=#666666, linewidth=5)

더 많은