
Chiến lược này dựa trên các chỉ số MACD, ADX và EMA200, giao dịch theo xu hướng trong nhiều khung thời gian bằng cách đánh giá xu hướng và động lực thị trường hiện tại. Ý tưởng chính của chiến lược là sử dụng chỉ số MACD để đánh giá xu hướng thị trường, chỉ số ADX xác nhận cường độ xu hướng, EMA200 làm điều kiện lọc xu hướng, đồng thời giao dịch với nhiều khung thời gian để có được nhiều cơ hội giao dịch và tỷ lệ lợi nhuận tốt hơn.
Giải pháp:
Bằng cách tối ưu hóa, bạn có thể cải thiện tính mạnh mẽ và lợi nhuận của chiến lược để thích ứng tốt hơn với các môi trường thị trường khác nhau.
Chiến lược này có một số ưu điểm và khả năng hoạt động bằng cách kết hợp các chỉ số như MACD, ADX và EMA200 để giao dịch theo xu hướng trong nhiều khung thời gian. Điều quan trọng của chiến lược là đánh giá xu hướng và xác nhận cường độ xu hướng, thông qua sự hoạt động chung của nhiều chỉ số, có thể nắm bắt cơ hội xu hướng tốt hơn. Đồng thời, chiến lược sử dụng các điểm dừng cố định giúp kiểm soát rủi ro.
/*backtest
start: 2024-02-01 00:00:00
end: 2024-02-29 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © colemanrumsey
//@version=5
strategy("15-Minute Trend Trading Strategy", overlay=true)
// Exponential Moving Average (EMA)
ema200 = ta.ema(close, 200)
// MACD Indicator
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
macdHistogram = macdLine - signalLine
// Calculate True Range (TR)
tr = ta.tr
// Calculate +DI and -DI
plusDM = high - high[1]
minusDM = low[1] - low
atr14 = ta.atr(14)
plusDI = ta.wma(100 * ta.sma(plusDM, 14) / atr14, 14)
minusDI = ta.wma(100 * ta.sma(minusDM, 14) / atr14, 14)
// Calculate Directional Movement Index (DX)
dx = ta.wma(100 * math.abs(plusDI - minusDI) / (plusDI + minusDI), 14)
// Calculate ADX
adxValue = ta.wma(dx, 14)
// Long Entry Condition
longCondition = close > ema200 and (macdLine > signalLine) and (macdLine < 0) and (adxValue >= 25)
// Short Entry Condition
shortCondition = close < ema200 and (macdLine < signalLine) and (macdLine > 0) and (adxValue >= 25)
// Calculate ATR for Stop Loss
atrValue = ta.atr(14)
// Initialize Take Profit and Stop Loss
var float takeProfit = na
var float stopLoss = na
// Calculate Risk (Stop Loss Distance)
risk = close - low[1] // Using the previous candle's low as stop loss reference
// Strategy Orders
if longCondition
stopLoss := close * 0.99 // Set Stop Loss 1% below the entry price
takeProfit := close * 1.015 // Set Take Profit 1.5% above the entry price
strategy.entry("Buy", strategy.long, stop=stopLoss, limit=takeProfit)
if shortCondition
stopLoss := close * 1.01 // Set Stop Loss 1% above the entry price
takeProfit := close * 0.985 // Set Take Profit 1.5% below the entry price
strategy.entry("Sell", strategy.short, stop=stopLoss, limit=takeProfit)
// Plot EMA
// plot(ema200, color=color.blue, linewidth=1, title="200 EMA")
// Plot MACD Histogram
// plot(macdHistogram, color=macdHistogram > 0 ? color.green : color.red, style=plot.style_columns, title="MACD Histogram")
// Display ADX Value
// plot(adxValue, color=color.purple, title="ADX Value")