
Chiến lược này là một hệ thống giao dịch tự động dựa trên khung thời gian 5 phút kết hợp phương pháp theo dõi xu hướng trung bình động và phân tích khối lượng. Chiến lược này sử dụng đường trung bình động đơn giản (SMA) 50 kỳ để xác định xu hướng thị trường và đưa ra phân tích khối lượng để xác minh tính hợp lệ của các tín hiệu giao dịch. Hệ thống sử dụng mục tiêu dừng lỗ và lợi nhuận cố định để đạt được giao dịch hoàn toàn tự động.
Logic cốt lõi của chiến lược bao gồm các thành phần chính sau:
Chiến lược này xây dựng một hệ thống giao dịch tần suất cao hoàn chỉnh bằng cách kết hợp theo dõi xu hướng và phân tích khối lượng. Ưu điểm chính của chiến lược này nằm ở cơ chế xác nhận tín hiệu đa chiều và hệ thống kiểm soát rủi ro hoàn hảo. Mặc dù có một số rủi ro cố hữu, tính ổn định và khả năng thích ứng của chiến lược có thể được cải thiện hơn nữa thông qua các hướng tối ưu hóa được đề xuất. Chiến lược này đặc biệt phù hợp để hoạt động trong môi trường thị trường có xu hướng rõ ràng và dự kiến sẽ đạt được kết quả giao dịch ổn định thông qua việc tối ưu hóa thông số hợp lý và quản lý rủi ro.
/*backtest
start: 2024-01-10 00:00:00
end: 2025-01-08 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Jerryorange
//@version=6
//@version=6
strategy("Autonomous 5-Minute Robot", overlay=true, fill_orders_on_standard_ohlc=true)
// --- Inputs ---
maLength = input.int(50, title="Trend MA Length") // Moving average length for trend detection
volumeLength = input.int(10, title="Volume Length") // Length for volume analysis
stopLossPercent = input.float(3, title="Stop Loss (%)") // 3% stop loss
takeProfitPercent = input.float(29, title="Take Profit (%)") // 29% take profit
// --- Market Trend Detection ---
ma = ta.sma(close, maLength) // Simple moving average for trend direction
isBullish = close > ma // Market is bullish if the close is above the moving average
isBearish = close < ma // Market is bearish if the close is below the moving average
// --- Volume Analysis ---
buyVolume = (high != low) ? volume * (close - low) / (high - low) : 0
sellVolume = (high != low) ? volume * (high - close) / (high - low) : 0
totalVolume = volume
// --- Define Market Direction over Last 30 Minutes (6 candles in 5-minute chart) ---
lookback = 6 // 30 minutes / 5 minutes = 6 bars
prevClose = close[lookback] // Previous close 30 minutes ago
currentClose = close // Current close
uptrend = currentClose > prevClose and isBullish // Uptrend condition
downtrend = currentClose < prevClose and isBearish // Downtrend condition
// --- Strategy Logic ---
longCondition = uptrend and buyVolume > sellVolume // Buy signal when trend is up and buy volume exceeds sell volume
shortCondition = downtrend and sellVolume > buyVolume // Sell signal when trend is down and sell volume exceeds buy volume
// --- Entry and Exit Strategy ---
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// --- Exit Strategy based on Stop Loss and Take Profit ---
strategy.exit("Exit Long", "Long", stop=close * (1 - stopLossPercent / 100), limit=close * (1 + takeProfitPercent / 100))
strategy.exit("Exit Short", "Short", stop=close * (1 + stopLossPercent / 100), limit=close * (1 - takeProfitPercent / 100))
// --- Plotting for Visualization ---
plot(ma, color=color.blue, title="50-period MA") // Trend line
plotshape(longCondition, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY")
plotshape(shortCondition, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL")