範囲フィルター 購入・販売信号戦略

作者: リン・ハーンチャオチャン開催日:2024-03-08 17:06:50
タグ:

img

概要

Range Filter Buy Sell Signals Strategyは,非常に実践的な定量的な取引戦略である.価格変動の範囲を使用して,低波動性の市場での偽信号を削減し,高波動性の市場での信号品質を向上させ,購入・売却信号をフィルターする.戦略名では,戦略の主な機能を正確に要約する.

戦略の論理

戦略は,まず,特定の期間における資産価格の変動範囲を計算します.具体的には,指定された期間中の最高価格と最低価格の違いを計算して価格変動の幅を決定します.

この後,購入・販売信号を生成する.しかし,すべての信号がエントリーを誘発するわけではありませんが,価格変動範囲のフィルタリング条件を満たす必要があります.例えば,価格が変動範囲を突破するときにのみ購入信号が発行されます.

この方法により,戦略は低変動市場環境でほとんどの誤った信号をフィルターし,不必要なエントリーを避けます.高変動状態では,利益を得るためにより大きな方向的な動きを捕捉します.

利点

この戦略の最大の利点は,シグナルのフィルタリング強度を動的に調整できるということです.低波動では,高品質のシグナルのみを選択しますが,高波動では,市場が提供するより多くの機会を把握できます.

固定パラメータフィルターと比較して この戦略は より賢く適応可能で 市場の状況に関係なく 優れたリスク報酬を提供します

さらに,単一の運用条件と比較して,この戦略は,より信頼性の高い取引信号を提供するためにトレンド方向判断を組み込む.同時に,個々の取引のリスクを効果的に制御するためにストップ・ロストと収益の機能も備えています.

リスク

この戦略の主なリスクは,変動範囲のパラメータの設定にあります.設定範囲が大きすぎたり小さすぎたりすると,信号品質と利益の可能性に悪影響を及ぼします.

さらに,この戦略は,短期間の振動傾向が強い市場では,利益の機会が比較的少ない.異なるサイクルシステムの組み合わせを使用することで,この問題を緩和することができます.

オプティマイゼーションの方向性

戦略は以下の側面で最適化できます.

  1. アダプティブパラメータアルゴリズムを使用して,自律的に波動範囲パラメータを最適化し,よりインテリジェントでダイナミックにします.

  2. 統合の罠を避けるために,大きなサイクル傾向に基づくフィルタリング規則を強化する.

  3. 戦略の異なるサイクルを組み合わせてシステムを形成し,全体的な安定性を向上させる.

  4. パラメータ設定やフィルタリング規則の効果を向上させるための機械学習アルゴリズムを追加します

結論

Range Filter Buy Sell Signals戦略は,非常に実用的で効果的な定量的な取引戦略である.それは,フィルタリング強度を動的に調整し,異なる市場環境で優れたリスク報酬を提供することができる.同時に,この戦略を最適化するのに,特にパラメータ最適化とルール最適化にはまだ大きな可能性がある.全体的に,この戦略は,安定した過剰収益を追求する定量的なトレーダーにとって優れたベースソリューションを提供します.


/*backtest
start: 2023-03-02 00:00:00
end: 2024-03-07 00:00:00
period: 1d
basePeriod: 1h
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/

// Credits to the original Script - Range Filter DonovanWall https://www.tradingview.com/script/lut7sBgG-Range-Filter-DW/
// This version is the old version of the Range Filter with less settings to tinker with

//@version=5
strategy(title='Range Filter - B&S Signals', shorttitle='[Doan]_RF-B&S Signals', overlay=true)

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
longLossPerc = input.float(title='Long Stop Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01
shortLossPerc = input.float(title='Short Stop Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01

longTakePerc = input.float(title='Long Take(%)', minval=0.0, step=0.1, defval=1) * 0.01
shortTakePerc = input.float(title='Short Take (%)', minval=0.0, step=0.1, defval=1) * 0.01

emaLength = input.int(200, title="EMA Length")

// Determine stop loss price

//Range Size Function
rng_size(x, qty, n) =>
    wper = n * 2 - 1
    avrng = ta.ema(math.abs(x - x[1]), n)
    AC = ta.ema(avrng, wper) * qty
    rng_size = AC

//Range Filter Function
rng_filt(x, rng_, n) =>
    r = rng_
    var rfilt = array.new_float(2, x)
    array.set(rfilt, 1, array.get(rfilt, 0))
    if x - r > array.get(rfilt, 1)
        array.set(rfilt, 0, x - r)
    if x + r < array.get(rfilt, 1)
        array.set(rfilt, 0, x + r)
    rng_filt1 = array.get(rfilt, 0)

    hi_band = rng_filt1 + r
    lo_band = rng_filt1 - r
    rng_filt = rng_filt1
    [hi_band, lo_band, rng_filt]

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Range Source
rng_src = input(defval=close, title='Swing Source')

//Range Period
rng_per = input.int(defval=20, minval=1, title='Swing Period')

//Range Size Inputs
rng_qty = input.float(defval=3.5, minval=0.0000001, title='Swing Multiplier')

//Bar Colors
use_barcolor = input(defval=false, title='Bar Colors On/Off')

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Range Filter Values
[h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per), rng_per)

//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0

//Trading Condition
longCond = rng_src > filt and rng_src > rng_src[1] and upward > 0 or rng_src > filt and rng_src < rng_src[1] and upward > 0
shortCond = rng_src < filt and rng_src < rng_src[1] and downward > 0 or rng_src < filt and rng_src > rng_src[1] and downward > 0

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

//Colors
filt_color = upward ? #05ff9b : downward ? #ff0583 : #cccccc
bar_color = upward and rng_src > filt ? rng_src > rng_src[1] ? #05ff9b : #00b36b : downward and rng_src < filt ? rng_src < rng_src[1] ? #ff0583 : #b8005d : #cccccc


ema = ta.ema(close, emaLength)

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
longStopPrice = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)

longTakePrice = strategy.position_avg_price * (1 + longTakePerc)
shortTakePrice = strategy.position_avg_price * (1 - shortTakePerc)

//Filter Plot
filt_plot = plot(filt, color=filt_color, linewidth=3, title='Filter', transp=67)

//Band Plots
h_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title='High Band')
l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title='Low Band')

//Band Fills
fill(h_band_plot, filt_plot, color=color.new(#00b36b, 92), title='High Band Fill')
fill(l_band_plot, filt_plot, color=color.new(#b8005d, 92), title='Low Band Fill')

//Bar Color
barcolor(use_barcolor ? bar_color : na)
// Entry
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)

plot(ema)

//Plot Buy and Sell Labels
plotshape(longCondition, title='Buy Signal', text='BUY', textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=color.new(color.green, 0))
plotshape(shortCondition, title='Sell Signal', text='SELL', textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.new(color.red, 0))

//Alerts
alertcondition(longCondition, title='Buy Alert', message='BUY')
alertcondition(shortCondition, title='Sell Alert', message='SELL')





もっと