SR 브레이크아웃 전략


생성 날짜: 2024-05-15 16:30:14 마지막으로 수정됨: 2024-05-15 16:30:14
복사: 1 클릭수: 568
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

SR 브레이크아웃 전략

개요

SR Breakout Strategy는 LonesomeTheBlue의 breakout finder 지표에 기반하여 개발된 지지부진을 돌파하는 전략이다. 이 전략의 주요 아이디어는 종결 가격이 지지부진이나 저항부위를 돌파했는지 판단함으로써 더 많은 또는 빈 신호를 생성하는 것이다. 기본 설정은 8시간 K선에 기반하지만 4시간 K선에는 더 나은 파라미터 설정이 있다. 이 전략은 지지부진과 저항부위를 결정하기 위해 pivothigh와 pivotlow 함수를 사용하며 최고 가격과 최저 가격을 사용하여 돌파를 판단한다.

전략 원칙

  1. pivothigh 및 pivotlow 함수를 사용하여 각각 과거 일정 주기 동안의 최고점과 최저점을 계산하고, 배열에 저장한다.
  2. 현재 종식 가격이 저항 수준보다 높지 않은지 판단하고, 만약 그렇다면, 포지셔널 브레이크로 판단하여, 더 많은 신호를 생성한다.
  3. 현재 종식 가격이 지지율보다 낮았는지 판단하고, 만약 그렇다면, 하향 돌파구로 판단하여 하향 신호를 생성한다.
  4. 거래 신호가 생성된 후, 설정된 스톱 스 비율에 따라 스톱 스 가격과 스톱 스 가격을 계산하고, 그에 따른 스톱 스 주문과 스톱 스 주문을 설정한다.
  5. 돌파 방향에 따라 해당 돌파 구간을 그리기

전략적 이점

  1. 지지부진을 뚫는 것은 실제 전투에 기반을 둔 고전적인 거래 전략이다.
  2. 피벗 하이 (pivothigh) 와 피벗 로우 (pivotlow) 함수를 사용하여 지지점과 저항점을 계산함으로써, 돌파 상황을 비교적 정확하게 포착할 수 있다.
  3. 이 전략의 코드 구조는 명확하고, 고점과 낮은 점을 배열에 저장하여, 쉽게 재검토 및 최적화를 할 수 있다.
  4. Stop Loss과 Stop Stop을 설정하여 위험을 더 잘 통제할 수 있습니다.

전략적 위험

  1. 지지부진한 전략은 흔들림 상황에서 잘 작동하지 않으며, 빈번한 가짜 브레이크아웃이 발생할 수 있습니다.
  2. 고정된 스톱 스 비율은 다른 상황에 적응하지 못할 수 있으며, 이로 인해 리스크-이익 불균형이 발생할 수 있다.
  3. 이 전략은 거래량과 같은 다른 중요한 지표를 고려하지 않고 가격 요소만을 고려하여 중요한 신호를 놓칠 수 있습니다.

전략 최적화 방향

  1. 신호의 정확성과 신뢰성을 높이기 위해 트래픽, MACD 등과 같은 더 많은 기술 지표를 도입하는 것을 고려할 수 있습니다.
  2. 스톱 및 스톱에 대해, 이동 스톱 또는 동적 스톱 스톱 비율을 사용하여 다른 상황에 더 잘 적응 할 수 있습니다.
  3. 추세 필터, 변동율 필터 등의 필터 조건을 도입하는 것을 고려할 수 있습니다.
  4. 지지점과 저항점의 최적화를 고려할 수 있다. 예를 들어, 적응주기를 사용하거나, 피보나치등급을 도입한다.

요약하다

SR Breakout Strategy는 고전적인 지지부진의 저항을 뚫는 아이디어에 기반한 거래 전략으로, pivothigh 및 pivotlow 함수를 사용하여 지지부진과 저항을 계산하고, 종결 가격이 이러한 위치를 뚫고 있는지 판단하여 거래 신호를 생성한다. 이 전략의 장점은 아이디어가 명확하고, 실행 및 최적화하기 쉽다는 것이다. 그러나 또한, 불안정한 상황에서 좋지 않은 성능과 고정된 스톱 손실 비율이 초래할 수 있는 위험도 존재한다.

전략 소스 코드
/*backtest
start: 2024-05-07 00:00:00
end: 2024-05-14 00:00:00
period: 10m
basePeriod: 1m
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/
// © LonesomeTheBlue © chanu_lev10k

//@version=5
strategy('SR Breakout Strategy', overlay=true, max_bars_back=500, max_lines_count=400)
prd = input.int(defval=5, title='Period', minval=2)
bo_len = input.int(defval=71, title='Max Breakout Length', minval=30, maxval=300)
cwidthu = input.float(defval=3., title='Threshold Rate %', minval=1., maxval=10) / 100
mintest = input.int(defval=2, title='Minimum Number of Tests', minval=1)
bocolorup = input.color(defval=color.blue, title='Breakout Colors', inline='bocol')
bocolordown = input.color(defval=color.red, title='', inline='bocol')
// lstyle = input.string(defval=line.style_solid, title='Line Style')
issl = input.bool(title='SL', inline='linesl1', group='Stop Loss / Take Profit:', defval=false)
slpercent = input.float(title=', %', inline='linesl1', group='Stop Loss / Take Profit:', defval=18.0, minval=0.0, step=0.1)
istp = input.bool(title='TP', inline='linetp1', group='Stop Loss / Take Profit:', defval=false)
tppercent = input.float(title=', %', inline='linetp1', group='Stop Loss / Take Profit:', defval=18.0, minval=0.0, step=0.1)

//width
lll = math.max(math.min(bar_index, 300), 1)
float h_ = ta.highest(lll)
float l_ = ta.lowest(lll)
float chwidth = (h_ - l_) * cwidthu

// check if PH/PL
ph = ta.pivothigh(prd, prd)
pl = ta.pivotlow(prd, prd)

//keep Pivot Points and their locations in the arrays
var phval = array.new_float(0)
var phloc = array.new_int(0)
var plval = array.new_float(0)
var plloc = array.new_int(0)

// keep PH/PL levels and locations
if bool(ph)
    array.unshift(phval, ph)
    array.unshift(phloc, bar_index - prd)
    if array.size(phval) > 1  // cleanup old ones
        for x = array.size(phloc) - 1 to 1 by 1
            if bar_index - array.get(phloc, x) > bo_len
                array.pop(phloc)
                array.pop(phval)

if bool(pl)
    array.unshift(plval, pl)
    array.unshift(plloc, bar_index - prd)
    if array.size(plval) > 1  // cleanup old ones
        for x = array.size(plloc) - 1 to 1 by 1
            if bar_index - array.get(plloc, x) > bo_len
                array.pop(plloc)
                array.pop(plval)

// check bullish cup
float bomax = na
int bostart = bar_index
num = 0
hgst = ta.highest(prd)[1]
if array.size(phval) >= mintest and close > open and close > hgst
    bomax := array.get(phval, 0)
    xx = 0
    for x = 0 to array.size(phval) - 1 by 1
        if array.get(phval, x) >= close
            break
        xx := x
        bomax := math.max(bomax, array.get(phval, x))
        bomax
    if xx >= mintest and open <= bomax
        for x = 0 to xx by 1
            if array.get(phval, x) <= bomax and array.get(phval, x) >= bomax - chwidth
                num += 1
                bostart := array.get(phloc, x)
                bostart
        if num < mintest or hgst >= bomax
            bomax := na
            bomax

// if not na(bomax) and num >= mintest
//     line.new(x1=bar_index, y1=bomax, x2=bostart, y2=bomax, color=bocolorup)
//     line.new(x1=bar_index, y1=bomax - chwidth, x2=bostart, y2=bomax - chwidth, color=bocolorup)
//     line.new(x1=bostart, y1=bomax - chwidth, x2=bostart, y2=bomax, color=bocolorup)
//     line.new(x1=bar_index, y1=bomax - chwidth, x2=bar_index, y2=bomax, color=bocolorup)

plotshape(not na(bomax) and num >= mintest, location=location.belowbar, style=shape.triangleup, color=bocolorup, size=size.small)
//alertcondition(not na(bomax) and num >= mintest, title='Breakout', message='Breakout')

// check bearish cup
float bomin = na
bostart := bar_index
num1 = 0
lwst = ta.lowest(prd)[1]
if array.size(plval) >= mintest and close < open and close < lwst
    bomin := array.get(plval, 0)
    xx = 0
    for x = 0 to array.size(plval) - 1 by 1
        if array.get(plval, x) <= close
            break
        xx := x
        bomin := math.min(bomin, array.get(plval, x))
        bomin
    if xx >= mintest and open >= bomin
        for x = 0 to xx by 1
            if array.get(plval, x) >= bomin and array.get(plval, x) <= bomin + chwidth
                num1 += 1
                bostart := array.get(plloc, x)
                bostart
        if num1 < mintest or lwst <= bomin
            bomin := na
            bomin

// if not na(bomin) and num1 >= mintest
//     line.new(x1=bar_index, y1=bomin, x2=bostart, y2=bomin, color=bocolordown)
//     line.new(x1=bar_index, y1=bomin + chwidth, x2=bostart, y2=bomin + chwidth, color=bocolordown)
//     line.new(x1=bostart, y1=bomin + chwidth, x2=bostart, y2=bomin, color=bocolordown)
//     line.new(x1=bar_index, y1=bomin + chwidth, x2=bar_index, y2=bomin, color=bocolordown)

plotshape(not na(bomin) and num1 >= mintest, location=location.abovebar, style=shape.triangledown, color=bocolordown, size=size.small)

//alertcondition(not na(bomin) and num1 >= mintest, title='Breakdown', message='Breakdown')
//alertcondition(not na(bomax) and num >= mintest or not na(bomin) and num1 >= mintest, title='Breakout or Breakdown', message='Breakout or Breakdown')

// Long Short conditions
longCondition = not na(bomax) and num >= mintest
if longCondition
    strategy.entry('Long', strategy.long)
shortCondition = not na(bomin) and num1 >= mintest
if shortCondition
    strategy.entry('Short', strategy.short)

// Entry price / Take Profit / Stop Loss
//entryprice = strategy.position_avg_price
entryprice = ta.valuewhen(condition=longCondition or shortCondition, source=close, occurrence=0)
pm = longCondition ? 1 : shortCondition ? -1 : 1 / math.sign(strategy.position_size)
takeprofit = entryprice * (1 + pm * tppercent * 0.01)
stoploss = entryprice * (1 - pm * slpercent * 0.01)
strategy.exit(id='Exit Long', from_entry='Long', stop=issl ? stoploss : na, limit=istp ? takeprofit : na, alert_message='Exit Long')
strategy.exit(id='Exit Short', from_entry='Short', stop=issl ? stoploss : na, limit=istp ? takeprofit : na, alert_message='Exit Short')