평균 반전과 추세를 따르는 양적 전략

저자:차오장, 날짜: 2023-09-14 20:45:20
태그:

이 문서에서는 평균 반전과 트렌드 다음 기법을 결합한 양적 거래 전략을 자세히 설명합니다. 트렌딩 시장에서 역 트렌드를 거래하고 트렌딩 시장에서 추진력을 타는 것을 목표로합니다.

I. 전략 논리

이 전략은 주로 간단한 이동 평균과 RSI 지표를 사용하여 거래 신호를 생성합니다.

  1. 가격이 200주기 SMA보다 낮으면 현재 시장이 하락 추세라고 판단됩니다.

  2. RSI가 20보다 낮을 때, 반동 트렌드 평균 반전 트레이드가 필요합니다.

  3. 가격이 200주기 SMA를 넘으면 현재 시장을 상승 추세로 판단합니다.

  4. 가격이 SMA를 넘으면 트렌드를 따르는 거래가 필요합니다.

  5. RSI가 80을 넘거나 가격이 특정 비율로 SMA 이하로 떨어지면 출입이 발생합니다.

  6. 평균 회귀와 추세에 대한 위치 크기는 별도로 조정할 수 있습니다.

이 전략은 평균 회전과 트렌드 추종 기술을 결합하고 다른 시장 단계에서 적용합니다.

II. 전략의 장점

주요 장점은 다음과 같습니다.

  1. 두 가지 기술을 결합하면 전략 적응력이 향상됩니다.

  2. 트렌딩과 다양한 시장에서 거래 기회를 찾을 수 있습니다.

  3. 리스크는 포지션 크기를 조정함으로써 제어할 수 있습니다.

  4. 간단한 매개 변수 설정으로 구현이 쉬워집니다.

III. 잠재적 위험

그러나 위험은 다음과 같습니다.

  1. SMA와 RSI와 같은 지표는 잘못된 파업에 민감합니다.

  2. 두 가지 모드 사이를 전환하는 데 지연이 있을 수 있습니다.

  3. 장기적인 이익을 위해 어떤 마감도 견뎌야 합니다.

IV. 요약

요약적으로,이 기사는 평균 회귀 및 트렌드 다음 기술을 활용한 양적 전략을 설명했습니다. 적응력을 향상시키기 위해 다른 시장 단계에서 거래 할 수 있습니다. 그러나 지표 실패 및 지연 모드 전환과 같은 위험이 관리되어야합니다. 전반적으로, 그것은 다른 기술을 결합하는 유연한 접근 방식을 제공합니다.


/*backtest
start: 2022-09-07 00:00:00
end: 2023-04-05 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/
// © I11L

//@version=5
strategy("Mean Reversion and Trendfollowing", overlay=true, pyramiding=1, default_qty_value=100000, initial_capital=100000, default_qty_type=strategy.cash, process_orders_on_close=false, calc_on_every_tick=false)

// Input for the starting date
start_date = input(timestamp("1 Feb 2000 12:00"), title="Starting Date")
enableMeanReversion = input.bool(true)
enableTrendfollowing = input.bool(true)
trendPositionFactor = input.float(1)
meanReversionPositionFactor = input.float(0.5)

// Convert the input string to a timestamp
start_ts = timestamp(year(start_date), month(start_date), dayofmonth(start_date), 0, 0)

// Check if the current bar's time is greater than or equal to the start timestamp
start_condition = time >= start_ts

var tradeOrigin = ""

sma200 = ta.sma(close,200)
rsi2 = ta.rsi(close,2)

isMeanReversionMode = close < sma200 or not(enableTrendfollowing)
isTrendfollowingMode = close > sma200 or not(enableMeanReversion)

isRsiBuy = rsi2 < 20 and enableMeanReversion
isRsiClose = rsi2 > 80 and enableMeanReversion

isSmaBuy = close > sma200 and enableTrendfollowing
isSmaClose = close < sma200 * 0.95 and enableTrendfollowing

isBuy = (isMeanReversionMode and isRsiBuy) or (isTrendfollowingMode and isSmaBuy)

positionSizeFactor = isSmaBuy ? trendPositionFactor : meanReversionPositionFactor

// Only execute the strategy after the starting date
if (start_condition)
    if (isBuy and strategy.opentrades == 0)
        tradeOrigin := isSmaBuy ? "SMA" : "RSI"
        strategy.entry("My Long Entry Id", strategy.long, qty=(strategy.equity / close) * positionSizeFactor, comment=str.tostring(positionSizeFactor))
    isClose = tradeOrigin == "SMA" ? isSmaClose : isRsiClose
    if (isClose)
        strategy.exit("Exit", limit = close)

plot(sma200)
plot(sma200 * 0.95, color=color.orange)

더 많은