
Đây là chiến lược giao dịch định lượng kết hợp xu hướng EMA, đột phá chu kỳ và lọc phiên giao dịch. Chiến lược này chủ yếu dựa trên phán đoán hướng xu hướng của đường trung bình động và sử dụng mô hình đột phá của giá tại vị trí chu kỳ quan trọng làm tín hiệu giao dịch. Đồng thời, giới thiệu bộ lọc thời gian giao dịch để cải thiện chất lượng giao dịch. Chiến lược này sử dụng phương pháp dừng lỗ và chốt lời theo phần trăm để kiểm soát rủi ro.
Logic cốt lõi của chiến lược bao gồm các yếu tố chính sau:
Chiến lược này xây dựng một hệ thống giao dịch logic chặt chẽ bằng cách kết hợp nhiều cơ chế như xu hướng trung bình động, mô hình giá và lọc theo thời gian. Mặc dù có một số hạn chế nhất định, nhưng hy vọng rằng tính ổn định và lợi nhuận của chiến lược sẽ được nâng cao hơn nữa thông qua quá trình tối ưu hóa và cải tiến liên tục. Chiến lược này phù hợp làm khuôn khổ cơ bản của hệ thống theo dõi xu hướng trung và dài hạn, đồng thời có thể tùy chỉnh và cải thiện theo nhu cầu giao dịch thực tế.
/*backtest
start: 2024-12-17 00:00:00
end: 2025-01-16 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=6
strategy("The Gold Box Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// Inputs
roundNumberInterval = input.int(5, title="Round Number Interval ($)", minval=1)
useEMA = input.bool(true, title="Use 20 EMA for Confluence")
emaLength = input.int(20, title="EMA Length")
// Session times for London and NY
londonSession = input("0300-1200", title="London Session (NY Time)")
nySession = input("0800-1700", title="New York Session (NY Time)")
// EMA Calculation
emaValue = ta.ema(close, emaLength)
// Plot Round Number Levels
roundLow = math.floor(low / roundNumberInterval) * roundNumberInterval
roundHigh = math.ceil(high / roundNumberInterval) * roundNumberInterval
// for level = roundLow to roundHigh by roundNumberInterval
// line.new(x1=bar_index - 1, y1=level, x2=bar_index, y2=level, color=color.new(color.gray, 80), extend=extend.both)
// Session Filter
inLondonSession = not na(time("1", londonSession))
inNYSession = not na(time("1", nySession))
inSession = true
// Detect Bullish and Bearish Engulfing patterns
bullishEngulfing = close > open[1] and open < close[1] and close > emaValue and inSession
bearishEngulfing = close < open[1] and open > close[1] and close < emaValue and inSession
// Entry Conditions
if bullishEngulfing
strategy.entry("Long", strategy.long, comment="Bullish Engulfing with EMA Confluence")
if bearishEngulfing
strategy.entry("Short", strategy.short, comment="Bearish Engulfing with EMA Confluence")
// Stop Loss and Take Profit
stopLossPercent = input.float(1.0, title="Stop Loss (%)", minval=0.1) / 100
takeProfitPercent = input.float(1.5, title="Take Profit (%)", minval=0.1) / 100
strategy.exit("Exit Long", "Long", stop=close * (1 - stopLossPercent), limit=close * (1 + takeProfitPercent))
strategy.exit("Exit Short", "Short", stop=close * (1 + stopLossPercent), limit=close * (1 - takeProfitPercent))