
Đây là một chiến lược giao dịch định lượng dựa trên nhiều đường trung bình chéo kết hợp với bộ lọc giao dịch. Chiến lược này sử dụng moving average của ba chu kỳ khác nhau (EMA nhanh, EMA chậm và SMA xu hướng) làm chỉ số cốt lõi và kết hợp bộ lọc giao dịch để xác nhận hiệu quả của tín hiệu giao dịch. Chiến lược cũng tích hợp các chức năng dừng lỗ và dừng để kiểm soát rủi ro hiệu quả.
Chiến lược này dựa trên các yếu tố cốt lõi sau:
Chiến lược này xây dựng một hệ thống giao dịch tương đối hoàn hảo thông qua sự kết hợp của nhiều chỉ số kỹ thuật. Lợi thế cốt lõi của chiến lược là cơ chế xác nhận nhiều lần và kiểm soát rủi ro tốt, nhưng vẫn cần tối ưu hóa tham số và cải tiến chiến lược theo tình hình thị trường thực tế. Với sự tối ưu hóa hợp lý và kiểm soát rủi ro, chiến lược này có thể đạt được lợi nhuận ổn định trong thị trường xu hướng.
/*backtest
start: 2024-02-22 00:00:00
end: 2024-12-17 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Optimized Moving Average Crossover Strategy with Volume Filter", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Inputs for Moving Averages
fastLength = input.int(9, title="Fast MA Length")
slowLength = input.int(21, title="Slow MA Length")
trendFilterLength = input.int(50, title="Trend Filter Length")
// Risk Management Inputs
stopLossPercent = input.float(1, title="Stop Loss (%)", step=0.1)
takeProfitPercent = input.float(400, title="Take Profit (%)", step=0.1)
// Volume Filter Input
volumeMultiplier = input.float(1.5, title="Volume Multiplier", step=0.1) // Multiplier for average volume
// Moving Averages
fastMA = ta.ema(close, fastLength)
slowMA = ta.ema(close, slowLength)
trendMA = ta.sma(close, trendFilterLength) // Long-term trend filter
// Volume Calculation
avgVolume = ta.sma(volume, 20) // 20-period average volume
volumeCondition = volume > avgVolume * volumeMultiplier // Volume must exceed threshold
// Plotting Moving Averages
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.red, title="Slow MA")
plot(trendMA, color=color.green, title="Trend Filter MA")
// Entry Conditions (Filtered by Trend and Volume)
longCondition = ta.crossover(fastMA, slowMA) and close > trendMA and volumeCondition
shortCondition = ta.crossunder(fastMA, slowMA) and close < trendMA and volumeCondition
// Execute Trades
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exit Conditions: Stop Loss and Take Profit
if (strategy.position_size > 0)
strategy.exit("Exit Long", "Long", stop=strategy.position_avg_price * (1 - stopLossPercent / 100), limit=strategy.position_avg_price * (1 + takeProfitPercent / 100))
if (strategy.position_size < 0)
strategy.exit("Exit Short", "Short", stop=strategy.position_avg_price * (1 + stopLossPercent / 100), limit=strategy.position_avg_price * (1 - takeProfitPercent / 100))
// Additional Alerts
alertcondition(longCondition, title="Long Signal", message="Go Long!")
alertcondition(shortCondition, title="Short Signal", message="Go Short!")
// Debugging Labels
if (longCondition)
label.new(bar_index, close, "Long", style=label.style_label_up, color=color.green, textcolor=color.white)
if (shortCondition)
label.new(bar_index, close, "Short", style=label.style_label_down, color=color.red, textcolor=color.white)