RSI 평균 회전 가격 변동 전략

저자:차오장, 날짜: 2023-09-26 19:55:03
태그:

전반적인 설명

이 전략은 RSI 지표를 사용하여 과잉 판매 기회를 식별하고 가격이 떨어지면 점수를 대량으로 취하여 점차 비용 기반을 낮추고 장기 수익을 달성합니다. 또한 위험을 관리하기위한 DCA 메커니즘을 통합합니다.

전략 논리

이 전략은 먼저 시장이 과판되었는지 여부를 결정하기 위해 RSI 지표를 계산합니다. RSI가 30 이하이면 과판 된 기회를 신호합니다. 이 경우 가격이 100 기간 이동 평균 이하라면 긴 포지션이 열립니다.

포지션 개척 후, 전략은 현재 가격의 98%, 97%, 95%, 90%, 84% 및 70%의 6 개의 평균 회전 가격 수준을 설정합니다. 가격이 이러한 수준을 달성하면 더 많은 포지션이 추가됩니다. 지속적으로 평균화하여 포지션의 비용 기반을 낮출 수 있습니다.

또한, 포지션의 평균 가격은 계산됩니다. 가격은 평균 가격보다 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. 더 나은 단일 거래 위험 통제를 위해 Stop Loss를 추가하십시오.

  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()





더 많은