Bollinger Bands와 RSI 지표를 기반으로 한 점진적 DCA 전략


생성 날짜: 2024-01-18 11:23:15 마지막으로 수정됨: 2024-01-18 11:23:15
복사: 2 클릭수: 941
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

Bollinger Bands와 RSI 지표를 기반으로 한 점진적 DCA 전략

개요

이 전략의 이름은 双指标渐进 DCA策略. 그것은 부린 통로와 상대 강도 지수 ((RSI)) 이 두 지표에 기반하여 거래 신호를 구축하고, 점진적 인 포지션 방법을 사용하여 위험 관리를 수행한다. 그것의 주요 아이디어는 황소 시장에서 트렌드를 포착하여 지표를 사용하여 다중 신호를 구축하는 것이다.

전략 원칙

이 전략은 부린 채널과 RSI 두 지표를 결합한다. 부린 채널은 시장의 흐름을 명확하게 판단하고, 부린 중간 궤도 상단에는 황소 시장, 하단에는 곰 시장이 있다. RSI 지표는 과매매 과매 현상을 판단한다. 전략은 MIX 지표를 구성하며, 부린 채널 가격 차와 RSI의 K값을 중화 평균으로 한다.

점진적 DCA 부분, 먼저 MIX 지표가 20을 돌파했을 때 첫 번째 주문을 열어요. 그 후 가격이 일정하게 떨어질 때마다 일정 금액으로 입장을 추가하십시오. 최대 입장량을 달성하거나 스톱 손실 철수 할 때까지하십시오. 이렇게하면 시장의 낮은 지점에서 여러 번 입장을 추가하여 비용 평균 가격의 하락을 달성 할 수 있습니다.

전략적 이점

  1. 두 개의 지표는 명확한 판단 경향과 결합하여 신호의 정확성을 증가시킵니다.

  2. 점진적 DCA 전략은 하향상태에서 포지션 비용을 낮추고 손실 위험을 줄일 수 있다. 동시에 수익 공간을 늘릴 수 있다.

  3. 스톱 로즈와 스톱 조건을 설정하여 적당히 스톱 로즈를 제어하고, 수익의 일부를 보장할 수 있다.

  4. 포지션 개시 날짜 범위를 추가하여 특정 시기를 대상으로 테스트 및 최적화를 할 수 있습니다.

위험과 해결책

  1. 부린 채널과 RSI 지표가 모두 실패할 수 있는 상황이다. 다양한 파라미터 조합을 테스트하여 최적의 위치를 찾을 수 있다.

  2. 점진적 DCA는 큰 하락 상황에서 지속적으로 추가 포지션으로 손실이 커질 수 있다. 최대 포지션 수를 설정할 수 있으며, 스톱 라인을 적절히 높여 리스크 제어를 개선할 수 있다.

  3. 갑작스러운 사건을 방지할 수 없는 비정상적인 행동. 대장 지표에 시스템적 위험을 판단할 수 있으며, 비정상적인 기간을 회피한다.

전략 최적화 방향

  1. 더 정확한 거래 신호를 얻기 위해 MIX 지표의 매개 변수를 최적화하는 테스트.

  2. 스톱 손실 스톱 패러미터를 최적화하여 수익 손실 비율을 극대화하십시오.

  3. 다른 추가 포지션의 크기와 수를 테스트하여 최적의 조합을 찾습니다.

  4. 거래량 제어 모듈을 추가하여 특정 거래량 조건에 따라 전략을 열거나 닫을 수 있습니다.

요약하다

双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化技术指标和方法. 双指标渐进DCA策略综合运用多项量化策

전략 소스 코드
/*backtest
start: 2023-01-11 00:00:00
end: 2024-01-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// © lagobrian23
//@version=4
strategy(title = 'Bollinger Bands and RSI mix with DCA', shorttitle = 'BB/RSI with DCA',pyramiding = 20, calc_on_every_tick = true, overlay = false )
source=close
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)

// Bollinger Band

length = input(20,title = 'BB lookback length', minval=1)
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
BBval = (src - basis)/dev*30+50
offset = input(0, title = "Offset", type = input.integer, minval = -500, maxval = 500)
mix=(d + BBval)/2

//plot
//plot(k, "K", color=#606060)
plot(BBval, "BBval", color=#872323, offset = offset)
plot(d, "D", color=#FF6A00)
h0 = hline(80, "Upper Band", color=#606060)
h1 = hline(20, "Lower Band", color=#606060)
plot(mix, "MIX", color=#888888, linewidth=3)

//background MIX
bgcolor(mix < 20 ? color.green : color.white, transp=50)
bgcolor(mix > 80 ? color.red : color.white, transp=50)

// Choosing the date range
fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear  = input(defval = 2020, title = "From Year",       type = input.integer, minval = 1970)
toMonth = input(defval = 1,    title = "To Month",      type = input.integer, minval = 1, maxval = 12)
toDay   = input(defval = 1,    title = "To Day",        type = input.integer, minval = 1, maxval = 31)
toYear  = input(defval = 2112, title = "To Year",       type = input.integer, minval = 1970)

start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(toYear, toMonth, toDay, 23, 59)        // backtest finish window
window()  => true

// Initializing the strategy paraeters

P = input(defval = 1, title = 'Amount (P)' , type = input.integer, minval = 1, maxval = 100)
X = input(defval = 2, title = '% Price drop for consecutive entries(X)', type = input.float, minval = 1, maxval = 100)
B_tp = input(defval = 10, title = '% Level for Take Profit (B)', type = input.float , minval = 1, maxval = 100)
D_sl = input(defval = 10, title = '% Level for Stop Loss (D)', type = input.float, minval = 1, maxval = 100)
A = input(defval = 5, title = 'Max consecutive entries (A)', type = input.integer, minval = 2, maxval = 20)
Z = input(defval = 0.5, title = 'Z', type = input.float , minval = 0, maxval = 10)

// Declaring key DCA variables
entry_price = 0.0
entry_price := na(entry_price[1]) ? na : entry_price[1]
new_entry = 0.0
consec_entryCondition = false
// Implementing the strategy
longEntry = crossover(mix,20)
exitLongs = crossunder(mix, 80)

if(longEntry)
    entry_price := close
    strategy.entry('main_LE', strategy.long , P, when = window() and longEntry)

// Exiting conditions
stoploss = strategy.position_avg_price*(1-(D_sl/100))
takeprofit = strategy.position_avg_price*(1+(B_tp/100))
slCondition = crossunder(close, stoploss)
tpCondition = crossover(close, takeprofit)

// We want to exit if the 'mix' indicator crosses 80, take profit is attained or stop loss is tagged.
exitConditions = exitLongs or slCondition or tpCondition

// Consecutive entries upto A times
// strategy.risk.max_intraday_filled_orders(A)

//Dollar-Cost-Averaging
// Enter long whenever price goes down X%: amount set to (P+Y)*Z
newAmount = (P+X)*Z
// If we haven't reached max open trades, buy newAmount immediately price crosses under X% lower the previous entry price
new_entry := entry_price - ((X/100)*entry_price)
consec_entryCondition := crossunder(close, new_entry)
if(consec_entryCondition and strategy.opentrades != A)
    strategy.entry('consec_LE', strategy.long, newAmount, oca_name = 'consecLongs', when = window() and consec_entryCondition)
    entry_price := close
    
// Exiting
// The main trade is closed only when the  main exit conditions are satisfied
strategy.close('main_LE', comment = 'Main Long Closed', when = window() and exitConditions)

// A consective long is closed only when tp or sl is tagged
strategy.exit('ext a consec', 'consec_LE', loss = D_sl*strategy.position_avg_price , profit = B_tp*strategy.position_avg_price, oca_name =  'consecLongs')