
Chiến lược theo dõi xu hướng ma trận ly khai là một chiến lược giao dịch định lượng kết hợp xu hướng, ly khai và đường trung bình. Chiến lược này sử dụng chỉ số RSI kép để xác định xu hướng thị trường, kết hợp với đường trung bình ma trận để thiết lập tín hiệu nhập cảnh.
Chiến lược theo dõi xu hướng của ma trận ly khai bao gồm:
Sử dụng RSI nhanh và RSI chậm để xác định xu hướng thị trường. Khi RSI nhanh xuất hiện quá mua hoặc quá bán, kết hợp với RSI chậm để xác định xu hướng.
Thiết lập một tập hợp các đường trung bình ma trận theo giá nhập, điều chỉnh vị trí khi giá chạm vào một đường trung bình. Như vậy, bạn có thể kiếm được nhiều lợi nhuận hơn trong xu hướng.
Định nghĩa mặc định là giao dịch hai chiều.
Các giao dịch được thực hiện theo các logic sau:
Sử dụng RSI nhanh để đánh giá tình trạng mua quá mức tạm thời trên thị trường.
Sử dụng RSI chậm để đánh giá xu hướng trung và dài hạn của thị trường.
Khi RSI nhanh xuất hiện quá mua quá bán, và RSI chậm cho thấy xu hướng đảo ngược, hãy đặt vị trí tương ứng theo phán quyết của RSI chậm.
Sau khi xây dựng nhà kho, thiết lập một tập trung bình của ma trận. Bộ trung bình của ma trận xoay quanh thiết lập giá mua, kích thước khoảng cách được thiết lập bởi tham số tỷ lệ phần trăm của ma trận.
Khi giá chạm vào đường trung bình của ma trận, hãy điều chỉnh số lượng nắm giữ phù hợp. Nếu vượt qua đường trung bình, tăng thêm lệnh; Nếu giảm xuống, giảm lệnh trống.
Khi giá có sự điều chỉnh lớn, vị trí sẽ được đặt lại mức ban đầu.
Đây là logic giao dịch chính của chiến lược này. Bằng phương tiện ma trận, bạn có thể khóa nhiều lợi nhuận hơn trong xu hướng.
Các chiến lược theo xu hướng theo mảng phân cách có một số lợi thế sau:
Các tín hiệu đánh giá RSI kép là đáng tin cậy hơn. RSI nhanh tránh phá vỡ giả, RSI chậm đảm bảo xu hướng lớn là đúng.
Hình trục trung bình theo dõi xu hướng có lợi nhuận. Điều chỉnh vị trí tùy theo mức độ chênh lệch giá, có thể tiếp tục có lợi nhuận.
Hỗ trợ giao dịch hai chiều. Các giao dịch hai chiều mặc định cũng có thể được thực hiện nhiều hơn.
Cơ chế đặt lại vị trí kiểm soát rủi ro. Việc đặt lại vị trí khi có sự điều chỉnh rõ ràng về giá có thể dừng lỗ kịp thời.
Thiết lập tham số linh hoạt. Người dùng có thể chọn các tham số phù hợp nhất dựa trên dữ liệu lịch sử, loại giao dịch.
Cấu trúc mã rõ ràng. Các trách nhiệm được phân chia rõ ràng, dễ hiểu, tối ưu hóa và mở rộng.
Nhìn chung, lợi thế lớn nhất của chiến lược này là sử dụng nhiều cơ chế để nâng cao chất lượng tín hiệu, theo đuổi lợi nhuận cao hơn trong khi kiểm soát rủi ro. Đây là một chiến lược giao dịch cân bằng lợi nhuận rủi ro.
Các chiến lược theo xu hướng theo mô-tơ phân cách cũng có một số rủi ro, chủ yếu tập trung vào các điểm sau:
RSI đôi đánh giá rủi ro thất bại. RSI thường phát ra tín hiệu sai khi thị trường đang trong điều chỉnh chấn động.
Chế độ trục trặc của matrix không phù hợp với rủi ro. Nếu các tham số của matrix được thiết lập không đúng, điều chỉnh vị trí có thể quá quyết liệt, do đó làm tăng tổn thất. Cần kiểm tra các tham số một cách cẩn thận.
Chuyển vị trí quá mức làm tăng rủi ro. Điều chỉnh vị trí quá lớn cũng có thể dẫn đến tổn thất mở rộng.
Rủi ro thay đổi xu hướng. Khi xu hướng thay đổi, bạn sẽ phải đối mặt với tổn thất lớn hơn nếu bạn không xóa vị thế kịp thời. Điều này cần chú ý đến các chỉ số xu hướng có chu kỳ dài hơn.
Khoảng không gian tối ưu hóa mã hạn chế rủi ro. Chiến lược này đã khá trưởng thành và không gian tối ưu hóa tiếp tục là hạn chế. Nếu môi trường thị trường thay đổi lớn, logic giao dịch tổng thể cần được đánh giá lại.
Đánh giá và tối ưu hóa chiến lược là chìa khóa để giảm các rủi ro này. Các biện pháp như điều chỉnh các tham số, giám sát các chỉ số có chu kỳ dài hơn có thể tránh rủi ro ở một mức độ nào đó.
Có nhiều cách để tối ưu hóa chiến lược này:
Tối ưu hóa các tham số RSI kép. Bạn có thể thử nghiệm nhiều tổ hợp tham số hơn, chọn để xác định giá trị chu kỳ RSI chính xác nhất.
Cài đặt đường trục trục trục tùy chỉnh. Cho phép người dùng đặt các tham số đường trục trục trục trục theo các tham số khác nhau để phù hợp hơn với đặc điểm của giống đó.
Tăng cơ chế dừng lỗ. Ví dụ: thiết lập đường trung bình, dừng lỗ khi giá giảm xuống đường trung bình.
Tăng quy tắc tỷ lệ vị trí. Điều chỉnh quy mô và tốc độ vị trí một cách khoa học và hợp lý hơn, ngăn chặn vị trí tăng quá mức.
Kết hợp với các chỉ số khác. Các chỉ số khác như MACD, KD có thể được đưa vào để đánh giá hỗ trợ, nâng cao độ chính xác của tín hiệu.
Tối ưu hóa cấu trúc mã. Tiếp tục cải thiện khả năng mở rộng, bảo trì và hiệu quả thực thi của mã.
Chiến lược theo dõi xu hướng theo mảng phân tách là một chiến lược giao dịch định lượng đa cơ chế. Nó chủ yếu sử dụng phương pháp định hướng xu hướng theo xu hướng theo xu hướng theo mảng.
/*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')