RSI 추세 전략

RSI SMA EMA
생성 날짜: 2024-06-14 15:28:38 마지막으로 수정됨: 2024-06-14 15:28:38
복사: 0 클릭수: 562
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

RSI 추세 전략

개요

이 전략은 상대적으로 강하고 약한 지수 ((RSI) 지표를 기반으로 RSI 지표의 값이 기본 상하 하위치를 초과했는지 판단하여 구매 및 판매 신호를 결정합니다. 이 전략은 또한 위험을 제어하기 위해 중지 및 지분 시간 제한을 설정합니다.

전략 원칙

  1. RSI의 값을 계산한다.
  2. RSI 값이 기본 구매 값보다 낮으면 구매 신호를 생성하고, RSI 값이 기본 판매 값보다 높으면 판매 신호를 생성한다.
  3. 구매 신호에 따라, 현재 종료 가격으로 구매 수량을 계산하고 주문 구매 .
  4. 만약 스톱로스 비율이 설정되어 있다면, 스톱로스 가격을 계산하고 스톱로스 주문한다.
  5. 판매 신호 또는 중지 조건에 따라 평점 모든 포지션을 보유하십시오.
  6. 최대 보유 시간 (maximum holding time) 을 설정하면, 보유 시간 (holding time) 이 최대 보유 시간 (maximum holding time) 을 초과하면, 이익과 손실에 관계없이, 모든 보유 지분을 청산한다.

전략적 이점

  1. RSI 지표는 널리 사용되는 기술적 분석 지표로, 시장의 과매매 및 과매매 신호를 효과적으로 포착할 수 있다.
  2. 이 전략은 위험을 통제하는 데 도움이 되는 스톱로스 및 포지션 보유 시간 제한을 도입했다.
  3. 전략의 논리는 명확하고, 이해하기 쉽고, 실행하기 쉽다.
  4. RSI의 변수와 마이너스를 조정하여 다양한 시장 환경에 적응할 수 있습니다.

전략적 위험

  1. RSI 지표는 경우에 따라 잘못된 신호를 보내서 전략에 손실을 초래할 수 있습니다.
  2. 이 전략은 거래 품종의 기본 요소를 고려하지 않고 기술 지표에만 의존하여 시장의 갑작스러운 위험에 직면 할 수 있습니다.
  3. 고정된 막부 비율은 시장의 변동성에 적응하지 못할 수 있다.
  4. 정책의 성능은 파라미터 설정에 의해 영향을 받을 수 있으며, 부적절한 파라미터는 정책의 성능이 좋지 않을 수 있다.

전략 최적화 방향

  1. 전략의 신뢰성을 높이기 위해 이동 평균과 같은 다른 기술 지표를 도입하십시오.
  2. 이동식 중지 또는 변동성 기반의 동적 중지와 같은 손실을 중지하는 전략을 최적화하십시오.
  3. 시장 상황에 따라 동적으로 조정되는 RSI의 파라미터와 값
  4. 전략의 위험 제어 능력을 개선하기 위해 거래 품종의 기본에 대한 분석을 결합하십시오.
  5. 전략에 대한 피드백과 변수 최적화를 통해 최적의 변수 조합을 찾습니다.

요약하다

이 전략은 RSI 지표를 사용하여 시장의 과매매 및 과매매 신호를 포착하고, 위험을 제어하기 위해 스톱로스 및 포지션 시간 제한을 도입합니다. 전략의 논리는 간단하고 구현 및 최적화하기가 쉽습니다. 그러나 전략의 성과는 시장의 변동과 파라미터 설정에 영향을받을 수 있으므로 전략의 안정성과 수익성을 높이기 위해 다른 분석 방법과 위험 관리 수단과 결합해야합니다.

전략 소스 코드
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Simple RSI Strategy", overlay=true,  initial_capital=20, commission_value=0.1, commission_type=strategy.commission.percent)

// Define the hardcoded date (Year, Month, Day, Hour, Minute)
var hardcodedYear = 2024
var hardcodedMonth = 6
var hardcodedDay = 10

// Convert the hardcoded date to a timestamp
var start_date = timestamp(hardcodedYear, hardcodedMonth, hardcodedDay)

// settings
order_size_usdt = input.float(20, title="Order Size (USDT)")
rsiLength = input.int(9, title="RSI Length")
rsiBuyThreshold = input.int(30, title="RSI Buy Threshold")
rsiSellThreshold = input.int(70, title="RSI Sell Threshold")
rsibuystrat = input.int(1, title="buy strat 1=achieved,2=recross")
rsisellstrat = input.int(1, title="sell strat 1=achieved,2=recross")
stoploss = input.int(1, title="Stop loss percent")
max_duration = input(24, title="Max Position Duration (hours)")*60

// emaPeriod = input.int(50, title="EMA Period")
// smaPeriod = input.int(200, title="SMA Period")

rsi = ta.rsi(close, rsiLength) 
// ma_rsi = ta.sma(rsi, rsiLength)
// ema = ta.ema(close,emaPeriod)
// sma = ta.sma(close,smaPeriod)
// plot(sma, color=color.red, title="exp Moving Average")
// plot(smal, color=color.blue, title="Simple Moving Average")

longCondition = ((ta.crossunder(rsi, rsiBuyThreshold) and rsibuystrat==1) or (ta.crossover(rsi, rsiBuyThreshold) and rsibuystrat==2) ) and strategy.position_size == 0
shortCondition = ( (ta.crossover(rsi, rsiSellThreshold) and rsisellstrat==1) or (ta.crossunder(rsi, rsiSellThreshold) and rsisellstrat==2) ) and strategy.position_size > 0 

// Execute Buy and Sell orders
if (longCondition)
	positionSize = order_size_usdt / close
	strategy.entry("Long", strategy.long,qty=positionSize)
	if (stoploss>0)
		stopLossPrice = close * (1 - stoploss/100 )
		strategy.exit("Stop Loss", from_entry="Long", stop=stopLossPrice)
	
if (shortCondition )//or stopCondition)
	strategy.close("Long")

//add condition open time
if (strategy.position_size > 0 and max_duration >0)
	var float entry_time = na
	if (strategy.opentrades > 0)
		entry_time := nz(strategy.opentrades.entry_time(0), na)
	else
		entry_time := na

	current_time = time
	var float duration_minutes = -1
	if (not na(entry_time))
		duration_minutes := (current_time - entry_time) / 60000

	
	// Close positions after a certain duration (e.g., 60 minutes)
	// if ( duration_minutes > max_duration and close>=strategy.opentrades.entry_price(0))
	if ( duration_minutes > max_duration )
		label.new(bar_index, high, text="Duration: " + str.tostring(duration_minutes/60) + " hrs", color=color.blue, textcolor=color.white, style=label.style_label_down, size=size.small)
		strategy.close("Long")


// Plot Buy and Sell signals
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
//plotshape(series=stopCondition, title="stop Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Plot RSI
// hline(rsiBuyThreshold, "RSI Buy Threshold", color=color.green)
// hline(rsiSellThreshold, "RSI Sell Threshold", color=color.red)