戦略をフォローするディバージェンツマトリックス傾向

作者: リン・ハーンチャオチャン開催日:2023年12月12日 17:05:27
タグ:

img

概要

格差マトリックストレンドフォロー戦略 (Divergence Matrix Trend Following Strategy) は,トレンド,格差,移動平均分析を組み合わせる定量的な取引戦略である.この戦略は,市場トレンド方向とマトリックス移動平均を判断するために二重RSI指標を使用し,エントリー信号を生成する.マトリックス移動平均は,価格格差の程度に基づいてポジションサイズを調整する.全体的に,この戦略の利点は複数の指標で取引信号を確認することであり,誤ったブレイクを効果的に回避できる.一方,マトリックスメカニズムはより高いリターンをロックすることができます.

戦略の論理

ダイバージェンスマトリックス トレンドフォロー戦略は以下の主要部分で構成されています.

  1. トレンド判断のための二重RSI

    市場トレンド方向を決定するために,高速RSIと遅いRSIを使用します.高速RSIが過買いまたは過売りレベルを示すとき,トレンド方向のために遅いRSIを確認します.

  2. トレーディング・シグナルのためのマトリックス移動平均値

    入場価格に基づいてマトリックス移動平均値のグループを設定します.価格が移動平均線に触ると,それに応じてポジションを調整します. これにより,トレンドでより多くの利益を得ることができます.

  3. 双方向取引

    デフォルトは双方向取引です 長期取引だけを選択できます

具体的な取引論理は:

  1. 市場での一時的な買い過ぎ/売り過ぎのレベルを特定するために,速いRSIを使用します.

  2. 市場の中期から長期間のトレンド方向を決定するために,ゆっくりとしたRSIを使用します.

  3. 急速なRSIが極端を示し,遅いRSIがトレンド逆転をシグナルすると,遅いRSIによる長/短トレンドに基づいてポジションを取ります.

  4. ポジションを入力した後,行列移動平均のグループを設定します.これらの行列線はエントリー価格を中心に設定され,間隔サイズは,行列間隔 % パラメータで定義されます.

  5. 価格がマトリックス線に触れたとき,その順にポジションサイズを調整します.例えば,上向きブレイクでロングを増加させ,下向きブレイクでショートを削減します.

  6. 価格が大きく調整されると ポジションは元のレベルに戻ります

上記は,この戦略の主な取引論理を記述しています.マトリックスメカニズムにより,より多くのトレンド利益がロックされます.

利点

ダイバージェンスマトリックストレンドフォロー戦略には以下の利点があります.

  1. ダブルRSI信号はより信頼性があります.高速RSIは誤ったブレイクを避け,遅いRSIは主要なトレンドが正しいことを保証します.

  2. マトリックス移動平均は,トレンドから利益を得ます.価格差異に基づいてポジションサイズを調整することで,持続的な利益が捕獲できます.

  3. 双方向取引をサポートします.デフォルトは双方向取引ですが,また,長期間のみに行うことができます.これはより多くの市場環境に適応します.

  4. ポジションリセットメカニズムはリスクを制御する.価格が大きな調整を見るときのポジションリセットは,タイムリーストップ損失を可能にします.

  5. フレキシブルなパラメータ設定.ユーザーは,過去のデータ,取引機器などに基づいて最適なパラメータ組み合わせを選択できます.

  6. 責任の明確な分離により,コードを理解し,最適化し,拡張することが容易になります.

要約すると,この戦略の最大の利点は,複数のメカニズムを通じて信号品質を改善し,同時に制御されたリスク下でより高い収益を追求することです.これはリスクと報酬をバランスする戦略です.

リスク

ダイバージェンスマトリックストレンドフォロー戦略には,主に次の分野において,いくつかのリスクがあります.

  1. 二重RSI信号の失敗リスク.市場が範囲に制限されているとき,RSIはしばしば誤った信号を与える.パラメータを調整または取引を停止するために手動介入が必要です.

  2. 不適切なマトリックス移動平均リスク.マトリックスパラメータが正しく設定されていない場合,位置調整はあまりにも攻撃的になり,損失を拡大する可能性があります.保守的なパラメータテストは必須です.

  3. 過剰にレバレッジされたポジションのリスク 過剰なポジションサイズ調整も損失を拡大させる.最大ポジションサイズパラメータは慎重に設定する必要があります.

  4. トレンド逆転リスク. トレンド逆転時に迅速にポジションを閉めなければ,大きな損失が発生する可能性があります.これは長期的トレンド指標の監視を必要とします.

  5. 限られた最適化空間リスク.この戦略は既にかなり成熟している.継続的な最適化の可能性は限られている.市場の体制が劇的に変化した場合,主要なアップグレードが必要になる可能性があります.

戦略の評価と最適化は,これらのリスクを軽減する鍵です.パラメータを調整し,長期指標を監視し,リスクを一定程度軽減することができます.

増進 の 機会

格差マトリックストレンドをさらに強化する余地がある.

  1. 2つのRSIパラメータを最適化します.より多くのパラメータの組み合わせをテストし,最も正確なRSI期間を選択します.

  2. カスタマイズ可能なマトリックスライン.ユーザが異なる機器に基づいてマトリックス設定をパラメータ化し,その特性に適するようにする.

  3. ストップ・ロスのメカニズムを追加します.例えば,価格がそのラインを突破した場合のポジションをストップする出口ラインを設定します.

  4. より科学的なポジションサイズルールを追加し,過剰なレバレッジを防ぐために,ポジションサイズ調整をより段階的に管理する.

  5. 他の指標を組み込む.信号の正確性を向上させるためにMACD,KDなど,追加の指標を導入する.

  6. コード構造を最適化する.さらに拡張性,維持性,実行効率を向上させる.

結論

ダイバージェンスマトリックストレンドフォロー戦略は,複数のメカニズムを組み合わせた洗練された定量的な取引戦略である.トレンド方向とトレンドから利益を得るためにマトリックスラインの二重RSIを使用する.単一指標戦略と比較して,より安定し効率的な取引信号を提供します.パラメータチューニングと最適化拡張により,この戦略はより多くの市場条件と体制に適応することができ,非常に汎用的です.全体として,この戦略はリスクとリターンとの間に良いバランスを保ち,投資家の積極的な適用と継続的な強化に値します.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-10-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("The Matrix 7.0 Strategy", overlay=false)

//Matrix Settings 
entry_size = input(title="Entry Size", defval = 1)
max_size = input(title="Max Size", defval = 10000)
matrix = input(title="Matrix Interval %", defval = 2)
matrix_price_overwrite = input(title="Matrix Overwrite $", defval = 0.0)
adjustment = input(title="Adjustment Size", defval = 1000)
trade_short = input(title="Trade Short", type=bool, defval = true)

//RSI Settings
periods = input(title="RSI Periods", defval = 14)
overbought_short = input(title="RSI Overbought", defval = 65)
oversold_short = input(title="RSI Oversold", defval = 30)

//RSI Trend Settings
resolution_long = input(title="Resolution Trend", defval = "D")
periods_long = input(title="RSI Trend Periods", defval = 14)
overbought_long = input(title="RSI Trend Overbought", defval = 64)
oversold_long = input(title="RSI Trend Oversold", defval = 30)

//Round Off to 2 decimals
round2(x) =>
    a = x * 10 * 10
    a := floor(a + 0.5)
    a := a / 10 / 10
    a

//RSI Function
RSI = rsi(close, periods)

//RSI Market Function
rsi_oversold = RSI < oversold_short
rsi_overbought = RSI > overbought_short

market_rsi = 0.0
market_rsi := if (rsi_oversold)
    RSI - oversold_short
else
    if (rsi_overbought)
        RSI - overbought_short
    else
        0

//RSI Trend Function
rsi_long = request.security(syminfo.tickerid,resolution_long,rsi(close,periods_long))
trend_rsi_long = rsi_long < oversold_long
trend_rsi_short = rsi_long > overbought_long
trend_rsi = 0
trend_rsi := if (trend_rsi_short)
    -1
else
    if (trend_rsi_long)
        1
    else
        trend_rsi[1] 

// // Shorter time resolution to make "close" crosses give faster positives.
// short_resolution = security(tickerid, "1", close)
// quick = round2(short_resolution) //ROUND OFF TO 2 DECIMAL PLACES.

//Declare Other Variables
entry_price = 0.0
entry_price := nz(entry_price[1])

position_size = 0.0
position_size := nz(position_size[1])

last_traded_price = 0.0
last_traded_price := nz(last_traded_price[1])


matrix_price = 0.0
if matrix_price_overwrite > 0.0
    matrix_price := matrix_price_overwrite
else
    matrix_price := round2((matrix/100) * entry_price)

level = 0
level := nz(level[1])

level_price = entry_price
if not na(level_price[1])
    level_price := level_price[1]

// Calculate Level
if close > level_price 
    level_change = floor((high - level_price)/matrix_price)
    level := level + level_change
else
    if close < level_price 
        level_change = ceil((low - level_price)/matrix_price)
        level := level + level_change
        
// Calculate Level Price   
level_price := (level * matrix_price) + entry_price

// Calculate Matrix Position
matrix_position = 0.0

if position_size > 0
    matrix_position :=  ((-1 * level) * adjustment) + entry_size
else
    if position_size < 0
        matrix_position :=  ((-1 * level) * adjustment) - entry_size
    
//Trend Entry or Reversal Conditions
trend_reversal_up = trend_rsi == 1 and (trend_rsi[1] == -1 or trend_rsi == 0) and position_size <= 0
trend_reversal_down = trend_rsi == -1 and (trend_rsi[1] == 1 or trend_rsi == 0) and position_size >= 0 and trade_short == true
flatten_position = trend_rsi == -1 and (trend_rsi[1] == 1 or trend_rsi == 0) and position_size >= 0 and trade_short == false

//Reset Conditions
reset_long = (position_size > 0) and (close - entry_price > matrix_price) and (market_rsi < 0) and (position_size != entry_size) 
reset_short = (position_size < 0) and (entry_price - close > matrix_price) and (market_rsi > 0) and (position_size != (-1 * entry_size)) 

//Adjustment Conditions
increase_long = (position_size > 0) and (matrix_position > position_size) and (market_rsi < 0) and (matrix_position <= max_size) 
decrease_long = (position_size > 0) and (matrix_position < position_size) and (market_rsi > 0) 
increase_short = (position_size < 0) and (matrix_position < position_size) and (market_rsi > 0) and (matrix_position >= (-1 * max_size)) 
decrease_short = (position_size < 0) and (matrix_position > position_size) and (market_rsi < 0)  

//Transactions
//Trend Reversals
if trend_reversal_up
    strategy.entry("OL", strategy.long, qty=entry_size)
    position_size := entry_size
    matrix_position := entry_size
    level := 0
else
    if trend_reversal_down 
        strategy.entry("OS", strategy.short, qty=entry_size)
        position_size := -1 * entry_size
        matrix_position := -1 * entry_size   
        level := 0
        
    //Reset Positions    
    else
        if reset_long
            order = entry_size - position_size[1]
            strategy.order("RL", strategy.long, qty=order)
            position_size := entry_size
            matrix_position := entry_size
            level := 0
        else
            if reset_short
                order = position_size[1] - (-1* entry_size)
                strategy.order("RS", strategy.short, qty=order)
                position_size := -1 * entry_size
                matrix_position := -1 * entry_size
                level := 0

    //Position Adjustments
            else    
                if increase_long
                    order = matrix_position - position_size[1]
                    strategy.order("IL", strategy.long, qty=order)
                    position_size := position_size[1] + order
                else
                    if decrease_long
                        order = position_size[1] - matrix_position
                        strategy.order("DL", strategy.short, qty=order)
                        position_size := position_size[1] - order
                    else
                        if increase_short
                            order = position_size[1] - matrix_position
                            strategy.order("IS", strategy.short, qty=order)
                            position_size := position_size[1] - order
                        else
                            if decrease_short
                                order = matrix_position - position_size[1]
                                strategy.order("DS", strategy.long, qty=order)
                                position_size := position_size[1] + order
                            else 
                                if flatten_position
                                    strategy.close_all()
                                    position_size := 0.0
                                    matrix_position := 0.0
                                    level := 0

//Grouped Actions
if trend_reversal_up or trend_reversal_down or reset_short or reset_long
    entry_price := round2(close)
    last_traded_price := round2(close)

if increase_long or decrease_long or increase_short or decrease_short
    last_traded_price := round2(close)

// //RSI Trend & Adjustment Moments. (strategy)
p1 = plot(market_rsi, color = trend_rsi > 0 ? green : red, linewidth = 4, title='Market', transp =0)
p2 = plot(trend_rsi, color = trend_rsi > 0 ? green : red, linewidth = 4, title='Trend', transp = 0)
fill(p1,p2, color=trend_rsi > 0 ? green : red, transp=0)
p3 = plot((rsi_long - 50) *2, color = white, title="Trend Index")
fill(p2,p3, color=white)
hline((overbought_long -50) * 2)
hline((oversold_long -50) * 2)

//Position Plots (strategy)
plot(matrix_position / 100, title='Matrix', color=white, linewidth = 4)
plot(position_size / 100, title='Position', color=blue, linewidth = 4)
plot(strategy.position_size / 100, title='Strategy', color=orange, linewidth = 4)

// //Price Plots (study)
// plot(level_price, title="Matrix Level Price", linewidth=4)
// plot(last_traded_price, title="Last Traded Price", linewidth=2, color=orange)
// plot(entry_price + (4 * matrix_price), title='Adjustment 4', color=white, linewidth = 1)
// plot(entry_price + (3 * matrix_price), title='Adjustment 3', color=white, linewidth = 1)
// plot(entry_price + (2 * matrix_price), title='Adjustment 2', color=white, linewidth = 1)
// plot(entry_price + matrix_price, title='Adjustment 1', color=white, linewidth = 1)
// plot(entry_price, title='Entry Price', color=white, linewidth = 3)
// plot(entry_price - matrix_price, title='Adjustment -1', color=white, linewidth = 1)
// plot(entry_price - (2 * matrix_price), title='Adjustment -2', color=white, linewidth = 1)
// plot(entry_price - (3 * matrix_price), title='Adjustment -3', color=white, linewidth = 1)
// plot(entry_price - (4 * matrix_price), title='Adjustment -4', color=white, linewidth = 1)


// //Alerts (study only)
// alertcondition(trend_reversal_up, title='Trend Reversal Up', message='Market Oversold, Lets Buy')
// alertcondition(trend_reversal_down, title='Trend Reversal Down', message='Market Overbought, Lets Sell')
// alertcondition(reset_long, title='Reset Long', message='Higher Bottom, Lets Buy')
// alertcondition(reset_short, title='Reset Short', message='Lower Top, Lets Sell')
// alertcondition(increase_long, title='Increase Long', message='Price Dropped, Lets Buy')
// alertcondition(decrease_long, title='Decrease Long', message='Price Spiked, Lets Sell')
// alertcondition(increase_short, title='Increase Short', message='Price Spiked, Lets Sell')
// alertcondition(decrease_short, title='Decrease Short', message='Price Dropped, Lets Buy')

// //Grouped Conditions
// condition_buy = trend_reversal_up or increase_long or decrease_short or reset_long
// condition_sell = trend_reversal_down or decrease_long or increase_short or reset_short
// adjustment_matrix = trend_reversal_up or increase_long or decrease_short or trend_reversal_down or decrease_long or increase_short or reset_long or reset_short

// //Grouped Alerts
// alertcondition(condition_buy, title='Condition Buy', message='You Need to Buy')
// alertcondition(condition_sell, title='Condition Sell', message='You Need to Sell!')
// alertcondition(adjustment_matrix, title='Adjustment Matrix', message='You Need to Adjust')



もっと