RSI 이중 경로 오시슬레이션 라인 긴 및 짧은 양방향 거래 전략

저자:차오장, 날짜: 2023-10-25 11:57:46
태그:

img

전반적인 설명

RSI 듀얼 레일 오시레이션 라인 롱 앤 쇼트 쌍방향 거래 전략은 RSI 지표를 이용한 쌍방향 거래 전략이다. 이 전략은 듀얼 레일 설정과 이동 평균 거래 신호와 결합한 RSI의 과잉 구매 및 과잉 판매 원칙을 통해 효율적인 양방향 포지션 개점 및 폐쇄를 구현한다.

전략 논리

이 전략은 주로 RSI 지표의 과잉 구매 및 과잉 판매 원칙에 기초하여 거래 결정을 내립니다. 먼저 RSI 값 vrsi, 그리고 이중 레일의 상부 레일 sn 및 하부 레일 ln을 계산합니다. RSI 값이 하부 레일 ln 아래로 넘어가면 긴 신호가 생성되며, RSI 값이 상부 레일 sn 위에 넘어가면 짧은 신호가 생성됩니다.

이 전략은 또한 촛불의 상승과 하락을 감지하여 더 많은 긴 및 짧은 신호를 생성합니다. 구체적으로, 촛불이 상향으로 깨지면 긴 신호가 생성되며, 촛불이 하향으로 깨지면 짧은 신호가 생성됩니다. 또한, 전략은 파러미터 스위치를 제공하여 단지 길게, 단지 짧게 또는 역 신호를 만듭니다.

긴 신호와 짧은 신호를 생성한 후, 전략은 개점 수를 제어하기 위해 신호의 수를 계산합니다. 매개 변수를 통해 다른 피라미드 규칙을 설정할 수 있습니다. 포지션 폐쇄 조건에는 수익을 취하고, 손실을 중지하고, 손실을 중지하는 등이 포함되며, 사용자 정의 가능한 이익과 손실 비율이 있습니다.

요약하면 전략은 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)
    


더 많은