
Chiến lược này là một hệ thống giao dịch thích ứng tích hợp nhiều chỉ báo phân tích kỹ thuật và chuyển đổi giữa các chiến lược giao dịch khác nhau bằng cách xác định động các điều kiện thị trường. Hệ thống chủ yếu dựa trên ba chỉ báo kỹ thuật: đường trung bình động (MA), Dải Bollinger (BB) và Chỉ số sức mạnh tương đối (RSI), tự động lựa chọn phương pháp giao dịch phù hợp nhất theo xu hướng thị trường và biến động phạm vi. Chiến lược này áp dụng các giải pháp quản lý rủi ro khác biệt cho thị trường xu hướng và phạm vi bằng cách thiết lập các thông số chốt lời và dừng lỗ khác nhau.
Chiến lược này sử dụng đường trung bình động 50 kỳ và 20 kỳ để xác định xu hướng thị trường và kết hợp dải Bollinger và chỉ báo RSI để xác định vùng quá mua và quá bán. Trong một thị trường có xu hướng, hệ thống giao dịch chủ yếu dựa trên mối quan hệ giữa giá và đường trung bình động chậm và sự giao nhau của các đường nhanh và chậm; trong một thị trường phạm vi, nó giao dịch chủ yếu dựa trên sự đột phá ranh giới của Dải Bollinger và các tín hiệu mua quá mức và bán quá mức của RSI . Hệ thống tự động điều chỉnh mức chốt lời theo môi trường thị trường. Mức chốt lời 6% được sử dụng cho thị trường có xu hướng và mức chốt lời 4% được sử dụng cho thị trường phạm vi. Mức dừng lỗ 2% được sử dụng đồng đều để kiểm soát rủi ro.
Chiến lược này tích hợp nhiều chỉ báo kỹ thuật cổ điển để xây dựng một hệ thống giao dịch có khả năng thích ứng với nhiều môi trường thị trường khác nhau. Trong khi vẫn giữ cho hoạt động đơn giản, hệ thống thực hiện nhận dạng động trạng thái thị trường và tự động chuyển đổi chiến lược giao dịch, có tính thực tiễn cao. Thông qua các thiết lập chốt lời và dừng lỗ khác biệt, chiến lược này duy trì lợi nhuận tốt trong khi vẫn kiểm soát được rủi ro. Trong tương lai, tính ổn định và độ tin cậy của chiến lược có thể được cải thiện hơn nữa bằng cách đưa ra nhiều chỉ số kỹ thuật hơn và tối ưu hóa cơ chế điều chỉnh tham số.
/*backtest
start: 2024-01-17 00:00:00
end: 2025-01-16 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=6
strategy("Supply & Demand Test 1 - Enhanced", overlay=true)
// Inputs
ma_length = input.int(50, title="50-period Moving Average Length", minval=1)
ma_length_fast = input.int(20, title="20-period Moving Average Length", minval=1)
bb_length = input.int(20, title="Bollinger Bands Length", minval=1)
bb_std_dev = input.float(2.0, title="Bollinger Bands Std Dev", step=0.1)
rsi_length = input.int(14, title="RSI Length", minval=1)
stop_loss_percent = input.float(0.02, title="Stop Loss Percent", step=0.001, minval=0.001)
take_profit_trend = input.float(0.06, title="Take Profit Percent (Trend)", step=0.001, minval=0.001)
take_profit_range = input.float(0.04, title="Take Profit Percent (Range)", step=0.001, minval=0.001)
// Moving Averages
ma_slow = ta.sma(close, ma_length)
ma_fast = ta.sma(close, ma_length_fast)
// Bollinger Bands
bb_basis = ta.sma(close, bb_length)
bb_dev = ta.stdev(close, bb_length)
bb_upper = bb_basis + bb_std_dev * bb_dev
bb_lower = bb_basis - bb_std_dev * bb_dev
// RSI
rsi = ta.rsi(close, rsi_length)
// Market Conditions
is_trending_up = close > ma_slow
is_trending_down = close < ma_slow
is_range_bound = not (is_trending_up or is_trending_down)
// Entry Conditions
long_trend_entry = is_trending_up and close >= ma_slow * 1.02
short_trend_entry = is_trending_down and close <= ma_slow * 0.98
long_ma_crossover = ta.crossover(ma_fast, ma_slow)
short_ma_crossover = ta.crossunder(ma_fast, ma_slow)
long_range_entry = is_range_bound and close <= bb_lower * 0.97
short_range_entry = is_range_bound and close >= bb_upper * 1.03
long_rsi_entry = is_range_bound and rsi < 30
short_rsi_entry = is_range_bound and rsi > 70
// Entry and Exit Logic
if long_trend_entry
strategy.entry("Long Trend", strategy.long)
strategy.exit("Exit Long Trend", from_entry="Long Trend", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))
alert("Entered Long Trend", alert.freq_once_per_bar)
if short_trend_entry
strategy.entry("Short Trend", strategy.short)
strategy.exit("Exit Short Trend", from_entry="Short Trend", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))
alert("Entered Short Trend", alert.freq_once_per_bar)
if long_ma_crossover
strategy.entry("Long MA Crossover", strategy.long)
strategy.exit("Exit Long MA Crossover", from_entry="Long MA Crossover", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))
alert("Entered Long MA Crossover", alert.freq_once_per_bar)
if short_ma_crossover
strategy.entry("Short MA Crossover", strategy.short)
strategy.exit("Exit Short MA Crossover", from_entry="Short MA Crossover", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))
alert("Entered Short MA Crossover", alert.freq_once_per_bar)
if long_range_entry
strategy.entry("Long Range", strategy.long)
strategy.exit("Exit Long Range", from_entry="Long Range", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))
alert("Entered Long Range", alert.freq_once_per_bar)
if short_range_entry
strategy.entry("Short Range", strategy.short)
strategy.exit("Exit Short Range", from_entry="Short Range", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))
alert("Entered Short Range", alert.freq_once_per_bar)
if long_rsi_entry
strategy.entry("Long RSI", strategy.long)
strategy.exit("Exit Long RSI", from_entry="Long RSI", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))
alert("Entered Long RSI", alert.freq_once_per_bar)
if short_rsi_entry
strategy.entry("Short RSI", strategy.short)
strategy.exit("Exit Short RSI", from_entry="Short RSI", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))
alert("Entered Short RSI", alert.freq_once_per_bar)
// Plotting
plot(ma_slow, color=color.blue, title="50-period MA")
plot(ma_fast, color=color.orange, title="20-period MA")
plot(bb_upper, color=color.red, title="Bollinger Upper")
plot(bb_lower, color=color.green, title="Bollinger Lower")
plot(bb_basis, color=color.gray, title="Bollinger Basis")
hline(70, "Overbought (RSI)", color=color.red, linestyle=hline.style_dotted)
hline(30, "Oversold (RSI)", color=color.green, linestyle=hline.style_dotted)