RSI 평균 회귀 가격 변동성 전략


생성 날짜: 2023-09-26 19:55:03 마지막으로 수정됨: 2023-09-26 19:55:03
복사: 2 클릭수: 749
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 RSI 지표를 사용하여 과매매 기회를 식별하고, 가격이 하락할 때 순차적으로 진입하여, 계속 평균값으로 지분 비용을 줄임으로써 장기적으로 이익을 얻습니다. 동시에, 전략은 DCA 메커니즘을 추가하여 위험을 더 제어합니다.

전략 원칙

이 전략은 먼저 RSI 지표를 계산하여 시장이 과매매되었는지 판단합니다. RSI가 30보다 낮으면 과매매 기회가 나타납니다.

포지션 개설 후, 전략은 6 개의 평균값 반환 가격을 설정합니다. 현재 가격의 98%, 97%, 95%, 90%, 84% 및 70%입니다. 가격이 이러한 가격을 만질 때, 포지션을 계속 추가합니다. 이렇게 계속 평균값을 통해 포지션 보유 비용을 줄일 수 있습니다.

또한, 전략은 포지션의 평균 가격을 계산한다. 가격이 평균 가격의 5%를 넘어서면 정지 시작한다. 동시에, 가격이 계속 상승하여 평균 가격의 5%를 넘어서면 정지 가격을 모두 정지한다.

마지막으로, 이 전략은 DCA 메커니즘을 추가한다. 매주 월요일, 지분을 가지고 있고, 가격이 평균 가격보다 낮으면, 고정 금액의 지점을 추가한다. 이것은 지분 비용을 더욱 낮춘다.

우위 분석

이 전략의 가장 큰 장점은 평균값과 DCA 메커니즘을 활용하여 위험을 통제하는 것입니다. 구체적으로, 다음과 같은 점들을 포함합니다:

  1. 분할 입시 전략으로 포지션의 위험을 분산하여 최저 지점을 놓치지 않도록 한다.

  2. 여러 평균 회귀 가격을 설정하여 포지션 보유 비용을 지속적으로 낮추고 하락 위험을 효과적으로 제어 할 수 있습니다.

  3. 지분 평균 가격을 계산하고, 수익을 달성한 후 적시에 중단하고, 수익을 잠금합니다.

  4. DCA 메커니즘을 적용하여 포지션 비용을 더 낮추고 위험을 통제하십시오.

  5. RSI를 사용하여 시점을 판단하고, 상점 포지션을 피하십시오.

  6. 상평선 필터링을 사용하여 반전 개장을 피하십시오.

위험 분석

이 전략에는 다음과 같은 위험도 있습니다.

  1. 전략은 시장의 역점을 결정할 수 없으며, 장기간 낮은 시장에 직면하면 계속적으로 더 많이하는 것이 손실을 증가시킬 수 있습니다.

  2. 이 전략은 단독 손실을 효과적으로 통제할 수 없는 막상 손실 메커니즘을 고려하지 않았다.

  3. 이 전략은 포지션 개설 수에 제한을 두지 않고, 시장이 급격히 하락하면 포지션은 계속 증가할 것이다.

  4. DCA 메커니즘은 시간적 위험성을 지니고 있으며, 최저점에서 반드시 포지션을 개시할 것을 보장할 수 없다.

대응방법:

  1. 다른 지표와 결합하여 시장 구조를 판단하여 RSI에만 의존하는 것을 피할 수 있습니다.

  2. 이동 중지 또는 축소 중지.

  3. 포지션이 너무 커지는 것을 방지하기 위해 포지션 개설 수를 제한하십시오.

  4. DCA 개시 시기를 최적화하여 보다 안정적인 방식을 채택한다.

최적화 방향

이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.

  1. 평균 회귀 알고리즘을 최적화하여 가격 회귀 값을 더 과학적으로 계산합니다.

  2. 최적화된 스톱 방식, 이동 스톱 또는 계단 스톱을 사용할 수 있다.

  3. 단독 손실을 통제하기 위해 손실을 막는 전략을 늘려야 합니다.

  4. 다른 지표와 함께 시장 구조를 판단하여 RSI에만 의존하는 것을 피하십시오.

  5. DCA 개시 논리를 최적화하여 고정 시간 개시의 위험을 피하십시오.

  6. 포지션 관리 모듈을 추가하여 포지션 크기를 최적화하십시오.

  7. 최적화된 파라미터 설정으로 전략이 시장의 통계적 특성에 더 잘 적응하도록 한다.

  8. 스위치 로직에 가입하여, 다른 시장 환경에서 스위치 전략 방식을 다.

요약하다

이 전략은 전반적으로 RSI 판단 시점을 활용하여, 분량 입시를 하는 평균값의 긴 라인 투자 전략이다. 그것은 현재 높은 변동성 디지털 통화 시장에 매우 적합하며, 흔들림 영역을 보유 비용 관리에 효과적으로 활용할 수 있다. 또한, 전략 메커니즘은 최적화 할 수있는 곳이 있으며, 더 많은 기술 지표 판단과 위험 제어 모듈을 추가하면 전략 효과를 더 향상시킬 수 있으며, 더 복잡한 시장 환경에 대응 할 수 있습니다.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
// © A3Sh

// RSI Strategy that buys the dips, works with Price Averaging and has a Dollar Cost Average option.
// When the price drops below specified percentages of the price (6 PA layers), new entries are openend to average the price of the assets.
// Open entries are closed by a specified take profit.
// Entries can be reopened, after closing and consequently crossing a PA layer again.
// The idea is to lower the average position price to a point that when the market rises, the current price crosses over the average position price.
// When the current price crosses the average position size and reaches the specified take profit, all entries are closed at once.
// In case the market drops significantly, there is an option to activate DCA to lower the average price further.

// RSI code adapted from the Optimized RSI Buy the Dips strategy, by Coinrule
// https://www.tradingview.com/script/Pm1WAtyI-Optimized-RSI-Strategy-Buy-The-Dips-by-Coinrule/
// Pyramiding entries code adapted from Pyramiding Entries on Early Trends startegy, by Coinrule
// https://www.tradingview.com/script/7NNJ0sXB-Pyramiding-Entries-On-Early-Trends-by-Coinrule/
// Plot entry layers code adapted from HOWTO Plot Entry Price by vitvlkv
// https://www.tradingview.com/script/bHTnipgY-HOWTO-Plot-Entry-Price/
// Buy every week code based on the following question in Stack Overflow
// https://stackoverflow.com/questions/59870411/in-pine-script-how-can-you-do-something-once-per-day-or-keep-track-if-somethin


strategy(title = "RSI+PA+DCA", pyramiding = 16, overlay = true, initial_capital = 400, default_qty_type = strategy.percent_of_equity, default_qty_value = 15, commission_type = strategy.commission.percent, commission_value = 0.075)

port = input(15, title = "Portfolio %", type = input.float, step = 0.1, minval = 0.1, maxval = 100)
q = (strategy.equity / 100 * port) / open

// Long position entry layers. Percentage from the entry price of the the first long
PositionInputs = input("++++", title = "+++++ Long Positions VA Layers +++++")

ps2 = input(2,  title = "2nd Long Entry %", step = 0.1)
ps3 = input(3,  title = "3rd Long Entry %", step = 0.1)
ps4 = input(5,  title = "4th Long Entry %", step = 0.1)
ps5 = input(10, title = "5th Long Entry %", step = 0.1)
ps6 = input(16, title = "6th Long Entry %", step = 0.1)


// Calculate Moving Averages
maInput = input("++++", title = "+++++ Moving Average Filter +++++")

plotMA = input(title = "Plot Moving Average", defval = false)
movingaverage_signal = sma(close, input(100))
plot (plotMA ? movingaverage_signal : na, color = color.white)

// RSI inputs and calculations
rsiInput = input( "++++", title = "+++++ RSI Inputs +++++" )

length =     input( 14 )
overSold =   input( 30, title = "oversold, entry trigger long position" )
overBought = input( 70, title = "overbought, has no specific function")
price = close
vrsi = rsi(price, length)

// Long trigger (co)
co = crossover(vrsi, overSold) and close < movingaverage_signal

// Take profit
takeprofit = input("++++", title = "+++++ Take Profit +++++")

ProfitTarget_Percent = input(5)


// Store values to create and plot the different DCA layers
long1 = valuewhen(co, close, 0)
long2 = valuewhen(co, close - (close / 100 * ps2), 0)
long3 = valuewhen(co, close - (close / 100 * ps3), 0)
long4 = valuewhen(co, close - (close / 100 * ps4), 0)
long5 = valuewhen(co, close - (close / 100 * ps5), 0)
long6 = valuewhen(co, close - (close / 100 * ps6), 0)

eps1 = 0.00
eps1 := na(eps1[1]) ? na : eps1[1]

eps2 = 0.00
eps2 := na(eps2[1]) ? na : eps2[1]

eps3 = 0.00
eps3 := na(eps3[1]) ? na : eps3[1]

eps4 = 0.00
eps4 := na(eps4[1]) ? na : eps4[1]

eps5 = 0.00
eps5 := na(eps5[1]) ? na : eps5[1]

eps6 = 0.00
eps6 := na(eps6[1]) ? na : eps6[1]

plot (strategy.position_size > 0 ? eps1 : na, title = "Long entry 1", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps2 : na, title = "Long entry 2", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps3 : na, title = "Long entry 3", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps4 : na, title = "Long entry 4", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps5 : na, title = "Long entry 5", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps6 : na, title = "Long entry 6", style = plot.style_linebr)


// Plot position average price
plot (strategy.position_avg_price, title = "Average price", style = plot.style_linebr, color = color.red, linewidth = 2)


// Take profit and exit all on take profit above position average price
tpv = strategy.position_avg_price + (strategy.position_avg_price / 100 * ProfitTarget_Percent)

tpl1 = close < tpv ? eps1 + close * (ProfitTarget_Percent / 100) : tpv
tpl2 = close < tpv ? eps2 + close * (ProfitTarget_Percent / 100) : tpv
tpl3 = close < tpv ? eps3 + close * (ProfitTarget_Percent / 100) : tpv
tpl4 = close < tpv ? eps4 + close * (ProfitTarget_Percent / 100) : tpv
tpl5 = close < tpv ? eps5 + close * (ProfitTarget_Percent / 100) : tpv
tpl6 = close < tpv ? eps6 + close * (ProfitTarget_Percent / 100) : tpv


// Open DCA order once at the start of the week
dcaWeek = input("++++", title = "+++++ Open DCA order once every week +++++")

newWeek = change(time("W"))
dcatime = input(title = "Buy a fixed amount every Monday", defval = false)
fixedAmount = input(40, title = "Fixed amount currency for DCA orders", step = 0.1)
dcaq = fixedAmount / open
plotchar (dcatime ? newWeek : na, "buy at Week start", "▼", location.top, size = size.tiny, color = color.white)
bgcolor (dcatime and newWeek ? color.white : na, transp = 50)

// Submit entry orders
if (co and strategy.opentrades == 0)
    eps1 := long1
    eps2 := long2
    eps3 := long3
    eps4 := long4
    eps5 := long5
    eps6 := long6

    strategy.entry("Long1", strategy.long, q)

if (strategy.opentrades == 1)
    strategy.entry("Long2", strategy.long, q, limit = eps2)

    
if (strategy.opentrades == 2)
    strategy.entry("Long3", strategy.long, q, limit = eps3)


if (strategy.opentrades == 3)
    strategy.entry("Long4", strategy.long, q, limit = eps4)


if (strategy.opentrades == 4)
    strategy.entry("Long5", strategy.long, q, limit = eps5)

    
if (strategy.opentrades == 5) 
    strategy.entry("Long6", strategy.long, q, limit = eps6)
    
// Submit Weekly DCA order, only when price is below position average price and when a position is open
if (dcatime and newWeek and strategy.position_size > 0 and close < strategy.position_avg_price) 
    strategy.entry("DCA", strategy.long, dcaq)


// Exit orders
if (strategy.position_size > 0)
    strategy.exit(id = "Exit 1", from_entry = "Long1", limit = tpl1)
    strategy.exit(id = "Exit 2", from_entry = "Long2", limit = tpl2)
    strategy.exit(id = "Exit 3", from_entry = "Long3", limit = tpl3)
    strategy.exit(id = "Exit 4", from_entry = "Long4", limit = tpl4)
    strategy.exit(id = "Exit 5", from_entry = "Long5", limit = tpl5)
    strategy.exit(id = "Exit 6", from_entry = "Long6", limit = tpl6)
    strategy.exit(id = "Exit DCA", from_entry = "DCA", limit = tpv)
 

// Make sure that all open limit orders are canceled after exiting all the positions 
longClose = strategy.position_size[1] > 0 and strategy.position_size == 0 ? 1 : 0   
if longClose
    strategy.cancel_all()