동적 이동 평균 이중 전략

저자:차오장, 날짜: 2023-12-13 16:37:05
태그:

img

전반적인 설명

이 전략은 거래 결정을 위해 이동 평균 (MA) 의 기울기와 모멘텀 지표의 기울기를 사용합니다. 그것은 MA 기울기와 모멘텀 기울기를 설정된 임계값과 비교하고 두 기울기가 임계값을 초과하면 거래 신호를 생성합니다. 이 전략에는 또한 낮은 변동성 필터가 포함되어 있으며 시장 변동성이 낮을 때 다른 MA를 사용하여 신호를 생성합니다.

전략 논리

이 전략의 핵심은 두 개의 기울기 곡선을 비교하는 데 있습니다. 첫째, MA와 운동량 지표의 기울기를 계산합니다. 기울기는 곡선의 변화 속도와 방향을 반영합니다. 두 개의 문턱이 사용됩니다. MA 기울기와 운동량 기울기 모두 해당 문턱을 초과하면 거래 신호가 생성됩니다.

예를 들어, MA 기울기와 모멘텀 기울기가 상선을 초과하면 구매 신호가 생성되며, 양 곡선이 하위 라인 아래에 떨어지면 판매 신호가 생성됩니다. 이것은 일부 잘못된 신호를 필터링 할 수 있습니다.

낮은 변동성 필터는 시장 변동성을 결정하기 위해 장기 MA를 사용합니다. 변동성이 낮을 때 다른 매개 변수를 가진 MA는 다른 시장 상태에 적응하기 위해 거래 신호를 생성하는 데 사용됩니다.

이점 분석

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

  1. 거래 신호를 설정하는 이중 필터는 소음을 필터링하고 신호 품질을 향상시킬 수 있습니다.

  2. 낮은 변동성 필터는 전략이 유연성을 가지고 다른 시장 조건에 적응할 수 있도록 합니다.

  3. 다른 매개 변수에 대한 높은 사용자 정의는 다른 제품에 최적화 될 수 있습니다.

  4. 구부러진 부착으로 인한 충격을 줄이기 위해 재칠 기능을 포함하지 않습니다.

위험 분석

이 전략에는 또한 몇 가지 위험이 있습니다.

  1. 이중 필터는 어떤 실제 신호를 필터링하고 기회를 놓칠 수 있습니다. 이것은 매개 변수를 조정함으로써 최적화 될 수 있습니다.

  2. 낮은 변동성 필터의 임계값 결정은 신중한 테스트가 필요합니다. 부적절한 설정으로 인해 신호 오차가 발생할 수 있습니다.

  3. MA 및 운동 지표의 매개 변수 설정은 특정 제품에 최적화되어야하며 보편적 매개 변수를 결정하는 것은 어렵습니다.

  4. 다시 칠하지 않는 기능은 백테스트 곡선 부착 문제를 완전히 피할 수 없으며 실제 거래 성능은 여전히 검증이 필요합니다.

  5. 높은 사용자 정의성은 매개 변수 공간의 복잡성과 최적화의 어려움을 증가시킵니다.

최적화 방향

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

  1. 가장 잘 일치하는 지표를 찾기 위해 MA와 모멘텀 지표의 더 많은 조합을 테스트합니다.

  2. MA의 길이 매개 변수와 모멘텀 지표를 최적화하여 지연과 소음을 균형 잡습니다.

  3. 기울기 계산을 위한 매개 변수를 최적화하여 더 안정적인 지표 조합을 찾습니다.

  4. 탄력을 향상시키기 위해 다양한 낮은 변동성 지표와 매개 변수를 테스트합니다.

  5. 가장 적합한 적용 범위를 찾기 위해 다른 제품과 시간 프레임에서 테스트합니다.

  6. 수동 최적화 작업 부하를 줄이기 위해 매개 변수 적응 메커니즘을 구축합니다.

결론

이것은 매우 유연하고 사용자 정의 가능한 이중 MA 전략입니다. 결정 수행을 위해 가격 및 추진력 정보를 모두 참조하여 잘못된 신호를 효과적으로 필터링할 수 있습니다. 낮은 변동성 필터는 또한 시장 변화에 적응하기 위해 전략을 더 유연하게 만듭니다.

매개 변수 최적화 및 지표 선택의 개선으로,이 전략은 실제 생활 거래에 적합한 선택이 될 수 있습니다. 그것은 MA 및 추진력 지표를 사용하여 거래 결정을위한 참조 템플릿을 제공합니다.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Allenlk
//@version=4
strategy("DRSI DMA Scalping Strategy", shorttitle="DRSIDMA", overlay=false, initial_capital=1000, pyramiding=2, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

//Inputs
matype             = input(7, minval=1, maxval=8, title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3", group="Moving Average")
masrc              = input(close, title="MA Source", group="Moving Average")
malen              = input(5, title="Moving Average Length - LookBack Period", group="Moving Average")
factorT3           = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0, group="Moving Average")
maderiv            = input(3, title="MA Slope Lookback", minval=1, group="Moving Average")
masmooth           = input(5, title="MA Slope Smoothing", minval=1, group="Moving Average")
momtype            = input(3, minval=1, maxval=3, title="1=RSI, 2=CCI, 3=RSI/ROC", group="Momentum Moving Average")
momsrc             = input(close, title="Momentum Source", group="Momentum Moving Average")
momlen             = input(3, title="Momentum Length", minval=1, group="Momentum Moving Average")
momderiv           = input(8, title="Momentum Slope Lookback", minval=1, group="Momentum Moving Average")
momsmooth          = input(7, title="Momentum Slope Smoothing", minval=1, group="Momentum Moving Average")
higherTf           = input("1", title="Higher timeframe?", type = input.resolution, group="Time Resolution")
higherTfmult       = input(130, title="MA Slope multiplier for Alternate Resolutions (Make the waves of the blue line similar size as the orange line)", group="Time Resolution")
buffup             = input(0.02, title="Buy when both slopes cross this line", step=0.01, group="Buy and Sell Threshold")
bufflow            = input(-0.03, title="Sell when both slopes cross this line", step=0.01, group="Buy and Sell Threshold")
lowVolMALength     = input(28, title="Big MA Length", minval=1, group="Low Volatility Function")
MAlength           = input(10, title="Low Volatility Moving Average Length", minval=1, group="Low Volatility Function")
MAThresh           = input(0.05, title="Low Volatility Buy and Sell Threshold", step=0.01, group="Low Volatility Function")
Volminimum         = input(2.5, title="Minimum volatility to trade", minval=0, step=0.01, group="Low Volatility Function")

//Low Volatility Function
//When Volatility is low refer to the slope of a long moving average
low_vol_MA         = sma(close, lowVolMALength)
low_vol_down       = (low_vol_MA[3] - low_vol_MA[1]) > MAThresh
low_vol_up         = (low_vol_MA[3] - low_vol_MA[1]) < MAThresh * -1
percent_volatility = (1 - (low / high)) * 100
chng_MA            = sma(percent_volatility, MAlength)
bad_vol            = chng_MA < Volminimum

//No repaint function
nrp_funct(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])

//hull ma definition
hullma = wma(2*wma(masrc, malen/2)-wma(masrc, malen), round(sqrt(malen)))

//TEMA definition
ema1 = ema(masrc, malen)
ema2 = ema(ema1, malen)
ema3 = ema(ema2, malen)
tema = 3 * (ema1 - ema2) + ema3

//Tilson T3
factor = factorT3 *.10
gd(masrc, malen, factor) => ema(masrc, malen) * (1 + factor) - ema(ema(masrc, malen), malen) * factor 
t3(masrc, malen, factor) => gd(gd(gd(masrc, malen, factor), malen, factor), malen, factor) 
tilT3 = t3(masrc, malen, factor) 
 
//MA Type 
avg = matype == 1 ? sma(masrc,malen) : matype == 2 ? ema(masrc,malen) : matype == 3 ? wma(masrc,malen) : matype == 4 ? hullma : matype == 5 ? vwma(masrc, malen) : matype == 6 ? rma(masrc,malen) : matype == 7 ? 3 * (ema1 - ema2) + ema3 : tilT3

//MA Slope Percentage
DeltaAvg      = (avg / avg[maderiv]) - 1
SmoothedAvg   = sma(DeltaAvg, masmooth) 
MAout         = nrp_funct(syminfo.tickerid, higherTf, SmoothedAvg) * higherTfmult

//Momentum indicators
Momentum = momtype == 1 ? rsi(momsrc, momlen) : momtype == 2 ? cci(momsrc, momlen) : momtype == 3 ? rsi(roc(momsrc,momlen),momlen) : na

//Momentum Slope Percentage
Deltamom = (Momentum / Momentum[momderiv]) - 1
SmoothedMom = sma(Deltamom, momsmooth) 
Momout   = nrp_funct(syminfo.tickerid, higherTf, SmoothedMom)

//Plottings
plot(buffup, color=color.green, title="Buy line")
plot(bufflow, color=color.red, title="Sell line")
plot(MAout, color=color.blue, linewidth=2, title="MA Slope")
plot(Momout, color=color.orange, linewidth=2, title="Momentum Slope")

longCondition = bad_vol ? low_vol_up : MAout > buffup and Momout > buffup
if (longCondition)
    strategy.entry("Buy", strategy.long)

shortCondition = bad_vol ? low_vol_down : MAout < bufflow and Momout < bufflow
if (shortCondition)
    strategy.entry("Sell", strategy.short)

더 많은