
Chiến lược này là một hệ thống giao dịch chéo dựa trên chỉ số trung bình di chuyển ((EMA) và chỉ số tương đối mạnh ((RSI)). Chiến lược xác định thời gian vào và ra thị trường bằng cách giao dịch chéo giá với EMA và mức bán tháo của chỉ số RSI. Hệ thống được thiết kế với cơ chế dừng lỗ và lợi nhuận hoàn chỉnh, có thể kiểm soát rủi ro một cách hiệu quả.
Chiến lược này hoạt động dựa trên các logic cốt lõi sau:
Chiến lược này kết hợp hai chỉ số kỹ thuật cổ điển EMA và RSI để xây dựng một hệ thống giao dịch có cả tính năng theo dõi xu hướng và đảo ngược. Cơ chế kiểm soát rủi ro tốt và thiết kế tham số có thể điều chỉnh làm cho nó có tính thực tế tốt. Tuy nhiên, tối ưu hóa tham số của chiến lược và khả năng thích ứng với thị trường vẫn còn chỗ để nâng cao, khuyến nghị các nhà giao dịch tối ưu hóa mục tiêu kết hợp với các đặc điểm của thị trường khi áp dụng trên thực tế.
/*backtest
start: 2024-02-21 00:00:00
end: 2024-10-05 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("EMA & RSI Custom Strategy", overlay=true)
// Input Parameters
emaLength = input.int(68, title="EMA Length")
rsiLength = input.int(13, title="RSI Period")
buyOffset = input.float(2, title="Buy Offset (above EMA)")
sellOffset = input.float(2, title="Sell Offset (below EMA)")
stopLossPoints = input.float(20, title="Stop Loss (points)")
buyRSIProfitLevel = input.int(70, title="Buy RSI Profit Level")
sellRSIProfitLevel = input.int(28, title="Sell RSI Profit Level")
// EMA and RSI Calculations
ema = ta.ema(close, emaLength)
rsi = ta.rsi(close, rsiLength)
// Buy Condition
buyPrice = ema + buyOffset
buyCondition = ta.crossover(close, buyPrice)
if buyCondition
strategy.entry("Buy", strategy.long)
// Stop Loss and Profit for Buy
if strategy.position_size > 0
if close <= strategy.position_avg_price - stopLossPoints
strategy.close("Buy", comment="Stop Loss")
if rsi >= buyRSIProfitLevel
strategy.close("Buy", comment="Profit Target")
// Sell Condition
sellPrice = ema - sellOffset
sellCondition = ta.crossunder(close, sellPrice)
if sellCondition
strategy.entry("Sell", strategy.short)
// Stop Loss and Profit for Sell
if strategy.position_size < 0
if close >= strategy.position_avg_price + stopLossPoints
strategy.close("Sell", comment="Stop Loss")
if rsi <= sellRSIProfitLevel
strategy.close("Sell", comment="Profit Target")
// Plot EMA
plot(ema, color=color.blue, title="EMA 68")