볼링거 밴드 표준 오차 파업 전략

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

img

전반적인 설명

이 전략은 고전적인 볼링거 밴드 지표에 기반합니다. 가격이 상단보다 높을 때 길게 가고, 가격이 하단보다 낮을 때 짧게됩니다. 브레이크아웃 전략을 따르는 트렌드에 속합니다.

전략 논리

  1. 기준은 55일 간 간편 이동평균입니다.
  2. 상단 및 하단 대역은 기준값보다 한 표준편차 이상, 기준값보다 한 표준편차 이하입니다.
  3. 가격이 상단 범위를 넘어서면 긴 신호가 생성됩니다.
  4. 코스가 하위 범위를 넘어서면 단축 신호가 생성됩니다.
  5. 고전적인 두 개의 표준편차 대신 하나의 표준편차를 사용하는 것은 위험을 줄입니다.

이점 분석

  1. 고정값 대신 표준편차를 사용하는 것은 위험을 줄여줍니다.
  2. 55일 이동 평균은 중장기 트렌드를 더 잘 반영할 수 있습니다.
  3. 가까운 탈출은 거짓 탈출을 필터링합니다.
  4. 다중 타임프레임 분석을 통해 트렌드 방향을 결정하는 것이 쉽습니다.

위험 분석

  1. 작은 수익을 얻는 경향이 있습니다.
  2. 거래 수수료의 영향을 고려해야 합니다.
  3. 탈출 신호는 가짜 탈출일 수도 있습니다.
  4. 미끄러지는 손실이 발생할 수 있습니다.

스톱 로스를 설정하거나 거래 수수료를 고려하거나 지표 필터를 추가함으로써 위험을 완화할 수 있습니다.

최적화 방향

  1. 가장 좋은 이동평균을 찾기 위해 기본 매개 변수를 최적화합니다.
  2. 최적의 매개 변수를 찾기 위해 표준편차 크기를 최적화합니다.
  3. 판단을 위해 보조 부피 표시기를 추가합니다.
  4. 스톱 손실 메커니즘을 추가합니다.

요약

이 전략의 전반적인 논리는 분명합니다. 표준 오차 대역 너비를 통해 위험을 조정하고 가까운 브레이크로 거짓 브레이크를 피합니다. 그러나 여전히 스톱 로스, 필터 등을 추가하여 오스실레이션 손실을 방지해야합니다.


/*backtest
start: 2023-11-13 00:00:00
end: 2023-11-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

//┌───── •••• ─────┐//
//   TradeChartist  //
//└───── •••• ─────┘//

//Bollinger Bands is a classic indicator that uses a simple moving average of 20 periods along with upper and lower bands that are 2 standard deviations away from the basis line. 
//These bands help visualize price volatility and trend based on where the price is in relation to the bands.

//This Bollinger Bands filter plots a long signal when price closes above the upper band and plots a short signal when price closes below the lower band. 
//It doesn't take into account any other parameters such as Volume/RSI/fundamentals etc, so user must use discretion based on confirmations from another indicator or based on fundamentals.

//This filter's default is 55 SMA and 1 standard deviation, but can be changed based on asset type

//It is definitely worth reading the 22 rules of Bollinger Bands written by John Bollinger. 


strategy(shorttitle="BB Breakout Strategy", title="Bollinger Bands Filter", overlay=true, 
             pyramiding=1, currency=currency.NONE , 
             initial_capital = 10000, default_qty_type = strategy.percent_of_equity, 
             default_qty_value=100, calc_on_every_tick= true, process_orders_on_close=false)

src         = input(close, title = "Source")
length      = input(55, minval=1, title = "SMA length")// 20 for classis Bollinger Bands SMA line (basis)


mult        = input(1., minval=0.236, maxval=2, title="Standard Deviation")//2 for Classic Bollinger Bands //Maxval = 2 as higher the deviation, higher the risk
basis       = sma(src, length)
dev         = mult * stdev(src,length)

CC          = input(true, "Color Bars")


upper       = basis + dev
lower       = basis - dev

//Conditions for Long and Short - Extra filter condition can be used such as RSI or CCI etc.

short       = src<lower// and rsi(close,14)<40
long        = src>upper// and rsi(close,14)>60

L1          = barssince(long)
S1          = barssince(short)

longSignal  = L1<S1 and not (L1<S1)[1]
shortSignal = S1<L1 and not (S1<L1)[1]

//Plots and Fills



////Long/Short shapes with text
// plotshape(S1<L1 and not (S1<L1)[1]?close:na, text = "sᴇʟʟ", textcolor=#ff0100, color=#ff0100, style=shape.triangledown, size=size.small, location=location.abovebar, transp=0, title = "SELL", editable = true)
// plotshape(L1<S1 and not (L1<S1)[1]?close:na, text = "ʙᴜʏ", textcolor = #008000, color=#008000, style=shape.triangleup, size=size.small, location=location.belowbar, transp=0, title = "BUY", editable = true)  


// plotshape(shortSignal?close:na, color=#ff0100, style=shape.triangledown, size=size.small, location=location.abovebar, transp=0, title = "Short Signal", editable = true)
// plotshape(longSignal?close:na, color=#008000, style=shape.triangleup, size=size.small, location=location.belowbar, transp=0, title = "Long Signal", editable = true)  



p1          = plot(upper, color=#ff0000, display=display.all, transp=75, title = "Upper Band")
p2          = plot(lower, color=#008000, display=display.all, transp=75, title = "Lower Band")


p           = plot(basis, color=L1<S1?#008000:S1<L1?#ff0000:na, linewidth=2, editable=false, title="Basis")


fill(p,p1, color=color.teal, transp=85, title = "Top Fill") //fill for basis-upper
fill(p,p2, color=color.orange, transp=85, title = "Bottom Fill")//fill for basis-lower


//Barcolor

bcol        = src>upper?color.new(#8ceb07,0): 
             src<lower?color.new(#ff0000,0):
             src>basis?color.green:
             src<basis?color.red:na


barcolor(CC?bcol:na, editable=false, title = "Color Bars")



// //Alerts ----  // Use 'Once per bar close'

// alertcondition(condition=longSignal, title="Long - BB Filter", message='BB Filter Long @ {{close}}') // Use 'Once per bar close'
// alertcondition(condition=shortSignal, title="Short - BB Filter", message='BB Filter Short @ {{close}}')  // Use 'Once per bar close'

Notestart1 = input(true, "╔═══ Time Range to BackTest ═══╗") 


// === INPUT BACKTEST RANGE ===
FromMonth = input(defval=1, title="From Month", minval=1, maxval=12)
FromDay = input(defval=1, title="From Day", minval=1, maxval=31)
FromYear = input(defval=2018, title="From Year", minval=2015)
ToMonth = input(defval=1, title="To Month", minval=1, maxval=12)
ToDay = input(defval=1, title="To Day", minval=1, maxval=31)
ToYear = input(defval=9999, title="To Year", minval=2010)

// === FUNCTION EXAMPLE === 
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)  // backtest finish window
window() =>  // create function "within window of time"
    time >= start and time <= finish ? true : false 

if(window())
    strategy.entry("Long", long=true, when =  longSignal)
    // strategy.close("Long", when = (short and S3==0), comment = "Close Long")

if(window())
    strategy.entry("Short", long=false, when = shortSignal)
    // strategy.close("Short", when = (long and L3==0), comment = "Close Short")



더 많은