RSI 이동평균선 이동 손절매 및 이익실현 전략


생성 날짜: 2023-09-13 14:26:43 마지막으로 수정됨: 2023-09-13 14:26:43
복사: 0 클릭수: 671
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

이 전략은 RSI 지표와 이동 평균을 결합하여 트렌드 판단과 거래 신호를 생성하고, 수익을 잠금하고 위험을 제어하기 위해 이동 스톱 스톱 방식을 사용합니다. 전형적인 트렌드 추적 거래 전략 중 하나입니다.

전략적 원칙:

  1. RSI를 계산하여 과매매를 판단하십시오. RSI가 50보다 높으면 다중 신호입니다.

  2. 빠른 느린 이동 평균을 계산하고, golden cross는 다중 헤드 신호이다.

  3. RSI의 지속적인 상승은 추적할 수 있는 거래 신호이기도 합니다.

  4. 출입 후, 이동 스톱 라인 및 스톱 라인을 설정하십시오.

  5. 스톱 라인은 고정 추적 가격 아래, 스톱 라인은 고정 추적 가격 위.

  6. 가격이 스톱로스 스톱 ?? 라인을 만지면 평행한다.

이 전략의 장점:

  1. RSI 지표는 과매매를 판단하고, 하락을 쫓는 것을 피한다.

  2. 이동 평균은 트렌드 방향을 인식한다. 조합은 판단의 정확성을 향상시킨다.

  3. 모바일 스톱스톱 방식, 실시간 가격 변화에 따라 스톱스톱 위치를 조정할 수 있다.

이 전략의 위험은:

  1. RSI 지표와 평균선은 변동 시 잘못된 신호를 발생시킬 수 있다.

  2. 이동식 손해 차단기는 신중하게 폭을 설정해야 하며, 너무 크고 너무 작으면 문제가 있다.

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

요약하자면, 이 전략은 RSI와 평균 지표의 장점을 통합하고, 모바일 스톱 스톱 방식을 사용하여 위험을 관리합니다. 변수 최적화 및 위험 제어 측면에서 향상하면 더 나은 효과를 얻을 수 있습니다.

전략 소스 코드
/*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)