Hướng Dẫn Sử Dụng Bot CNPS79 - Liquidity Sweep Reversal V2.1 cho VN30F1M
TradingviewBot CNPS79 Liquidity Sweep Reversal V2.1 phát hiện các pha quét thanh khoản (Liquidity Sweep) dưới Swing Low / trên Swing High kèm râu nến từ chối, xác nhận nến đảo chiều theo xu hướng EMA và quản trị rủi ro cố định SL 5 điểm / TP 15 điểm cho VN30F1M.

Mục lục
Khi giao dịch hợp đồng tương lai chỉ số VN30F1M, một trong những kịch bản gây thua lỗ phổ biến nhất là hiện tượng quét thanh khoản (Liquidity Sweep / Stop-Hunt): giá xuyên thủng vùng hỗ trợ hoặc kháng cự gần nhất để kích hoạt các lệnh dừng lỗ (Stop Loss) của đám đông, sau đó nhanh chóng rút chân và đảo chiều mạnh theo hướng ngược lại. Nếu vào lệnh quá sớm khi chưa có xác nhận hoặc đặt dừng lỗ ngay tại đỉnh/đáy cũ, nhà giao dịch rất dễ bị quét khỏi thị trường trước khi sóng chính thực sự bắt đầu.
Chiến lược CNPS79 LIQUIDITY SWEEP REVERSAL V2.1 (tên ngắn: CNPS79 SWEEP V2.1), được viết bằng Pine Script v6 trên TradingView, được thiết kế chuyên biệt để giải quyết bài toán này. Bot tự động nhận diện các pha quét thanh khoản hợp lệ tại vùng Swing 20 nến gần nhất, chờ nến xác nhận đảo chiều đồng thuận với xu hướng EMA và thực thi lệnh hoàn toàn trên nến đã đóng (barstate.isconfirmed).
Những điểm nổi bật cốt lõi của Bot CNPS79:
- Không nhìn trước tương lai (No future-looking pivots): Vùng
Swing HighvàSwing Lowđược tính hoàn toàn từ dữ liệu quá khứ (high[1],low[1]), đảm bảo tín hiệu backtest và thực chiến nhất quán. - Đo lường pha quét bằng ATR và râu nến từ chối: Lọc bỏ các pha phá vỡ quá nông hoặc quá sâu bất thường bằng ngưỡng
0.10 – 1.50 ATR, đồng thời yêu cầu râu nến từ chối tối thiểu25%biên độ nến. - Cơ chế State Machine chờ nến xác nhận: Thay vì bắt dao rơi ngay tại nến quét, mặc định bot chờ nến xác nhận đảo chiều trong cửa sổ tối đa
5nến và tự động hủy setup nếu cực trị nến quét bị phá vỡ. - Quản trị rủi ro chặt chẽ theo phiên VN30F1M: Cố định Stop Loss
5.0điểm và Take Profit15.0điểm (tỷ lệ Risk:Reward1:3), giới hạn tối đa2lệnh/ngày, thời gian nghỉ3nến sau khi đóng lệnh và tự động tất toán trước phiên ATC lúc14:45.
1. CNPS79 Liquidity Sweep Reversal V2.1 là gì?
CNPS79 Liquidity Sweep Reversal V2.1 là một hệ thống giao dịch đảo chiều sau quét thanh khoản (Liquidity Sweep Reversal) kết hợp lọc xu hướng, được xây dựng xoay quanh 4 trụ cột kỹ thuật chính:
- Nhận diện quét thanh khoản (Liquidity Sweep Detection): Theo dõi biên độ
Swing HighvàSwing Lowcủa 20 cây nến trước đó. Khi giá xuyên qua biên này nhưng đóng cửa rút lại vào bên trong vùng Swing với độ sâu đạt chuẩn ATR và có râu nến từ chối rõ rệt, bot ghi nhận một pha quét thanh khoản (bullSweephoặcbearSweep). - Máy trạng thái & Xác nhận điểm vào lệnh (Sweep State Machine): Lưu giữ trạng thái chờ (
pendingLong/pendingShort) trong tối đa 5 nến kể từ nến quét. Lệnh chỉ được kích hoạt khi xuất hiện nến xác nhận cùng chiều đảo chiều, đóng cửa tiến triển so với nến trước và giữ vững trên/dưới mức thanh khoản vừa quét. - Bộ lọc xu hướng & hợp lưu đa lớp (Trend & Optional Filters): Sử dụng đường
EMA 50(yêu cầu độ dốc tăng/giảm so với 3 nến trước và giá nằm đúng phía EMA) làm bộ lọc xu hướng chính. Ngoài ra, bot tích hợp sẵn các bộ lọc tùy chọn gồmADXtối đa, đột biến khối lượng (Volume Spike) và xu hướng khung giờ lớnH1 EMA 50. - Quản trị rủi ro & Kiểm soát phiên giao dịch: Áp dụng SL/TP cố định quy đổi theo
syminfo.mintick, giới hạn tần suất giao dịch mỗi ngày, thời gian làm nguội (cooldown) sau khi thoát lệnh và bộ đếm thời gian đóng toàn bộ vị thế cuối phiên theo múi giờAsia/Ho_Chi_Minh.
Bảng thông số mặc định
Dưới đây là toàn bộ các nhóm thông số đầu vào (input.*) và giá trị mặc định được lập trình trong mã nguồn của CNPS79:
| Nhóm thông số | Tên biến / Nhãn hiển thị | Giá trị mặc định | Mô tả chức năng |
|---|---|---|---|
| 01. Liquidity Sweep | Swing Lookback (swingLength) | 20 | Số nến quá khứ tính Swing High / Swing Low |
ATR Length (atrLength) | 14 | Chu kỳ tính chỉ báo ATR đo độ sâu pha quét | |
Minimum Sweep Depth / ATR (minSweepATR) | 0.10 | Độ sâu quét tối thiểu tính theo hệ số ATR | |
Reject Excessively Deep Sweeps (useMaxSweepFilter) | true | Bật/tắt bộ lọc loại bỏ pha quét quá sâu | |
Maximum Sweep Depth / ATR (maxSweepATR) | 1.50 | Độ sâu quét tối đa cho phép theo hệ số ATR | |
Require Rejection Wick (requireWick) | true | Yêu cầu nến quét phải có râu nến từ chối | |
Minimum Rejection Wick Ratio (minWickRatio) | 0.25 | Tỷ lệ râu nến từ chối tối thiểu (25% biên độ nến) | |
Require Sweep Candle Direction (requireSweepCandleDirection) | false | Yêu cầu nến quét phải là nến xanh (Long) / đỏ (Short) | |
| 02. Entry Confirmation | Entry Mode (entryMode) | "Next Candle Confirmation" | Chế độ vào lệnh: chờ nến xác nhận hoặc vào ngay nến quét |
Maximum Confirmation Bars (confirmationBars) | 5 | Số nến tối đa chờ nến xác nhận sau pha quét | |
Require Break of Sweep Candle High/Low (requireBreakSweepCandle) | false | Yêu cầu nến xác nhận phá đỉnh/đáy nến quét | |
Require Bullish/Bearish Confirmation Candle (requireConfirmCandle) | true | Yêu cầu nến xác nhận đúng màu xanh (Long) / đỏ (Short) | |
Require Close Beyond Previous Close (requireConfirmCloseProgress) | true | Yêu cầu giá đóng cửa vượt close[1] theo hướng lệnh | |
Cancel Setup If Sweep Extreme Is Broken (cancelOnNewSweepExtreme) | true | Hủy setup nếu giá phá cực trị của nến quét | |
| 03. EMA Trend | Use EMA Trend Filter (useEMAFilter) | true | Bật/tắt bộ lọc xu hướng EMA |
EMA Length (emaLength) | 50 | Chu kỳ đường EMA xu hướng | |
EMA Slope Lookback (emaSlopeBars) | 3 | Số nến so sánh độ dốc của EMA | |
Require Price Above/Below EMA (requirePriceEMA) | true | Yêu cầu giá đóng cửa nằm trên/dưới EMA | |
| 04. Optional Filters | Use Maximum ADX Filter (useADXFilter) | false | Bật/tắt giới hạn ADX tối đa (diLength=14, adxSmoothing=14, maxADX=35.0) |
Require Volume Spike (useVolumeFilter) | false | Bật/tắt lọc đột biến khối lượng (volumeLength=20, volumeFactor=1.20) | |
| 05. H1 Trend | Use Confirmed H1 EMA Bias (useH1Bias) | false | Bật/tắt bộ lọc xu hướng khung H1 (h1EMALength=50) |
| 06. Risk Management | Stop Loss (Points) (stopLossPoints) | 5.0 | Mức cắt lỗ cố định theo điểm |
Take Profit (Points) (takeProfitPoints) | 15.0 | Mức chốt lời cố định theo điểm | |
Use Time Exit (useTimeExit) | false | Bật/tắt thoát lệnh theo thời gian (maxHoldingBars=20) | |
| 07. Trade Control | Trade Direction (tradeDirection) | "Long" | Chiều giao dịch cho phép (Long, Short, Both) |
Contracts (contracts) | 3 | Số lượng hợp đồng (tham số input; chiến lược dùng default_qty_value=1 nếu không truyền qty) | |
Maximum Trades Per Day (maxTradesPerDay) | 2 | Số lệnh tối đa trong một ngày giao dịch | |
Cooldown Bars After Exit (cooldownBars) | 3 | Số nến nghỉ tối thiểu sau khi đóng lệnh | |
| 08. Session | Use Entry Session Filter (useSessionFilter) | true | Lọc khung giờ vào lệnh theo Asia/Ho_Chi_Minh |
Entry Start / Last Entry / Force Close | 09:15 / 14:15 / 14:45 | Giờ mở cửa nhận lệnh, giờ chốt sổ vào lệnh và giờ đóng vị thế | |
| 09. Alerts | Disable SL/TP Alerts (disableExitAlerts) | false | Tắt/bật thông báo khi khớp lệnh SL hoặc TP |
| 10. Display | Show Swing/EMA/Sweeps/Entries/SLTP | true | Hiển thị các đường mức giá và ký hiệu tín hiệu trên biểu đồ |
Show Diagnostics (showDiagnostics) | false | Bật/tắt bảng chẩn đoán ở góc trên bên phải |
Source Code CNPS79 Liquidity Sweep Reversal V2.1
Bạn có thể sao chép toàn bộ mã nguồn Pine Script v6 dưới đây để dán trực tiếp vào Pine Editor trên TradingView:
//@version=6
strategy(title="CNPS79 LIQUIDITY SWEEP REVERSAL V2.1", shorttitle="CNPS79 SWEEP V2.1", overlay=true, initial_capital=100000000, default_qty_type=strategy.fixed, default_qty_value=1, pyramiding=0, margin_long=0, margin_short=0, slippage=0, commission_type=strategy.commission.cash_per_contract, commission_value=0, fill_orders_on_standard_ohlc=true, process_orders_on_close=true, calc_on_order_fills=false, max_labels_count=300, max_lines_count=300, max_bars_back=5000)
// ============================================================================
// CNPS79 V2.1 - LIQUIDITY SWEEP REVERSAL
//
// MORE FREQUENT SIGNALS THAN V2.
//
// LONG:
// 1. Price sweeps below previous 20-bar low.
// 2. Close recovers above swept level.
// 3. Lower rejection wick >= 25%.
// 4. Wait for a later bullish confirmation candle.
// 5. EMA trend confirms direction.
// 6. LONG.
//
// SHORT: opposite logic.
//
// DEFAULT:
// SL = 5 POINTS
// TP = 15 POINTS
// QTY = 3
// MAX TRADES/DAY = 2
//
// No future-looking pivots.
// Entry is based on confirmed candles.
// ============================================================================
// ============================================================================
// 01. LIQUIDITY SWEEP
// ============================================================================
gSweep = "01. Liquidity Sweep"
swingLength = input.int(20, "Swing Lookback", minval=3, maxval=300, group=gSweep)
atrLength = input.int(14, "ATR Length", minval=1, group=gSweep)
minSweepATR = input.float(0.10, "Minimum Sweep Depth / ATR", minval=0.0, step=0.05, group=gSweep)
useMaxSweepFilter = input.bool(true, "Reject Excessively Deep Sweeps", group=gSweep)
maxSweepATR = input.float(1.50, "Maximum Sweep Depth / ATR", minval=0.1, step=0.1, group=gSweep)
requireWick = input.bool(true, "Require Rejection Wick", group=gSweep)
minWickRatio = input.float(0.25, "Minimum Rejection Wick Ratio", minval=0.0, maxval=1.0, step=0.05, group=gSweep)
requireSweepCandleDirection = input.bool(false, "Require Sweep Candle Direction", group=gSweep)
// ============================================================================
// 02. ENTRY CONFIRMATION
// ============================================================================
gConfirm = "02. Entry Confirmation"
entryMode = input.string("Next Candle Confirmation", "Entry Mode", options=["Sweep Candle", "Next Candle Confirmation"], group=gConfirm)
confirmationBars = input.int(5, "Maximum Confirmation Bars", minval=1, maxval=30, group=gConfirm)
requireBreakSweepCandle = input.bool(false, "Require Break of Sweep Candle High/Low", group=gConfirm)
requireConfirmCandle = input.bool(true, "Require Bullish/Bearish Confirmation Candle", group=gConfirm)
requireConfirmCloseProgress = input.bool(true, "Require Close Beyond Previous Close", group=gConfirm)
cancelOnNewSweepExtreme = input.bool(true, "Cancel Setup If Sweep Extreme Is Broken", group=gConfirm)
// ============================================================================
// 03. EMA TREND FILTER
// ============================================================================
gTrend = "03. EMA Trend"
useEMAFilter = input.bool(true, "Use EMA Trend Filter", group=gTrend)
emaLength = input.int(50, "EMA Length", minval=5, group=gTrend)
emaSlopeBars = input.int(3, "EMA Slope Lookback", minval=1, maxval=50, group=gTrend)
requirePriceEMA = input.bool(true, "Require Price Above/Below EMA", group=gTrend)
// ============================================================================
// 04. OPTIONAL ADX AND VOLUME
// ============================================================================
gFilters = "04. Optional Filters"
useADXFilter = input.bool(false, "Use Maximum ADX Filter", group=gFilters)
diLength = input.int(14, "DI Length", minval=2, group=gFilters)
adxSmoothing = input.int(14, "ADX Smoothing", minval=2, group=gFilters)
maxADX = input.float(35.0, "Maximum ADX", minval=1.0, step=1.0, group=gFilters)
useVolumeFilter = input.bool(false, "Require Volume Spike", group=gFilters)
volumeLength = input.int(20, "Volume Average Length", minval=2, group=gFilters)
volumeFactor = input.float(1.20, "Volume Spike Factor", minval=0.1, step=0.1, group=gFilters)
// ============================================================================
// 05. H1 EMA BIAS
// ============================================================================
gH1 = "05. H1 Trend"
useH1Bias = input.bool(false, "Use Confirmed H1 EMA Bias", group=gH1)
h1EMALength = input.int(50, "H1 EMA Length", minval=1, group=gH1)
// ============================================================================
// 06. RISK MANAGEMENT
// ============================================================================
gRisk = "06. Risk Management"
stopLossPoints = input.float(5.0, "Stop Loss (Points)", minval=0.1, step=0.5, group=gRisk)
takeProfitPoints = input.float(15.0, "Take Profit (Points)", minval=0.1, step=0.5, group=gRisk)
useTimeExit = input.bool(false, "Use Time Exit", group=gRisk)
maxHoldingBars = input.int(20, "Maximum Holding Bars", minval=1, maxval=200, group=gRisk)
// ============================================================================
// 07. TRADE CONTROL
// ============================================================================
gTrade = "07. Trade Control"
tradeDirection = input.string("Long", "Trade Direction", options=["Long", "Short", "Both"], group=gTrade)
contracts = input.int(3, "Contracts", minval=1, maxval=100, group=gTrade)
maxTradesPerDay = input.int(2, "Maximum Trades Per Day", minval=1, maxval=20, group=gTrade)
cooldownBars = input.int(3, "Cooldown Bars After Exit", minval=0, maxval=100, group=gTrade)
bool allowLong = (tradeDirection == "Long" or tradeDirection == "Both")
bool allowShort = (tradeDirection == "Short" or tradeDirection == "Both")
// ============================================================================
// 08. SESSION
// ============================================================================
gSession = "08. Session"
useSessionFilter = input.bool(true, "Use Entry Session Filter", group=gSession)
tz = input.string("Asia/Ho_Chi_Minh", "Timezone", group=gSession)
startHour = input.int(9, "Entry Start Hour", minval=0, maxval=23, group=gSession)
startMinute = input.int(15, "Entry Start Minute", minval=0, maxval=59, group=gSession)
lastHour = input.int(14, "Last Entry Hour", minval=0, maxval=23, group=gSession)
lastMinute = input.int(15, "Last Entry Minute", minval=0, maxval=59, group=gSession)
endHour = input.int(14, "Force Close Hour", minval=0, maxval=23, group=gSession)
endMinute = input.int(45, "Force Close Minute", minval=0, maxval=59, group=gSession)
// ============================================================================
// 09. ALERTS
// ============================================================================
gAlerts = "09. Alerts"
disableExitAlerts = input.bool(false, "Disable SL/TP Alerts", group=gAlerts)
// ============================================================================
// 10. DISPLAY
// ============================================================================
gDisplay = "10. Display"
showSwing = input.bool(true, "Show Swing Levels", group=gDisplay)
showEMA = input.bool(true, "Show EMA", group=gDisplay)
showSweeps = input.bool(true, "Show Sweep Markers", group=gDisplay)
showEntries = input.bool(true, "Show Entry Markers", group=gDisplay)
showSLTP = input.bool(true, "Show SL/TP", group=gDisplay)
showDiagnostics = input.bool(false, "Show Diagnostics", group=gDisplay)
// ============================================================================
// 11. TIME ENGINE
// ============================================================================
int openMin = (hour(time, tz) * 60 + minute(time, tz))
int closeMin = (hour(time_close, tz) * 60 + minute(time_close, tz))
int entryStart = (startHour * 60 + startMinute)
int entryLast = (lastHour * 60 + lastMinute)
int forceCloseMin = (endHour * 60 + endMinute)
bool sessionOK = (not useSessionFilter or (openMin >= entryStart and closeMin <= entryLast))
bool beforeClose = (closeMin < forceCloseMin)
bool forceCloseBar = (openMin < forceCloseMin and closeMin >= forceCloseMin)
// ============================================================================
// 12. TRADING DAY
// ============================================================================
int dayKey = (year(time, tz) * 10000 + month(time, tz) * 100 + dayofmonth(time, tz))
bool newDay = (na(dayKey[1]) or dayKey != dayKey[1])
var int tradesToday = 0
if newDay
tradesToday := 0
// ============================================================================
// 13. SWING LEVELS
// ============================================================================
float swingHigh = ta.highest(high[1], swingLength)
float swingLow = ta.lowest(low[1], swingLength)
float atr = ta.atr(atrLength)
bool levelsReady = (not na(swingHigh) and not na(swingLow) and not na(atr) and atr > 0)
// ============================================================================
// 14. CANDLE ANATOMY
// ============================================================================
float candleRange = (high - low)
float lowerWick = (math.min(open, close) - low)
float upperWick = (high - math.max(open, close))
float lowerWickRatio = (candleRange > 0 ? lowerWick / candleRange : 0.0)
float upperWickRatio = (candleRange > 0 ? upperWick / candleRange : 0.0)
bool bullishCandle = close > open
bool bearishCandle = close < open
// ============================================================================
// 15. SWEEP DEPTH
// ============================================================================
float sellSweepATR = (levelsReady ? (swingLow - low) / atr : na)
float buySweepATR = (levelsReady ? (high - swingHigh) / atr : na)
bool sellDepthOK = (not na(sellSweepATR) and sellSweepATR >= minSweepATR and (not useMaxSweepFilter or sellSweepATR <= maxSweepATR))
bool buyDepthOK = (not na(buySweepATR) and buySweepATR >= minSweepATR and (not useMaxSweepFilter or buySweepATR <= maxSweepATR))
// ============================================================================
// 16. LIQUIDITY SWEEP DETECTION
// ============================================================================
bool bullSweep = (levelsReady and low < swingLow and close > swingLow and sellDepthOK and (not requireWick or lowerWickRatio >= minWickRatio) and (not requireSweepCandleDirection or bullishCandle))
bool bearSweep = (levelsReady and high > swingHigh and close < swingHigh and buyDepthOK and (not requireWick or upperWickRatio >= minWickRatio) and (not requireSweepCandleDirection or bearishCandle))
// ============================================================================
// 17. EMA TREND FILTER
// ============================================================================
float ema = ta.ema(close, emaLength)
bool emaUp = (not na(ema[emaSlopeBars]) and ema > ema[emaSlopeBars])
bool emaDown = (not na(ema[emaSlopeBars]) and ema < ema[emaSlopeBars])
bool longTrendOK = (not useEMAFilter or (emaUp and (not requirePriceEMA or close > ema)))
bool shortTrendOK = (not useEMAFilter or (emaDown and (not requirePriceEMA or close < ema)))
// ============================================================================
// 18. ADX AND VOLUME FILTERS
// ============================================================================
[diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
bool adxOK = (not useADXFilter or (not na(adx) and adx <= maxADX))
float avgVolume = ta.sma(volume, volumeLength)
bool volumeOK = (not useVolumeFilter or (not na(volume) and not na(avgVolume) and volume >= avgVolume * volumeFactor))
// ============================================================================
// 19. CONFIRMED H1 BIAS
// ============================================================================
float h1EMA = request.security(syminfo.tickerid, "60", ta.ema(close, h1EMALength)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
float h1Close = request.security(syminfo.tickerid, "60", close[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
bool validH1Chart = (timeframe.isintraday and timeframe.in_seconds() < 3600)
bool longH1OK = (not useH1Bias or (validH1Chart and not na(h1EMA) and not na(h1Close) and h1Close > h1EMA))
bool shortH1OK = (not useH1Bias or (validH1Chart and not na(h1EMA) and not na(h1Close) and h1Close < h1EMA))
// ============================================================================
// 20. POSITION AND COOLDOWN
// ============================================================================
bool flat = strategy.position_size == 0
bool inLong = strategy.position_size > 0
bool inShort = strategy.position_size < 0
var int lastExitBar = na
bool closedTradeNow = (strategy.closedtrades > nz(strategy.closedtrades[1], 0))
if closedTradeNow
lastExitBar := bar_index
bool cooldownOK = (na(lastExitBar) or bar_index - lastExitBar > cooldownBars)
// ============================================================================
// 21. SWEEP STATE MACHINE
// ============================================================================
var bool pendingLong = false
var bool pendingShort = false
var int longSweepBar = na
var int shortSweepBar = na
var float longSweepHigh = na
var float longSweepLow = na
var float longSweepLevel = na
var float shortSweepHigh = na
var float shortSweepLow = na
var float shortSweepLevel = na
var int bullSweepCount = 0
var int bearSweepCount = 0
var int longExpireCount = 0
var int shortExpireCount = 0
var int lastProcessedBar = na
bool processState = (barstate.isconfirmed and (na(lastProcessedBar) or lastProcessedBar != bar_index))
if processState
lastProcessedBar := bar_index
if newDay
pendingLong := false
pendingShort := false
longSweepBar := na
shortSweepBar := na
longSweepHigh := na
longSweepLow := na
longSweepLevel := na
shortSweepHigh := na
shortSweepLow := na
shortSweepLevel := na
// Expire or invalidate existing LONG setup.
if pendingLong and not na(longSweepBar)
bool longExpired = (bar_index - longSweepBar > confirmationBars)
bool longInvalid = (cancelOnNewSweepExtreme and not na(longSweepLow) and low < longSweepLow)
if longExpired or longInvalid
pendingLong := false
longSweepBar := na
longExpireCount += 1
// Expire or invalidate existing SHORT setup.
if pendingShort and not na(shortSweepBar)
bool shortExpired = (bar_index - shortSweepBar > confirmationBars)
bool shortInvalid = (cancelOnNewSweepExtreme and not na(shortSweepHigh) and high > shortSweepHigh)
if shortExpired or shortInvalid
pendingShort := false
shortSweepBar := na
shortExpireCount += 1
// Register fresh bullish sweep.
if bullSweep and not pendingLong
pendingLong := true
longSweepBar := bar_index
longSweepHigh := high
longSweepLow := low
longSweepLevel := swingLow
pendingShort := false
shortSweepBar := na
bullSweepCount += 1
// Register fresh bearish sweep.
if bearSweep and not pendingShort
pendingShort := true
shortSweepBar := bar_index
shortSweepHigh := high
shortSweepLow := low
shortSweepLevel := swingHigh
pendingLong := false
longSweepBar := na
bearSweepCount += 1
// ============================================================================
// 22. ENTRY CONFIRMATION
// ============================================================================
bool immediateMode = (entryMode == "Sweep Candle")
bool validLongWindow = (pendingLong and not na(longSweepBar) and bar_index > longSweepBar and bar_index - longSweepBar <= confirmationBars)
bool validShortWindow = (pendingShort and not na(shortSweepBar) and bar_index > shortSweepBar and bar_index - shortSweepBar <= confirmationBars)
bool confirmedLong = (validLongWindow and close > longSweepLevel and (not requireConfirmCandle or bullishCandle) and (not requireConfirmCloseProgress or close > close[1]) and (not requireBreakSweepCandle or close > longSweepHigh))
bool confirmedShort = (validShortWindow and close < shortSweepLevel and (not requireConfirmCandle or bearishCandle) and (not requireConfirmCloseProgress or close < close[1]) and (not requireBreakSweepCandle or close < shortSweepLow))
bool longBase = (immediateMode ? bullSweep : confirmedLong)
bool shortBase = (immediateMode ? bearSweep : confirmedShort)
// ============================================================================
// 23. FILTERED ENTRY SIGNALS
// ============================================================================
bool rawLong = (longBase and longTrendOK and adxOK and volumeOK and longH1OK)
bool rawShort = (shortBase and shortTrendOK and adxOK and volumeOK and shortH1OK)
// ============================================================================
// 24. ENTRY GATES
// ============================================================================
var int lastEntryBar = na
bool freshEntryBar = (na(lastEntryBar) or lastEntryBar != bar_index)
bool canTrade = (barstate.isconfirmed and flat and strategy.opentrades == 0 and tradesToday < maxTradesPerDay and cooldownOK and sessionOK and beforeClose and freshEntryBar)
bool ambiguous = rawLong and rawShort
bool enterLong = (canTrade and allowLong and rawLong and not ambiguous)
bool enterShort = (canTrade and allowShort and rawShort and not ambiguous)
// ============================================================================
// 25. DIAGNOSTICS COUNTERS
// ============================================================================
var int longBaseCount = 0
var int shortBaseCount = 0
var int longFilteredCount = 0
var int shortFilteredCount = 0
var int longEntryCount = 0
var int shortEntryCount = 0
if processState
if longBase
longBaseCount += 1
if shortBase
shortBaseCount += 1
if rawLong
longFilteredCount += 1
if rawShort
shortFilteredCount += 1
// ============================================================================
// 26. SL / TP IN TICKS
// ============================================================================
int slTicks = math.max(1, int(math.round(stopLossPoints / syminfo.mintick)))
int tpTicks = math.max(1, int(math.round(takeProfitPoints / syminfo.mintick)))
float effectiveSL = slTicks * syminfo.mintick
float effectiveTP = tpTicks * syminfo.mintick
// ============================================================================
// 27. LONG ENTRY
// ============================================================================
if enterLong
strategy.entry("Long", strategy.long, comment="Sell-side Sweep V2.1", alert_message="🟢 VÀO VỊ THẾ LONG (CNPS79 Liquidity Sweep V2.1)\\n🎯 Giá vào: " + str.tostring(close, format.mintick) + "\\n🛑 Cắt lỗ (SL): " + str.tostring(close - effectiveSL, format.mintick) + "\\n💰 Chốt lời (TP): " + str.tostring(close + effectiveTP, format.mintick))
tradesToday += 1
longEntryCount += 1
lastEntryBar := bar_index
pendingLong := false
longSweepBar := na
// ============================================================================
// 28. SHORT ENTRY
// ============================================================================
if enterShort
strategy.entry("Short", strategy.short, comment="Buy-side Sweep V2.1", alert_message="🔴 VÀO VỊ THẾ SHORT (CNPS79 Liquidity Sweep V2.1)\\n🎯 Giá vào: " + str.tostring(close, format.mintick) + "\\n🛑 Cắt lỗ (SL): " + str.tostring(close + effectiveSL, format.mintick) + "\\n💰 Chốt lời (TP): " + str.tostring(close - effectiveTP, format.mintick))
tradesToday += 1
shortEntryCount += 1
lastEntryBar := bar_index
pendingShort := false
shortSweepBar := na
// ============================================================================
// 29. LONG EXIT
// ============================================================================
strategy.exit("Long Exit", from_entry="Long", profit=tpTicks, loss=slTicks, comment_profit="TP Long", comment_loss="SL Long", alert_profit="💰 CHỐT LỜI LONG (TP HIT)\\n🎯 Giá chốt: " + str.tostring(strategy.position_avg_price + effectiveTP, format.mintick), alert_loss="🛑 CẮT LỖ LONG (SL HIT)\\n🎯 Giá cắt: " + str.tostring(strategy.position_avg_price - effectiveSL, format.mintick), disable_alert=disableExitAlerts)
// ============================================================================
// 30. SHORT EXIT
// ============================================================================
strategy.exit("Short Exit", from_entry="Short", profit=tpTicks, loss=slTicks, comment_profit="TP Short", comment_loss="SL Short", alert_profit="💰 CHỐT LỜI SHORT (TP HIT)\\n🎯 Giá chốt: " + str.tostring(strategy.position_avg_price - effectiveTP, format.mintick), alert_loss="🛑 CẮT LỖ SHORT (SL HIT)\\n🎯 Giá cắt: " + str.tostring(strategy.position_avg_price + effectiveSL, format.mintick), disable_alert=disableExitAlerts)
// ============================================================================
// 31. OPTIONAL TIME EXIT
// ============================================================================
int barsHeld = (strategy.opentrades > 0 ? bar_index - strategy.opentrades.entry_bar_index(0) : 0)
bool timeExit = (useTimeExit and strategy.position_size != 0 and barsHeld >= maxHoldingBars and barstate.isconfirmed)
if timeExit and not forceCloseBar
strategy.close_all(immediately=true, comment="Time Exit", alert_message="⏱️ ĐÓNG VỊ THẾ HẾT THỜI GIAN GIỮ (Time Exit)\\n🎯 Giá đóng: " + str.tostring(close, format.mintick))
// ============================================================================
// 32. SESSION CLOSE
// ============================================================================
if forceCloseBar and strategy.position_size != 0
strategy.close_all(immediately=true, comment="Session End", alert_message="⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (Session End)\\n🎯 Giá đóng: " + str.tostring(close, format.mintick))
// ============================================================================
// 33. SWING LEVEL PLOTS
// ============================================================================
plot(showSwing ? swingHigh : na, title="Swing High", color=color.red, linewidth=2, style=plot.style_stepline)
plot(showSwing ? swingLow : na, title="Swing Low", color=color.green, linewidth=2, style=plot.style_stepline)
// ============================================================================
// 34. EMA PLOT
// ============================================================================
plot(showEMA ? ema : na, title="EMA Trend", color=color.orange, linewidth=2)
// ============================================================================
// 35. SWEEP MARKERS
// ============================================================================
plotshape(showSweeps and bullSweep, title="Bullish Sweep", style=shape.circle, location=location.belowbar, color=color.aqua, size=size.tiny, text="SW")
plotshape(showSweeps and bearSweep, title="Bearish Sweep", style=shape.circle, location=location.abovebar, color=color.orange, size=size.tiny, text="SW")
// ============================================================================
// 36. ENTRY MARKERS
// ============================================================================
plotshape(showEntries and enterLong, title="CNPS79 V2.1 LONG", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="LONG", textcolor=color.white)
plotshape(showEntries and enterShort, title="CNPS79 V2.1 SHORT", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="SHORT", textcolor=color.white)
// ============================================================================
// 37. ACTIVE SL / TP
// ============================================================================
float longSL = (inLong ? strategy.position_avg_price - effectiveSL : na)
float longTP = (inLong ? strategy.position_avg_price + effectiveTP : na)
float shortSL = (inShort ? strategy.position_avg_price + effectiveSL : na)
float shortTP = (inShort ? strategy.position_avg_price - effectiveTP : na)
plot(showSLTP ? longSL : na, title="Long SL", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showSLTP ? longTP : na, title="Long TP", color=color.green, linewidth=2, style=plot.style_linebr)
plot(showSLTP ? shortSL : na, title="Short SL", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showSLTP ? shortTP : na, title="Short TP", color=color.green, linewidth=2, style=plot.style_linebr)
// ============================================================================
// 38. DATA WINDOW
// ============================================================================
plot(sellSweepATR, title="Sell Sweep Depth / ATR", color=color.green, display=display.data_window)
plot(buySweepATR, title="Buy Sweep Depth / ATR", color=color.red, display=display.data_window)
plot(adx, title="ADX", color=color.purple, display=display.data_window)
// ============================================================================
// 39. DIAGNOSTICS
// ============================================================================
var table diagnostics = table.new(position.top_right, 2, 20, border_width=1)
if showDiagnostics and barstate.islast
table.cell(diagnostics, 0, 0, "CNPS79 V2.1")
table.cell(diagnostics, 1, 0, timeframe.period)
table.cell(diagnostics, 0, 1, "Swing High")
table.cell(diagnostics, 1, 1, str.tostring(swingHigh, format.mintick))
table.cell(diagnostics, 0, 2, "Swing Low")
table.cell(diagnostics, 1, 2, str.tostring(swingLow, format.mintick))
table.cell(diagnostics, 0, 3, "EMA Up")
table.cell(diagnostics, 1, 3, emaUp ? "YES" : "NO")
table.cell(diagnostics, 0, 4, "EMA Down")
table.cell(diagnostics, 1, 4, emaDown ? "YES" : "NO")
table.cell(diagnostics, 0, 5, "ADX")
table.cell(diagnostics, 1, 5, str.tostring(adx, "#.##"))
table.cell(diagnostics, 0, 6, "Bull Sweeps")
table.cell(diagnostics, 1, 6, str.tostring(bullSweepCount))
table.cell(diagnostics, 0, 7, "Bear Sweeps")
table.cell(diagnostics, 1, 7, str.tostring(bearSweepCount))
table.cell(diagnostics, 0, 8, "Long Bases")
table.cell(diagnostics, 1, 8, str.tostring(longBaseCount))
table.cell(diagnostics, 0, 9, "Short Bases")
table.cell(diagnostics, 1, 9, str.tostring(shortBaseCount))
table.cell(diagnostics, 0, 10, "Filtered Long")
table.cell(diagnostics, 1, 10, str.tostring(longFilteredCount))
table.cell(diagnostics, 0, 11, "Filtered Short")
table.cell(diagnostics, 1, 11, str.tostring(shortFilteredCount))
table.cell(diagnostics, 0, 12, "Pending Long")
table.cell(diagnostics, 1, 12, pendingLong ? "YES" : "NO")
table.cell(diagnostics, 0, 13, "Pending Short")
table.cell(diagnostics, 1, 13, pendingShort ? "YES" : "NO")
table.cell(diagnostics, 0, 14, "Long Expired")
table.cell(diagnostics, 1, 14, str.tostring(longExpireCount))
table.cell(diagnostics, 0, 15, "Short Expired")
table.cell(diagnostics, 1, 15, str.tostring(shortExpireCount))
table.cell(diagnostics, 0, 16, "Long Entries")
table.cell(diagnostics, 1, 16, str.tostring(longEntryCount))
table.cell(diagnostics, 0, 17, "Short Entries")
table.cell(diagnostics, 1, 17, str.tostring(shortEntryCount))
table.cell(diagnostics, 0, 18, "Trades Today")
table.cell(diagnostics, 1, 18, str.tostring(tradesToday) + "/" + str.tostring(maxTradesPerDay))
table.cell(diagnostics, 0, 19, "Position")
table.cell(diagnostics, 1, 19, inLong ? "LONG" : inShort ? "SHORT" : "FLAT")
2. Những khái niệm kỹ thuật cốt lõi trong CNPS79
2.1. Đo độ sâu quét thanh khoản theo ATR và giải phẫu râu nến từ chối
Thay vì dùng khoảng điểm cố định, CNPS79 chuẩn hóa độ sâu của pha quét thanh khoản theo biến động thực tế ATR(14):
- Vùng thanh khoản được xác định bằng
swingHigh = ta.highest(high[1], 20)vàswingLow = ta.lowest(low[1], 20). Do dịch lùi 1 nến ([1]), vùng này cố định trong suốt nến hiện tại và không bị vẽ lại (repaint). - Độ sâu quét bên dưới (
sellSweepATR = (swingLow - low) / atr) và bên trên (buySweepATR = (high - swingHigh) / atr) phải nằm trong biên độ[0.10, 1.50]ATR (khiuseMaxSweepFilter = true). Điều này giúp loại bỏ nhiễu vi mô quá nhỏ hoặc các cú sập/bật quá mạnh mang tính phá vỡ thật. - Tỷ lệ râu nến từ chối được tính trên toàn bộ biên độ nến (
candleRange = high - low):lowerWickRatio = (math.min(open, close) - low) / candleRange >= 0.25cho pha quét đáy (bullSweep).upperWickRatio = (high - math.max(open, close)) / candleRange >= 0.25cho pha quét đỉnh (bearSweep).
2.2. Máy trạng thái Sweep State Machine và cơ chế tự hủy (Invalidation)
Khi xuất hiện một nến quét hợp lệ trên nến đã đóng (processState), bot không nhất thiết vào lệnh ngay mà chuyển sang trạng thái chờ xác nhận:
- Nếu có
bullSweep(và chưapendingLong), bot bậtpendingLong := true, lưu lại vị trílongSweepBar, đỉnh/đáy nến quét (longSweepHigh,longSweepLow) và mốc thanh khoảnlongSweepLevel = swingLow, đồng thời xóa trạng tháipendingShortnếu đang tồn tại. Logic tương tự áp dụng chobearSweep. - Setup chờ sẽ tự động hết hạn hoặc bị hủy (
longExpireCount/shortExpireCounttăng lên1) nếu rơi vào một trong hai trường hợp:- Quá số nến chờ tối đa:
bar_index - longSweepBar > 5(vớiconfirmationBars = 5). - Giá phá vỡ cực trị của chính nến quét (
cancelOnNewSweepExtreme = true):low < longSweepLowđối với setup Long hoặchigh > shortSweepHighđối với setup Short.
- Quá số nến chờ tối đa:
2.3. Bộ lọc xu hướng EMA(50) và các lớp lọc tùy chọn
Để tránh bắt đáy/bắt đỉnh ngược xu hướng chính, CNPS79 sử dụng đường EMA(50) làm bộ lọc mặc định (useEMAFilter = true):
- Xu hướng tăng (
longTrendOK):ema > ema[3](EMA đang dốc lên so với 3 nến trước) vàclose > ema(requirePriceEMA = true). - Xu hướng giảm (
shortTrendOK):ema < ema[3]vàclose < ema.
Bên cạnh đó, bot cung cấp 3 bộ lọc mở rộng (mặc định đang tắt false):
- Bộ lọc ADX tối đa (
useADXFilter): Sử dụngta.dmi(14, 14)và chỉ cho phép giao dịch khiadx <= 35.0, tránh vào lệnh đảo chiều khi xu hướng đang quá mạnh. - Bộ lọc đột biến khối lượng (
useVolumeFilter): Yêu cầuvolume >= ta.sma(volume, 20) * 1.20tại nến kích hoạt tín hiệu. - Bộ lọc xu hướng H1 (
useH1Bias): Lấy dữ liệu đã đóng của khung giờ H1 (request.security(..., "60", ...[1])) để đối chiếuh1Close > h1EMA(50)(Long) hoặch1Close < h1EMA(50)(Short). Bộ lọc này chỉ hợp lệ trên biểu đồ intraday nhỏ hơn 1 giờ (timeframe.in_seconds() < 3600).
3. Nguyên lý hoạt động của CNPS79
Toàn bộ chu trình vận hành của CNPS79 diễn ra tuần tự qua 5 bước trên mỗi nến đã đóng (barstate.isconfirmed):
- Bước 1 – Khởi tạo phiên và reset trạng thái ngày mới: Khi phát hiện sang ngày giao dịch mới (
newDay), bot đưa bộ đếmtradesToday := 0và xóa sạch toàn bộ trạng thái chờpendingLong,pendingShorttừ phiên hôm trước. - Bước 2 – Tính vùng Swing và quét tín hiệu thanh khoản: Tính
swingHigh,swingLow,atr(14)và kiểm tra điều kiện quét thanh khoảnbullSweep/bearSweep. - Bước 3 – Cập nhật Sweep State Machine: Kiểm tra hết hạn/hủy setup cũ trước, sau đó đăng ký setup mới nếu xuất hiện nến quét hợp lệ.
- Bước 4 – Xác nhận điểm vào lệnh và kiểm tra cổng rủi ro: Kiểm tra nến xác nhận (
confirmedLong/confirmedShort) kết hợp với các bộ lọc xu hướng (longTrendOK/shortTrendOK,adxOK,volumeOK,longH1OK/shortH1OK) và cổng kiểm soátcanTrade. - Bước 5 – Thực thi lệnh và quản trị vị thế: Gửi lệnh
strategy.entry, tăngtradesToday, cập nhậtlastEntryBar, gắn ngay cặp lệnh thoátstrategy.exittheo SL/TP cố định, đồng thời giám sát điều kiện thoát theo thời gian (nếu bật) hoặc đóng cưỡng bức lúc14:45.
4. Điều kiện vào lệnh Long và Short của CNPS79
4.1. Điều kiện vào lệnh Long
Lệnh Long (enterLong) được kích hoạt khi tất cả các điều kiện sau đồng thời thỏa mãn:
- Pha quét đáy (
bullSweep):low < swingLow,close > swingLow, độ sâu(swingLow - low) / atrnằm trong[0.10, 1.50], tỷ lệ râu dướilowerWickRatio >= 0.25. - Xác nhận đảo chiều (
confirmedLong, theo chế độ mặc địnhNext Candle Confirmation): Trong vòng1đến5nến sau nến quét, giá đóng cửa vẫn giữ trên mức quét (close > longSweepLevel), là nến tăng (close > open), đóng cửa cao hơn nến liền trước (close > close[1]). (Nếu chuyểnentryModesang"Sweep Candle", bot sẽ vào ngay tại nếnbullSweep). - Bộ lọc xu hướng & hợp lưu:
ema > ema[3]vàclose > ema(longTrendOK), cộng thêm các bộ lọc tùy chọnadxOK,volumeOK,longH1OK(nếu bật). - Chiều giao dịch:
tradeDirectionđược đặt là"Long"(mặc định) hoặc"Both". - Không xung đột tín hiệu: Không đồng thời xuất hiện cả
rawLongvàrawShorttrên cùng một nến (not ambiguous).
4.2. Điều kiện vào lệnh Short
Lệnh Short (enterShort) hoạt động theo logic đối xứng hoàn toàn:
- Pha quét đỉnh (
bearSweep):high > swingHigh,close < swingHigh, độ sâu(high - swingHigh) / atrnằm trong[0.10, 1.50], tỷ lệ râu trênupperWickRatio >= 0.25. - Xác nhận đảo chiều (
confirmedShort): Trong vòng1đến5nến sau nến quét,close < shortSweepLevel, là nến giảm (close < open) vàclose < close[1]. - Bộ lọc xu hướng & hợp lưu:
ema < ema[3]vàclose < ema(shortTrendOK), cộng thêmadxOK,volumeOK,shortH1OK. - Chiều giao dịch: Cần chuyển thông số
Trade Directiontừ mặc định"Long"sang"Short"hoặc"Both"thì bot mới thực thi lệnh Short.
4.3. Điều kiện kiểm soát giao dịch chung
Cổng kiểm soát canTrade đảm bảo mọi lệnh vào đều tuân thủ kỷ luật phiên giao dịch:
- Nến đã xác nhận:
barstate.isconfirmedphải làtruevàfreshEntryBarđảm bảo không vào lặp trên cùng một nến. - Trạng thái rỗng vị thế:
strategy.position_size == 0(flat) vàstrategy.opentrades == 0(không nhồi lệnh). - Giới hạn số lệnh/ngày:
tradesToday < maxTradesPerDay(mặc định tối đa2lệnh/ngày). - Thời gian nghỉ (Cooldown):
bar_index - lastExitBar > cooldownBars(mặc định phải cách lần đóng lệnh gần nhất ít nhất hơn3nến). - Khung giờ phiên giao dịch (
Asia/Ho_Chi_Minh):sessionOKyêu cầu nến nằm trong khoảng09:15đến14:15, vàbeforeCloseyêu cầu thời điểm đóng nến trước14:45.
5. Quản trị Stop Loss, Take Profit và Thoát lệnh
5.1. Cơ chế Stop Loss và quy đổi sang Tick
CNPS79 sử dụng mức cắt lỗ cố định theo điểm (stopLossPoints = 5.0), sau đó quy đổi chính xác sang đơn vị tick của hợp đồng VN30F1M:
slTicks = math.max(1, int(math.round(stopLossPoints / syminfo.mintick)))effectiveSL = slTicks * syminfo.mintick- Với lệnh Long, mức SL nằm tại
strategy.position_avg_price - effectiveSL. Với lệnh Short, mức SL nằm tạistrategy.position_avg_price + effectiveSL.
5.2. Cơ chế Take Profit, Time Exit và đóng lệnh cuối phiên
- Take Profit cố định:
takeProfitPoints = 15.0được quy đổi thànhtpTicksvàeffectiveTPtương tự như SL, tạo tỷ lệ Risk:Reward mặc định1:3. Cặp lệnhstrategy.exitđược gắn liên tục ngay khi vị thế mở. Bot không sử dụng cơ chế dời hòa vốn (Break Even) hay Trailing Stop. - Thoát lệnh theo thời gian (
useTimeExit): Mặc định tắt (false). Nếu bật, khi số nến nắm giữbarsHeld >= maxHoldingBars(20nến) tại nến đã đóng (và không trùng nếnforceCloseBar), bot gọistrategy.close_all(immediately=true, comment="Time Exit"). - Đóng vị thế cuối phiên (
forceCloseBar): Tại cây nến cóopenMin < 14:45vàcloseMin >= 14:45, nếu vẫn còn vị thế mở, bot tự động đóng toàn bộ bằngstrategy.close_all(immediately=true, comment="Session End")để tránh rủi ro giữ lệnh qua đêm hoặc kẹt thanh khoản phiên ATC.
5.3. Bảng tổng hợp cơ chế bảo vệ vị thế
| Cơ chế thoát lệnh | Trạng thái mặc định | Thông số / Điều kiện kích hoạt | Hành động thực thi |
|---|---|---|---|
| Stop Loss (Cắt lỗ) | Luôn bật | 5.0 điểm (slTicks) | Đóng vị thế qua strategy.exit (SL Long / SL Short) |
| Take Profit (Chốt lời) | Luôn bật | 15.0 điểm (tpTicks) | Đóng vị thế qua strategy.exit (TP Long / TP Short) |
| Time Exit (Hết thời gian giữ) | Tắt (false) | Giữ đủ 20 nến (maxHoldingBars) | Đóng toàn bộ qua strategy.close_all (Time Exit) |
| Session End (Hết phiên) | Luôn bật | Nến chạm mốc 14:45 (Asia/Ho_Chi_Minh) | Đóng toàn bộ qua strategy.close_all (Session End) |
6. Hướng dẫn cài đặt và đọc bảng Diagnostics trên TradingView
Các bước cài đặt
- Mở biểu đồ hợp đồng tương lai VN30F1M trên TradingView (khuyến nghị khung thời gian intraday như M5 hoặc M15 để tận dụng tốt bộ lọc phiên và H1 Bias).
- Mở tab Pine Editor ở phía dưới màn hình, xóa toàn bộ đoạn code mẫu hiện có.
- Sao chép toàn bộ mã nguồn Pine Script v6 ở Mục 1 và dán vào Pine Editor.
- Nhấn Save để lưu script, sau đó nhấn Add to chart để gắn chiến lược CNPS79 LIQUIDITY SWEEP REVERSAL V2.1 lên biểu đồ.
- Vào phần Settings (Cài đặt) của chiến lược để điều chỉnh chiều giao dịch (
Long,ShorthoặcBoth), mức SL/TP hoặc bậtShow Diagnosticsnếu muốn theo dõi bảng thống kê trực tiếp.
Cách đọc bảng chẩn đoán (Diagnostics Table)
Khi bật tùy chọn Show Diagnostics = true, bot sẽ hiển thị một bảng gồm 20 dòng tại góc trên bên phải biểu đồ (position.top_right) ở nến cuối cùng:
- CNPS79 V2.1 | Khung thời gian: Tên bot và chu kỳ biểu đồ đang chạy (
timeframe.period). - Swing High / Swing Low: Mức đỉnh và đáy 20 nến gần nhất đang được dùng để phát hiện quét thanh khoản.
- EMA Up / EMA Down: Trạng thái độ dốc của đường
EMA(50)(YEShoặcNO). - ADX: Giá trị ADX hiện tại.
- Bull Sweeps / Bear Sweeps: Tổng số pha quét đáy / quét đỉnh hợp lệ đã ghi nhận.
- Long Bases / Short Bases: Số tín hiệu cơ sở (trước khi qua bộ lọc EMA/ADX/Volume/H1).
- Filtered Long / Filtered Short: Số tín hiệu đã vượt qua đầy đủ các bộ lọc xu hướng và hợp lưu.
- Pending Long / Pending Short: Trạng thái máy đang chờ nến xác nhận (
YES/NO). - Long Expired / Short Expired: Số lượng setup bị hủy do quá 5 nến chờ hoặc bị phá cực trị nến quét.
- Long Entries / Short Entries: Tổng số lệnh Long / Short thực tế đã vào.
- Trades Today: Số lệnh đã thực hiện trong ngày hiện tại so với giới hạn (
0/2,1/2,2/2). - Position: Trạng thái vị thế hiện tại (
LONG,SHORThoặcFLAT).
7. Cách thiết lập cảnh báo tín hiệu giao dịch (Alert)
Để nhận thông báo tự động hoặc kết nối webhook thực thi lệnh từ CNPS79, bạn thực hiện thiết lập Alert trên TradingView như sau:
- Nhấn vào biểu tượng Alert (Đồng hồ báo thức) hoặc phím tắt
Alt + Atrên biểu đồ đã gắn CNPS79. - Tại mục Condition, chọn chiến lược
CNPS79 LIQUIDITY SWEEP REVERSAL V2.1. - Tại mục Message, xóa nội dung mặc định và điền duy nhất biến:
{{strategy.order.alert_message}} - Chọn kênh nhận thông báo (Popup, Email, App TradingView hoặc Webhook URL) rồi nhấn Create.
Bảng thông điệp Alert của CNPS79
Mã nguồn của CNPS79 định nghĩa sẵn các thông điệp chi tiết cho từng sự kiện giao dịch (lưu ý các thông điệp SL/TP chỉ gửi khi Disable SL/TP Alerts = false):
| Sự kiện | Thông số Alert trong code | Nội dung thông điệp thực tế |
|---|---|---|
| Vào lệnh Long | alert_message (strategy.entry) | 🟢 VÀO VỊ THẾ LONG (CNPS79 Liquidity Sweep V2.1) kèm Giá vào, SL và TP |
| Vào lệnh Short | alert_message (strategy.entry) | 🔴 VÀO VỊ THẾ SHORT (CNPS79 Liquidity Sweep V2.1) kèm Giá vào, SL và TP |
| Chốt lời Long | alert_profit (strategy.exit) | 💰 CHỐT LỜI LONG (TP HIT) kèm Giá chốt (position_avg_price + effectiveTP) |
| Cắt lỗ Long | alert_loss (strategy.exit) | 🛑 CẮT LỖ LONG (SL HIT) kèm Giá cắt (position_avg_price - effectiveSL) |
| Chốt lời Short | alert_profit (strategy.exit) | 💰 CHỐT LỜI SHORT (TP HIT) kèm Giá chốt (position_avg_price - effectiveTP) |
| Cắt lỗ Short | alert_loss (strategy.exit) | 🛑 CẮT LỖ SHORT (SL HIT) kèm Giá cắt (position_avg_price + effectiveSL) |
| Hết thời gian giữ | alert_message (strategy.close_all) | ⏱️ ĐÓNG VỊ THẾ HẾT THỜI GIAN GIỮ (Time Exit) kèm Giá đóng |
| Đóng hết phiên | alert_message (strategy.close_all) | ⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (Session End) kèm Giá đóng |
Kết luận
CNPS79 Liquidity Sweep Reversal V2.1 là một hệ thống giao dịch bài bản dành cho VN30F1M, kết hợp chặt chẽ giữa hành vi quét thanh khoản (Liquidity Sweep), xác nhận động lượng đảo chiều qua State Machine và bộ lọc xu hướng EMA(50). Với tỷ lệ R:R cố định 1:3 (SL 5.0 điểm / TP 15.0 điểm), giới hạn 2 lệnh mỗi ngày và cơ chế đóng vị thế trước ATC lúc 14:45, bot đặc biệt phù hợp với thị trường có xu hướng rõ ràng kèm các nhịp rũ bỏ (shakeout) tại vùng hỗ trợ/kháng cự ngắn hạn.
Bạn có thể tham khảo thêm các hệ thống giao dịch khác trên hệ sinh thái như Bot CNPS50 - Trend Analysis V2 và Bot CNPS49 - Daily Open để đa dạng hóa chiến lược giao dịch phái sinh.
Thông tin chỉ mang tính tham khảo, không phải khuyến nghị đầu tư. Kết quả kiểm thử quá khứ không đảm bảo lợi nhuận trong tương lai.
Thông tin trong bài chỉ mang tính tham khảo, không phải khuyến nghị mua bán. Giao dịch phái sinh có rủi ro cao do sử dụng đòn bẩy; nhà đầu tư tự chịu trách nhiệm với quyết định của mình.





