// Lấy giá của cặp coin hiện hành coinSymbol = syminfo.tickerid closePrice = close
// Tính toán MA10 và EMA99 ma10 = ta.sma(closePrice, 10) ema99 = ta.ema(closePrice, 99)
// Điều kiện Buy: MA10 cắt lên EMA99 và giá hiện tại lớn hơn giá đóng cửa trước đó buySignal = ta.crossover(ma10, ema99) and closePrice > close[1]
// Điều kiện Sell: MA10 cắt xuống EMA99 và giá hiện tại nhỏ hơn giá đóng cửa trước đó sellSignal = ta.crossunder(ma10, ema99) and closePrice < close[1]
// Các giá trị chi tiết cho thông báo takeProfitPercent = input.float(1.05, title="Take Profit (%)") // 5% tăng giá stopLossPercent = input.float(0.95, title="Stop Loss (%)") // 5% giảm giá
// Khai báo các biến toàn cục cho giá TP và SL var float entryPrice = na var float takeProfitPrice = na var float stopLossPrice = na
// Kiểm tra điều kiện để không nhận tín hiệu liên tục var int lastSignalBarIndex = na
// Lưu giá vào lệnh khi có tín hiệu Buy hoặc Sell if (buySignal and na(entryPrice) and (na(lastSignalBarIndex) or (bar_index - lastSignalBarIndex >= 1))) entryPrice := closePrice takeProfitPrice := entryPrice * takeProfitPercent stopLossPrice := entryPrice * stopLossPercent lastSignalBarIndex := bar_index
// Kiểm tra nếu đạt Take Profit (TP) hoặc Stop Loss (SL) if (not na(entryPrice)) if closePrice >= takeProfitPrice alert("TP: " + str.tostring(takeProfitPrice) + " đã đạt cho " + coinSymbol, alert.freq_once_per_bar_close) entryPrice := na // Reset giá vào lệnh
if closePrice <= stopLossPrice alert("SL: " + str.tostring(stopLossPrice) + " đã chạm cho " + coinSymbol, alert.freq_once_per_bar_close) entryPrice := na // Reset giá vào lệnh
// Hiển thị tín hiệu trên biểu đồ plot(ma10, title="MA10", color=color.blue, linewidth=2) plot(ema99, title="EMA99", color=color.orange, linewidth=2)