月間閉店価格と移動平均のクロスオーバー戦略

作者: リン・ハーンチャオチャン開催日:2023年11月23日17時09分01秒
タグ:

img

概要

この戦略は,月額閉じる価格と移動平均線のクロスオーバーに基づいて取引信号を生成する.月額閉じる価格が移動平均値を超えると長くなって,月額閉じる価格が移動平均値を下回るとフラットになる.

戦略の論理

この戦略の基本的な論理は

  1. 移動平均周期パラメータを入力します. SMA と EMA のどちらかを選択します.
  2. 移動平均線を表示するオプション
  3. 信号源として他のティッカーの閉値を使用するオプション
  4. 月間閉値と移動平均値の関係に基づいて取引シグナルを決定する.
    • 閉じる価格がMAを上回る - ロング
    • 閉じる価格がMAを下回る - 閉じる長所

この戦略は,移動平均値のスムージング能力を利用し,価格ノイズをフィルタリングし,中期トレンド逆転を捕捉します.MAを超越すると,上昇傾向が示され,下を横切ると,トレンドが下落傾向を示します.

利点

この戦略の主な利点は以下の通りです.

  1. 月間データを活用して,日中のノイズを効果的にフィルタリングし,中長期トレンドを把握します
  2. 異なるティッカーの最適化のための可変MA期間
  3. 信号源として別のティッカーを使用するオプションは安定性を向上させる
  4. 先進的な反塗装技術を実装する
  5. テストを容易にするための柔軟なバックテスト時間枠

要約すると,これはシンプルで実用的な戦略の枠組みであり,パラメータ調整によってほとんどの株式に適応でき,特に中長期投資家に適しています.

リスク

リスクもいくつかあります.

  1. 月間データ更新が遅いため,価格変動をリアルタイムに反映できない.
  2. 遅れており,短期的な機会を逃す可能性があります
  3. MAには 欠陥があり 信号のタイミングは予測不能
  4. 適正でないパラメータ選択は過度に保守主義や機会を逃してしまう

リスクを軽減するための提案:

  1. 補助判断のためのより速いタイムフレームの技術指標を組み込む
  2. 最適なパラメータを見つけるために MA 期間を最適化
  3. 信号源としてより安定したベンチマークを使用する
  4. 損失を制限するためにポジションサイズを調整する

増進 の 機会

この戦略には大きな改善の可能性があります.

  1. ストップロスを組み込み,利益を固定し,リスクを制御する
  2. KD,MACDなどの補完指標を追加して信号精度を向上させる
  3. MA パラメータをダイナミックに最適化するために機械学習技術を使用する
  4. トレンドに合わせたポジションサイズを導入
  5. 市場状況に基づいて長/短切り機能を組み込む
  6. 迅速な反応のために,より速いタイムフレーム価格と合併

結論

月間閉店とMAクロスオーバー戦略は,シンプルで直接的な論理を持ち,パラメータチューニングを通じてさまざまなティッカーに適応することができます.それは特に中長期投資家に適しています.ストップ損失,パラメータ最適化および他のモジュールの継続的な強化により,この戦略は大きな希望を示しています.


/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 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/
// © universique

//@version=4
strategy("Monthly MA Close ", shorttitle="MMAC", overlay=true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)
//MAY 6 2020 18:00

// No repaint function 
// Function to securely and simply call `security()` so that it never repaints and never looks ahead.
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
//sec10 = f_secureSecurity(syminfo.tickerid, higherTf, data)

// ————— Converts current chart resolution into a float minutes value.
f_resInMinutes() => 
    _resInMinutes = timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
// ————— Returns the float minutes value of the string _res.
f_tfResInMinutes(_res) =>
    // _res: resolution of any TF (in "timeframe.period" string format).
    // Dependency: f_resInMinutes().
    security(syminfo.tickerid, _res, f_resInMinutes())

// —————————— Determine if current timeframe is smaller that higher timeframe selected in Inputs.
// Get higher timeframe in minutes.
//higherTfInMinutes = f_tfResInMinutes(higherTf)
// Get current timeframe in minutes.
currentTfInMinutes = f_resInMinutes()
// Compare current TF to higher TF to make sure it is smaller, otherwise our plots don't make sense.
//chartOnLowerTf = currentTfInMinutes < higherTfInMinutes

// Input
switch1=input(true, title="Show MA")
exponential = input(true, title="Exponential MA")
ticker = input(false, title="Other ticker MA")

tic_ma = input(title="Ticker MA", type=input.symbol, defval="BTC_USDT:swap")
res_ma = input(title="Time MA (W, D, [min])", type=input.string, defval="M")
len_ma = input(8, minval=1, title="Period MA")

ma_cus = exponential?f_secureSecurity(tic_ma, res_ma, ema(close,len_ma)) : f_secureSecurity(tic_ma, res_ma, sma(close,len_ma))
ma_long = exponential?f_secureSecurity(syminfo.tickerid, res_ma, ema(close,len_ma)) : f_secureSecurity(syminfo.tickerid, res_ma, sma(close,len_ma))

cl1 = f_secureSecurity(syminfo.tickerid, 'M', close)
cl2 = f_secureSecurity(tic_ma, 'M', close)

// Input Backtest Range
showDate  = input(defval = false, title = "Show Date Range", type = input.bool)
fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear  = input(defval = 1995, title = "From Year",       type = input.integer, minval = 1850)
thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)
thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)
thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1850)

// Funcion Example
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false       // create function "within window of time"

// Calculation
bullish_cross = ticker?cl2>ma_cus : cl1>ma_long
bearish_cross = ticker?cl2<ma_cus : cl1<ma_long

MAColor = bullish_cross ? color.green : bearish_cross ? color.red : color.orange

// Strategy
strategy.entry("long", strategy.long, when = window() and bullish_cross)
strategy.close("long", when = window() and bearish_cross)

// Output
plot(switch1?ma_long:na,color = MAColor,linewidth=4)

// Alerts
alertcondition(bullish_cross, title='Bullish', message='Bullish')
alertcondition(bearish_cross, title='Bearish', message='Bearish')

もっと