MFIとMAに基づく定量的反転戦略


作成日: 2023-12-27 14:42:16 最終変更日: 2023-12-27 14:42:16
コピー: 5 クリック数: 761
1
フォロー
1623
フォロワー

MFIとMAに基づく定量的反転戦略

概要

この戦略は,MFI指数を使用して過買過売の領域を特定し,MAフィルターと組み合わせて価格逆転方向を判断するショートライン取引戦略である.これは,株式,外貨,商品,および暗号通貨などの市場で有効である.

戦略原則

戦略は,MFI指標を用いて市場の超買超売現象を判断する.MFIが20未満の超売り領域に入ると,下部地域を表し,価値が過小評価され,その時点で看落する.MFIが80以上の超買領域に入ると,上部地域を表し,資産が過大評価され,その時点で下落する.

偽反転をフィルターするために,戦略はまた,価格の傾向の方向を判断するMA指標を導入した. MFIが反転すると同時に,価格がMA平均線上または下を下回った場合にのみ,取引シグナルが生成される.

取引の論理は以下の通りです.

  1. MFIは20を下回って超売り区に入ると同時に,閉店価格がMA平均線に上がり,買い信号を生成する
  2. MFIは80以上を突破して超買区に入ると同時に,閉盘価格がMA平均線を下回り,売り込みシグナルを生む.

このように,ダブル指標フィルターによって,反転の機会を効果的に識別することができ,入場信号はより信頼性が高くなります.

戦略的優位性

  1. 双指数確認を使用し,偽突破を回避し,信号信頼性が高い
  2. 超買超売の区間反転は,古典的で効果的な取引技術です.
  3. トレンドフィルターと組み合わせて,信号をより正確で信頼性のあるものにします.
  4. 複数の市場に対応し,柔軟性があります.

戦略リスク

  1. 市場が長期にわたって上昇したり下落したりして,ストップダウンの原因になる可能性があります.
  2. システム上のリスクに注目し,極端な状況から誤った転換点を回避する
  3. 取引の頻度が高くなり,取引コストの管理に注意が必要

どう対処するか?

  1. 戦略に余裕を与えるため,適正にストップ・ロスの幅を緩める.
  2. ポジションを拡大する際には,より大きなレベルのグラフに注目し,システムリスクの判断をしてください.
  3. パラメータを最適化して 無意味な取引を減らす

戦略最適化の方向性

  1. 取引品種の特性にマッチするMAパラメータを最適化
  2. 市場情勢に合わせて,超買超売のパラメータを最適化する
  3. ポジション管理の強化により,収益をコントロールできる

要約する

この戦略は,古典的な分析方法と近代的な量化技術を統合し,厳格な二重指標のフィルタリングによって,様々な品種で強い適応性を示し,一般的なショートライン戦略として推奨されます.

ストラテジーソースコード
/*backtest
start: 2023-12-19 00:00:00
end: 2023-12-26 00:00:00
period: 1m
basePeriod: 1m
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/
// © vikris

//@version=4
strategy("[VJ]Thor for MFI", overlay=true, calc_on_every_tick = false,pyramiding=0)

// ********** Strategy inputs - Start **********

// Used for intraday handling
// Session value should be from market start to the time you want to square-off 
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session, 
     defval="0915-1455", confirm=true)

// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01

shortProfitPerc = input(title="Short Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
     
// Set stop loss level with input options (optional)
longLossPerc = input(title="Long Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01

shortLossPerc = input(title="Short Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01    

i_MFI = input(3, title="MFI Length")
OB=input(100, title="Overbought Level")
OS=input(0, title="Oversold Level")
barsizeThreshold=input(.5, step=.05, minval=.1, maxval=1, title="Bar Body Size, 1=No Wicks")
i_MAFilter = input(true, title="Use MA Trend Filter")
i_MALen = input(80, title="MA Length")
// ********** Strategy inputs - End **********


// ********** Supporting functions - Start **********

// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0
// Figure out take profit price
longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)

// Determine stop loss price
longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)


// ********** Supporting functions - End **********


// ********** Strategy - Start **********
// See if intraday session is active
bool intradaySession = true

// Trade only if intraday session is active

//=================Strategy logic goes in here===========================
 

MFI=mfi(close,i_MFI)
barsize=high-low
barbodysize=close>open?(open-close)*-1:(open-close)
shortwicksbar=barbodysize>barsize*barsizeThreshold
SMA=sma(close, i_MALen)
MAFilter=close > SMA



BUY = MFI[1] == OB and close > open and shortwicksbar and (i_MAFilter ? MAFilter : true)

SELL = MFI[1] == OS and close < open and shortwicksbar and (i_MAFilter ? not MAFilter : true) 

//Final Long/Short Condition
longCondition = BUY
shortCondition = SELL
 
//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
    stop_level = longStopPrice
    profit_level = longExitPrice
    strategy.entry("Buy", strategy.long)
    strategy.exit("TP/SL", "Buy", stop=stop_level, limit=profit_level)


//Short Strategy - sell condition and exits with Take profit and SL
if (shortCondition and intradaySession)
    stop_level = shortStopPrice
    profit_level = shortExitPrice
    strategy.entry("Sell", strategy.short)
    strategy.exit("TP/SL", "Sell", stop=stop_level, limit=profit_level)
 
 
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")

// ********** Strategy - End **********