RSI 볼링거 밴드 TP/SL 전략

저자:차오장, 날짜: 2023-12-21 11:17:19
태그:

img

I. 전략 개요

이 전략은 RSI 볼링거 밴드 TP/SL 전략 (RSI Bollinger Bands TP/SL Strategy) 이라고 불린다. 이는 RSI 지표와 볼링거 밴드를 결합하여 트렌드와 거래 신호를 식별한다. RSI 지표가 과잉 구매 또는 과잉 판매 신호를 표시하고 가격이 볼링거 밴드를 만지고 또는 뚫을 때, 긴 또는 짧은 포지션이 열릴 것이다. 또한, 리스크를 제어하기 위해 수익을 취하고 스톱 로스 포인트도 설정된다.

II. 전략 논리

1. 반전 에 대한 RSI 지표

RSI 지표는 주가가 과잉 구매되거나 과잉 판매되는지를 판단합니다. 과잉 구매 라인의 위의 RSI 판독은 과잉 구매 조건을 나타냅니다. 과잉 판매 라인의 아래 판독은 과잉 판매 조건을 나타냅니다. 이 전략에서 과잉 구매 라인은 50로 설정되며 과잉 판매 라인은 50로 설정됩니다.

2. 트렌드를 위한 볼링거 밴드

볼링거 밴드는 간단한 이동 평균의 위와 아래의 표준 편차선을 그래프화한다. 상단역은 저항으로 작용하고 하단역은 지원으로 작용한다. 하단역의 상단역은 구매 신호이고 상단역의 하단역은 판매 신호이다.

3. RSI 와 볼링거 밴드의 조합

RSI 지표가 하위 반전 신호를 표시하고 가격이 볼링거 밴드의 하위 대역을 통과하면 상승 반전으로 간주되며, 따라서 길게됩니다. RSI 지표가 상위 반전 신호를 표시하고 가격이 상위 대역을 깨면 하향 반전으로 간주되며, 따라서 짧게됩니다.

III. 장점

1. 이중 지표 를 사용 하여 정확성 을 향상 시킨다

RSI와 볼링거 밴드는 트렌드 및 역전을 결정하는 데 사용됩니다. 이 조합은 신호 인식 정확성을 향상시키고 잘못된 브레이크오프를 피합니다.

2. TP/SL 를 이용한 위험 관리

전략 세트는 수익을 취하고 손실 감소를 극대화하기 위해 이익 (TP) 및 손실 중지 (SL) 포인트를 설정합니다.

3. 사용자 지정 할 수 있는 방향

사용자들은 시장 조건에 따라 단, 긴 또는 두 방향으로만 갈 수 있고, 유연한 위험 통제를 가능하게 합니다.

IV. 위험

1. 민감한 볼링거 밴드 매개 변수

표준편차 크기는 대역 너비와 거래 신호에 영향을 미칩니다. 부적절한 설정은 과도한 잘못된 신호를 생성 할 수 있습니다.

2. TP/SL 의 위험

V 모양의 반전은 TP/SL 설정이 너무 공격적이어서 불필요한 손실을 유발할 수 있습니다.

3. 민감 한 RSI 매개 변수

잘못된 RSI 매개 변수 설정은 반전 신호의 정확도를 감소시킵니다.

V. 최적화 방향

1. RSI 매개 변수를 최적화

최적의 매개 변수 조합을 찾기 위해 더 많은 RSI 길이 값을 테스트 할 수 있습니다.

2. 볼링거 밴드 매개 변수를 최적화

최적의 매개 변수 조합을 찾기 위해 더 많은 길이와 표준 편차를 테스트 할 수 있습니다.

3. 다른 TP/SL 비율을 테스트

백테스팅은 최적의 TP/SL 비율을 찾는 데 도움이 될 수 있습니다.

VI 결론

이 전략은 트렌드 및 반전을 식별하기 위해 RSI와 볼링거 밴드를 활용하고 위험을 제어하기 위해 TP/SL를 설정합니다. 자동으로 거래 신호를 감지하고 출구를 관리 할 수 있습니다. 매개 변수 최적화로 개선 할 수있는 위험이 여전히 있습니다. 일반적으로 이것은 강력한 응용력을 가진 실용적인 전략입니다.


/*backtest
start: 2023-11-20 00:00:00
end: 2023-12-20 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/
// © BigCoinHunter

//@version=5
strategy(title="RSI_Boll-TP/SL", overlay=true, 
     pyramiding=0, default_qty_type=strategy.percent_of_equity, 
     default_qty_value=100, initial_capital=1000, 
     currency=currency.USD, commission_value=0.05, 
     commission_type=strategy.commission.percent, 
     process_orders_on_close=true)

//----------- get the user inputs --------------

//---------- RSI -------------
price = input(close, title="Source")

RSIlength = input.int(defval=6,title="RSI Length") 
RSIoverSold = input.int(defval=50, title="RSI OverSold", minval=1)
RSIoverBought = input.int(defval=50, title="RSI OverBought", minval=1)

//------- Bollinger Bands -----------
BBlength = input.int(defval=200, title="Bollinger Period Length", minval=1)
BBmult = input.float(defval=2.0, minval=0.001, maxval=50, step=0.1, title="Bollinger Bands Standard Deviation")
BBbasis = ta.sma(price, BBlength)
BBdev = BBmult * ta.stdev(price, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
source = close
buyEntry = ta.crossover(source, BBlower)
sellEntry = ta.crossunder(source, BBupper)
plot(BBbasis, color=color.aqua, title="Bollinger Bands SMA Basis Line")
p1 = plot(BBupper, color=color.silver, title="Bollinger Bands Upper Line")
p2 = plot(BBlower, color=color.silver, title="Bollinger Bands Lower Line")
fill(plot1=p1, plot2=p2, title="Bollinger BackGround", color=color.new(color.aqua,90), fillgaps=false, editable=true)

//---------- input TP/SL ---------------
tp = input.float(title="Take Profit:", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01
sl = input.float(title="Stop Loss:  ", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01

longEntry = input.bool(defval=true, title= 'Long Entry', inline="11")
shortEntry = input.bool(defval=true, title='Short Entry', inline="11")

//---------- backtest range setup ------------
fromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear  = input.int(defval = 2021, title = "From Year", minval = 2010)
toDay     = input.int(defval = 30, title = "To Day", minval = 1, maxval = 31)
toMonth   = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear    = input.int(defval = 2042, title = "To Year", minval = 2010)

//------------ time interval setup -----------
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)  // backtest start window
finish    = timestamp(toYear, toMonth, toDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false // create function "within window of time"

//------- define the global variables ------
var bool long = true
var bool stoppedOutLong = false
var bool stoppedOutShort = false
//--------- Colors ---------------

TrendColor = RSIoverBought and (price[1] > BBupper and price < BBupper) and BBbasis < BBbasis[1] ? color.red : RSIoverSold and (price[1] < BBlower and price > BBlower) and BBbasis > BBbasis[1] ? color.green : na
//bgcolor(switch2?(color.new(TrendColor,50)):na)


//--------- calculate the input/output points -----------
longProfitPrice  = strategy.position_avg_price * (1 + tp)     // tp -> take profit percentage
longStopPrice = strategy.position_avg_price * (1 - sl)        // sl -> stop loss percentage

shortProfitPrice  = strategy.position_avg_price * (1 - tp)
shortStopPrice = strategy.position_avg_price * (1 + sl)


//---------- RSI + Bollinger Bands Strategy -------------
vrsi = ta.rsi(price, RSIlength)

rsiCrossOver = ta.crossover(vrsi, RSIoverSold)
rsiCrossUnder = ta.crossunder(vrsi, RSIoverBought)

BBCrossOver = ta.crossover(source, BBlower)
BBCrossUnder = ta.crossunder(source, BBupper)

if (not na(vrsi))

    if rsiCrossOver and BBCrossOver
        long := true
        
    if rsiCrossUnder and BBCrossUnder
        long := false

//------------------- determine buy and sell points ---------------------
buySignall = window() and long  and (not stoppedOutLong)
sellSignall = window() and (not long)  and (not stoppedOutShort)

//---------- execute the strategy -----------------
if(longEntry and shortEntry)
    if long 
        strategy.entry("LONG", strategy.long, when = buySignall, comment = "ENTER LONG")
        stoppedOutLong := true
        stoppedOutShort := false
    else 
        strategy.entry("SHORT", strategy.short, when = sellSignall, comment = "ENTER SHORT")
        stoppedOutLong  := false
        stoppedOutShort := true

else if(longEntry)
    strategy.entry("LONG", strategy.long,  when = buySignall)
    strategy.close("LONG", when = sellSignall)
    if long 
        stoppedOutLong := true
    else
        stoppedOutLong  := false

else if(shortEntry)
    strategy.entry("SHORT", strategy.short, when = sellSignall)
    strategy.close("SHORT", when = buySignall)
    if not long
        stoppedOutShort := true
    else
        stoppedOutShort := false
    

//----------------- take profit and stop loss -----------------
if(tp>0.0 and sl>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG", limit=longProfitPrice, stop=longStopPrice, comment="Long TP/SL Trigger")

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT", limit=shortProfitPrice, stop=shortStopPrice, comment="Short TP/SL Trigger")

else if(tp>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG", limit=longProfitPrice, comment="Long TP Trigger")

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT", limit=shortProfitPrice, comment="Short TP Trigger")
        
else if(sl>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG",  stop=longStopPrice, comment="Long SL Trigger")

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT",  stop=shortStopPrice, comment="Short SL Trigger")



















더 많은