
Chiến lược này là hệ thống giao dịch theo xu hướng kết hợp các tín hiệu giao cắt trung bình động với quản lý rủi ro ATR. Chiến lược này nắm bắt xu hướng thị trường thông qua sự giao nhau của đường trung bình động nhanh và chậm, đồng thời sử dụng chỉ báo ATR để điều chỉnh mức dừng lỗ và mức lợi nhuận một cách linh hoạt nhằm kiểm soát chính xác rủi ro giao dịch. Chiến lược này cũng bao gồm một mô-đun quản lý tiền tự động điều chỉnh quy mô vị thế dựa trên vốn chủ sở hữu của tài khoản và các thông số rủi ro được cài đặt trước.
Logic cốt lõi của chiến lược này dựa trên các thành phần chính sau:
Chiến lược này nắm bắt xu hướng thông qua đường trung bình động giao nhau và kết hợp với kiểm soát rủi ro động ATR để đạt được hệ thống giao dịch theo dõi xu hướng hoàn chỉnh. Điểm mạnh của chiến lược này nằm ở khả năng thích ứng và kiểm soát rủi ro, nhưng nó có thể hoạt động kém trong thị trường biến động. Hiệu suất chung của chiến lược có thể được cải thiện bằng cách thêm bộ lọc xu hướng và tối ưu hóa hệ thống quản lý tiền.
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © davisash666
//@version=5
strategy("Trend-Following Strategy", overlay=true)
// Inputs for strategy parameters
timeframe = input.timeframe("D", "Timeframe")
risk_tolerance = input.float(2.0, "Risk Tolerance (%)", step=0.1) / 100
capital_allocation = input.float(200, "Capital Allocation (%)", step=1) / 100
// Technical indicators (used to emulate machine learning)
ma_length_fast = input.int(10, "Fast MA Length")
ma_length_slow = input.int(50, "Slow MA Length")
atr_length = input.int(14, "ATR Length")
atr_multiplier = input.float(1.5, "ATR Multiplier")
// Calculations
fast_ma = ta.sma(close, ma_length_fast)
slow_ma = ta.sma(close, ma_length_slow)
atr = ta.atr(atr_length)
// Entry and exit conditions
long_condition = ta.crossover(fast_ma, slow_ma)
short_condition = ta.crossunder(fast_ma, slow_ma)
// Risk management
stop_loss_long = close - (atr * atr_multiplier)
stop_loss_short = close + (atr * atr_multiplier)
take_profit_long = close + (atr * atr_multiplier)
take_profit_short = close - (atr * atr_multiplier)
// Capital allocation
position_size = strategy.equity * capital_allocation
// Execute trades
if long_condition
strategy.entry("Long", strategy.long, qty=position_size / close)
strategy.exit("Take Profit/Stop Loss", "Long", stop=stop_loss_long, limit=take_profit_long)
if short_condition
strategy.entry("Short", strategy.short, qty=position_size / close)
strategy.exit("Take Profit/Stop Loss", "Short", stop=stop_loss_short, limit=take_profit_short)
// Plotting for visualization
plot(fast_ma, color=color.green, title="Fast MA")
plot(slow_ma, color=color.red, title="Slow MA")
plot(stop_loss_long, color=color.blue, title="Stop Loss (Long)", linewidth=1, style=plot.style_cross)
plot(take_profit_long, color=color.purple, title="Take Profit (Long)", linewidth=1, style=plot.style_cross)