ツインレンジフィルター取引戦略

作者: リン・ハーンチャオチャン,日付: 2023-11-13 10:38:20
タグ:

img

概要

ツインレンジフィルター戦略は,価格変動に基づいた取引戦略である.これは,価格と範囲の関係と組み合わせて,異なるパラメータ設定を持つ2つの平均レンジ指標を使用して,取引信号を生成する.この戦略は,ビットコインのような非常に不安定なデジタル資産に適している.

戦略の論理

この戦略では,異なる期間の長さの2つのスムーズレンジ指標を使用します. 急速なレンジ指標 (デフォルト期 27) とスローレンジ指標 (デフォルト期 55) です.レンジ指標の式は,現在の期間の価格レンジの指数移動平均を因数で掛けます (例えば1.6).

ツインレンジフィルター戦略は,価格が特定の振動範囲内に存在するかどうかを判断するために,価格を2つの振動範囲指標と比較します.価格がこの振動範囲を突破すると取引信号が生成されます.

戦略は,メディアンラインを基準として使用し,これは2つのレンジ指標の平均値である.価格がメディアンラインを1つの速い範囲で上回るときに長い信号が生成され,価格がメディアンラインを下回るときに1つの速い範囲で短い信号が生成される.

偽信号をフィルタリングするために,条件も追加します.現在の価格動きが前期と一致するときにのみ信号が生成されます.例えば,価格が上昇し,ミディアンラインを1レンジを超えるとだけロング信号が起動します.

要するに,この戦略は,ツインレンジ指標で振動範囲を識別し,価格が範囲を突破したときの注文を生成する. 誤った信号を減らすために価格方向フィルタが追加される.

利点

ツインレンジフィルター戦略の利点:

  1. ビットコインのような非常に不安定な資産に適応できる価格変動機能を使用します. ツインレンジインジケーターは価格範囲をより正確に位置付けることができます.

  2. 双子範囲の指標には異なる時間枠が含まれます.速い指標は短期的な機会を捉え,遅い指標は長期的な傾向を考慮します.

  3. 価格指向フィルターを追加することで 短期変動からの誤った信号が減少します

  4. シンプルで明快な論理で 理解し実行しやすい アルゴ取引に適しています

リスク

戦略のリスクは以下の通りです.

  1. 変動指標に頼るため,変動が低い環境では劣る可能性があります.

  2. 範囲のパラメータは異なる製品に最適化する必要があります.そうでなければ,取引機会が逃れられ,誤った信号が発生する可能性があります.

  3. 価格と波動性の差は考慮されません.相応の価格上昇なしに波動性が上昇した場合,誤った信号が発生します.

  4. ストップ損失レベルは,高い変動環境で調整が必要になる可能性があります.過度に緊密なストップは過度のストップアウトを引き起こします.

強化

この戦略は,いくつかの側面で強化できます.

  1. 様々な製品と時間枠に最適な組み合わせを見つけるために範囲パラメータをテストし最適化します.

  2. ストップ・ロスの戦略を最適化するために,最近の波動性に基づいて動的なストップ・ロスのメカニズムを追加します.

  3. 誤った信号を避けるために 価格変動の差値に基づくフィルターを追加します

  4. 進出の確実性を高めるため,容量の変化などの他の指標を組み込む.

  5. 戦略に適した脱出メカニズムをテストし,適切な利益を得て追加する.

概要

ツインレンジフィルターは,非常に不安定な資産のための効果的な取引戦略である.価格変動の特徴をうまく利用し,シンプルで明確な取引論理を生成する.パラメータ最適化やリスク管理などのさらなる改善により,量子取引システムにおける貴重な構成要素になり得る.また,市場変動の特徴に基づいてアルゴリズム取引への洞察を提供します.


/*backtest
start: 2023-11-05 00:00:00
end: 2023-11-12 00:00:00
period: 30m
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/
// © colinmck, greenmask9

//@version=4

strategy(title="Twin Range Filter Algo", overlay=true)

source = input(defval=close, title="Source")

// Smooth Average Range

per1 = input(defval=27, minval=1, title="Fast period")
mult1 = input(defval=1.6, minval=0.1, title="Fast range")

per2 = input(defval=55, minval=1, title="Slow period")
mult2 = input(defval=2, minval=0.1, title="Slow range")

smoothrng(x, t, m) =>
    wper = t * 2 - 1
    avrng = ema(abs(x - x[1]), t)
    smoothrng = ema(avrng, wper) * m
    smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2

// Range Filter

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])

hband = filt + smrng
lband = filt - smrng

longCond = bool(na)
shortCond = bool(na)
longCond := source > filt and source > source[1] and upward > 0 or source > filt and source < source[1] and upward > 0
shortCond := source < filt and source < source[1] and downward > 0 or source < filt and source > source[1] and downward > 0

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]

long = longCond and CondIni[1] == -1
short = shortCond and CondIni[1] == 1

// Plotting

// Strategy
// From this part on, programmer is greenmaks9
//
Separator = input(title="Following conditions and backtest algorithm are added by @greenmask9 🎯, original script is written by @colinmck 👍. Read both of their's release notes for more info on how this script works.", type=input.bool, defval=false)
disabler = input(title="Disable greenmask9's ATR conditions", type=input.bool, defval=false)

//second
l2 = input(title="ATR1", defval=32, minval=1)
s2 = input(title="Smoothing", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])
atr2(source, l2) => 
    if s2 == "SMA"
        sma(source, l2)
    else
        if s2 == "RMA"
            rma(source, l2)
        else
            if s2 == "EMA"
                ema(source, l2)
            else
                wma(source, l2)

//third
l3 = input(title="ATR2", defval=64, minval=1)
s3 = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
atr3(source, l3) => 
    if s3 == "RMA"
        rma(source, l3)
    else
        if s3 == "SMA"
            sma(source, l3)
        else
            if s3 == "EMA"
                ema(source, l3)
            else
                wma(source, l3)

atr20=atr2(tr(true), l2)
atr30=atr3(tr(true), l3)
strategy.initial_capital = 50000
ordersize=floor(strategy.initial_capital/close)
profit = input(title="Ticks profit", type=input.integer, defval=900)
stop = input(title="Ticks stoploss", type=input.integer, defval=300)
maxcandles_till_close = input(title="Time stoploss", type=input.integer, defval=17)


bull = long and (atr20<atr30 or disabler)
bear = short and (atr20<atr30 or disabler)

bullclock = barssince(bull)
bearclock = barssince(bear)

if (bull)
    strategy.entry("Twin Long", strategy.long, ordersize)
    strategy.exit("Exit", from_entry =  "Twin Long", profit = profit, loss = stop)

if (bear)
    strategy.entry("Twin Short", strategy.short, ordersize)
    strategy.exit("Exit", from_entry = "Twin Short", profit = profit, loss = stop)

//time stoploss
strategy.close("Twin Long", when = bullclock == maxcandles_till_close, comment = "Timed out")
strategy.close("Twin Short", when = bearclock == maxcandles_till_close, comment = "Timed out")



もっと