
Chiến lược này là hệ thống giao dịch siêu xu hướng thích ứng dựa trên máy học. Nó cải thiện độ tin cậy của các chỉ báo SuperTrend truyền thống bằng cách tích hợp cụm biến động, phát hiện xu hướng ATR thích ứng và cơ chế vào và ra có cấu trúc. Cốt lõi của chiến lược này là phân loại sự biến động của thị trường thông qua các phương pháp học máy, thực hiện các giao dịch theo dõi xu hướng trong môi trường thị trường phù hợp và sử dụng lệnh dừng lỗ và chốt lời động để kiểm soát rủi ro.
Chiến lược bao gồm ba thành phần chính: 1) Tính toán SuperTrend thích ứng dựa trên ATR để xác định hướng xu hướng và điểm ngoặt; 2) Phân cụm biến động dựa trên thuật toán K-means để phân loại trạng thái thị trường thành ba loại: cao, trung bình và thấp. môi trường biến động ; 3) các quy tắc giao dịch khác nhau dựa trên môi trường biến động. Tìm kiếm cơ hội xu hướng trong môi trường biến động thấp và thận trọng trong môi trường biến động cao. Hệ thống nắm bắt các tín hiệu đảo ngược xu hướng thông qua các hàm ta.crossunder và ta.crossover, và xác định hướng giao dịch dựa trên mối quan hệ vị trí giữa giá và đường SuperTrend.
Chiến lược này tạo ra một hệ thống thông minh theo dõi xu hướng bằng cách kết hợp các kỹ thuật học máy với các phương pháp phân tích kỹ thuật truyền thống. Ưu điểm cốt lõi của chiến lược này nằm ở khả năng thích ứng và kiểm soát rủi ro, cho phép xác định thông minh các điều kiện thị trường thông qua nhóm biến động. Mặc dù có những rủi ro như độ nhạy của tham số, thông qua quá trình tối ưu hóa và cải tiến liên tục, chiến lược này dự kiến sẽ duy trì hiệu suất ổn định trong nhiều môi trường thị trường khác nhau. Các nhà giao dịch nên kiểm tra đầy đủ độ nhạy của tham số khi áp dụng theo thời gian thực và thực hiện tối ưu hóa có mục tiêu dựa trên các đặc điểm cụ thể của thị trường.
/*backtest
start: 2025-01-09 00:00:00
end: 2025-01-16 00:00:00
period: 10m
basePeriod: 10m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("Adaptive SuperTrend Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// Import Indicator Components
atr_len = input.int(10, "ATR Length", group="SuperTrend Settings")
fact = input.float(3, "SuperTrend Factor", group="SuperTrend Settings")
training_data_period = input.int(100, "Training Data Length", group="K-Means Settings")
// Volatility Clustering
volatility = ta.atr(atr_len)
upper = ta.highest(volatility, training_data_period)
lower = ta.lowest(volatility, training_data_period)
high_volatility = lower + (upper-lower) * 0.75
medium_volatility = lower + (upper-lower) * 0.5
low_volatility = lower + (upper-lower) * 0.25
cluster = volatility >= high_volatility ? 0 : volatility >= medium_volatility ? 1 : 2
// SuperTrend Calculation
pine_supertrend(factor, atr) =>
src = hl2
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
int _direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
_direction := 1
else if prevSuperTrend == prevUpperBand
_direction := close > upperBand ? -1 : 1
else
_direction := close < lowerBand ? 1 : -1
superTrend := _direction == -1 ? lowerBand : upperBand
[superTrend, _direction]
[ST, dir] = pine_supertrend(fact, volatility)
// Entry Conditions
longEntry = ta.crossunder(dir, 0) and cluster > 1 and close > ST
shortEntry = ta.crossover(dir, 0) and cluster == 0 and close < ST
// Stop Loss & Take Profit
atr_mult = input.float(2, "ATR Multiplier for SL/TP", group="Risk Management")
sl = atr_mult * ta.atr(atr_len)
longStopLoss = close - sl
longTakeProfit = close + (sl * 1.5)
shortStopLoss = close + sl
shortTakeProfit = close - (sl * 1.5)
// Execute Trades
if longEntry
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit", from_entry="Long", limit=longTakeProfit, stop=longStopLoss)
if shortEntry
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit", from_entry="Short", limit=shortTakeProfit, stop=shortStopLoss)
// Plot SuperTrend
plot(ST, title="SuperTrend", color=dir > 0 ? color.green : color.red, linewidth=2)
// Alerts
alertcondition(longEntry, title="Long Entry Signal", message="Buy Signal - Trend Shift Up")
alertcondition(shortEntry, title="Short Entry Signal", message="Sell Signal - Trend Shift Down")