거리 기반 트레일링 스톱로스 정량적 전략


생성 날짜: 2023-11-15 11:24:16 마지막으로 수정됨: 2023-11-15 11:24:16
복사: 0 클릭수: 682
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

거리 기반 트레일링 스톱로스 정량적 전략

개요

이 전략은 이동적 상쇄의 아이디어에 기반하여, 거리 근접 바스 ((DCB) 지표를 사용하여 가격 움직임을 판단하고, 빠른 RSI 지표와 결합하여 필터링하여, 이동적 상쇄를 실현하고, 상쇄를 추적한다. 전략은 또한 마틴겔의 포지션 증가 원리를 사용하여, 중장선 트렌드 거래에 적합하다.

원칙

  1. lastg와 lastr을 계산하여 마지막 상승한 K선과 마지막 하락한 K선의 폐막 가격을 나타냅니다.

  2. dist를 lastg와 lastr의 가격차로 계산한다.

  3. adist를 dist의 30주기 간단한 이동 평균으로 계산한다.

  4. dist가 adist의 두 배에 달할 때 거래 신호를 생성한다.

  5. 빠른 RSI 지표 필터링 신호와 결합하여 가짜 브레이크를 피하십시오.

  6. 신호가 있고 포지션이 없는 경우, 고정된 비율로 입시 포지션을 개설한다.

  7. 마틴겔의 법칙을 이용해서 손실을 감수하고

  8. 가격이 스톱로스 (Stop Loss) 또는 스톱 스톱 (Stop Stop) 후 평형을 촉발한다.

장점

  1. DCB 지표를 사용하여 트렌드 방향을 판단하여 중·장선 트렌드를 효과적으로 포착할 수 있다.

  2. 빠른 RSI 지표 필터링은 가짜 브레이크를 방지하여 손실을 초래합니다.

  3. 이동식 상쇄장치는 수익을 잠금하고 위험을 효과적으로 제어한다.

  4. 마틴겔 원칙은 손실을 감수하고 더 높은 수익을 추구하기 위해 포지션을 늘릴 수 있다.

  5. 다양한 시장 환경에 맞는 합리적인 전략 매개 변수 설정

위험

  1. DCB 지표는 잘못된 신호를 발산할 수 있으며, 다른 지표와 함께 필터링이 필요합니다.

  2. 마틴게일 (MartinGel) 은 손실을 증가시키고, 엄격한 자금 관리가 필요합니다.

  3. 부당한 스톱포인트 설정으로 예상보다 더 많은 손실이 발생할 수 있습니다.

  4. 포지션 수를 엄격히 통제해야 하며, 자금 부담을 초과하는 것을 피해야 한다.

  5. 거래계약의 잘못된 설정은 극단적인 상황에서는 엄청난 손실을 초래할 수 있다.

더 나은 생각

  1. DCB 변수를 최적화하여 최적의 변수 조합을 찾습니다.

  2. 빠른 RSI를 필터링하기 위해 다른 지표를 시도하십시오.

  3. 스톱로스 스톱 변수를 최적화하여 전략의 승률을 높인다.

  4. 마틴겔 변수를 최적화하여 부채가 증가하는 위험을 줄여줍니다.

  5. 다양한 거래 품종을 테스트하고, 가장 좋은 품종 중심을 선택하십시오.

  6. 기계 학습과 같은 기술 동적 최적화 전략 파라미터를 결합한다.

요약하다

이 전략 Overall는 좀 더 성숙한 트렌드 추적 전략이다. DCB를 사용하여 트렌드 방향을 결정하고, 빠른 RSI 필터링 신호를 사용하면 잘못된 입장을 피할 수 있다. 동시에 손해 막기 메커니즘은 단일 손실을 효과적으로 제어 할 수 있다. 그러나 전략에는 약간의 위험이 있으며, 위험을 줄이고 안정성을 향상시키기 위해 파라미터를 추가적으로 최적화해야 한다.

전략 소스 코드
/*backtest
start: 2023-11-07 00:00:00
end: 2023-11-14 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Distance Strategy v1.0", shorttitle = "Distance str 1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 10)

//Settings 
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usemar = input(true, defval = true, title = "Use Martingale")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
usersi = input(true, defval = true, title = "Use RSI-Filter")
periodrsi = input(7, defval = 7, minval = 2, maxval = 50, title = "RSI Period")
limitrsi = input(30, defval = 30, minval = 1, maxval = 50, title = "RSI Limit")
fromyear = input(2018, defval = 2018, 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")

//Fast RSI
fastup = rma(max(change(close), 0), periodrsi)
fastdown = rma(-min(change(close), 0), periodrsi)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//Distance
bar = close > open ? 1 : close < open ? -1 : 0
lastg = bar == 1 ? close : lastg[1]
lastr = bar == -1 ? close : lastr[1]
dist = lastg - lastr
adist = sma(dist, 30)
plot(lastg, linewidth = 3, color = lime)
plot(lastr, linewidth = 3, color = red)
up = bar == -1 and dist > adist * 2
dn = bar == 1 and dist > adist * 2

//RSI Filter
rsidn = fastrsi < limitrsi or usersi == false
rsiup = fastrsi > 100 - limitrsi or usersi == false

//Signals
up1 = up and rsidn
dn1 = dn and rsiup
exit = ((strategy.position_size > 0 and close > open) or (strategy.position_size < 0 and close < open))

//Arrows
plotarrow(up1 ? 1 : na, colorup = blue, colordown = blue)
plotarrow(dn1 ? -1 : na, colorup = blue, colordown = blue)

//Trading
profit = exit ? ((strategy.position_size > 0 and close > strategy.position_avg_price) or (strategy.position_size < 0 and close < strategy.position_avg_price)) ? 1 : -1 : profit[1]
mult = usemar ? exit ? profit == -1 ? mult[1] * 2 : 1 : mult[1] : 1
lot = strategy.position_size == 0 ? strategy.equity / close * capital / 100 * mult : lot[1]

signalup = up1
if signalup
    if strategy.position_size < 0
        strategy.close_all()
        
    strategy.entry("long", strategy.long, needlong == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

signaldn = dn1
if signaldn
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    
if time > timestamp(toyear, tomonth, today, 23, 59) or exit
    strategy.close_all()