ダブルインターバルフィルターモメンタムトレーディング戦略


作成日: 2024-04-01 10:54:47 最終変更日: 2024-04-01 10:54:47
コピー: 3 クリック数: 590
1
フォロー
1617
フォロワー

ダブルインターバルフィルターモメンタムトレーディング戦略

概要

この戦略は,二区間フィルターに基づく動量取引戦略である.この戦略は,快速と遅速の2つの周期の平滑区間を計算することによって,現在の価格の動きを判断するために,総合的な区間フィルターを得ます.価格がこの区間を上/下を通過すると,戦略は,買/売信号を生成します.同時に,この戦略は,リスク管理と利益のロックのために4つの梯度ストップと1つのストップロスを設定します.

戦略原則

  1. 速いと遅い2周期の平滑区間を計算する.速い区間はより短い周期とより小さな倍数,ゆっくりとした区間はより長い周期とより大きな倍数を使用する.
  2. 総合区間フィルター ((TRF) としては,高速区間と遅速区間の平均値を使用する.
  3. 現在の価格と前の価格の関係を計算し,上昇傾向 ((upward) と下降傾向 ((downward) を判断する.
  4. 動的上線 (FUB) と下線 (FLB) を計算し,トレンドの参考となる.
  5. TRFと閉盘価格の関係によって,買入と売却のシグナルが生成されます.
  6. 4つの梯度ストップと1つのストップを設定し,異なるポジション比率と利益/損失比率に対応します.

優位分析

  1. 双区間フィルターは,高速と遅い2つのサイクルを組み合わせて,異なる市場のリズムに適応し,より多くの取引機会を捉えることができます.
  2. 動的上下軌の設計は,現在のトレンドに沿って,偽信号を減らすのに役立ちます.
  3. 4つの梯度ストップの設定は,トレンドが継続するときにより多くの利益を得ることができ,また,トレンドが逆転するときに利益の一部を間に合うようにロックすることができます.
  4. ストップ・ロスの設定は,単一取引の最大損失を制御し,アカウントの安全性を保護するのに役立ちます.

リスク分析

  1. 市場が揺れ動いたり区間走行が起きたとき,この戦略は偽のシグナルを多く生み出し,頻繁な取引と手数料の損失を引き起こす可能性があります.
  2. 梯度制約の設定により,利益の一部が前もってロックされ,トレンドの利益が完全に享受できない可能性があります.
  3. ブラック・スヴェンダー事件による極端な損失を完全に防ぐことはできません.

最適化の方向

  1. より多くの技術指標や市場情緒指標を導入することを検討し,偽の信号を減らすためにトレンド判断の補助条件として使用することができます.
  2. ストップとストップの設定は,異なる市場環境と取引品種に応じて動的に調整され,戦略の適応性を向上させることができます.
  3. 回測に基づいて,高速と遅い区間の周期選択,停止と停止のパーセント設定などのパラメータ設定をさらに最適化して,戦略の安定性と収益性を向上させることができる.

要約する

双区間波動量取引戦略は,2周期の平滑区間を高速で構築し,同時にダイナミックな上下を組み合わせ,価格動きを判断し,買入シグナルを生成する.この戦略は,リスク制御と利益のロックをするために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)