스톱 로스 추적 전략과 동적 가격 채널

저자:차오장, 2024-02-01 10:52:33
태그:

img

전반적인 설명

이 전략은 돈치안 가격 채널 지표에 기초하여 개발된다. 지표는 특정 기간 동안 가장 높고 가장 낮은 가격을 계산하여 가격 채널을 형성한다. 전략은 가격 채널을 활용하여 양방향 거래를 구현하고 스톱 로스 및 영업 가격을 설정한다. 스톱 로스 가격은 가격 채널의 중간선에 고정되어 있으며, 영업 가격은 가격 채널의 상부 및 하부 한계를 넘어 특정 비율로 설정된다. 전략은 또한 스톱 로스 및 영업의 추적을 구현한다.

전략 원칙

우선, 전략은 매개 변수 pclen을 기반으로 가격 채널의 상위 한도 h와 하위 한도 l를 계산합니다. 중간 라인 센터는 가격 채널의 상위 및 하위 한도의 평균입니다. 그 다음, 수익을 취하는 가격 tpl 및 tps는 긴 및 짧은 포지션의 수익을 취하는 매개 변수 tp에 따라 계산됩니다. 스톱 손실 가격은 가격 채널의 중간 라인 센터에 고정됩니다. 가격이 가격 채널을 통과 할 때, 다른 방향의 거래 포지션은 위험 크기에 따라 계산됩니다. 위험 긴 및 위험 짧은 포지션. 전략은 가격이 채널에 다시 들어갈 때 닫을 것입니다. 또한, 시간 필터링은 지정된 날짜 범위 내에서만 거래하도록 설정됩니다.

구체적인 거래 논리는 다음과 같습니다.

긴 진입 신호: 가격이 채널 상단 h를 넘어서 다시 채널로 떨어지면 긴 진입 신호를 열고

긴 출구 신호: 가격이 채널 중간 라인 센터보다 낮거나 수익을 취하는 가격보다 높을 때 긴 문을 닫습니다

코트 엔트리 신호: 가격이 채널 하위 한계 l보다 낮고 채널로 다시 떨어지면 코트를 열고

쇼트 출구 신호: 가격이 채널 중간 라인 센터보다 높을 때 쇼트를 닫습니다 (손실 중지) 또는 수익을 취하는 가격 tps (이익을 취하십시오) 보다 낮습니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 쌍방향 거래는 가격 동향의 반전을 포착 할 수 있습니다.
  2. 가격 채널을 사용하여 트렌드 방향을 결정하고 잘못된 브레이크를 피합니다.
  3. 스톱 로스를 설정하고 리스크를 제어하기 위해 수익을 취하십시오.
  4. 통제 가능한 위험을 달성하기 위해 위험 규모와 관련된 지점 크기를 계산합니다.
  5. 더 많은 수익을 확보하기 위해 손해를 멈추고 수익을 취하는 추적을 구현하십시오.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. 가격 채널의 잘못된 매개 변수 설정은 너무 높은 거래 빈도 또는 놓친 거래 기회를 초래할 수 있습니다.
  2. 너무 넓게 설정된 스톱 로스 가격은 위험 노출을 증가시킬 수 있습니다.
  3. 트래킹 취득은 높은 변동성 기간에 조기에 시작될 수 있습니다.

이러한 위험은 매개 변수를 조정하고 수동 모니터링을 통해 줄이고 통제 할 수 있습니다.

최적화 방향

이 전략은 다음 측면에서도 최적화 될 수 있습니다.

  1. 범위에 묶인 시장에서 빈번한 개장 및 폐쇄를 피하기 위해 더 많은 지표 필터를 추가합니다.
  2. 다른 스톱 로스 알고리즘과 ATR 스톱 로스 알고리즘을 테스트할 수 있습니다.
  3. 트렌드 방향을 결정하기 위해 더 높은 시간 프레임을 사용하는 크로스 타임프레임 거래 시스템으로 확장
  4. 자본 활용률에 기초한 포지션을 조정하기 위해 포지션 사이징 모듈을 추가합니다.
  5. 가짜 브레이크를 피하기 위해 가격 브레이크의 성공률을 판단하기 위해 기계 학습 모델을 통합합니다.

결론

결론적으로, 이것은 가격 채널 지표를 사용하여 양방향 거래를 구현하는 효과적인 전략입니다. 적절한 스톱 로스, 영업 취득 및 포지션 사이징 제어 모듈을 사용하면 위험을 잘 제어 할 수 있습니다. 일부 최적화 및 조정으로 강력한 양적 거래 전략이 될 수 있습니다.


/*backtest
start: 2023-01-31 00:00:00
end: 2024-01-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2020

//@version=4
strategy(title = "Noro's RiskDonchian Strategy", shorttitle = "RiskDonchian str", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 100, default_qty_value = 100, commission_value = 0.1)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
tp = input(defval = 20.0, minval = 1, title = "Take-profit, %")
tptype = input(defval = "2. Fix", options = ["1. None", "2. Fix", "3. Trailing"], title = "Take-profit type")
sltype = input(defval = "2. Center", options = ["1. None", "2. Center"], title = "Take-profit type")
risklong  = input(5.0, minval = 0.0, maxval = 99.9, title = "Risk size for long, %")
riskshort = input(5.0, minval = 0.0, maxval = 99.9, title = "Risk size for short, %")
pclen = input(50, minval = 1, title = "Price Channel Length")
showll = input(true, defval = true, title = "Show lines")
showbg = input(false, defval = false, title = "Show Background")
showof = input(true, defval = true, title = "Show Offset")
showlabel = input(true, defval = true, title = "Show label")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Price Channel
h = highest(high, pclen)
l = lowest(low, pclen)
center = (h + l) / 2

//Take-profit
tpl = 0.0
tpl := tptype == "2. Fix" and strategy.position_size > 0 ? tpl[1] : h * (100 + tp) / 100

//Stop-loss
tps = 0.0
tps := tptype == "2. Fix" and strategy.position_size < 0 ? tps[1] : l * (100 - tp) / 100

//Lines
tplcol = showll and needlong and tptype != "1. None" ? color.lime : na
pclcol = showll and needlong ? color.blue : na
sllcol = showll and needlong and sltype != "1. None" ? color.red : na
tpscol = showll and needshort and tptype != "1. None" ? color.lime : na
pcscol = showll and needshort ? color.blue : na
slscol = showll and needshort and sltype != "1. None" ? color.red : na
offset = showof ? 1 : 0
plot(tpl, offset = offset, color = tplcol, title = "TP Long")
plot(h, offset = offset, color = pclcol, title = "Channel High")
plot(center, offset = offset, color = sllcol, title = "SL Long")
plot(center, offset = offset, color = slscol, title = "SL Short")
plot(l, offset = offset, color = pcscol, title = "Channel Low")
plot(tps, offset = offset, color = tpscol, title = "TP Short")

//Background
size = strategy.position_size
bgcol = showbg == false ? na : size > 0 ? color.lime : size < 0 ? color.red : na
bgcolor(bgcol, transp = 70)

//Lot size
risksizelong = -1 * risklong
risklonga = ((center / h) - 1) * 100
coeflong = abs(risksizelong / risklonga)
lotlong = (strategy.equity / close) * coeflong
risksizeshort = -1 * riskshort
riskshorta = ((center / l) - 1) * 100
coefshort = abs(risksizeshort / riskshorta)
lotshort = (strategy.equity / close) * coefshort

//Trading
truetime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
mo = 0
mo := strategy.position_size != 0 ? 0 : high >= center[1] and low <= center[1] ? 1 : mo[1]

if h > 0
    longlimit = tptype == "1. None" ? na : tpl
    longstop = sltype == "1. None" ? na : center
    strategy.entry("Long", strategy.long, lotlong, stop = h, when = strategy.position_size <= 0 and needlong and truetime and mo)
    strategy.exit("TP Long", "Long", limit = longlimit, stop = longstop)
    shortlimit = tptype == "1. None" ? na : tps
    shortstop = sltype == "1. None" ? na : center
    strategy.entry("Short", strategy.short, lotshort, stop = l, when = strategy.position_size >= 0 and needshort and truetime and mo)
    strategy.exit("Exit Short", "Short", limit = shortlimit, stop = shortstop)
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
    strategy.cancel("Long")
    strategy.cancel("Short")
    
if showlabel

    //Drawdown
    max = 0.0
    max := max(strategy.equity, nz(max[1]))
    dd = (strategy.equity / max - 1) * 100
    min = 100.0
    min := min(dd, nz(min[1]))
    
    //Label
    min := round(min * 100) / 100
    labeltext = "Drawdown: " + tostring(min) + "%"
    var label la = na
    label.delete(la)
    tc = min > -100 ? color.white : color.red
    osx = timenow + round(change(time)*10)
    osy = highest(100)

더 많은