
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng dựa trên chéo hai đường trung bình, kết hợp với cơ chế quản lý rủi ro. Chiến lược sử dụng trung bình di chuyển đơn giản ((SMA) với 9 chu kỳ và 21 chu kỳ để nắm bắt xu hướng thị trường, đồng thời thiết lập mức dừng và dừng 1% để kiểm soát rủi ro.
Lập luận cốt lõi của chiến lược dựa trên các đặc điểm liên tục của xu hướng thị trường. Đánh giá điểm chuyển hướng bằng cách quan sát sự giao thoa của đường trung bình di chuyển ngắn hạn (thời kỳ 9) và dài hạn (thời kỳ 21). Khi đường trung bình ngắn hạn tạo thành “vòng vàng” khi đi qua đường trung bình dài hạn, cho thấy xu hướng tăng bắt đầu, hệ thống phát ra nhiều tín hiệu; khi đường trung bình ngắn hạn tạo thành “vòng chết” khi đi qua đường trung bình dài hạn, cho thấy xu hướng tăng có thể kết thúc, hệ thống thoát khỏi vị trí bằng phẳng.
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng hoàn chỉnh hơn bằng cách nắm bắt xu hướng ngang qua hai đường thẳng và kết hợp với cơ chế dừng lỗ để kiểm soát rủi ro. Mặc dù có thể tạo ra tín hiệu giả trong thị trường biến động, nhưng bằng cách tối ưu hóa các tham số hợp lý và tăng các chỉ số phụ trợ, bạn có thể nâng cao hơn nữa sự ổn định và khả năng lợi nhuận của chiến lược. Ưu điểm cốt lõi của chiến lược là mức độ tự động cao, kiểm soát rủi ro hoàn hảo, phù hợp với khung chiến lược cơ bản để theo dõi xu hướng dài hạn.
/*backtest
start: 2024-02-21 00:00:00
end: 2024-12-13 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Moving Average Crossover with Stop Loss and Take Profit", overlay=true)
// Parameters for moving averages
short_length = input.int(9, title="Short Moving Average Length") // Optimized for 15-minute time frame
long_length = input.int(21, title="Long Moving Average Length") // Optimized for 15-minute time frame
// Parameters for risk management
stop_loss_percent = input.float(1.0, title="Stop Loss (%)") / 100 // 1% stop loss
take_profit_percent = input.float(1.0, title="Take Profit (%)") / 100 // 1% take profit
// Calculate moving averages
short_ma = ta.sma(close, short_length)
long_ma = ta.sma(close, long_length)
// Plot moving averages
plot(short_ma, color=color.blue, title="Short MA")
plot(long_ma, color=color.orange, title="Long MA")
// Entry and exit conditions
long_condition = ta.crossover(short_ma, long_ma) // Golden Cross
short_condition = ta.crossunder(short_ma, long_ma) // Death Cross
// Execute strategy with stop loss and take profit
if (long_condition)
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Long", stop=strategy.position_avg_price * (1 - stop_loss_percent), limit=strategy.position_avg_price * (1 + take_profit_percent) )
if (short_condition)
strategy.close("Long") // Close long position on Death Cross
// Plot Buy/Sell Signals
plotshape(series=long_condition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=short_condition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Draw 1% stop loss level as a transparent red rectangle
var float stop_loss_level = na
var float entry_price = na
if (strategy.position_size > 0) // Only update when in a trade
stop_loss_level := strategy.position_avg_price * (1 - stop_loss_percent)
entry_price := strategy.position_avg_price
// Create transparent colors
transparent_red = color.new(color.black, 90) // 90% transparency
transparent_green = color.new(color.green, 90) // 90% transparency
// Plot stop loss and entry levels conditionally
plot(strategy.position_size > 0 ? stop_loss_level : na, color=transparent_red, title="Stop Loss Level", linewidth=1)
plot(strategy.position_size > 0 ? entry_price : na, color=transparent_green, title="Entry Price", linewidth=1)
// Fill the area between stop loss and entry price conditionally
fill( plot(strategy.position_size > 0 ? stop_loss_level : na), plot(strategy.position_size > 0 ? entry_price : na), color=transparent_red)