트렌드 다음 전략 트렌드 신뢰에 기초

저자:차오장, 날짜: 2023-11-22 15:50:07
태그:

img

전반적인 설명

이 전략의 주요 아이디어는 가능한 한 정확한 트렌드를 따르는 전략을 구현하는 것입니다. 이 전략은 과거 폐쇄 가격의 특정 수의 "신뢰"를 계산하여 현재 선형 트렌드의 연속 가능성을 판단합니다. 전략은 신뢰도가 특정 수준을 초과하면 현재 선형 트렌드가 계속될 가능성이 높다고 가정합니다.

전략 원칙

전략은 일반적인 선형 회귀를 사용하여 과거의 N 종료 가격의 선형 적합성을 계산하여 종료 가격의 오차의 기울기 k와 표준편차 σ를 얻습니다. 그 다음 트렌드 신뢰도는 k/σ로 정의됩니다.

트렌드 신뢰도가 롱 엔트리 문턱을 초과할 때, 롱으로 이동; 롱 출구 문턱에 떨어지면, 롱으로 닫는다. 마찬가지로, 트렌드 신뢰도가 롱 엔트리 문턱을 초과할 때, 쇼트로 이동; 롱 출구 문턱을 초과할 때, 쇼트로 닫는다.

이렇게 하면 명확한 선형 추세를 따르지 않는 야생 가격 움직임의 신호를 필터링할 수 있습니다.

이점 분석

이 전략은 추세와 선형 회귀 방법을 통계에 결합하여 단기 가격 변동을 피하고 장기적인 추세를 따르며 거래 빈도가 낮고 승률이 높습니다.

이 전략은 큰 매개 변수 조정 공간을 가지고 있으며 매개 변수를 조정하여 다른 제품과 시간 프레임에 적응하여 좋은 일반화를 달성 할 수 있습니다.

위험 분석

이 전략은 함정에 빠질 위험이 있습니다. 중요한 트렌드 반전이 발생하면 큰 손실을 발생시킬 것입니다. 또한 부적절한 매개 변수 설정은 과도한 거래 또는 좋은 거래 기회를 놓칠 수도 있습니다.

스톱 로스는 하향 위험을 제어하기 위해 설정할 수 있습니다. 동시에, 파라미터 선택은 과잉 조정을 피하기 위해 신중하게 평가해야합니다.

최적화 방향

이 전략은 다음 측면에서 더 이상 최적화 될 수 있습니다.

  1. 스톱 로스/이익 취득 논리를 추가하여 수익을 확보하고 위험을 제어합니다.

  2. 동적 매개 변수 조정에 대한 적응 최적화 모듈을 추가

  3. 트렌드 반전 포인트를 결정하고 승률을 더 향상시키기 위해 기계 학습 모델을 추가

  4. 일반화를 개선하기 위해 다른 제품과 시간 프레임에 적응성을 테스트하십시오.

결론

일반적으로 이것은 위험 통제와 함께 장기적인 트렌드 추적 전략이다. 트렌드 추적 및 선형 회귀 방법을 결합하여 노이즈 거래 신호를 필터링한다. 매개 변수 조정을 통해 다양한 제품과 시간 프레임에 잘 적응할 수 있으며, 심도 있는 연구와 개선이 필요한 효과적인 전략이다.


/*backtest
start: 2022-11-15 00:00:00
end: 2023-11-21 00:00:00
period: 1d
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/
// © carefulCamel61097

// ################################################################################################

// "This is a trend following strategy that performed very well on the past 5 years"
// "Intended to be used on BTC-USDT, 4hr timeframe"

// "A factor 2 Leverage can be added by changing Order Size to 200% of equity"
// "Higher leverage is not recommended due to big drawdowns"

// "Also seems to work on 1D timeframe, although ideal parameters may be different"
// "Also seems to work on ETH-USDT and some other altcoins, although ideal parameters are different"

// ################################################################################################

//@version=5
strategy("Trend Following based on Trend Confidence", overlay=false )

// Inputs

source      = input(close)

since       = input(timestamp('2000-01-01'), title='Start trading interval')
till        = input(timestamp('2030-01-01'), title='End trading interval')

length      = input(30, title='Length')

longs_on    = input.bool(true, title='Longs')
shorts_on   = input.bool(true, title='Shorts')

// Parameters for best performance 2018 - 2022
// long_entry  = input.float(0.26, step=0.01, title='Long entry threshold')
// long_exit   = input.float(-0.10, step=0.01, title='Long exit threshold')
// short_entry = input.float(-0.24, step=0.01, title='Short entry threshold')
// short_exit  = input.float(-0.04, step=0.01, title='Short exit threshold')

long_entry  = input.float(0.25, step=0.01, title='Long entry threshold')
long_exit   = input.float(-0.10, step=0.01, title='Long exit threshold')
short_entry = input.float(-0.25, step=0.01, title='Short entry threshold')
short_exit  = input.float(-0.05, step=0.01, title='Short exit threshold')

stop_loss   = input.float(10, step=1, title='Stop loss (percentage)') / 100

// Trend Confidence

linreg = ta.linreg(source, length, 0)
linreg_p = ta.linreg(source, length, 0+1)

x = bar_index
slope = linreg - linreg_p
intercept = linreg - x*slope
deviationSum = 0.0
for i = 0 to length-1
    deviationSum := deviationSum + math.pow(source[i]-(slope*(x-i)+intercept), 2)
deviation = math.sqrt(deviationSum/(length))

slope_perc = slope / source[0]
deviation_perc = deviation / source[0]
trend_confidence = slope_perc / deviation_perc

// Strategy

in_interval = true

sl_long = strategy.position_avg_price * (1 - stop_loss)
sl_short = strategy.position_avg_price * (1 + stop_loss)

if in_interval and longs_on and ta.crossover(trend_confidence, long_entry)
    strategy.entry("TC Long Entry", strategy.long)
    strategy.exit("TC Long Exit", stop=sl_long)
if in_interval and longs_on and ta.crossunder(trend_confidence, long_exit)
    strategy.close("TC Long Entry")

if in_interval and shorts_on and ta.crossunder(trend_confidence, short_entry)
    strategy.entry("TC Short Entry", strategy.short)
    strategy.exit("TC Short Exit", stop=sl_short)
if in_interval and shorts_on and ta.crossover(trend_confidence, short_exit)
    strategy.close("TC Short Entry")

// Plots 

plot(trend_confidence, "Trend Confidence", color.rgb(255, 255, 255))

plot(long_entry, "", color.rgb(0, 255, 0), linewidth=1)
plot(long_exit, "", color.rgb(255, 0, 0), linewidth=1)
plot(short_entry, "", color=bar_index % 10 == 0 ? color.rgb(0, 255, 0) : #00000000, linewidth=1)
plot(short_exit, "", color=bar_index % 10 == 0 ? color.rgb(255, 0, 0) : #00000000, linewidth=1)


더 많은