RSI 더블트랙 오실레이터 롱앤숏 양방향 트레이딩 전략


생성 날짜: 2023-10-25 11:57:46 마지막으로 수정됨: 2023-10-25 11:57:46
복사: 1 클릭수: 627
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

RSI 더블트랙 오실레이터 롱앤숏 양방향 트레이딩 전략

개요

RSI 이중 궤도 흔들림 라인 긴 양방향 거래 전략은 RSI 지표를 사용하여 양방향 거래를하는 전략이다. 이 전략은 RSI 지표의 초매 초매 원칙을 통해, 양 궤도 설정과 일률 거래 신호를 결합하여 효율적인 양방향 개시 포지션과 평지 포지션을 달성한다.

전략 원칙

이 전략은 주로 RSI 지표의 오버 바이 오버 셀 원칙에 따라 거래 결정을 내립니다. 전략은 먼저 RSI 지표의 값vrsi, 그리고 쌍궤도 상단 궤도 sn 및 하단 궤도 ln을 계산합니다. RSI 값이 아래로 내려가면 다중 신호가 발생하고, RSI 값이 위로 올라갈 때 빈 신호가 발생합니다.

전략은 또한 K선의 위아래 변화를 감지하여 더 많은 공백 신호를 생성한다. 구체적으로, K선에서 아래로 위를 돌파 할 때 더 많은 신호를 생성한다.longLocic, K선에서 위를 아래로 돌파 할 때 공백 신호를 생성한다.shortLogic. 또한, 전략은 변수 스위치를 제공하며, 그냥 더, 그냥 공백, 또는 반전 신호를 생성한다.

다중 하락 신호를 생성한 후, 전략은 신호의 수를 통계적으로 계산하고, 포지션의 개수를 제어한다. 파라미터를 통해 다른 포지션의 규칙을 설정할 수 있다. 평형 포지션 조건은 스톱, 스톱 손실, 이동 스톱 손실 등의 방법을 포함하고, 다른 스톱 스톱 손실 비율을 설정할 수 있다.

요약하자면, 이 전략은 RSI 지표, 평평선 교차, 통계적 부가, 스톱 스로즈와 같은 여러 가지 기술적 수단을 통합하여 자동으로 장단 양방향 거래를 수행합니다.

전략적 이점

  • RSI 지표의 초과 구매 초과 판매 원칙을 사용하여 합리적인 위치에 더 많은 하위 상품을 설정하십시오.
  • 쌍궤도 설정으로 잘못된 신호를 피한다. 상반선은 다중중 위치의 조기 평준화를 막고, 하반선은 공중 위치의 조기 평준화를 막는다.
  • 평균선 거래 신호 필터링 거짓 돌파 . 주가가 평균선을 돌파하기 전에 신호를 생성하여 거짓 신호를 피한다.
  • 통계 신호 횟수 및 재고 횟수, 위험 관리
  • 사용자 정의 스톱 스톱 손실 비율, 수익 위험 제어
  • 모바일 스톱로스는 스톱로스를 추적하여 수익을 더욱 고정시킵니다.
  • 다른 시장 환경에 적응하기 위해, 더 많은 것을 할 수 있고, 빈 것을 할 수 있습니다.
  • 자동화 거래 시스템, 인적 운영 비용 절감.

전략적 위험

  • RSI 지표에는 역전 실패의 위험이 있다. RSI가 초고매구역에 들어간다고 해서 반드시 역전될 필요는 없다.
  • 고정 스톱 스톱 지점은 설정되어 있습니다. 부적절한 스톱 스톱 설정은 조기 중단 또는 스톱을 유발할 수 있습니다.
  • 기술 지표에 의존하고, 변수 최적화 위험이 있다. 지표 변수 설정이 잘못되면, 전략 효과에 영향을 줄 수 있다.
  • 여러 가지 조건이 동시에 발생하면, 표가 빠질 위험이 있습니다.
  • 자동 거래 시스템은 비정상적인 오류의 위험이 있습니다.

위와 같은 위험을 대비하여 파라미터 설정을 최적화하고, 스톱 스톱 손실 전략을 조정하고, 유동성 필러닝을 증가시키고, 신호 생성 논리를 최적화하고, 비정상적인 오류 모니터링을 증가시킬 수 있습니다.

전략 최적화 방향

  • RSI 지표 파라미터를 최적화하기 위한 다양한 주기적 파라미터를 테스트한다.
  • 다른 스톱 스톱 손실 비율 설정을 테스트하십시오.
  • 거래량을 늘리거나 수익률을 가하여 유동성이 부족할 수 있습니다.
  • 신호 생성 논리를 최적화하고 평행선 교차 방식을 개선한다.
  • 여러 시간 동안 반복 테스트를 추가하여 안정성을 검증하십시오.
  • 신호 효과를 최적화하기 위해 다른 지표를 추가하는 것을 고려하십시오.
  • 포지션 관리 전략에 가입하십시오.
  • 비정상 오류 모니터링을 추가합니다.
  • 자동 상쇄 손실 추적 알고리즘을 최적화한다.
  • 기계학습을 강화하는 전략을 고려하십시오.

요약하다

RSI 쌍로 흔들림 라인 길고 짧은 쌍방향 거래 전략은 RSI 지표, 통계적 개시 및 중지 원칙과 같은 여러 가지 기술 수단을 종합적으로 사용하여 자동화 된 쌍방향 거래를 구현합니다. 이 전략은 강력한 사용자 정의가 있으며 사용자가 필요에 따라 파라미터를 조정하여 다른 시장 환경에 적응 할 수 있습니다. 또한, 전략에는 개선할 수있는 부분이 있습니다. 최적화 파라미터 설정, 풍선 제어 전략, 신호 생성 논리 등에서 최적화 할 수 있습니다. 전략은 더 안정적이고 신뢰할 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-09-24 00:00:00
end: 2023-10-24 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Learn more about Autoview and how you can automate strategies like this one here: https://autoview.with.pink/
// strategy("Autoview Build-a-bot - 5m chart", "Strategy", overlay=true, pyramiding=2000, default_qty_value=10000)
// study("Autoview Build-a-bot", "Alerts")

///////////////////////////////////////////////
//* Backtesting Period Selector | Component *//
///////////////////////////////////////////////

//* https://www.tradingview.com/script/eCC1cvxQ-Backtesting-Period-Selector-Component *//
//* https://www.tradingview.com/u/pbergden/ *//
//* Modifications made *//

testStartYear = input(1, "Backtest Start Year") 
testStartMonth = input(11, "Backtest Start Month")
testStartDay = input(10, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(77777777, "Backtest Stop Year")
testStopMonth = input(11, "Backtest Stop Month")
testStopDay = input(15, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() => true

/////////////////////////////////////
//* Put your strategy logic below *//
/////////////////////////////////////
RSIlength = input(1,title="RSI Period Length") 
price = close
vrsi = (rsi(price, RSIlength))
src = close
len = input(2, 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(12)
sn = 100 - rsin
ln = 0 + rsin

// Put your long and short rules here
longLocic = crossunder(rsi, ln)
shortLogic = crossover(rsi, sn)

//////////////////////////
//* Strategy Component *//
//////////////////////////

isLong = input(true, "Longs Only")
isShort = input(false, "Shorts Only")
isFlip = input(false, "Flip the Opens")

long = longLocic
short = shortLogic

if isFlip
    long := shortLogic
    short := longLocic
else
    long := longLocic
    short := shortLogic

if isLong
    long := long
    short := na

if isShort
    long := na
    short := short
    
////////////////////////////////
//======[ Signal Count ]======//
////////////////////////////////

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

//////////////////////////////
//======[ Pyramiding ]======//
//////////////////////////////

pyrl = input(2, "Pyramiding less than") // If your count is less than this number
pyre = input(1, "Pyramiding equal to") // If your count is equal to this number
pyrg = input(1000000, "Pyramiding greater than") // If your count is greater than this number

longCondition = long and sectionLongs <= pyrl or long and sectionLongs >= pyrg or long and sectionLongs == pyre ? 1 : 0 and vrsi < 20
shortCondition = short and sectionShorts <= pyrl or short and sectionShorts >= pyrg or short and sectionShorts == pyre ? 1 : 0

////////////////////////////////
//======[ Entry Prices ]======//
////////////////////////////////

last_open_longCondition = na
last_open_shortCondition = na
last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])

////////////////////////////////////
//======[ Open Order Count ]======//
////////////////////////////////////

sectionLongConditions = 0
sectionLongConditions := nz(sectionLongConditions[1])
sectionShortConditions = 0
sectionShortConditions := nz(sectionShortConditions[1])

if longCondition
    sectionLongConditions := sectionLongConditions + 1
    sectionShortConditions := 0

if shortCondition
    sectionLongConditions := 0
    sectionShortConditions := sectionShortConditions + 1
    
///////////////////////////////////////////////
//======[ Position Check (long/short) ]======//
///////////////////////////////////////////////

last_longCondition = na
last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])

in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition

/////////////////////////////////////
//======[ Position Averages ]======//
/////////////////////////////////////

totalLongs = 0.0
totalLongs := nz(totalLongs[1])
totalShorts = 0.0
totalShorts := nz(totalShorts[1])
averageLongs = 0.0
averageLongs := nz(averageLongs[1])
averageShorts = 0.0
averageShorts := nz(averageShorts[1]) 

if longCondition
    totalLongs := totalLongs + last_open_longCondition
    totalShorts := 0.0

if shortCondition
    totalLongs := 0.0
    totalShorts := totalShorts + last_open_shortCondition

averageLongs := totalLongs / sectionLongConditions
averageShorts := totalShorts / sectionShortConditions

/////////////////////////////////
//======[ Trailing Stop ]======//
/////////////////////////////////

isTS = input(false, "Trailing Stop")
tsi = input(100, "Activate Trailing Stop Price (%). Divided by 100 (1 = 0.01%)") / 100 
ts = input(100, "Trailing Stop (%). Divided by 100 (1 = 0.01%)") / 100

last_high = na
last_low = na
last_high_short = na
last_low_short = na
last_high := not in_longCondition ? na : in_longCondition and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_high_short := not in_shortCondition ? na : in_shortCondition and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_low := not in_shortCondition ? na : in_shortCondition and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])
last_low_short := not in_longCondition ? na : in_longCondition and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])

long_ts = isTS and not na(last_high) and low <= last_high - last_high / 100 * ts and longCondition == 0 and last_high >= averageLongs + averageLongs / 100 * tsi
short_ts = isTS and not na(last_low) and high >= last_low + last_low / 100 * ts and shortCondition == 0 and last_low <= averageShorts - averageShorts/ 100 * tsi

///////////////////////////////
//======[ Take Profit ]======//
///////////////////////////////

isTP = input(true, "Take Profit")
tp = input(125, "Take Profit (%). Divided by 100 (1 = 0.01%)") / 100
long_tp = isTP and close > averageLongs + averageLongs / 100 * tp and not longCondition
short_tp = isTP and close < averageShorts - averageShorts / 100 * tp and not shortCondition

/////////////////////////////
//======[ Stop Loss ]======//
/////////////////////////////

isSL = input(true, "Stop Loss")
sl = input(140, "Stop Loss (%). Divided by 100 (1 = 0.01%)") / 100
long_sl = isSL and close < averageLongs - averageLongs / 100 * sl and longCondition == 0
short_sl = isSL and close > averageShorts + averageShorts / 100 * sl and shortCondition == 0

/////////////////////////////////
//======[ Close Signals ]======//
/////////////////////////////////

longClose = long_tp or long_sl or long_ts ? 1 : 0
shortClose = short_tp or short_sl or short_ts ? 1: 0

///////////////////////////////
//======[ Plot Colors ]======//
///////////////////////////////

longCloseCol = na
shortCloseCol = na
longCloseCol := long_tp ? purple : long_sl ? maroon : long_ts ? blue : longCloseCol[1]
shortCloseCol := short_tp ? purple : short_sl ? maroon : short_ts ? blue : shortCloseCol[1]
tpColor = isTP and in_longCondition ? purple : isTP and in_shortCondition ? purple : white
slColor = isSL and in_longCondition ? red : isSL and in_shortCondition ? red : white

//////////////////////////////////
//======[ Strategy Plots ]======//
//////////////////////////////////

plot(isTS and in_longCondition ? averageLongs + averageLongs / 100 * tsi : na, "Long Trailing Activate", blue, style=3, linewidth=2)
plot(isTS and in_longCondition and last_high >= averageLongs +  averageLongs / 100 * tsi ? last_high - last_high / 100 * ts : na, "Long Trailing", fuchsia, style=2, linewidth=3)
plot(isTS and in_shortCondition ? averageShorts - averageShorts/ 100 * tsi : na, "Short Trailing Activate", blue, style=3, linewidth=2)
plot(isTS and in_shortCondition and last_low <= averageShorts - averageShorts/ 100 * tsi ? last_low + last_low / 100 * ts : na, "Short Trailing", fuchsia, style=2, linewidth=3)
plot(isTP and in_longCondition and last_high < averageLongs + averageLongs / 100 * tp ? averageLongs + averageLongs / 100 * tp : na, "Long TP", tpColor, style=3, linewidth=2)
plot(isTP and in_shortCondition and last_low > averageShorts - averageShorts / 100 * tp ? averageShorts - averageShorts / 100 * tp : na, "Short TP", tpColor, style=3, linewidth=2)
plot(isSL and in_longCondition and last_low_short > averageLongs - averageLongs / 100 * sl ? averageLongs - averageLongs / 100 * sl : na, "Long SL", slColor, style=3, linewidth=2)
plot(isSL and in_shortCondition and last_high_short < averageShorts + averageShorts / 100 * sl ? averageShorts + averageShorts / 100 * sl : na, "Short SL", slColor, style=3, linewidth=2)

///////////////////////////////
//======[ Alert Plots ]======//
///////////////////////////////

// plot(longCondition, "Long", green)
// plot(shortCondition, "Short", red)
// plot(longClose, "Long Close", longCloseCol)
// plot(shortClose, "Short Close", shortCloseCol)

///////////////////////////////////
//======[ Reset Variables ]======//
///////////////////////////////////

if longClose or not in_longCondition
    averageLongs := 0
    totalLongs := 0.0
    sectionLongs := 0
    sectionLongConditions := 0

if shortClose or not in_shortCondition
    averageShorts := 0
    totalShorts := 0.0
    sectionShorts := 0
    sectionShortConditions := 0

////////////////////////////////////////////
//======[ Strategy Entry and Exits ]======//
////////////////////////////////////////////

if testPeriod()
    strategy.entry("Long", 1, when=longCondition)
    strategy.entry("Short", 0,  when=shortCondition)
    strategy.close("Long", when=longClose)
    strategy.close("Short", when=shortClose)