
Chiến lược này là một hệ thống giao dịch tự điều chỉnh kết hợp các chỉ số biến động và động lực để nắm bắt xu hướng thị trường thông qua sự phối hợp phối hợp của nhiều chỉ số kỹ thuật. Chiến lược sử dụng chỉ số ATR để giám sát biến động thị trường, MACD để đánh giá động lực xu hướng, đồng thời kết hợp với chỉ số động lực giá để xác nhận tín hiệu giao dịch và thiết lập cơ chế dừng lỗ linh hoạt. Hệ thống có khả năng thích ứng mạnh mẽ, có thể tự động điều chỉnh tần số giao dịch và kiểm soát vị trí tùy theo tình trạng thị trường.
Chiến lược này dựa chủ yếu vào hệ thống ba chỉ số như logic giao dịch cốt lõi: đầu tiên sử dụng ATR để đo lường tình trạng biến động của thị trường, cung cấp tham chiếu biến động cho các quyết định giao dịch; thứ hai sử dụng các chỉ số MACD để bắt điểm biến động xu hướng, giao thoa của MACD đường nhanh và đường chậm được sử dụng làm tín hiệu kích hoạt giao dịch chính; thứ ba kiểm chứng lại sử dụng chỉ số động lượng giá để xác nhận cường độ xu hướng bằng cách quan sát sự thay đổi của giá so với thời gian trước. Hệ thống cũng thêm đường trung bình 50 ngày làm bộ lọc xu hướng, chỉ khi giá trên đường trung bình được phép làm nhiều, ngược lại được phép làm nhiều. Để tránh giao dịch quá mức, chiến lược đã thiết lập khoảng cách giao dịch tối thiểu và có thể chọn thực hiện tín hiệu thay thế.
Chiến lược này là một hệ thống giao dịch định lượng được thiết kế hợp lý, logic nghiêm ngặt, thông qua việc sử dụng kết hợp nhiều chỉ số kỹ thuật, để nắm bắt hiệu quả các xu hướng thị trường. Hệ thống được xem xét kỹ lưỡng về kiểm soát rủi ro và thực hiện giao dịch, có tính thực tế tốt. Mặc dù có một số rủi ro tiềm ẩn, nhưng với hướng tối ưu hóa được đề xuất, sự ổn định và lợi nhuận của chiến lược có thể được nâng cao hơn nữa.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("[ETH] Volatility & Momentum Adaptive Strategy", shorttitle="Definitive 1 day Ethereum Signal", overlay=true, initial_capital=10000, currency=currency.USD)
// === Input Parameters === //
trade_size = input.float(5, title="Trade Size (ETH)")
atr_length = input.int(8, minval=1, title="ATR Length")
macd_fast = input.int(8, minval=1, title="MACD Fast Length")
macd_slow = input.int(7, minval=1, title="MACD Slow Length")
macd_signal = input.int(9, minval=1, title="MACD Signal Length")
momentum_length = input.int(37, title="Momentum Length")
stop_loss_percent = input.float(9.9, title="Stop Loss Percentage (%)")
take_profit_percent = input.float(9.0, title="Take Profit Percentage (%)")
alternate_signal = input.bool(true, title="Alternate Buy/Sell Signals")
// === Indicators === //
// ATR to measure volatility
atr = ta.atr(atr_length)
// MACD for trend momentum
[macd_line, signal_line, _] = ta.macd(close, macd_fast, macd_slow, macd_signal)
macd_cross_up = ta.crossover(macd_line, signal_line)
macd_cross_down = ta.crossunder(macd_line, signal_line)
// Momentum
momentum = ta.mom(close, momentum_length)
// === Signal Control Variables === //
var bool last_signal_long = na
var int last_trade_bar = na
min_bars_between_trades = 5 // Adjust for minimal trade frequency control
time_elapsed = na(last_trade_bar) or (bar_index - last_trade_bar) >= min_bars_between_trades
// === Buy and Sell Conditions === //
// Buy when:
buy_signal = (macd_cross_up and momentum > 0 and close > ta.sma(close, 50) and time_elapsed)
// Sell when:
sell_signal = (macd_cross_down and momentum < 0 and close < ta.sma(close, 50) and time_elapsed)
// Enforce alternate signals if selected
if alternate_signal
buy_signal := buy_signal and (na(last_signal_long) or not last_signal_long)
sell_signal := sell_signal and (not na(last_signal_long) and last_signal_long)
// === Trade Execution === //
// Buy Position
if (buy_signal)
if strategy.position_size < 0
strategy.close("Short")
strategy.entry("Long", strategy.long, qty=trade_size)
last_signal_long := true
last_trade_bar := bar_index
// Sell Position
if (sell_signal)
if strategy.position_size > 0
strategy.close("Long")
strategy.entry("Short", strategy.short, qty=trade_size)
last_signal_long := false
last_trade_bar := bar_index
// === Stop Loss and Take Profit === //
if strategy.position_size > 0
long_take_profit = strategy.position_avg_price * (1 + take_profit_percent / 100)
long_stop_loss = strategy.position_avg_price * (1 - stop_loss_percent / 100)
strategy.exit("TP/SL Long", from_entry="Long", limit=long_take_profit, stop=long_stop_loss)
if strategy.position_size < 0
short_take_profit = strategy.position_avg_price * (1 - take_profit_percent / 100)
short_stop_loss = strategy.position_avg_price * (1 + stop_loss_percent / 100)
strategy.exit("TP/SL Short", from_entry="Short", limit=short_take_profit, stop=short_stop_loss)
// === Visual Signals === //
plotshape(series=buy_signal and time_elapsed, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sell_signal and time_elapsed, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")