커널 회귀 및 ATR 동적 대역을 기반으로 한 적응형 추세 추종 전략

NW ATR ROC MA
생성 날짜: 2025-02-18 15:33:21 마지막으로 수정됨: 2025-02-18 15:33:21
복사: 0 클릭수: 400
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

커널 회귀 및 ATR 동적 대역을 기반으로 한 적응형 추세 추종 전략

개요

이 전략은 Nadaraya-Watson 핵 회귀와 ATR 동적 파장의 결합된 자기 적응 트렌드 추적 시스템이다. 그것은 합리적인 2차 핵 함수를 통해 가격 추세를 예측하고 ATR 기반의 동적 지원과 저항을 사용하여 거래 기회를 식별한다. 시스템은 구성 가능한 회귀 창과 무게 매개 변수를 통해 시장에 대한 정밀한 모델링을 구현한다.

전략 원칙

전략의 핵심은 나다라야-왓슨 방식에 기반한 비변수 핵 회귀이며, 합리적인 2차 핵 함수를 사용하여 가격 서열을 부드럽게 처리한다. 회귀는 설정된 시작 바에서 시작하여, lookback window ((h) 와 상대 무게 (® 의 두 가지 핵심 매개 변수를 통해 적합성의 정도를 제어한다. ATR 지표와 결합하여 역동적인 대역을 구성하며, 상단 및 하단 대역은 각각 ATR의 곱하기 값을 더하거나 줄이는 것으로 회귀한다. 시스템은 가격과 대역의 교차로 거래 신호를 유발한다.

전략적 이점

  1. 원자력 회귀 방법은 좋은 수학적 기반을 가지고 있으며, 과잉 맞춤 없이 가격 추세를 효과적으로 포착할 수 있다.
  2. 동적 파장은 시장의 변동에 적응하여 더 합리적인 지지 저항 지점을 제공합니다.
  3. 다양한 시장 특성에 따라 조정할 수 있는 강력한 구성 성능
  4. 트렌드 인식 메커니즘은 부드러운 또는 민감한 모드를 선택할 수 있습니다.
  5. 시각화 효과는 직관적이고 거래 신호는 명확합니다.

전략적 위험

  1. 잘못 선택된 파라미터는 과도한 적합성이나 지연으로 이어질 수 있습니다.
  2. 불안한 시장에서 과도한 거래 신호가 발생할 수 있습니다.
  3. ATR 배수 설정이 부적절하여 너무 넓거나 너무 좁은 정지 손실이 발생할 수 있습니다.
  4. 트렌드 전환 기간에 잘못된 신호가 발생할 수 있습니다. 역사 회귀를 통해 최적화 매개 변수를 제안하고, 다른 지표와 결합하여 보조 확인으로.

전략 최적화 방향

  1. 트렌드 확인으로 거래량 지표 도입
  2. 적응 변수 최적화 메커니즘 개발
  3. 트렌드 강도 필터를 증가시키고, 위축 시장의 가짜 신호를 감소시킨다.
  4. 제1차 세계대전 당시의 경제상황을 살펴보면,
  5. 시장 환경 분류를 고려하여 다른 시장에서 다른 매개 변수를 사용하십시오.

요약하다

이 전략은 통계학습 방법과 기술 분석을 결합하여 이론적 기반이 튼튼하고 실용적인 거래 시스템을 구축한다. 그것의 자기 적응 특성과 구성성은 다양한 시장 환경에 적응할 수 있게 해 주지만, 사용 시 변수 최적화 및 위험 통제에 주의를 기울여야 한다. 지속적인 개선과 최적화를 통해 이 전략은 실전 거래에서 중요한 역할을 할 전망이다.

전략 소스 코드
/*backtest
start: 2025-01-18 00:00:00
end: 2025-02-17 00:00:00
period: 1h
basePeriod: 1h
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/
// © Lupown

//@version=5
strategy("Nadaraya-Watson non repainting Strategy", overlay=true)  // PARAMETER timeframe ODSTRÁNENÝ

//--------------------------------------------------------------------------------
// INPUTS
//--------------------------------------------------------------------------------
src = input.source(close, 'Source')
h   = input.float(8., 'Lookback Window', minval=3., tooltip='The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50')
r   = input.float(8., 'Relative Weighting', step=0.25, tooltip='Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25')
x_0 = input.int(25, "Start Regression at Bar", tooltip='Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25')
showMiddle    = input.bool(true, "Show middle band")
smoothColors  = input.bool(false, "Smooth Colors", tooltip="Uses a crossover based mechanism to determine colors. This often results in less color transitions overall.", inline='1', group='Colors')
lag           = input.int(2, "Lag", tooltip="Lag for crossover detection. Lower values result in earlier crossovers. Recommended range: 1-2", inline='1', group='Colors')

lenjeje = input.int(32, "ATR Period",    tooltip="Period to calculate upper and lower band", group='Bands')
coef    = input.float(2.7, "Multiplier", tooltip="Multiplier to calculate upper and lower band", group='Bands')

//--------------------------------------------------------------------------------
// ARRAYS & VARIABLES
//--------------------------------------------------------------------------------
float y1 = 0.0
float y2 = 0.0
srcArray = array.new<float>(0)
array.push(srcArray, src)
size = array.size(srcArray)

//--------------------------------------------------------------------------------
// KERNEL REGRESSION FUNCTIONS
//--------------------------------------------------------------------------------
kernel_regression1(_src, _size, _h) =>
    float _currentWeight = 0.
    float _cumulativeWeight = 0.
    for i = 0 to _size + x_0
        y = _src[i]
        w = math.pow(1 + (math.pow(i, 2) / ((math.pow(_h, 2) * 2 * r))), -r)
        _currentWeight    += y * w
        _cumulativeWeight += w
    [_currentWeight, _cumulativeWeight]

[currentWeight1, cumulativeWeight1] = kernel_regression1(src, size, h)
yhat1 = currentWeight1 / cumulativeWeight1

[currentWeight2, cumulativeWeight2] = kernel_regression1(src, size, h - lag)
yhat2 = currentWeight2 / cumulativeWeight2

//--------------------------------------------------------------------------------
// TREND & COLOR DETECTION
//--------------------------------------------------------------------------------
// Rate-of-change-based
bool wasBearish   = yhat1[2] > yhat1[1]
bool wasBullish   = yhat1[2] < yhat1[1]
bool isBearish    = yhat1[1] > yhat1
bool isBullish    = yhat1[1] < yhat1
bool isBearishChg = isBearish  and wasBullish
bool isBullishChg = isBullish  and wasBearish

// Crossover-based (for "smooth" color changes)
bool isBullishCross  = ta.crossover(yhat2, yhat1)
bool isBearishCross  = ta.crossunder(yhat2, yhat1)
bool isBullishSmooth = yhat2 > yhat1
bool isBearishSmooth = yhat2 < yhat1

color c_bullish    = input.color(#3AFF17, 'Bullish Color', group='Colors')
color c_bearish    = input.color(#FD1707, 'Bearish Color', group='Colors')

color colorByCross = isBullishSmooth ? c_bullish : c_bearish
color colorByRate  = isBullish       ? c_bullish : c_bearish
color plotColor    = smoothColors ? colorByCross : colorByRate

// Middle Estimate
plot(showMiddle ? yhat1 : na, "Rational Quadratic Kernel Estimate", color=plotColor, linewidth=2)

//--------------------------------------------------------------------------------
// UPPER / LOWER BANDS
//--------------------------------------------------------------------------------
upperjeje = yhat1 + coef * ta.atr(lenjeje)
lowerjeje = yhat1 - coef * ta.atr(lenjeje)

plotUpper = plot(upperjeje, "Rational Quadratic Kernel Upper", color=color.rgb(0, 247, 8), linewidth=2)
plotLower = plot(lowerjeje, "Rational Quadratic Kernel Lower", color=color.rgb(255, 0, 0), linewidth=2)

//--------------------------------------------------------------------------------
// SYMBOLS & ALERTS
//--------------------------------------------------------------------------------
plotchar(ta.crossover(close, upperjeje),  char="🥀", location=location.abovebar, size=size.tiny)
plotchar(ta.crossunder(close, lowerjeje), char="🍀", location=location.belowbar, size=size.tiny)

// Alerts for Color Changes (estimator)
alertcondition(smoothColors ? isBearishCross : isBearishChg, title="Bearish Color Change", message="Nadaraya-Watson: {{ticker}} ({{interval}}) turned Bearish ▼")
alertcondition(smoothColors ? isBullishCross : isBullishChg, title="Bullish Color Change", message="Nadaraya-Watson: {{ticker}} ({{interval}}) turned Bullish ▲")

// Alerts when price crosses upper and lower band
alertcondition(ta.crossunder(close, lowerjeje), title="Price close under lower band", message="Nadaraya-Watson: {{ticker}} ({{interval}}) crossed under lower band 🍀")
alertcondition(ta.crossover(close, upperjeje),  title="Price close above upper band", message="Nadaraya-Watson: {{ticker}} ({{interval}}) Crossed above upper band 🥀")

//--------------------------------------------------------------------------------
// STRATEGY LOGIC (EXAMPLE)
//--------------------------------------------------------------------------------
if ta.crossunder(close, lowerjeje)
    // zatvoriť short
    strategy.close("Short")
    // otvoriť long
    strategy.entry("Long", strategy.long)

if ta.crossover(close, upperjeje)
    // zatvoriť long
    strategy.close("Long")
    // otvoriť short
    strategy.entry("Short", strategy.short)