
이 전략은 RSI 불린 밴드 스톱 스톱 전략 (RSI Bollinger Bands TP/SL Strategy) 이라고 불린다. 이 전략은 RSI 지표와 불린 밴드 지표를 결합하여 트렌드 포지션과 브레이크 거래를 구현한다. RSI 지표가 오버 바이 오버 셀 신호를 나타내고 가격이 불린 밴드를 상회하거나 하락하면 추가 또는 공백 작업을 수행한다.
RSI 지표는 주가가 오버 바이 오버 소드 영역에 있는지 판단할 수 있다. RSI가 설정된 오버 바이 라인보다 크면 오버 바이, 설정된 오버 소드 영역보다 작으면 오버 소드이다. 이 전략은 오버 바이 라인을 50로 설정하고, 오버 소드 라인을 50로 설정한다.
브린 띠는 주가 가격의 표준 차이를 계산하여 주가 가격의 상하 궤도를 얻는다. 상하 궤도는 저항선이며, 하하 궤도는 지지선이다. 주가 가격이 상하 궤도를 통과할 때 구매점이며, 하하 궤도를 통과할 때 판매점이다.
RSI 지표가 하위 반전 신호를 나타낼 때, 동시 가격이 부린 대역 하향 궤도를 돌파 할 때, 아래에서 위쪽으로 반전한다고 생각하면, 더 많은 것을 할 수 있습니다. RSI 지표가 상위 반전 신호를 나타낼 때, 동시 주가가 부린 대역 상향 궤도를 돌파 할 때, 위에서 아래로 반전한다고 생각하면, 공백을 할 수 있습니다.
RSI 지표와 브린 밴드 지표는 트렌드와 역점을 판단하는 데 사용됩니다. 둘을 결합하여 사용하면 실제 구매 신호의 식별 정확도를 높여서 가짜 돌파구를 피할 수 있습니다.
이 전략은 스톱 스톱 손실 지점을 설정하고, 더 많은 스톱 스톱을 입시 가격으로 설정합니다.(1 + Stop Loss Ratio)(1-stop loss ratio) 이고, 포커스는 수익을 고정시키고, 손실을 최대한 방지하고, 위험을 통제할 수 있다.
전략 선택은 다만, 다만 또는 양방향 거래, 사용자는 시장 환경에 따라 다른 방향을 선택할 수 있으며, 위험을 유연하게 제어할 수 있다.
브린 밴드의 표준 차이는 브린 밴드의 폭에 영향을 미치며 거래 신호 발생에 영향을 미칩니다. 파라미터가 잘못 설정되면 많은 잘못된 신호가 발생할 수 있습니다.
만약 시장이 V형으로 역전되면, 스톱 스톱 손실 설정이 너무 급진적이어서 불필요한 손실을 초래할 수 있다.
RSI의 매개 변수는 RSI 곡선의 모양에도 영향을 미칩니다. RSI 매개 변수가 잘못 설정되면 RSI 역전 신호의 정확도가 떨어집니다.
더 많은 RSI 길이 변수를 테스트하여 최적의 변수 조합을 찾을 수 있습니다.
더 많은 브린 대역 길이와 표준 차차 변수를 테스트하여 최적의 변수 조합을 찾을 수 있다.
역측정으로 최적의 스톱 스톱 손실 비율 파라미터를 찾을 수 있다.
이 전략은 RSI 지표와 브린 밴드 지표를 종합적으로 사용하여 추세와 반향을 판단하고, 스톱 스톱 메커니즘 제어 위험을 추가하여 자동으로 매도 시점을 식별하고 제 시간에 스톱 스톱을 중지 할 수 있습니다. 이 전략에는 또한 특정 위험이 있으며, 주로 변수 최적화와 같은 방법으로 개선 할 수 있습니다.
/*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")