
この戦略では、トレンドの判断と取引の決定に二重移動平均システムを使用し、特定の時点での高速移動平均と低速移動平均の相対的な位置関係を通じて、市場トレンドの始まり、継続、または終了を識別します。この戦略は、毎日決まった時間に高速EMAと低速EMAの位置関係をチェックし、高速ラインが低速ラインより上にある場合はロングポジションを確立し、高速ラインが低速ラインより下にある場合はショートポジションを確立します。これにより、トレンド追跡取引が実現します。
この戦略の核心は、異なる期間の 2 つの指数移動平均 (EMA) に基づいてトレンドを判断することです。高速 EMA (デフォルトの期間は 10) は価格の変化に敏感で、市場のトレンドをより迅速に捉えることができます。一方、低速 EMA (デフォルトの期間は 50) はより長期的なトレンドを反映します。この戦略は、各取引日の指定された時間(デフォルトは 9:00)に 2 つの移動平均の位置関係をチェックし、市場のトレンドの方向を決定し、移動平均のクロスオーバー信号に基づいて取引を行います。高速EMAが低速EMAを上回った場合、短期的な上昇の勢いが増していることを示しており、市場に参入してロングポジションを取るタイミングです。高速EMAが低速EMAを下回った場合、短期的な上昇の勢いが増していることを示しています。長期的には下落の勢いが強まっており、空売りするために市場に参入する時期が来ています。
この戦略は、高速および低速のデュアル移動平均システムと固定時間チェックメカニズムを組み合わせることで、シンプルで効果的なトレンド追跡取引システムを実現します。この戦略の利点は、明確なロジックと高度な自動化ですが、移動平均ラグや固定エントリ時間などの制限もあります。追加のテクニカル指標を導入し、パラメータ選択メカニズムを最適化し、リスク管理措置を強化することで、戦略を改善する余地はまだたくさんあります。全体として、これは実用的な価値を持つ基本的な戦略フレームワークであり、特定のニーズに応じてさらに改善および最適化することができます。
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Daily EMA Comparison Strategy", shorttitle="Daily EMA cros Comparison", overlay=true)
//------------------------------------------------------------------------------
// Inputs
//------------------------------------------------------------------------------
fastEmaLength = input.int(10, title="Fast EMA Length", minval=1) // Fast EMA period
slowEmaLength = input.int(50, title="Slow EMA Length", minval=1) // Slow EMA period
checkHour = input.int(9, title="Check Hour (24h format)", minval=0, maxval=23) // Hour to check
checkMinute = input.int(0, title="Check Minute", minval=0, maxval=59) // Minute to check
//------------------------------------------------------------------------------
// EMA Calculation
//------------------------------------------------------------------------------
fastEMA = ta.ema(close, fastEmaLength)
slowEMA = ta.ema(close, slowEmaLength)
//------------------------------------------------------------------------------
// Time Check
//------------------------------------------------------------------------------
// Get the current bar's time in the exchange's timezone
currentTime = timestamp("GMT-0", year, month, dayofmonth, checkHour, checkMinute)
// Check if the bar's time equals or passes the daily check time
isCheckTime = (time >= currentTime and time < currentTime + 60 * 1000) // 1-minute tolerance
//------------------------------------------------------------------------------
// Entry Conditions
//------------------------------------------------------------------------------
// Buy if Fast EMA is above Slow EMA at the specified time
buyCondition = isCheckTime and fastEMA > slowEMA
// Sell if Fast EMA is below Slow EMA at the specified time
sellCondition = isCheckTime and fastEMA < slowEMA
//------------------------------------------------------------------------------
// Strategy Execution
//------------------------------------------------------------------------------
// Enter Long
if buyCondition
strategy.entry("Long", strategy.long)
// Enter Short
if sellCondition
strategy.entry("Short", strategy.short)
//------------------------------------------------------------------------------
// Plot EMAs
//------------------------------------------------------------------------------
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.orange, title="Slow EMA")