//@version=5
strategy("RSI(6) Buy at 30, EMA(34) Sell with Stop Loss", overlay=true)
// Cài đặt tham số
rsiPeriod = 6
emaPeriod = 54
buyLevel = 30
positionSize = 0.02
// Xác định RSI và EMA
rsiValue = ta.rsi(close, rsiPeriod)
emaValue = ta.ema(close, emaPeriod)
Điều kiện mua: RSI dưới 30
buySignal = ta.crossunder(rsiValue, buyLevel)
// Điều kiện bán: Giá cao hơn EMA 54
sellSignal = close > emaValue
// Ghi lại giá mở kho
var float entryPrice = na
// Buy logic: chỉ làm nhiều hơn
if (buySignal and strategy.position_size == 0)
strategy.entry("Buy", strategy.long, qty=positionSize)
entryPrice: = close // Ghi lại giá mở khi mua
// Stop Loss Logic: thiết lập Stop Loss là 0.5%
if (strategy.position_size > 0)
stopLossPrice = entryPrice * 0.995 // 0.5% dừng lỗ
if (close <= stopLossPrice)
strategy.close (("Buy", comment="Stop Loss") // Giảm lỗ
// Logic giao dịch: giá giao dịch khi giao dịch cao hơn EMA 54
if (strategy.position_size > 0 and sellSignal)
strategy.close (("Buy", comment="Take Profit") // Đạt mức cân bằng
- 1