더블 인터벌 필터 모멘텀 트레이딩 전략


생성 날짜: 2024-04-01 10:54:47 마지막으로 수정됨: 2024-04-01 10:54:47
복사: 3 클릭수: 590
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

더블 인터벌 필터 모멘텀 트레이딩 전략

개요

이 전략은 쌍방향 필터 기반의 동적 거래 전략이다. 전략은 빠른 속도와 느린 속도 두 개의 주기 평평한 범위를 계산하여 현재 가격의 움직임을 판단하기 위해 통합 범위 필터를 얻는다. 가격이 범위를 넘으면 구매/판매 신호를 발생시킨다. 동시에, 이 전략은 위험을 제어하고 수익을 잠금하기 위해 4 개의梯度 스톱과 1 개의 스톱을 설정한다.

전략 원칙

  1. 빠르고 느린 두 주기간의 평평한 구간을 계산한다. 빠른 구간은 더 짧은 주기와 더 작은 배수를 사용하고, 느린 구간은 더 긴 주기와 더 큰 배수를 사용합니다.
  2. 빠른 속도와 느린 속도 구간의 평균값을 종합 구간 필터로 사용한다.
  3. 현재 가격과 이전 가격의 관계를 계산하여 상승 경향 ((upward) 과 하락 경향 ((downward) 을 판단한다.
  4. 동적 상단 (FUB) 과 하단 (FLB) 을 계산하여 트렌드의 참고로 사용한다.
  5. 종결 가격과 TRF의 관계에 따라 구매 및 판매 신호를 생성한다.
  6. 4개의 스티드 스톱과 1개의 스톱로드를 설정하여 서로 다른 포지션 비율과 수익/손실 비율에 대응한다.

우위 분석

  1. 이중 간 필터는 빠른 주기와 느린 주기를 결합하여 다른 시장의 리듬에 적응하여 더 많은 거래 기회를 잡을 수 있습니다.
  2. 역동적으로 선로에 오르내리는 디자인은 현재의 추세에 따라 움직이고 잘못된 신호를 줄이는 데 도움이 됩니다.
  3. 4개의 사다리 정지 설정으로 트렌드가 지속될 때 더 많은 수익을 얻을 수 있고, 트렌드가 역전될 때에도 적시에 수익을 잠금할 수 있다.
  4. 손실을 막는 설정은 단일 거래의 최대 손실을 제어하고 계정 보안을 보호합니다.

위험 분석

  1. 시장의 흔들림이나 간격상황이 발생했을 때, 이 전략은 더 많은 가짜 신호를 생성할 수 있으며, 이는 빈번한 거래와 수수료 손실을 초래한다.
  2. 사다리 막을 설정하면 일부 수익이 조기 잠겨져 트렌드 상황의 이익을 완전히 누리지 못하게 될 수 있습니다.
  3. 피해 방지 설정은 블랙 스 사건으로 인한 극심한 피해를 완전히 피할 수 없습니다.

최적화 방향

  1. 트렌드 판단의 보조 조건으로 더 많은 기술 지표 또는 시장 정서 지표를 도입하는 것이 고려될 수 있으며, 잘못된 신호를 줄일 수 있습니다.
  2. 정지 및 손실 설정은 다양한 시장 환경 및 거래 유형에 따라 동적으로 조정되어 전략의 적응성을 향상시킬 수 있습니다.
  3. 재검토를 기반으로 빠른 속도와 느린 속도 간격의 주기 선택, 중지 및 중지 손실의 비율 설정 등과 같은 파라미터 설정을 추가로 최적화하여 전략의 안정성과 수익성을 향상시킬 수 있다.

요약하다

이중 간격 변동량 거래 전략은 빠른 느린 두 주기의 평평한 간격으로 통합 필터를 구축하고, 동적으로 오르락 내리락을 결합하여 가격 움직임을 판단하여 구매 신호를 생성한다. 이 전략은 또한 위험을 제어하고 이익을 잠금하기 위해 4 개의 사다리 스톱 및 1 개의 스톱을 설정한다. 이 전략은 트렌드 상황에서 사용하기에 적합하지만, 흔들리는 시장에서 더 많은 가짜 신호를 생성 할 수 있습니다.

전략 소스 코드
/*backtest
start: 2024-03-01 00:00:00
end: 2024-03-31 23:59:59
period: 1h
basePeriod: 15m
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/
//@version=5
strategy(title='2"Twin Range Filter', overlay=true)
strat_dir_input = input.string(title='İşlem Yönü', defval='Alis', options=['Alis', 'Satis', 'Tum'])
strat_dir_value = strat_dir_input == 'Alis' ? strategy.direction.long : strat_dir_input == 'Satis' ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)

////////////////////////////

// Backtest inputs
BaslangicAy = input.int(defval=1, title='İlk ay', minval=1, maxval=12)
BaslangicGun = input.int(defval=1, title='İlk Gün', minval=1, maxval=31)
BaslangicYil = input.int(defval=2023, title='İlk Yil', minval=2000)
SonAy = input.int(defval=1, title='Son Ay', minval=1, maxval=12)
SonGun = input.int(defval=1, title='Son Gün', minval=1, maxval=31)
SonYil = input.int(defval=9999, title='Son Yıl', minval=2000)

start = timestamp(BaslangicYil, BaslangicAy, BaslangicGun, 00, 00)  // backtest start window
finish = timestamp(SonYil, SonAy, SonGun, 23, 59)  // backtest finish window
window() => true

source = input(defval=close, title='Source')
showsignals = input(title='Show Buy/Sell Signals ?', defval=true)
per1 = input.int(defval=27, minval=1, title='Fast period')
mult1 = input.float(defval=1.6, minval=0.1, title='Fast range')
per2 = input.int(defval=55, minval=1, title='Slow period')
mult2 = input.float(defval=2, minval=0.1, title='Slow range')
smoothrng(x, t, m) =>
    wper = t * 2 - 1
    avrng = ta.ema(math.abs(x - x[1]), t)
    smoothrng = ta.ema(avrng, wper) * m
    smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2
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(source, smrng)
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])
STR = filt + smrng
STS = filt - smrng
FUB = 0.0
FUB := STR < nz(FUB[1]) or close[1] > nz(FUB[1]) ? STR : nz(FUB[1])
FLB = 0.0
FLB := STS > nz(FLB[1]) or close[1] < nz(FLB[1]) ? STS : nz(FLB[1])
TRF = 0.0
TRF := nz(TRF[1]) == FUB[1] and close <= FUB ? FUB : nz(TRF[1]) == FUB[1] and close >= FUB ? FLB : nz(TRF[1]) == FLB[1] and close >= FLB ? FLB : nz(TRF[1]) == FLB[1] and close <= FLB ? FUB : FUB
al = ta.crossover(close, TRF)
sat = ta.crossunder(close, TRF)
plotshape(showsignals and al, title='Long', text='BUY', style=shape.labelup, textcolor=color.white, size=size.tiny, location=location.belowbar, color=color.rgb(0, 19, 230))
plotshape(showsignals and sat, title='Short', text='SELL', style=shape.labeldown, textcolor=color.white, size=size.tiny, location=location.abovebar, color=color.rgb(0, 19, 230))
alertcondition(al, title='Long', message='Long')
alertcondition(sat, title='Short', message='Short')
Trfff = plot(TRF)
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
longFillColor = close > TRF ? color.green : na
shortFillColor = close < TRF ? color.red : na
fill(mPlot, Trfff, title='UpTrend Highligter', color=longFillColor, transp=90)
fill(mPlot, Trfff, title='DownTrend Highligter', color=shortFillColor, transp=90)

//////////////////////



renk1 = input(true, "Mum Renk Ayarları?")
mumrenk = input(true,title="Trend Bazlı Mum Rengi Değişimi?")
htaColor = renk1 ? (al ? color.rgb(224, 230, 57) : #E56337) : #c92626
barcolor(color = mumrenk ? (renk1 ? htaColor : na) : na)
if (al) and window()
    strategy.entry("Al", strategy.long)
if (sat) and window()
    strategy.entry("Sat", strategy.short)


per1(pcnt) =>
    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)
zarkesmgb = input.float(title='Zarar Kes Yüzdesi', defval=100, minval=0.01)
zarkeslos = per1(zarkesmgb)
q1 = input.int(title='Satış Lot Sayısı 1.Kısım %', defval=5, minval=1)
q2 = input.int(title='Satış Lot Sayısı 2.Kısım %', defval=8, minval=1)
q3 = input.int(title='Satış Lot Sayısı 3.Kısım %', defval=13, minval=1)
q4 = input.int(title='Satış Lot Sayısı 4.Kısım %', defval=21, minval=1)
tp1 = input.float(title='Kar Yüzdesi 1.Kısım', defval=13, minval=0.01)
tp2 = input.float(title='Kar Yüzdesi 2.Kısım', defval=21, minval=0.01)
tp3 = input.float(title='Kar Yüzdesi 3.Kısım', defval=29, minval=0.01)
tp4 = input.float(title='Kar Yüzdesi 4.Kısım', defval=34, minval=0.01)
strategy.exit('✨KS1', qty_percent=q1, profit=per1(tp1), loss=zarkeslos)
strategy.exit('✨KS2', qty_percent=q2, profit=per1(tp2), loss=zarkeslos)
strategy.exit('✨KS3', qty_percent=q3, profit=per1(tp3), loss=zarkeslos)
strategy.exit('✨KS4', qty_percent=q4, profit=per1(tp4), loss=zarkeslos)