
Chiến lược này là một hệ thống giao dịch định lượng dựa trên tín hiệu giao chéo hai đường cong, xác định sự thay đổi xu hướng thị trường thông qua giao chéo của đường trung bình di chuyển ngắn hạn và dài hạn, và kết hợp với quản lý dừng lỗ động để kiểm soát rủi ro. Chiến lược sử dụng đơn giá thị trường để giao dịch, tự động xóa vị trí hiện tại và mở vị trí mới khi tín hiệu được kích hoạt, để bảo vệ tài sản bằng cách thiết lập điểm dừng lỗ.
Chiến lược sử dụng trung bình di chuyển đơn giản (SMA) của hai chu kỳ khác nhau làm cơ sở chính của tín hiệu giao dịch. Khi đường trung bình ngắn hạn vượt qua đường trung bình dài hạn, hệ thống tạo ra nhiều tín hiệu; Khi đường trung bình ngắn hạn vượt qua đường trung bình dài hạn, hệ thống tạo ra tín hiệu dừng.
Đây là một chiến lược giao dịch định lượng có cấu trúc, logic rõ ràng. Bằng cách nắm bắt các thay đổi xu hướng bằng đường giao chéo hai đường bằng nhau, kết hợp với các rủi ro quản lý dừng lỗ động. Ưu điểm của chiến lược là có mức độ hệ thống hóa cao, rủi ro có thể kiểm soát được, nhưng trong thực tế vẫn cần chú ý đối phó với các loại rủi ro thị trường. Bằng cách tối ưu hóa và hoàn thiện liên tục, chiến lược có thể duy trì hiệu suất ổn định trong các môi trường thị trường khác nhau.
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("BTCUSD Daily Strategy - Market Orders Only", overlay=true, initial_capital=10000, currency=currency.USD)
// Configurable Inputs
stop_loss_percent = input.float(title="Stop Loss (%)", defval=1.0, minval=0.0, step=0.1)
take_profit_percent = input.float(title="Take Profit (%)", defval=2.0, minval=0.0, step=0.1)
short_ma_length = input.int(title="Short MA Length", defval=9, minval=1)
long_ma_length = input.int(title="Long MA Length", defval=21, minval=1)
// Moving Averages
short_ma = ta.sma(close, short_ma_length)
long_ma = ta.sma(close, long_ma_length)
// Plotting Moving Averages
plot(short_ma, color=color.blue, title="Short MA")
plot(long_ma, color=color.red, title="Long MA")
// Buy and Sell Signals
buy_signal = ta.crossover(short_ma, long_ma)
sell_signal = ta.crossunder(short_ma, long_ma)
// Market Buy Logic
if (buy_signal and strategy.position_size <= 0)
// Close any existing short position
if (strategy.position_size < 0)
strategy.close(id="Market Sell")
// Calculate Stop Loss and Take Profit Prices
entry_price = close
long_stop = entry_price * (1 - stop_loss_percent / 100)
long_take_profit = entry_price * (1 + take_profit_percent / 100)
// Enter Long Position
strategy.entry(id="Market Buy", direction=strategy.long)
strategy.exit(id="Exit Long", from_entry="Market Buy", stop=long_stop, limit=long_take_profit)
// Alert for Market Buy
alert("Market Buy Signal at price " + str.tostring(close) + ". Stop Loss: " + str.tostring(long_stop) + ", Take Profit: " + str.tostring(long_take_profit), alert.freq_once_per_bar_close)
// Market Sell Logic
if (sell_signal and strategy.position_size >= 0)
// Close any existing long position
if (strategy.position_size > 0)
strategy.close(id="Market Buy")
// Calculate Stop Loss and Take Profit Prices
entry_price = close
short_stop = entry_price * (1 + stop_loss_percent / 100)
short_take_profit = entry_price * (1 - take_profit_percent / 100)
// Enter Short Position
strategy.entry(id="Market Sell", direction=strategy.short)
strategy.exit(id="Exit Short", from_entry="Market Sell", stop=short_stop, limit=short_take_profit)
// Alert for Market Sell
alert("Market Sell Signal at price " + str.tostring(close) + ". Stop Loss: " + str.tostring(short_stop) + ", Take Profit: " + str.tostring(short_take_profit), alert.freq_once_per_bar_close)