RSI 신호 추적 역전 거래 전략

저자:차오장, 날짜: 2023-09-28 10:54:24
태그:

전반적인 설명

이 전략은 RSI 지표에서 놓친 과잉 구매 및 과잉 판매 신호를 추적하여 반전 거래를 구현합니다. RSI가 과잉 구매 수준에서 떨어지면 구매 신호가 생성되며, RSI가 과잉 판매 수준에서 반등하면 판매 신호가 생성되며, 반전 기회를 잡는 것을 목표로합니다.

전략 논리

신호 식별

RSI 지표는 과잉 구매/ 과잉 판매 수준을 식별합니다. RSI가 과잉 구매 임계값을 넘어서면 과잉 구매, 과잉 판매 임계값을 넘어서면 과잉 판매됩니다.

overbought = rsi > uplimit
oversold = rsi < dnlimit

만약 RSI가 지난 바에서 과잉 구매되고 이 바에서 과잉 출입한 경우, 구매 신호가up1RSI가 지난 바에서 과잉 판매되고 이 바에서 빠져나간 경우, 판매 신호가 표시됩니다dn1생성됩니다.

up1 = bar == -1 and strategy.position_size == 0 and overbought[1] and overbought == false
dn1 = bar == 1 and strategy.position_size == 0 and oversold[1] and oversold == false

출구 논리

바 방향이 위치 방향과 정렬되고 바 몸체가 10주기 평균의 절반을 초과하면 출구 신호가 발사됩니다.

exit = (((strategy.position_size > 0 and bar == 1) or  
         (strategy.position_size < 0 and bar == -1)) and  
        body > abody / 2)

장점

  1. 놓친 RSI 반전 신호를 추적하여 과도한 구매 / 과도한 판매 지점을 적시에 잡는 것을 피합니다.

  2. 전환점을 파악하기 위해 RSI의 반전 특성을 활용합니다.

  3. 철회 후 추가 추적을 피하기 위해 출구 논리에 바 방향과 크기를 포함합니다.

위험 과 해결책

  1. RSI로부터 나오는 잘못된 신호의 위험

    • 해결책: 잘못된 신호를 피하기 위해 신호를 다른 표시기로 확인합니다.
  2. 가격이 신호를 추적할 때 이미 크게 하락했을 수도 있고 손실 위험이 증가할 수도 있습니다.

    • 솔루션: 입시에 위치 크기를 줄이거나 입시 시기를 최적화
  3. 전체 수익성 전환 전에 조기 퇴출 위험

    • 해결책: 출구 논리를 개선하여 수익을 얻을 수있는 기회를 높입니다.

더 나은 기회

  1. 다른 시장에 기초하여 과반 구매 / 과반 판매 수준, 뷰백 기간 등과 같은 매개 변수를 최적화

  2. 위치 크기를 조정, 추적 신호를 할 때 크기를 낮추는 것과 같은

  3. 추적 신호 이외의 필터를 추가하여 입력 시기를 개선합니다.

  4. 수익성을 높이기 위해 출구를 강화합니다.

  5. 트레일링 스톱이나 콘 스톱과 같은 손실을 줄이기 위해 스톱을 최적화하십시오.

요약

이 전략은 RSI 과잉 구매 / 과잉 판매 신호를 추적하여 반전 거래를 구현합니다. 반전 신호를 잡는 장점이 있지만 잘못된 신호 및 손실의 위험도 있습니다. 추가 최적화는 전략의 안정성과 수익성을 향상시킬 수 있습니다.


/*backtest
start: 2023-09-20 00:00:00
end: 2023-09-27 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Anti RSI Strategy v1.0", shorttitle = "Anti RSI str 1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usemar = input(false, defval = false, title = "Use Martingale")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
rsiperiod1 = input(14, defval = 14, minval = 2, maxval = 50, title = "RSI Period")
rsilimit1 = input(25, defval = 25, minval = 1, maxval = 100, title = "RSI limit")
showarr = input(false, defval = false, title = "Show Arrows")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//RSI
uprsi1 = rma(max(change(close), 0), rsiperiod1)
dnrsi1 = rma(-min(change(close), 0), rsiperiod1)
rsi = dnrsi1 == 0 ? 100 : uprsi1 == 0 ? 0 : 100 - (100 / (1 + uprsi1 / dnrsi1))
uplimit = 100 - rsilimit1
dnlimit = rsilimit1

//Body
body = abs(close - open)
abody = sma(body, 10)

//Signals
bar = close > open ? 1 : close < open ? -1 : 0
overbought = rsi > uplimit
oversold = rsi < dnlimit

up1 = bar == -1 and strategy.position_size == 0 and overbought[1] and overbought == false
dn1 = bar == 1 and strategy.position_size == 0 and oversold[1] and oversold == false
up2 = bar == -1 and strategy.position_size > 0 and overbought == false
dn2 = bar == 1 and strategy.position_size < 0 and oversold == false

norma = overbought == false and oversold == false
exit = (((strategy.position_size > 0 and bar == 1) or (strategy.position_size < 0 and bar == -1)) and body > abody / 2)

//Arrows
col = exit ? black : up1 or dn1 or up2 or dn2 ? blue : na
needup = up1 or up2
needdn = dn1 or dn2
needexitup = exit and strategy.position_size < 0
needexitdn = exit and strategy.position_size > 0
plotarrow(showarr and needup ? 1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(showarr and needdn ? -1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(showarr and needexitup ? 1 : na, colorup = black, colordown = black, transp = 0)
plotarrow(showarr and needexitdn ? -1 : na, colorup = black, colordown = black, transp = 0)

//Trading
profit = exit ? ((strategy.position_size > 0 and close > strategy.position_avg_price) or (strategy.position_size < 0 and close < strategy.position_avg_price)) ? 1 : -1 : profit[1]
mult = usemar ? exit ? profit == -1 ? mult[1] * 2 : 1 : mult[1] : 1
lot = strategy.position_size == 0 ? strategy.equity / close * capital / 100 * mult : lot[1]

if up1 or up2
    if strategy.position_size < 0
        strategy.close_all()
        
    strategy.entry("Long", strategy.long, needlong == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

if dn1 or dn2
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    
if time > timestamp(toyear, tomonth, today, 23, 59) or exit
    strategy.close_all()

더 많은