범위 필터 브레이크오웃 단기 거래 전략

저자:차오장, 날짜: 2023-09-21 21:17:40
태그:

전반적인 설명

이 단기 거래 전략은 가격 변동 범위를 기반으로 구매 및 판매 신호를 생성합니다. 기간 동안 가격 이동 범위를 계산하고 거래 신호를 필터로 사용합니다. 가격이 범위를 넘어서면 신호가 발생합니다.

전략 논리

핵심 지표는 가격 변동 범위입니다. 구체적인 단계는 다음과 같습니다.

  1. 지난 N 기간 동안의 높은-저한 범위는 가격 진폭으로 계산합니다

  2. 범위 필터를 도출하기 위해 이동 평균을 사용하여 진폭을 부드럽게

  3. 구매 신호는 가격이 범위 필터 이상으로 상승하면 생성됩니다.

  4. 판매 신호는 가격이 범위 필터 이하로 떨어지면 생성됩니다.

이 방법으로 가격 범위의 파업은 트렌드 방향을 결정하고 더 깨끗한 신호를 위해 소음을 필터링하는 데 사용됩니다.

장점

  • 가격 범위를 쉽게 판단 할 수 있습니다.
  • 평평 한 범위 는 소음을 효과적으로 필터 합니다
  • 브레이크오웃 신호는 단기 트렌드를 감지합니다.
  • 단기 거래에 적합한 더 높은 거래 빈도
  • 조정 가능한 매개 변수 최적화 쉬운

위험성

  • 범위를 벗어나는 경우
  • 범위를 계산하기 위해 충분한 역사 데이터가 필요합니다.
  • 나쁜 매개 변수는 과민성 또는 느림성을 유발합니다.
  • 실질적인 중단이 없고, 큰 마이너오웃
  • 높은 주파수로 인한 수수료의 영향으로 성능

위험은 다음과 같이 완화 될 수 있습니다.

  • 릴래싱 범위 필터 변동성 계수
  • 이상적인 설정에 대한 매개 변수 최적화
  • 스톱 로스 또는 트레일링 스톱을 실행
  • 더 낮은 수수료로 거래 빈도를 줄이는 것
  • 제품별 매개 변수 테스트

개선 방향

이 전략은 다음과 같이 개선될 수 있습니다.

  1. 다른 범위 계산 기간의 테스트

  2. 범위 필터 변동성 계수를 최적화

  3. MACD와 같은 확인 지표를 추가합니다.

  4. 이동 또는 후속 정지 사용

  5. 각 제품에 대한 특정 조정 매개 변수

  6. 위치 크기 시스템을 최적화

요약

이 전략은 단기 신호를 생성하기 위해 가격 범위를 깨고 일시적인 트렌드를 효과적으로 포착합니다. 그러나 윙사와 같은 위험이 있습니다. 효율성을 유지하면서 위험을 제어하기 위해 매개 변수 최적화, 손실 중지, 필터 등을 추가하여 개선이 가능합니다. 제품 특성에 따라 매개 변수를 세밀하게 조정하는 것도 중요합니다. 지속적인 최적화는 탄력성을 가져옵니다.


/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy(title="Range Filter Buy and Sell 5min [Strategy]", overlay=true, commission_type=strategy.commission.percent, commission_value=0.025, default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000, slippage=0)

// === INPUT BACKTEST RANGE ===
useDate = input(true,     title='---------------- Use Date ----------------', type=bool)
FromMonth = input(defval = 7, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 25, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2019, title = "From Year", minval = 2017)
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 = 2017)
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => true  // create function "within window of time"
// === INPUT BACKTEST RANGE ===


sources = input(defval=close, title="Source")
isHA = input(false, "Use HA Candles", bool)
src = isHA ? security(heikenashi(tickerid), period, sources) : sources
// Sampling Period
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters

per = input(defval=50, minval=1, title="Sampling Period")

// Range Multiplier

mult = input(defval=3.0, minval=0.1, title="Range Multiplier")

// Smooth Average Range

smoothrng(x, t, m)=>
    wper      = (t*2) - 1
    avrng     = ema(abs(x - x[1]), t)
    smoothrng = ema(avrng, wper)*m
    smoothrng
smrng = smoothrng(src, per, mult)

// Range Filter

rngfilt(x, r)=>
    rngfilt  = x
    rngfilt := x > nz(rngfilt[1]) ? ((x - r) < nz(rngfilt[1]) ? nz(rngfilt[1]) : (x - r)) : ((x + r) > nz(rngfilt[1]) ? nz(rngfilt[1]) : (x + r))
    rngfilt
filt = rngfilt(src, smrng)

// Filter Direction

upward   = 0.0
upward  := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])

// Target Bands

hband = filt + smrng
lband = filt - smrng

// Colors

filtcolor = upward > 0 ? lime : downward > 0 ? red : orange
barcolor  = (src > filt) and (src > src[1]) and (upward > 0) ? lime : (src > filt) and (src < src[1]) and (upward > 0) ? green : 
   (src < filt) and (src < src[1]) and (downward > 0) ? red : (src < filt) and (src > src[1]) and (downward > 0) ? maroon : orange

filtplot = plot(filt, color=filtcolor, linewidth=3, title="Range Filter")

// Target

hbandplot = plot(hband, color=aqua, transp=100, title="High Target")
lbandplot = plot(lband, color=fuchsia, transp=100, title="Low Target")

// Fills

fill(hbandplot, filtplot, color=aqua, title="High Target Range")
fill(lbandplot, filtplot, color=fuchsia, title="Low Target Range")

// Bar Color

//barcolor(barcolor)

// Break Outs 

longCond = na
shortCond = na
longCond := ((src > filt) and (src > src[1]) and (upward > 0)) or ((src > filt) and (src < src[1]) and (upward > 0)) 
shortCond := ((src < filt) and (src < src[1]) and (downward > 0)) or ((src < filt) and (src > src[1]) and (downward > 0))

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

//Alerts

plotshape(longCondition, title = "Buy Signal", text ="BUY", textcolor = white, style=shape.labelup, size = size.normal, location=location.belowbar, color = green, transp = 0)
plotshape(shortCondition, title = "Sell Signal", text ="SELL", textcolor = white, style=shape.labeldown, size = size.normal, location=location.abovebar, color = red, transp = 0)

//strategy.entry("Long", strategy.long, stop = hband, when = window() , comment="Long")
//strategy.entry("Short", strategy.short, stop = lband, when = window() , comment="Short")

strategy.entry("Long", strategy.long, when = longCondition and window() , comment="Long")
strategy.entry("Short", strategy.short, when = shortCondition and window() , comment="Short")



// === Stop LOSS ===
useStopLoss = input(false, title='----- Use Stop Loss / Take profit -----', type=bool)
sl_inp = input(100, title='Stop Loss %', type=float, step=0.25)/100
tp_inp = input(1.5, title='Take Profit %', type=float, step=0.25)/100
stop_level = strategy.position_avg_price * (1 - sl_inp)
take_level = strategy.position_avg_price * (1 + tp_inp)
stop_level_short = strategy.position_avg_price * (1 + sl_inp)
take_level_short = strategy.position_avg_price * (1 - tp_inp)
// === Stop LOSS ===

if useStopLoss
    strategy.exit("Stop Loss/Profit Long","Long", stop=stop_level, limit=take_level)
    strategy.exit("Stop Loss/Profit Short","Short", stop=stop_level_short, limit=take_level_short)


더 많은