RSI 이동 평균 후속 중지 전략

저자:차오장, 날짜: 2023-09-13 14:26:43
태그:

이 전략은 트렌드 편향을 위해 RSI와 이동 평균을 결합하고 리스크 관리에 트레일링 스톱을 추가합니다. 적응 출구로 트렌드를 따라가는 것을 목표로합니다.

전략 논리:

  1. RSI를 계산하면 과잉 구매/ 과잉 판매 수준을 판단할 수 있습니다. RSI 50 이상은 상승세를 나타냅니다.

  2. 속도가 빨라지고 느린 이동 평균을 계산합니다. 금색 십자가는 황소 추세를 나타냅니다.

  3. RSI 상승률은 긴 진입을 신호합니다.

  4. 진입 후 후속 스톱 로스를 설정하고 수익 라인을 취합니다.

  5. 가격 아래의 손실을 멈추고, 상위에서 수익을 얻습니다.

  6. 가격이 정지하거나 수익을 취하면 빠져나갑니다.

장점:

  1. RSI는 위와 아래를 쫓는 것을 피합니다.

  2. 이동 평균은 트렌드 방향을 파악합니다. 조합은 정확성을 향상시킵니다.

  3. 트레일링 스톱/이익은 가격에 동적으로 조정됩니다.

위험성:

  1. RSI와 MAs는 다양한 시장에서 잘못된 신호에 취약합니다.

  2. 후속 스톱 너비는 신중한 캘리브레이션을 요구합니다. 너무 넓거나 너무 좁은 것이 문제입니다.

  3. 손실 규모를 제한할 수 없으니 큰 손실을 초래할 위험이 있습니다.

요약하자면, 이 전략은 RSI와 MAs를 결합하고 리스크 관리를 위해 트레일링 스톱을 사용합니다. 강력한 최적화와 리스크 통제로 좋은 결과를 얻을 수 있습니다.


/*backtest
start: 2022-09-06 00:00:00
end: 2023-09-12 00:00:00
period: 4d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("RSI and MA Strategy with Trailing Stop Loss and Take Profit",
         overlay=true,
         initial_capital=1000,
         process_orders_on_close=true,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=100,
         commission_type=strategy.commission.percent,
         commission_value=0.1)

showDate = input(defval=true, title='Show Date Range')
timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)
notInTrade = strategy.position_size <= 0

//==================================Buy Conditions============================================

//RSI
length = input(14)
rsi = ta.rsi(close, length)
buyCondition1 = rsi > 50

//MA
SMA9 = ta.sma(close, 9)
SMA50 = ta.sma(close, 50)
SMA100 = ta.sma(close, 100)
plot(SMA9, color = color.green)
plot(SMA50, color = color.orange)
plot(SMA100, color = color.blue)
buyCondition2 = SMA9 > SMA50//ta.crossover(SMA9, SMA100)

//RSI Increase
increase = 5
buyCondition3 = (rsi > rsi[1] + increase)


if (buyCondition1 and buyCondition2 and buyCondition3 and timePeriod) //and buyCondition
    strategy.entry("Long", strategy.long)

//==================================Sell Conditions============================================

//Trailing Stop Loss and Take Profit
longTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=2) * 0.01
shortTrailPerc = input.float(title='Trail Short Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01

longStopPrice = 0.0
shortStopPrice = 0.0

longStopPrice := if strategy.position_size > 0
    stopValue = close * (1 - longTrailPerc)
    math.max(stopValue, longStopPrice[1])
else
    0

shortStopPrice := if strategy.position_size < 0
    stopValue = close * (1 + shortTrailPerc)
    math.min(stopValue, shortStopPrice[1])
else
    999999


strategy.exit(id="Exit", stop = longStopPrice, limit = shortStopPrice)

더 많은