RSI 지표 두 가지 전략

저자:차오장, 날짜: 2023-09-19 19:43:19
태그:

전반적인 설명

이 전략은 쇼트 및 롱에 대한 과잉 구매 및 과잉 판매 수준을 결정하기 위해 상대적 강도 지표 (RSI) 지표를 사용합니다. 이것은 전형적인 RSI 역전 거래 전략입니다. 이 전략은 또한 매개 변수 최적화, 스톱 손실 등을 통합하여 다른 시장 조건에 적응합니다.

전략 논리

핵심 논리는 다음과 같습니다.

  1. RSI 값 계산
  2. RSI 상단 및 하단 한도를 설정
  3. RSI가 상한값을 넘을 때 단축
  4. RSI가 하위 한도를 넘을 때 긴 경로
  5. 수익을 취하고 손실을 멈추는 수준을 설정
  6. RSI가 역전되거나 수익/손실 중단이 발생했을 때 출전하는 지점

RSI 지표는 70 이상의 과반 매입과 30 이하의 과반 매출을 보여줍니다. 전략은 사전 설정된 제한에 대한 RSI 값을 기반으로 긴 / 짧은 항목을 결정하기 위해 이러한 고전적 논리를 사용합니다. 사용자 정의 가능한 매개 변수는 또한 시장 적응을 위해 제한, 스톱 로스 등을 최적화 할 수 있습니다.

장점

  • RSI는 과잉 구매/ 과잉 판매 시장 상태를 효과적으로 식별합니다.
  • RSI는 확실한 이론적 근거가 있습니다.
  • 사용자 정의 가능한 매개 변수는 기기와 조건에 따라 적응합니다.
  • 적립된 영업/손실 중지 통제 위험

위험 및 완화

  • 손실로 이어지는 잘못된 RSI 신호의 가능성
  • RSI 레벨의 지속적인 최적화를 요구합니다.
  • 가격 움직임이 흔들리는 동안 정지점이 자주 발생할 수 있습니다.

완화:

  1. 신호 를 확인 하고 거짓 신호 를 피 하기 위한 추가적 요인
  2. 기기 특성에 따라 RSI 수준을 최적화
  3. 스톱 로스 배치를 조정하여 윙사 리스크를 줄이십시오

더 나은 기회

이 전략은 다음을 통해 강화될 수 있습니다.

  1. 자동 RSI 레벨 최적화를 위한 기계 학습

  2. 부진을 방지하기 위한 부피 확인

  3. 다중 요인 확인을 위한 이동 평균과 같은 추가 요소

  4. 시장 변동성에 기초한 적응식 중지

  5. 기금 유입/출입을 측정하기 위한 부피 분석

  6. 연결되지 않은 전략과 결합하여 포트폴리오 소모를 줄이십시오.

결론

이 전략은 지나치게 많이 구매/ 지나치게 많이 팔린 것을 탐지하기 위해 RSI를 이용한 간단하고 실용적인 평균 역전 전략이다. 사용자 정의 가능한 매개 변수는 변화하는 시장에 적응할 수 있다. 적응식 정지, 다중 인자 확인, 매개 변수 최적화 등의 개선은 전략을 더욱 견고하게 만들 수 있다.


/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("4All V3", shorttitle="Strategy", overlay=true)

/////////////// Component Code Start ///////////////
testStartYear = input(2011, "Backtest Start Year") 
testStartMonth = input(8, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(9, "Backtest Stop Month")
testStopDay = input(29, "Backtest Stop Day")
// testStopDay = testStartDay + 1
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() => true
/////////////// Component Code Stop ///////////////

src = close
len = input(4, minval=1, title="Length")

up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

rsin = input(5)
sn = 100 - rsin
ln = 0 + rsin

/////////////// STRATEGY ///////////////
ts = input(99999, "Trailing Stop") / 10000
tp = input(15, "Take Profit") / 10000
sl = input(23, "Stop Loss") / 10000

pyr = input(1, "Pyramiding")

short = crossover(rsi, sn)
long = crossunder(rsi, ln)

totalLongs = 0
totalLongs := nz(totalLongs[1])
totalShorts = 0
totalShorts := nz(totalShorts[1])

totalLongsPrice = 0
totalLongsPrice := nz(totalLongsPrice[1])
totalShortsPrice = 0
totalShortsPrice := nz(totalShortsPrice[1])

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if long
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if short
    sectionLongs := 0
    sectionShorts := sectionShorts + 1

longCondition = long and sectionLongs >= pyr
shortCondition = short and sectionShorts >= pyr

last_long = na
last_short = na
last_long := longCondition ? time : nz(last_long[1])
last_short := shortCondition ? time : nz(last_short[1])

long_signal = crossover(last_long, last_short)
short_signal = crossover(last_short, last_long)

last_open_long_signal = na
last_open_short_signal = na
last_open_long_signal := long_signal ? open : nz(last_open_long_signal[1])
last_open_short_signal := short_signal ? open : nz(last_open_short_signal[1])

last_long_signal = na
last_short_signal = na
last_long_signal := long_signal ? time : nz(last_long_signal[1])
last_short_signal := short_signal ? time : nz(last_short_signal[1])

in_long_signal = last_long_signal > last_short_signal
in_short_signal = last_short_signal > last_long_signal

last_high = na
last_low = na
last_high := not in_long_signal ? na : in_long_signal and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_low := not in_short_signal ? na : in_short_signal and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])

long_ts = not na(last_high) and high <= (last_high - ts) //and high >= last_open_long_signal
short_ts = not na(last_low) and low >= (last_low + ts) //and low <= last_open_short_signal

long_tp = high >= (last_open_long_signal + tp)
short_tp = low <= (last_open_short_signal - tp)

long_sl = low <= (last_open_long_signal - sl)
short_sl = high >= (last_open_short_signal + sl)

leverage = input(1, "Leverage")
long_call = last_open_long_signal - (0.8 + 0.2 * (1/leverage)) / leverage * last_open_long_signal
short_call = last_open_short_signal + (0.78 + 0.2 * (1/leverage)) / leverage * last_open_short_signal
long_call_signal = low <= long_call
short_call_signal = high >= short_call

if testPeriod()
    strategy.entry("Long", strategy.long, when=longCondition)
    strategy.entry("Short", strategy.short, when=shortCondition)
    
    strategy.close("Long", when=long_call_signal)
    strategy.close("Short", when=short_call_signal)
    strategy.close("Long", when=long_tp)
    strategy.close("Short", when=short_tp)
    strategy.close("Long", when=long_sl)
    strategy.close("Short", when=short_sl)
    strategy.close("Long", when=long_ts)
    strategy.close("Short", when=short_ts)

더 많은