ハルフ・フィルター移動平均戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-04 15:16:34 詳細はこちら
タグ:

img

概要

この戦略は,短期および長期のハル移動平均値を利用して取引信号を生成し,フィルタリングする.短期ハル移動平均値は,シグナルを生成するために使用され,長期ハル移動平均値は,シグナルをフィルタリングするために使用される.短期ハル移動平均が方向を変え,長期ハル移動平均が全体的に同じ方向に動いている場合にのみ取引が行われる.

この戦略は,ATR指標を使用して,ストップロスを動的に設定し,取引を行うときに利益レベルを設定します.

戦略の論理

短期Hull移動平均は,短期的な価格動向とターニングポイントを記録します.方向が変わると,短期的な価格動向の変化をシグナルします.

Hull 長期移動平均は,全体的な価格動向を決定します.例えば,上昇しているとき,価格は全体的な上昇傾向にあります.

取引は,短期ハル移動平均が方向転換し,その新しい方向が長期ハル移動平均の方向に一致するときにのみ行われます.これは,全体的な傾向に反する信号をフィルタリングし,短期市場騒音かもしれません.

ポジションを入力した後,ストップ・ロストとテイク・プロフィートのレベルはATR指標値に基づいて設定されます.ATRは市場の変動とリスクレベルを反映しています.ストップ・ロスは価格の低値以下に置かれ,テイク・プロフィートの目標は価格の高値以下に置かれ,範囲は現在のATR読み取りに関連付けられています.

利点分析

短期信号と長期フィルタを組み合わせることで 中期トレンドとターニングポイントを効果的に特定し,市場の騒音による誤った信号を避ける.

動的ストップ損失とATRに基づく利益の引き上げは,現在の変動,利益の引き上げのバランス,損失の防止に基づいて合理的な範囲を設定します.

Hull移動平均は,より優れたトレンド追跡により,標準移動平均よりも柔軟性と精度が優れている.

リスク分析

この戦略は,シグナルを生成するためにハル移動平均値間の交差に依存する.偽の交差は,悪い取引につながり,全体的な市場構造の分析を必要とする.

取引範囲内での価格の振動で揺れ動いている市場では,シグナルエラーと不必要な取引が積み重なることがあります.このような市場でのより広い条件のシグナルをフィルタリングすることで,これは回避できます.

ストップ損失とATRへの利益の取組は,不正確な波動性読み込みが不適切な投資につながることを意味します.他の波動性対策は,これを修正するためにATRを増加させることができます.

最適化

RSIのような短期指標は 収束によって信号の精度を向上させることができます

Hull移動平均値間のフィルター論理は,誤った信号を避けるため,より厳格なエントリー要件を持つために強化することができます.

パラメータ調節の研究では,移動平均長度,ATR期間等の変化による安定性と収益性の向上が明らかになる.

概要

この戦略は,短期信号生成,長期信号フィルタリング,およびATRベースのストップ損失/収益を堅牢な中期トレンドフォローフレームワークで組み合わせます.短期ノイズをフィルタリングしながら中期インブレクションポイントを巧みに識別します.パラメータ最適化と追加フィルタにより,さらに優れたパフォーマンスを達成できます.


/*backtest
start: 2023-12-04 00:00:00
end: 2024-01-03 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Hull Filtered Strategy", overlay=true, pyramiding=0, default_qty_type= strategy.percent_of_equity, default_qty_value = 10, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0)

// Parameters for Hull Moving Averages
src = input(close, title="Source")
signal_period = input(50, title="Period of signal HMA")
filter_period = input(200, title="Period of filter HMA")

strat_dir_input = input(title="Strategy Direction", defval="all", options=["long", "short", "all"])

// Set allowed trading directions
strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)

// stop loss and take profit
sl_factor = input(2,title="Stop Loss Factor")
tp_factor = input(3,title="Take Profit Factor")
atr_period = input(14, title="ATR Period (SL/TP)")

// Testing Start dates
testStartYear = input(2010, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

//Stop date if you want to use a specific range of dates
testStopYear = input(2030, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)


// -----------------------------------------------------------------------------
// Global variables
// -----------------------------------------------------------------------------
var float tp = na
var float sl = na
var float position = na


// -----------------------------------------------------------------------------
// Functions
// -----------------------------------------------------------------------------
testWindow() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false


// -----------------------------------------------------------------------------
// The engine
// -----------------------------------------------------------------------------
hma_signal = hma(src, signal_period)
hma_filter = hma(src, filter_period)

// Used to determine exits and stop losses
atr_e = atr(atr_period)

// if hma_filter increases hma_trend is set to 1, if it decreases hma_trend is set to -1. If no trend is available, hma_trend is set to ß0
trend = hma_filter > hma_filter[1]  ?  1 : hma_filter < hma_filter[1] ? -1 : 0
signal = hma_signal > hma_signal[1] ? 1 : hma_signal  < hma_signal[1] ? -1 : 0


// -----------------------------------------------------------------------------
// signals
// -----------------------------------------------------------------------------
if signal[0] == 1 and signal[1] != 1 and trend == 1 and testWindow()
    sl := close - sl_factor*atr_e
    tp := close + tp_factor*atr_e
    strategy.entry("HMA_LNG", strategy.long)
    strategy.exit("LE", "HMA_LNG", profit=100*tp_factor*atr_e, loss=100*sl_factor*atr_e)
    
if signal[0] == -1 and signal[1] != -1 and trend == -1 and testWindow()
    sl := close + sl_factor*atr_e
    tp := close - tp_factor*atr_e
    strategy.entry("HMA_SHRT", strategy.short)
    strategy.exit("SE", "HMA_SHRT", profit=100*tp_factor*atr_e, loss=100*sl_factor*atr_e)


if strategy.position_size != 0
    sl := sl[1]
    tp := tp[1]

// -----------------------------------------------------------------------------
// PLOT
// -----------------------------------------------------------------------------
hma_s = plot(hma_signal, title="SIGNAL", color = signal == 1 ? color.green : color.red)
hma_l = plot(hma_filter, title="TREND", color = trend == 1 ? color.green : color.red)

plot(tp, title="TAKE PROFIT", color= strategy.position_size != 0 ? color.blue: na, linewidth=1)  
plot(sl, title="STOP LOSS", color= strategy.position_size != 0 ? color.red: na, linewidth = 1)


もっと