月次終値と移動平均のクロスオーバー戦略


作成日: 2023-11-23 17:09:01 最終変更日: 2023-11-23 17:09:01
コピー: 0 クリック数: 570
1
フォロー
1617
フォロワー

月次終値と移動平均のクロスオーバー戦略

概要

この戦略は,月線の閉じる価格と移動平均線の交差を活用して取引信号を生成する.月線の閉じる価格の上部で移動平均線を横切るときは,多めに;月線の閉じる価格の下部で移動平均線を横切るときは,平仓する.

戦略原則

この戦略の核心的な論理は:

  1. 移動平均線の周期パラメータを入力し,SMAまたはEMAを選択できます.
  2. 移動平均線が表示されます.
  3. 他の株の閉店価格をシグナルとして選択できます.
  4. 月線閉盤価格と移動平均線の関係による取引シグナル判断
    • 移動平均線を閉店価格に並べて,多額の投資を行います.
    • 移動平均線を横切って,平仓

この戦略は,移動平均線の平滑な特性を利用し,価格の部分的なノイズをフィルターして,株価の中期トレンドの転換を捕捉する.株価が平均線を越えたとき,株価が牛市トレンドを形成していることを示す;株価が平均線を越えたとき,株価トレンドが熊市に転換していることを示す.

戦略的優位性

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

  1. 月経データを活用して,夜間の騒音をフィルターし,株価の中長期トレンドを捉える
  2. 移動平均線周期をカスタマイズし,パラメータを異なる株式に最適化
  3. 安定性を高めるため,別の株を信号源として選択できます.
  4. アドバンストな反塗装技術により,復旧を防止します.
  5. 任意の反測時間周期を入力して,テストを最適化できます.

全体として,この戦略の枠組みはシンプルで実用的で,パラメータ最適化によってほとんどの株式に適用でき,特に中長期投資家に適しています.

戦略リスク

この戦略にはいくつかのリスクがあり,以下のような部分に重点を置いています.

  1. 月次データ更新が遅いため,価格の変化をリアルタイムで反映できない.
  2. 遅滞があり,ショートラインの取引機会が逃れることもある.
  3. 移動平均線は遅滞性があり,信号の発生時刻は制御できない.
  4. パラメータの不適切な選択は,過度に保守的または機会を逃す可能性があります

リスクの低減のために,以下の方法で最適化できます.

  1. より短い時間枠の技術指標を組み合わせた補助判断
  2. 移動平均線周期を調整して,最適なパラメータの組み合わせを見つける
  3. より安定した標識を信号源として利用する
  4. ポジションの規模を適切に調整し,単発損失を制御する

戦略最適化の方向性

この戦略は,以下のようないくつかの点で最適化できる大きな余地があります.

  1. 利潤を固定し,リスクをコントロールするストップ・ロスの策略を増やす
  2. KD,MACDなどの他の指標と組み合わせて,取引信号の正確性を向上させる
  3. 機械学習技術による移動平均線参数動的最適化
  4. ポジション管理モジュールを追加し,トレンドに合わせてポジションのallocatorsizeを変更します.
  5. 多空変換機能が追加され,市場の状況に応じて柔軟に調整できます.
  6. 低時間枠のK線に joiningして,より機敏な取引を実現

要約する

月線終盤価格と移動均線交差策の全体的な構想は明確で,容易に実現し,パラメータ調整により,異なる株式に適用され,特に中長期線投資家に適しています. 止損,最適化パラメータなどのモジュールの継続的な強化とともに,この戦略はより優れたパフォーマンスを期待できます.

ストラテジーソースコード
/*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')