
離離マトリックスのトレンドフォロー戦略は,トレンド,離離と均線を組み合わせた量化取引戦略である.この戦略は,二重RSI指標を使用して市場の傾向の方向を判断し,マトリックスの均線と組み合わせてエントリーシグナルを設定する.マトリックスの均線は,価格の離離程度に応じてポジションの位尺を調整する.全体的に,この戦略の優点は,複数の指標を使用して取引シグナルを確認することで,偽突破を効果的に回避でき,同時に,マトリックスの均線機構は,より高い収益をロックすることができます.
離子行列のトレンドフォロー戦略は主に以下の部分で構成されています.
急速RSIと遅いRSIを使用して市場のトレンド方向を判断する. 急速RSIが超買いまたは超売れるとき,遅いRSIと組み合わせてトレンド方向を判断する.
入場価格に応じてマトリックス平均線をセットし,価格が一定の平均線に触れたときに,それに応じてポジションを調整する.
デフォルトで二方向取引. 余分な取引のみを選択できます.
取引の論理は以下の通りです.
市場が一時的に過買過売している状況を判断するために,速度のRSIを使用します.
RSIは,市場の中長期のトレンド方向を判断するために,ゆっくりとしたRSIを使用します.
急速RSIが超買い超売りを示し,緩慢RSIがトレンド転換を示しているとき,緩慢RSIの多空判断に基づいて,対応する方向のポジションを行う.
倉庫を建てた後,一組のマトリックス平均線を設定する.このマトリックス平均線は,入場価格設定の周りにあり,間隔の大きさはマトリックス区間の百分パラメータによって設定される.
価格がマトリックス平均線に触れたとき,それに応じて保有量を調整する.平均線を上方突破すると,多項を増加させ,下方突破すると,空券を減少させる.
価格が大きく調整された場合,ポジションは初期レベルに戻されます.
この戦略の主要な取引論理は, 上の通りです. 矩陣平均線を介して, 傾向の中でより多くの利益をロックすることができます.
離散行列のトレンドフォロー戦略には以下の利点があります.
双RSI判断信号はより信頼性が高い。急速RSIは偽突破を避け,遅いRSIは大きなトレンドを正しく確保する。
マトリックスの平均線はトレンドを追跡して利益を得る.価格離散度に応じてポジションを調整し,継続的に利益を得る.
双方向取引をサポートします. 既定の双方向取引は,より多く行うことができます. より多くの市場環境に対応できます.
ポジション再設定メカニズム リスク制御 価格が明らかに調整されたときにポジションを再設定し,損失を間に合うように止めてください
パラメータ設定の柔軟性 ユーザは,歴史データ,取引品種などに基づいて最適なパラメータ組み合わせを選択できます.
コード構造が明確.各部門の責任が明確に区分され,理解,最適化,拡張が容易である.
全体として,この戦略の最大の利点は,複数のメカニズムを利用して信号の質を向上させ,リスクをコントロールしながら,より高い収益を追求することにある. これは,リスクと収益のバランスを取った取引戦略である.
脱離マトリックスのトレンドフォロー戦略にはいくつかのリスクがあります.
双RSIは失敗のリスクを判断する. 市場は震動の調整中にいる時,RSIはしばしば偽信号を発する. このとき,試行錯誤,適切なパラメータの調整,または取引の停止が必要である.
マトリックス均線方式は不適切なリスクである.マトリックスパラメータが正しく設定されていない場合,ポジションの調整は過度に激化し,損失を増加させる可能性がある.パラメータを慎重にテストする必要があります.
ポジションを過剰に拡大するリスク.ポジション幅を過剰に調整することは,損失の拡大にもつながる.最大ポジションパラメータは慎重に設定する必要があります.
トレンド反転リスク. トレンドが反転したとき,早期に平仓しなければ,大きな損失に直面する. これは,より長い周期のトレンド指標に注目する必要があります.
コード最適化スペースの限られたリスク。この戦略は比較的成熟しており,引き続き最適化スペースの限られた。市場環境が大きく変化した場合,全体的な取引論理は再評価する必要がある。
戦略の評価と最適化は,これらのリスクを低減する鍵である.パラメータの組み合わせの調整,より長い周期の指標の監視などの手段は,ある程度リスクを回避することができます.
離散行列のトレンドは,この戦略をさらに最適化する余地があります.
二重RSIパラメータを最適化します.より多くのパラメータの組み合わせをテストして,最も正確なRSI周期数値を判断することができます.
カスタム行列均線設定 ◎ ユーザが異なる品種のパラメータ化により行列均線パラメータを設定し,その品種の特性に適したものにします.
ストップ・メカニズムを増やす.例えば,出場平均線を設定し,価格がその平均線を下回るとストップ・ストップする.
ポジションの比率ルールを増やす.より科学的にポジションの規模と速度を合理的に調整し,ポジションの過剰拡大を防止する.
他の指標と組み合わせて.MACD,KDなどの他の指標を補助判断のために導入し,信号の正確性を向上させることができる.
コード構造の最適化. 拡張性,維持性,実行効率の改善を継続する.
離散行列トレンドフォロー戦略は,複数のメカニズムを統合した量化取引戦略である.これは,主に双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')