RSI 긴 짧은 자동 거래 전략

저자:차오장, 날짜: 2023-10-30 17:13:24
태그:

img

전반적인 설명

이 전략은 상대적 강도 지표 (RSI) 지표에 기반한 장기 및 단위 자동 거래 시스템을 설계합니다. RSI가 과소매 또는 과소매 수준에 도달하면 자동으로 장기 및 단위 신호를 생성하고 자동 거래를 수행 할 수 있습니다.

전략 논리

이 전략은 가격 상승과 하락을 기준으로 0-100 범위의 RSI 값을 계산합니다. RSI가 30 이하이면 과판 상태입니다. RSI가 70 이상이면 과판 상태입니다. 이 규칙에 따르면, 전략은 자동으로 RSI가 과판 구역에 도달하면 길고 RSI가 과판 구역에 도달하면 짧습니다.

특히, 전략은 먼저 15 기간 RSI를 계산합니다. RSI가 20 이하로 떨어지면 과판된 것으로 간주됩니다. 이 시점에서, 가격이 200 일 이동 평균 이상으로 넘어지면 긴 지위가 열립니다. RSI가 80 이상으로 상승하면 과반된 것으로 간주됩니다. 이 시점에서 짧은 지점이 열립니다. 길거나 짧게 나간 후, 수익을 취하고 손실을 중지하여 출구 포지션을 설정합니다.

또한, 전략은 거래 신호를 더 직관적으로 만들기 위해 가격 신호가 발생했을 때 대응하는 랜드마크 라인 및 라벨을 그립니다.

전략 의 장점

  • 전략 아이디어는 명확하고 이해하기 쉽고 실행하기 쉽습니다.
  • RSI 지표에 기초하여, 과잉 구매와 과잉 판매의 판단은 정확합니다.
  • 수동 개입 없이 완전히 자동화 된 거래
  • 리스크를 효과적으로 제어하기 위해 수익을 취하고 손실을 멈추는 설정
  • 직관적이고 쉽게 모니터링 할 수있는 거래 신호

전략 의 위험

  • RSI 지표가 다소 뒤떨어져 판단이 잘못될 수 있습니다.
  • 고정된 과잉 구매 및 과잉 판매 기준은 모든 제품에 적합하지 않습니다.
  • 잘못된 스톱 손실 설정은 더 큰 손실을 일으킬 수 있습니다.
  • 트렌딩 시장의 주요 트렌드에 따라 거래하면 손실이 발생할 수 있습니다.

리스크 제어 조치로는: RSI 매개 변수를 최적화하고, 다른 제품에 맞게 과반 구매 및 과반 판매의 문턱을 조정하고, 합리적으로 스톱 로스를 설정하고, 트렌드 지표와 결합하여 트렌드에 반대하는 거래를 피합니다.

전략 최적화의 방향

  • RSI 매개 변수를 최적화하여 과반 구매 및 과반 판매를 판단하는 정확도를 향상시킵니다.
  • KDJ, MACD 등과 같은 다른 지표로 거래 신호를 확인합니다.
  • 시장 조건에 따라 스톱 로스 설정을 최적화
  • 역동 연산을 피하기 위해 트렌드 판단을 추가합니다.
  • 주식 곡선 추적 정지 손실
  • 단일 및 전체 위험을 제어하기 위한 위험 관리 모듈 개발

요약

전체적으로 이것은 RSI 지표를 사용하여 과소비 및 과소비 조건을 판단하는 자동화된 거래 전략이다. RSI가 극심한 과소비 또는 과소비 수준에 도달하면 거래 신호를 생성하고 자동으로 장기 및 단거래를 수행할 수 있다. 전략 아이디어는 간단하고 명확하고 구현하기 쉽고 기본적인 자동화 거래 전략으로 적합하다. 그러나 RSI 지표에는 약간의 지체점이 있으므로 신호 정확성을 향상시키기 위해 다른 지표와 함께 최적화하는 것이 좋습니다. 또한 위험 통제, 스톱 로스 메커니즘을 최적화하고, 거래 위험을 줄이기 위해 위험 제어 모듈을 개발하는 데주의를 기울여야 한다. 라이브 트레이딩에서 최적화 및 검증되면 전략은 장기 및 단거래에 효과적인 자동화 시스템으로 변할 수 있다.


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

//@version=5
strategy("RSI Improved strategy", overlay=true)
higherTF1 = input.timeframe('15' , "Resolution", options = ['5', '15', '1H', 'D', 'W', 'M'])
dailyopen = request.security(syminfo.tickerid, higherTF1, close)

Reward = input(1600)
Risk = input(1600)

length = input( 5 )
overSold = input( 30 )
overBought = input( 70 )
EMA = input(200)
price = close

vrsi = ta.rsi(price, length)

RSIlowest =  vrsi[1] > vrsi ? true : false
RSIhighest = vrsi[1] < vrsi ? true : false

//ro = ta.crossunder(vrsi, 20)
//ru = ta.crossover(vrsi, 80)

co = ta.crossunder(vrsi, overSold)
cu = ta.crossunder(vrsi, overBought)

plot(ta.ema(close, EMA))
plot(ta.ema(close, 50), color = color.orange)

UponEMA = close > ta.ema(close, EMA) ? true : false
belowEMA = close < ta.ema(close, EMA) ? true : false
//transfer 'float' to 'int' to 'string'
r = int(vrsi)
value = str.tostring(r)

m = int(strategy.openprofit)
money = str.tostring(m)
if (not na(vrsi))
	//when price stand up on 200ema and rsi is at oversold area, open long position 
//	if (co and UponEMA)
  //      strategy.order("Rsi long", strategy.long, 1 , comment = "Rsi long")
        
    if(vrsi < 20 and RSIlowest)
        // line1 = line.new(x1=bar_index, y1=dailyopen, x2=bar_index+1, y2=dailyopen, xloc=xloc.bar_index, style=line.style_solid,extend=extend.right, color=color.aqua, width = 2)
        // line.delete(line1[1])  // remove the previous line when new bar appears
        // label1 = label.new(x=bar_index, y=dailyopen,yloc=yloc.belowbar, text = value,textcolor = color.white, color = color.green, style = label.style_label_up)
        // label.delete(label1[1])
        strategy.order("Rsi long", strategy.long, 1 , comment = "Rsi long")
        strategy.exit("exit", "Rsi long", profit = Reward, loss = Risk, comment = "Rsi long exit")
//strategy.close("Rsi short", comment = "Rsi close")

	
	

	if(vrsi > 80 and RSIhighest)
        // line2 = line.new(x1=bar_index, y1=dailyopen, x2=bar_index+1, y2=dailyopen, xloc=xloc.bar_index, style=line.style_solid,extend=extend.right, color = #e65100, width = 2)
        // line.delete(line2[1])  // remove the previous line when new bar appears
        // label2 = label.new(x=bar_index, y=dailyopen,yloc=yloc.abovebar, text = value, textcolor = color.white, color = color.red)            
        // label.delete(label2[1])
        strategy.order("Rsi short",strategy.short, 1,  comment = "Rsi short ")
        strategy.exit("exit", "Rsi short", profit = Reward,loss = Risk, comment = "Rsi short exit")
//	if(UponEMA)
//        strategy.close("Rsi short", comment = "Rsi short close")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_cross)
//plotshape(confirmPH, title="Label",offset = 1,text="Bull",style=shape.labeldown,location=location.abovebar,color=color.green,textcolor=color.green)




//when Rsi reaches overbought, draw a Horizontal Ray to close prices, similarly when it comes to oversold.(accomplished)
//detects when there is more lower/higher RSI values, adjust horizontal Ray and label to new posistion.(accomplished)

더 많은