Hướng Dẫn Sử Dụng Bot CNPS63 - Relative Volume Expansion V1 cho VN30F1M
TradingviewBot CNPS63 giao dịch VN30F1M theo mô hình xung lực khối lượng tương đối (RVOL), theo dõi nhịp điều chỉnh cạn cung và tái tăng tốc dòng tiền để vào lệnh chuẩn xác.

Mục lục
Trong giao dịch phái sinh VN30F1M trong ngày (khung M1, M3, M5), một trong những rủi ro lớn nhất của nhà đầu tư là mua đuổi vào các cây nến bùng nổ thanh khoản giả (volume spike nhưng thiếu lực duy trì) hoặc bị quét dừng lỗ trong các nhịp rung lắc ngắn hạn ngay sau khi giá phá vỡ.
Bot CNPS63 — tên đầy đủ trong mã nguồn là CNPS63 RELATIVE VOLUME EXPANSION V1 - VN30F1M (viết bằng Pine Script v6 trên TradingView) — được thiết kế để giải quyết bài toán này theo chuỗi 3 pha: Xung lực khối lượng (Volume impulse) → Hấp thụ điều chỉnh có kiểm soát (Controlled digestion) → Tái tham gia theo xu hướng (Renewed directional participation). Mọi tín hiệu đều chỉ xử lý trên nến đã đóng cửa xác nhận (barstate.isconfirmed).
Những điểm nổi bật cốt lõi của Bot CNPS63:
- Đo lường xung lực khối lượng đa tầng: Kết hợp khối lượng tương đối
RVOL(so với EMA 40 phiên trước) cùng tỷ lệ gia tốc khối lượng ngắn/dài (EMA 4 / EMA 20) và chất lượng thân nến mở rộng theoATR(14). - Máy trạng thái 5 bước (State Machine): Theo dõi chặt chẽ diễn biến sau nến xung lực, phân biệt giữa nhịp tiếp diễn trực tiếp (Follow-Through) và nhịp điều chỉnh cạn kiệt khối lượng (Volume Dryback) trước khi tái tăng tốc.
- Lọc xu hướng nghịch chiều mạnh bằng ADX/DMI: Chủ động chặn các lệnh ngược xu hướng khi
ADX(14) >= 38.0kết hợp vị trí giá so vớiEMA(34)và hướngDI+/DI-. - Quản trị rủi ro cấu trúc & phiên VN30F1M chặt chẽ: Tính Stop Loss theo cấu trúc đáy/đỉnh gần nhất, giới hạn khoảng cách rủi ro
1.5 – 12.0điểm, chốt lời1.65R, giới hạn thời gian giữ lệnh tối đa45phút, khóa lỗ ngày và tự động đóng vị thế trước giờ nghỉ trưa (11:25) cũng như trước phiên ATC (14:25).
1. CNPS63 Relative Volume Expansion V1 là gì?
CNPS63 Relative Volume Expansion V1 là hệ thống giao dịch theo dòng tiền và cấu trúc giá trên hợp đồng tương lai VN30F1M, vận hành dựa trên 4 trụ cột kỹ thuật chính:
- Xung lực khối lượng tương đối (Relative Volume Impulse): Xác định thời điểm dòng tiền tham gia đột biến (
RVOL >= 1.55vàEMA(4)/EMA(20) >= 1.05) đi kèm nến có thân đặc (bodyRatio >= 0.45), giá đóng cửa sát cực trị (closeLocation >= 0.70với Long hoặc<= 0.30với Short) và phá vỡ đỉnh/đáy vi mô6nến gần nhất. - Hấp thụ điều chỉnh cạn cung (Controlled Digestion / Dryback): Sau nến xung lực, nếu giá không chạy tiếp ngay, hệ thống theo dõi nhịp hồi về từ
22%đến85%biên độ nến xung lực với điều kiện khối lượng suy giảm (<= 85%volume nến xung lực hoặcRVOL <= 1.10). - Xác nhận tái tăng tốc dòng tiền (Volume Re-Acceleration): Chỉ kích hoạt lệnh khi có nến xác nhận hướng đi với
RVOL >= 0.95, thân nến tối thiểu25%biên độ, đóng cửa vượt cấu trúc đỉnh/đáy trước đó cộng khoảng đệm0.10điểm. - Bảo vệ vị thế & kiểm soát phiên giao dịch: Áp dụng bộ lọc rủi ro đầu vào (
minimumStopPoints,maximumStopPoints,minimumGrossTarget), kiểm tra lại giá khớp thực tế (INVALID FILLED RISK), giới hạn lỗ đã chốt trong ngày (2,400,000 VND) và ép đóng toàn bộ lệnh trước giờ nghỉ trưa/ATC.
Bảng thông số mặc định
| Nhóm thông số | Tham số trong code | Giá trị mặc định | Ý nghĩa chính |
|---|---|---|---|
| 01 - Trade Control | tradeDirection | "Both" | Chiều giao dịch (Both, Long, Short) |
contracts | 3 | Số hợp đồng mỗi lệnh (1 – 20) | |
maximumTradesPerDay | 5 | Số lệnh tối đa trong ngày | |
cooldownBars | 3 | Số nến nghỉ tối thiểu sau khi đóng lệnh | |
oneTradePerSide | false | Giới hạn tối đa 1 lệnh mỗi chiều/ngày | |
| 02 - Volume Impulse | volumeBaselineBars | 40 | Chu kỳ EMA nền tính RVOL (lấy giá trị [1]) |
fastVolumeBars / slowVolumeBars | 4 / 20 | Chu kỳ EMA khối lượng nhanh và chậm | |
minimumImpulseRVOL | 1.55 | Ngưỡng RVOL tối thiểu cho nến xung lực | |
minimumVolumeAcceleration | 1.05 | Tỷ lệ EMA(4) / EMA(20) tối thiểu | |
| 03 - Price Impulse | impulseBreakBars | 6 | Số nến nhìn lại phá vỡ cấu trúc vi mô |
minimumImpulseBody | 0.45 | Tỷ lệ thân/biên độ tối thiểu của nến xung lực | |
minimumImpulseCloseLocation | 0.70 | Vị trí đóng cửa hướng về cực trị nến | |
minimumImpulseRangeATR / maximum | 0.65 / 2.70 | Biên độ nến xung lực giới hạn theo ATR(14) | |
| 04 - Entry Engine | entryMode | "Hybrid" | Chế độ vào lệnh (Hybrid, Pullback Re-Acceleration, Impulse Follow-Through, Direct Impulse) |
maximumSetupBars | 9 | Số nến tối đa duy trì trạng thái sau xung lực | |
minimumPullbackFraction / maximum | 0.22 / 0.85 | Biên độ thoái lui hợp lệ so với nến xung lực | |
maximumDrybackVolumeRatio / RVOL | 0.85 / 1.10 | Ngưỡng khối lượng cạn kiệt khi điều chỉnh | |
maximumWaitAfterPullback | 5 | Số nến tối đa chờ xác nhận sau nhịp pullback | |
| 05 - Confirmation | minimumEntryRVOL | 0.95 | RVOL tối thiểu của nến xác nhận vào lệnh |
minimumConfirmationBody | 0.25 | Tỷ lệ thân/biên độ tối thiểu nến xác nhận | |
confirmationBuffer | 0.10 | Khoảng đệm vượt cấu trúc (điểm) | |
maximumFollowExtensionATR | 2.00 | Độ giãn tối đa khi vào lệnh tiếp diễn (x ATR) | |
| 06 - Filters | useTrendFilter / trendEMALength | false / 34 | Bật/tắt bộ lọc xu hướng theo EMA 34 |
trendSlopeBars / minimumTrendSlopeATR | 5 / 0.00 | Chu kỳ và độ dốc EMA chuẩn hóa theo ATR | |
useVWAPFilter | false | Bật/tắt lọc theo Session VWAP | |
useAdverseTrendGuard / strongTrendADX | true / 38.0 | Chặn lệnh ngược xu hướng mạnh khi ADX >= 38 | |
| 07 - Risk | stopMode | "Recent Structure" | Chế độ SL (Recent Structure, Impulse Extreme, ATR Fixed) |
recentStopBars / stopBufferATR | 5 / 0.15 | Lookback cấu trúc SL và khoảng đệm x ATR14 | |
fixedStopATR | 1.30 | Hệ số ATR nếu dùng ATR Fixed | |
minimumStopPoints / maximumStopPoints | 1.50 / 12.0 | Khoảng cách SL hợp lệ (điểm) | |
| 08 - Exits | takeProfitR / minimumGrossTarget | 1.65 / 2.50 | Mục tiêu chốt lời 1.65R và tối thiểu 2.50 điểm |
useBreakEven / breakEvenAtR / Offset | false / 1.00 / 0.20 | Dời SL hòa vốn tại 1.00R cộng 0.20 điểm | |
useTimeExit / maximumHoldMinutes | true / 45 | Đóng lệnh nếu giữ quá 45 phút | |
| 09 - Protection | useDailyLossGuard / maximumDailyLossVND | true / 2,400,000 | Dừng mở lệnh mới khi lỗ đã chốt đạt ngưỡng |
| 10 - Session | morningEntry / afternoonEntry | 0905-1120 / 1305-1415 | Khung giờ tìm tín hiệu vào lệnh (UTC+7) |
closeBeforeLunch / lunchFlatMinute | true / 25 | Đóng lệnh lúc 11:25 trước giờ nghỉ trưa | |
finalFlatHour / finalFlatMinute | 14 / 25 | Đóng toàn bộ vị thế lúc 14:25 trước ATC | |
| 11 - Display | showEntryMarkers / showTradeLevels | true / true | Hiển thị tín hiệu L/S và đường SL/TP |
showImpulseMarkers / showPullbackMarkers / showVWAP | false | Tùy chọn hiện nhãn RV+/RV-, PB+/PB- và VWAP |
Source Code CNPS63 Relative Volume Expansion V1
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
// CNPS63 - Relative Volume Expansion V1 - VN30F1M.
// Volume impulse -> controlled digestion -> renewed directional participation.
// Research strategy. No dashboard. Signals use confirmed candles only.
strategy(title="CNPS63 RELATIVE VOLUME EXPANSION V1 - VN30F1M", shorttitle="CNPS63 RVOL V1", overlay=true, initial_capital=100000000, currency=currency.VND, default_qty_type=strategy.fixed, default_qty_value=1, pyramiding=0, margin_long=12, margin_short=12, slippage=0, commission_type=strategy.commission.cash_per_contract, commission_value=0, process_orders_on_close=false, calc_on_order_fills=false, calc_on_every_tick=false, fill_orders_on_standard_ohlc=true, max_bars_back=5000, max_labels_count=100)
// ============================================================================
// SECTION 1: TRADE CONTROL
// ============================================================================
tradeDirection = input.string("Both", title="Trade Direction", options=["Both", "Long", "Short"], group="01 - Trade Control")
contracts = input.int(3, title="Contracts Per Trade", minval=1, maxval=20, group="01 - Trade Control")
maximumTradesPerDay = input.int(5, title="Maximum Trades Per Day", minval=1, maxval=20, group="01 - Trade Control")
cooldownBars = input.int(3, title="Cooldown Bars After Exit", minval=0, maxval=100, group="01 - Trade Control")
oneTradePerSide = input.bool(false, title="One Trade Per Direction Per Day?", group="01 - Trade Control")
// ============================================================================
// SECTION 2: RELATIVE VOLUME EXPANSION
// ============================================================================
volumeBaselineBars = input.int(40, title="Previous Volume EMA Baseline", minval=10, maxval=300, group="02 - Volume Impulse")
fastVolumeBars = input.int(4, title="Fast Volume EMA", minval=2, maxval=20, group="02 - Volume Impulse")
slowVolumeBars = input.int(20, title="Slow Volume EMA", minval=5, maxval=100, group="02 - Volume Impulse")
minimumImpulseRVOL = input.float(1.55, title="Minimum Impulse Relative Volume", minval=0.50, maxval=6.0, step=0.05, group="02 - Volume Impulse")
minimumVolumeAcceleration = input.float(1.05, title="Fast / Slow Volume Expansion Ratio", minval=0.5, maxval=4.0, step=0.05, group="02 - Volume Impulse")
// ============================================================================
// SECTION 3: PRICE RESPONSE TO VOLUME IMPULSE
// ============================================================================
impulseBreakBars = input.int(6, title="Impulse Micro Structure Lookback", minval=2, maxval=30, group="03 - Price Impulse")
minimumImpulseBody = input.float(0.45, title="Minimum Impulse Body / Range", minval=0.1, maxval=1.0, step=0.05, group="03 - Price Impulse")
minimumImpulseCloseLocation = input.float(0.70, title="Impulse Close Location Toward Direction", minval=0.5, maxval=0.95, step=0.05, group="03 - Price Impulse")
minimumImpulseRangeATR = input.float(0.65, title="Minimum Impulse Range x ATR14", minval=0.1, maxval=4.0, step=0.05, group="03 - Price Impulse")
maximumImpulseRangeATR = input.float(2.70, title="Maximum Impulse Range x ATR14", minval=0.5, maxval=10.0, step=0.1, group="03 - Price Impulse")
// ============================================================================
// SECTION 4: DIGESTION / VOLUME DRYBACK
// ============================================================================
entryMode = input.string("Hybrid", title="Entry Mode", options=["Hybrid", "Pullback Re-Acceleration", "Impulse Follow-Through", "Direct Impulse"], group="04 - Entry Engine")
maximumSetupBars = input.int(9, title="Maximum Bars After Volume Impulse", minval=2, maxval=40, group="04 - Entry Engine")
minimumPullbackFraction = input.float(0.22, title="Minimum Pullback Fraction Of Impulse Candle", minval=0.05, maxval=0.8, step=0.05, group="04 - Entry Engine")
maximumPullbackFraction = input.float(0.85, title="Maximum Pullback Fraction Of Impulse Candle", minval=0.30, maxval=1.5, step=0.05, group="04 - Entry Engine")
maximumDrybackVolumeRatio = input.float(0.85, title="Maximum Pullback Volume / Impulse Volume", minval=0.20, maxval=1.5, step=0.05, group="04 - Entry Engine")
maximumDrybackRVOL = input.float(1.10, title="Alternative Maximum Pullback RVOL", minval=0.20, maxval=3.0, step=0.05, group="04 - Entry Engine")
maximumWaitAfterPullback = input.int(5, title="Maximum Confirmation Bars After Pullback", minval=1, maxval=25, group="04 - Entry Engine")
// ============================================================================
// SECTION 5: VOLUME RE-ACCELERATION CONFIRMATION
// ============================================================================
minimumEntryRVOL = input.float(0.95, title="Minimum Relative Volume On Entry Confirmation", minval=0.1, maxval=4.0, step=0.05, group="05 - Confirmation")
minimumConfirmationBody = input.float(0.25, title="Minimum Entry Candle Body / Range", minval=0.0, maxval=1.0, step=0.05, group="05 - Confirmation")
confirmationBuffer = input.float(0.10, title="Close Beyond Prior Structure (points)", minval=0.0, step=0.1, group="05 - Confirmation")
maximumFollowExtensionATR = input.float(2.00, title="Maximum Follow-Through Extension From Impulse x ATR", minval=0.25, maxval=8.0, step=0.25, group="05 - Confirmation")
// ============================================================================
// SECTION 6: OPTIONAL TREND AND MARKET CONTEXT
// ============================================================================
useTrendFilter = input.bool(false, title="Require EMA Trend Alignment?", group="06 - Filters")
trendEMALength = input.int(34, title="Trend EMA", minval=5, maxval=200, group="06 - Filters")
trendSlopeBars = input.int(5, title="EMA Slope Lookback", minval=1, maxval=40, group="06 - Filters")
minimumTrendSlopeATR = input.float(0.00, title="Minimum Trend Slope / ATR", minval=-1.0, maxval=3.0, step=0.05, group="06 - Filters")
useVWAPFilter = input.bool(false, title="Require Session VWAP Alignment?", group="06 - Filters")
useAdverseTrendGuard = input.bool(true, title="Block Strong Adverse Trend?", group="06 - Filters")
strongTrendADX = input.float(38.0, title="Strong Adverse ADX Threshold", minval=10.0, maxval=60.0, step=1.0, group="06 - Filters")
// ============================================================================
// SECTION 7: STRUCTURAL RISK MANAGEMENT
// ============================================================================
stopMode = input.string("Recent Structure", title="Stop Mode", options=["Recent Structure", "Impulse Extreme", "ATR Fixed"], group="07 - Risk")
recentStopBars = input.int(5, title="Recent Structure Stop Lookback", minval=2, maxval=30, group="07 - Risk")
stopBufferATR = input.float(0.15, title="Structure Stop Buffer x ATR14", minval=0.0, maxval=2.0, step=0.05, group="07 - Risk")
fixedStopATR = input.float(1.30, title="ATR Fixed Stop Multiple", minval=0.25, maxval=5.0, step=0.05, group="07 - Risk")
minimumStopPoints = input.float(1.50, title="Minimum Stop Distance (points)", minval=0.1, step=0.5, group="07 - Risk")
maximumStopPoints = input.float(12.0, title="Maximum Stop Distance (points)", minval=0.5, step=0.5, group="07 - Risk")
// ============================================================================
// SECTION 8: PROFIT TARGET / EXITS
// ============================================================================
takeProfitR = input.float(1.65, title="Take Profit Multiple (R)", minval=0.25, maxval=8.0, step=0.05, group="08 - Exits")
minimumGrossTarget = input.float(2.50, title="Minimum Gross Target (points)", minval=0.0, step=0.5, group="08 - Exits")
useBreakEven = input.bool(false, title="Enable Break Even?", group="08 - Exits")
breakEvenAtR = input.float(1.00, title="Break Even At R", minval=0.25, maxval=5.0, step=0.25, group="08 - Exits")
breakEvenOffset = input.float(0.20, title="Break Even Offset (points)", minval=0.0, step=0.1, group="08 - Exits")
useTimeExit = input.bool(true, title="Use Maximum Hold Minutes?", group="08 - Exits")
maximumHoldMinutes = input.int(45, title="Maximum Hold (minutes)", minval=5, maxval=240, group="08 - Exits")
// ============================================================================
// SECTION 9: DAILY RISK LIMIT
// ============================================================================
useDailyLossGuard = input.bool(true, title="Block New Trades After Daily Closed Loss?", group="09 - Protection")
maximumDailyLossVND = input.float(2400000, title="Daily Closed Loss Threshold (VND)", minval=100000, step=100000, group="09 - Protection")
// ============================================================================
// SECTION 10: VN30F1M SESSION
// ============================================================================
string timezoneVN = "Asia/Ho_Chi_Minh"
morningEntry = input.session("0905-1120", title="Morning Entry Window", group="10 - Session")
afternoonEntry = input.session("1305-1415", title="Afternoon Entry Window", group="10 - Session")
closeBeforeLunch = input.bool(true, title="Force Flat Before Lunch?", group="10 - Session")
lunchFlatMinute = input.int(25, title="Lunch Flat Minute (11:xx)", minval=15, maxval=30, group="10 - Session")
finalFlatHour = input.int(14, title="Final Flat Hour", minval=0, maxval=23, group="10 - Session")
finalFlatMinute = input.int(25, title="Final Flat Minute", minval=0, maxval=59, group="10 - Session")
// ============================================================================
// SECTION 11: CLEAN DISPLAY - NO TABLE
// ============================================================================
showImpulseMarkers = input.bool(false, title="Show Volume Impulse Markers?", group="11 - Display")
showPullbackMarkers = input.bool(false, title="Show Low-Volume Digestion Markers?", group="11 - Display")
showEntryMarkers = input.bool(true, title="Show Entry Signals?", group="11 - Display")
showTradeLevels = input.bool(true, title="Show Active SL / TP?", group="11 - Display")
showVWAP = input.bool(false, title="Show Session VWAP?", group="11 - Display")
// ============================================================================
// SECTION 12: TIME ENGINE
// ============================================================================
int minuteOpen = hour(time, timezoneVN) * 60 + minute(time, timezoneVN)
int minuteClose = hour(time_close, timezoneVN) * 60 + minute(time_close, timezoneVN)
int lunchCutoff = 660 + lunchFlatMinute
int finalCutoff = finalFlatHour * 60 + finalFlatMinute
bool continuousMorning = minuteOpen >= 540 and minuteOpen < 690
bool continuousAfternoon = minuteOpen >= 780 and minuteOpen < 870
bool continuousSession = continuousMorning or continuousAfternoon
bool morningBegins = continuousMorning and not continuousMorning[1]
bool afternoonBegins = continuousAfternoon and not continuousAfternoon[1]
bool inMorningEntry = not na(time(timeframe.period, morningEntry + ":23456", timezoneVN))
bool inAfternoonEntry = not na(time(timeframe.period, afternoonEntry + ":23456", timezoneVN))
bool entrySession = (continuousSession and (inMorningEntry or inAfternoonEntry))
int dayKey = (year(time, timezoneVN) * 10000 + month(time, timezoneVN) * 100 + dayofmonth(time, timezoneVN))
bool newTradingDay = (bar_index == 0 or dayKey != nz(dayKey[1], dayKey))
bool beforeCutoff = (not na(time_close) and minuteClose < finalCutoff and (not closeBeforeLunch or not continuousMorning or minuteClose < lunchCutoff))
bool lunchFlatBar = (closeBeforeLunch and barstate.isconfirmed and continuousMorning and minuteOpen < lunchCutoff and minuteClose >= lunchCutoff)
bool finalFlatBar = (barstate.isconfirmed and continuousAfternoon and minuteOpen < finalCutoff and minuteClose >= finalCutoff)
// ============================================================================
// SECTION 13: VOLUME / CANDLE / PRICE METRICS
// ============================================================================
float atr = ta.atr(14)
float trendEMA = ta.ema(close, trendEMALength)
float candleRange = math.max(high - low, syminfo.mintick)
float bodyRatio = (math.abs(close - open) / candleRange)
float closeLocation = (close - low) / candleRange
float priorMicroHigh = ta.highest(high, impulseBreakBars)[1]
float priorMicroLow = ta.lowest(low, impulseBreakBars)[1]
float recentStopLow = ta.lowest(low, recentStopBars)
float recentStopHigh = ta.highest(high, recentStopBars)
float volumeBaseline = ta.ema(volume, volumeBaselineBars)[1]
float fastVolumeAverage = ta.ema(volume, fastVolumeBars)
float slowVolumeAverage = ta.ema(volume, slowVolumeBars)
float rvol = (not na(volumeBaseline) and volumeBaseline > 0 ? volume / volumeBaseline : na)
float volumeAcceleration = (slowVolumeAverage > 0 ? fastVolumeAverage / slowVolumeAverage : na)
float trendSlopeATR = (not na(atr) and atr > 0 ? (trendEMA - trendEMA[trendSlopeBars]) / atr : 0.0)
[pDI, mDI, adx] = ta.dmi(14, 14)
bool bullishCandle = (close > open and bodyRatio >= minimumConfirmationBody and closeLocation >= 0.55)
bool bearishCandle = (close < open and bodyRatio >= minimumConfirmationBody and closeLocation <= 0.45)
bool impulseVolumeOK = (not na(rvol) and not na(volumeAcceleration) and rvol >= minimumImpulseRVOL and volumeAcceleration >= minimumVolumeAcceleration)
bool impulseRangeOK = (not na(atr) and atr > 0 and candleRange >= minimumImpulseRangeATR * atr and candleRange <= maximumImpulseRangeATR * atr)
bool bullishImpulseCandle = (close > open and bodyRatio >= minimumImpulseBody and closeLocation >= minimumImpulseCloseLocation)
bool bearishImpulseCandle = (close < open and bodyRatio >= minimumImpulseBody and closeLocation <= 1.0 - minimumImpulseCloseLocation)
// ============================================================================
// SECTION 14: SESSION VWAP / REGIME FILTERS
// ============================================================================
var float cumulativePV = 0.0
var float cumulativeVolume = 0.0
if newTradingDay
cumulativePV := 0.0
cumulativeVolume := 0.0
if (continuousSession and barstate.isconfirmed and not na(volume) and volume > 0)
cumulativePV += hlc3 * volume
cumulativeVolume += volume
float sessionVWAP = (cumulativeVolume > 0 ? cumulativePV / cumulativeVolume : na)
bool longTrendOK = (not useTrendFilter or (close > trendEMA and trendSlopeATR >= minimumTrendSlopeATR))
bool shortTrendOK = (not useTrendFilter or (close < trendEMA and trendSlopeATR <= -minimumTrendSlopeATR))
bool longVWAPOK = (not useVWAPFilter or (not na(sessionVWAP) and close > sessionVWAP))
bool shortVWAPOK = (not useVWAPFilter or (not na(sessionVWAP) and close < sessionVWAP))
bool adverseLongTrend = (useAdverseTrendGuard and not na(adx) and adx >= strongTrendADX and close < trendEMA and mDI > pDI)
bool adverseShortTrend = (useAdverseTrendGuard and not na(adx) and adx >= strongTrendADX and close > trendEMA and pDI > mDI)
// ============================================================================
// SECTION 15: DAILY TRADE CONTROL
// ============================================================================
var int tradesToday = 0
var int closedTradesSeen = 0
var int lastExitBar = na
var int lastOrderBar = na
var float dayStartNetProfit = na
var bool tradedLongToday = false
var bool tradedShortToday = false
if newTradingDay
tradesToday := 0
dayStartNetProfit := strategy.netprofit
tradedLongToday := false
tradedShortToday := false
if strategy.closedtrades > closedTradesSeen
closedTradesSeen := strategy.closedtrades
lastExitBar := bar_index
bool flat = strategy.position_size == 0
bool inLong = strategy.position_size > 0
bool inShort = strategy.position_size < 0
bool allowLong = (tradeDirection != "Short" and (not oneTradePerSide or not tradedLongToday))
bool allowShort = (tradeDirection != "Long" and (not oneTradePerSide or not tradedShortToday))
float dailyClosedPnL = (strategy.netprofit - nz(dayStartNetProfit, strategy.netprofit))
bool tradeCountOK = (tradesToday < maximumTradesPerDay)
bool cooldownOK = (na(lastExitBar) or bar_index - lastExitBar > cooldownBars)
bool dailyLossOK = (not useDailyLossGuard or dailyClosedPnL > -maximumDailyLossVND)
bool oncePerBar = (na(lastOrderBar) or lastOrderBar != bar_index)
bool commonEntryOK = (flat and entrySession and beforeCutoff and tradeCountOK and cooldownOK and dailyLossOK and oncePerBar and barstate.isconfirmed)
// ============================================================================
// SECTION 16: NEW DIRECTIONAL VOLUME IMPULSE
// ============================================================================
bool newBullishImpulse = (barstate.isconfirmed and entrySession and beforeCutoff and impulseVolumeOK and impulseRangeOK and bullishImpulseCandle and close > priorMicroHigh and longTrendOK and longVWAPOK and not adverseLongTrend)
bool newBearishImpulse = (barstate.isconfirmed and entrySession and beforeCutoff and impulseVolumeOK and impulseRangeOK and bearishImpulseCandle and close < priorMicroLow and shortTrendOK and shortVWAPOK and not adverseShortTrend)
// ============================================================================
// SECTION 17: IMPULSE / DRYBACK STATE MACHINE
// ============================================================================
// State 0: Waiting for qualified volume impulse.
// State 1: Bull impulse; waiting for follow-through or low-volume pullback.
// State -1: Bear impulse; waiting for follow-through or low-volume pullback.
// State 2: Bull pullback recorded; waiting for volume re-acceleration.
// State -2: Bear pullback recorded; waiting for volume re-acceleration.
// ============================================================================
var int setupState = 0
var int impulseBar = na
var int pullbackBar = na
var float impulseHigh = na
var float impulseLow = na
var float impulseClose = na
var float impulseVolume = na
var float impulseRange = na
var float pullbackLow = na
var float pullbackHigh = na
var float pullbackTrigger = na
bool newLongImpulseMark = false
bool newShortImpulseMark = false
bool longPullbackMark = false
bool shortPullbackMark = false
bool rawLong = false
bool rawShort = false
float stopAnchor = na
if (newTradingDay or morningBegins or afternoonBegins or lunchFlatBar or finalFlatBar)
setupState := 0
impulseBar := na
pullbackBar := na
// ============================================================================
// SECTION 18: LONG IMPULSE -> FOLLOW-THROUGH OR DRYBACK
// ============================================================================
if (setupState == 1 and barstate.isconfirmed and bar_index > impulseBar)
bool expired = (bar_index - impulseBar > maximumSetupBars)
bool invalid = (close < impulseLow - confirmationBuffer)
if (expired or invalid or not entrySession or not beforeCutoff)
setupState := 0
else
bool followThrough = ((entryMode == "Hybrid" or entryMode == "Impulse Follow-Through") and not na(rvol) and rvol >= minimumEntryRVOL and close > impulseHigh + confirmationBuffer and close - impulseHigh <= atr * maximumFollowExtensionATR and bullishCandle)
float fractionRetraced = (impulseRange > 0 ? (impulseHigh - low) / impulseRange : na)
bool controlledPullback = ((entryMode == "Hybrid" or entryMode == "Pullback Re-Acceleration") and not na(fractionRetraced) and fractionRetraced >= minimumPullbackFraction and fractionRetraced <= maximumPullbackFraction and close > impulseLow and (volume <= impulseVolume * maximumDrybackVolumeRatio or (not na(rvol) and rvol <= maximumDrybackRVOL)))
if followThrough
rawLong := true
stopAnchor := math.min(recentStopLow, impulseHigh)
setupState := 0
else if controlledPullback
pullbackBar := bar_index
pullbackLow := low
pullbackHigh := high
pullbackTrigger := high
longPullbackMark := true
setupState := 2
// ============================================================================
// SECTION 19: SHORT IMPULSE -> FOLLOW-THROUGH OR DRYBACK
// ============================================================================
if (setupState == -1 and barstate.isconfirmed and bar_index > impulseBar)
bool expired = (bar_index - impulseBar > maximumSetupBars)
bool invalid = (close > impulseHigh + confirmationBuffer)
if (expired or invalid or not entrySession or not beforeCutoff)
setupState := 0
else
bool followThrough = ((entryMode == "Hybrid" or entryMode == "Impulse Follow-Through") and not na(rvol) and rvol >= minimumEntryRVOL and close < impulseLow - confirmationBuffer and impulseLow - close <= atr * maximumFollowExtensionATR and bearishCandle)
float fractionRetraced = (impulseRange > 0 ? (high - impulseLow) / impulseRange : na)
bool controlledPullback = ((entryMode == "Hybrid" or entryMode == "Pullback Re-Acceleration") and not na(fractionRetraced) and fractionRetraced >= minimumPullbackFraction and fractionRetraced <= maximumPullbackFraction and close < impulseHigh and (volume <= impulseVolume * maximumDrybackVolumeRatio or (not na(rvol) and rvol <= maximumDrybackRVOL)))
if followThrough
rawShort := true
stopAnchor := math.max(recentStopHigh, impulseLow)
setupState := 0
else if controlledPullback
pullbackBar := bar_index
pullbackLow := low
pullbackHigh := high
pullbackTrigger := low
shortPullbackMark := true
setupState := -2
// ============================================================================
// SECTION 20: LONG DRYBACK -> RENEWED BUYING PARTICIPATION
// ============================================================================
if (setupState == 2 and barstate.isconfirmed and bar_index > pullbackBar)
bool expired = (bar_index - impulseBar > maximumSetupBars or bar_index - pullbackBar > maximumWaitAfterPullback)
bool invalid = (close < impulseLow - confirmationBuffer or low < impulseHigh - impulseRange * maximumPullbackFraction - confirmationBuffer)
if (expired or invalid or not entrySession or not beforeCutoff)
setupState := 0
else
bool reAcceleration = (not na(rvol) and rvol >= minimumEntryRVOL and bullishCandle and close > high[1] + confirmationBuffer and close > pullbackTrigger + confirmationBuffer and close > impulseLow + impulseRange * (1.0 - maximumPullbackFraction))
if reAcceleration
rawLong := true
stopAnchor := pullbackLow
setupState := 0
else
pullbackLow := math.min(pullbackLow, low)
// ============================================================================
// SECTION 21: SHORT DRYBACK -> RENEWED SELLING PARTICIPATION
// ============================================================================
if (setupState == -2 and barstate.isconfirmed and bar_index > pullbackBar)
bool expired = (bar_index - impulseBar > maximumSetupBars or bar_index - pullbackBar > maximumWaitAfterPullback)
bool invalid = (close > impulseHigh + confirmationBuffer or high > impulseLow + impulseRange * maximumPullbackFraction + confirmationBuffer)
if (expired or invalid or not entrySession or not beforeCutoff)
setupState := 0
else
bool reAcceleration = (not na(rvol) and rvol >= minimumEntryRVOL and bearishCandle and close < low[1] - confirmationBuffer and close < pullbackTrigger - confirmationBuffer and close < impulseHigh - impulseRange * (1.0 - maximumPullbackFraction))
if reAcceleration
rawShort := true
stopAnchor := pullbackHigh
setupState := 0
else
pullbackHigh := math.max(pullbackHigh, high)
// ============================================================================
// SECTION 22: ARM A NEW RELATIVE-VOLUME IMPULSE
// ============================================================================
bool directImpulseMode = (entryMode == "Direct Impulse")
if (setupState == 0 and not rawLong and not rawShort and commonEntryOK)
if newBullishImpulse and allowLong
impulseBar := bar_index
impulseHigh := high
impulseLow := low
impulseClose := close
impulseVolume := volume
impulseRange := candleRange
newLongImpulseMark := true
setupState := 1
if directImpulseMode
rawLong := true
stopAnchor := low
setupState := 0
else if newBearishImpulse and allowShort
impulseBar := bar_index
impulseHigh := high
impulseLow := low
impulseClose := close
impulseVolume := volume
impulseRange := candleRange
newShortImpulseMark := true
setupState := -1
if directImpulseMode
rawShort := true
stopAnchor := high
setupState := 0
// ============================================================================
// SECTION 23: STOP LOSS / PROFIT TARGET
// ============================================================================
float longStopReference = (stopMode == "Impulse Extreme" ? impulseLow : stopAnchor)
float shortStopReference = (stopMode == "Impulse Extreme" ? impulseHigh : stopAnchor)
float longStopCandidate = (not na(atr) and atr > 0 ? math.round_to_mintick(stopMode == "ATR Fixed" ? close - fixedStopATR * atr : longStopReference - stopBufferATR * atr) : na)
float shortStopCandidate = (not na(atr) and atr > 0 ? math.round_to_mintick(stopMode == "ATR Fixed" ? close + fixedStopATR * atr : shortStopReference + stopBufferATR * atr) : na)
float longRisk = (close - longStopCandidate)
float shortRisk = (shortStopCandidate - close)
bool longRiskOK = (not na(longRisk) and longRisk >= minimumStopPoints and longRisk <= maximumStopPoints and longRisk * takeProfitR >= minimumGrossTarget)
bool shortRiskOK = (not na(shortRisk) and shortRisk >= minimumStopPoints and shortRisk <= maximumStopPoints and shortRisk * takeProfitR >= minimumGrossTarget)
float longTargetCandidate = (not na(longRisk) ? math.round_to_mintick(close + longRisk * takeProfitR) : na)
float shortTargetCandidate = (not na(shortRisk) ? math.round_to_mintick(close - shortRisk * takeProfitR) : na)
bool finalLong = (rawLong and allowLong and longTrendOK and longVWAPOK and not adverseLongTrend and longRiskOK and commonEntryOK)
bool finalShort = (rawShort and allowShort and shortTrendOK and shortVWAPOK and not adverseShortTrend and shortRiskOK and commonEntryOK and not finalLong)
// ============================================================================
// SECTION 24: ACTIVE TRADE STATE
// ============================================================================
var float activeStop = na
var float activeTarget = na
var float entryPriceSeen = na
var float initialFillRisk = na
var int entryBarSeen = na
var bool breakEvenActive = false
// ============================================================================
// SECTION 25: LONG ENTRY + INITIAL PROTECTIVE BRACKET
// ============================================================================
if finalLong
activeStop := longStopCandidate
activeTarget := longTargetCandidate
entryPriceSeen := na
initialFillRisk := na
entryBarSeen := na
breakEvenActive := false
strategy.entry("CNPS63-L", strategy.long, comment="VOLUME EXPANSION LONG", alert_message="🟢 VÀO VỊ THẾ LONG (Relative Volume Expansion)\n🎯 Giá vào: " + str.tostring(close, format.mintick) + "\n🛑 SL dự kiến: " + str.tostring(activeStop, format.mintick) + "\n🎯 TP dự kiến: " + str.tostring(activeTarget, format.mintick))
strategy.exit("CNPS63-L-X", from_entry="CNPS63-L", stop=activeStop, limit=activeTarget, comment_profit="TP Long", comment_loss="SL Long", alert_profit="💰 CHỐT LỜI LONG (TP HIT)\n🎯 Giá chốt: " + str.tostring(activeTarget, format.mintick), alert_loss="🛑 CẮT LỖ LONG (SL HIT)\n🎯 Giá cắt: " + str.tostring(activeStop, format.mintick))
tradesToday += 1
tradedLongToday := true
lastOrderBar := bar_index
setupState := 0
// ============================================================================
// SECTION 26: SHORT ENTRY + INITIAL PROTECTIVE BRACKET
// ============================================================================
else if finalShort
activeStop := shortStopCandidate
activeTarget := shortTargetCandidate
entryPriceSeen := na
initialFillRisk := na
entryBarSeen := na
breakEvenActive := false
strategy.entry("CNPS63-S", strategy.short, comment="VOLUME EXPANSION SHORT", alert_message="🔴 VÀO VỊ THẾ SHORT (Relative Volume Expansion)\n🎯 Giá vào: " + str.tostring(close, format.mintick) + "\n🛑 SL dự kiến: " + str.tostring(activeStop, format.mintick) + "\n🎯 TP dự kiến: " + str.tostring(activeTarget, format.mintick))
strategy.exit("CNPS63-S-X", from_entry="CNPS63-S", stop=activeStop, limit=activeTarget, comment_profit="TP Short", comment_loss="SL Short", alert_profit="💰 CHỐT LỜI SHORT (TP HIT)\n🎯 Giá chốt: " + str.tostring(activeTarget, format.mintick), alert_loss="🛑 CẮT LỖ SHORT (SL HIT)\n🎯 Giá cắt: " + str.tostring(activeStop, format.mintick))
tradesToday += 1
tradedShortToday := true
lastOrderBar := bar_index
setupState := 0
// ============================================================================
// SECTION 27: ACTUAL FILL VALIDATION / OPTIONAL BREAK EVEN
// ============================================================================
if (strategy.position_size != 0 and strategy.opentrades > 0 and barstate.isconfirmed)
int fillBar = (strategy.opentrades.entry_bar_index(0))
float fillPrice = (strategy.position_avg_price)
if na(entryBarSeen) or entryBarSeen != fillBar
entryBarSeen := fillBar
entryPriceSeen := fillPrice
initialFillRisk := (inLong ? fillPrice - activeStop : activeStop - fillPrice)
bool fillValid = (not na(initialFillRisk) and initialFillRisk > syminfo.mintick and (inLong ? activeTarget > fillPrice : activeTarget < fillPrice))
if not fillValid
strategy.close(inLong ? "CNPS63-L" : "CNPS63-S", immediately=true, comment="INVALID FILLED RISK", alert_message="🔄 ĐÓNG VỊ THẾ (Khớp lệnh không hợp lệ)\n🎯 Giá đóng: " + str.tostring(close, format.mintick))
else
float openR = (inLong ? (close - fillPrice) / initialFillRisk : (fillPrice - close) / initialFillRisk)
if useBreakEven and openR >= breakEvenAtR
float breakEvenStop = math.round_to_mintick(inLong ? fillPrice + breakEvenOffset : fillPrice - breakEvenOffset)
activeStop := (inLong ? math.max(activeStop, breakEvenStop) : math.min(activeStop, breakEvenStop))
breakEvenActive := true
if inLong
strategy.exit("CNPS63-L-X", from_entry="CNPS63-L", stop=activeStop, limit=activeTarget, comment_profit="TP Long", comment_loss=breakEvenActive ? "BE Long" : "SL Long", alert_profit="💰 CHỐT LỜI LONG (TP HIT)\n🎯 Giá chốt: " + str.tostring(activeTarget, format.mintick), alert_loss=breakEvenActive ? ("🛡️ HÒA VỐN LONG (BE HIT)\n🎯 Giá thoát: " + str.tostring(activeStop, format.mintick)) : ("🛑 CẮT LỖ LONG (SL HIT)\n🎯 Giá cắt: " + str.tostring(activeStop, format.mintick)))
else
strategy.exit("CNPS63-S-X", from_entry="CNPS63-S", stop=activeStop, limit=activeTarget, comment_profit="TP Short", comment_loss=breakEvenActive ? "BE Short" : "SL Short", alert_profit="💰 CHỐT LỜI SHORT (TP HIT)\n🎯 Giá chốt: " + str.tostring(activeTarget, format.mintick), alert_loss=breakEvenActive ? ("🛡️ HÒA VỐN SHORT (BE HIT)\n🎯 Giá thoát: " + str.tostring(activeStop, format.mintick)) : ("🛑 CẮT LỖ SHORT (SL HIT)\n🎯 Giá cắt: " + str.tostring(activeStop, format.mintick)))
// ============================================================================
// SECTION 28: MAXIMUM HOLD TIME
// ============================================================================
if (strategy.position_size != 0 and strategy.opentrades > 0 and barstate.isconfirmed)
int entryTimestamp = (strategy.opentrades.entry_time(0))
if (useTimeExit and not na(time_close) and time_close >= entryTimestamp + maximumHoldMinutes * 60000)
strategy.close(inLong ? "CNPS63-L" : "CNPS63-S", comment="MAXIMUM HOLD", alert_message="⏱️ ĐÓNG VỊ THẾ (Hết thời gian giữ lệnh tối đa)\n🎯 Giá đóng: " + str.tostring(close, format.mintick))
// ============================================================================
// SECTION 29: FORCE FLAT BEFORE LUNCH / ATC
// ============================================================================
if ((lunchFlatBar or finalFlatBar) and strategy.position_size != 0)
strategy.close_all(immediately=true, comment="VN30F1M CONTINUOUS SESSION END", alert_message="⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (Session End)\n🎯 Giá đóng: " + str.tostring(close, format.mintick))
// ============================================================================
// SECTION 30: CLEANUP AFTER EXIT
// ============================================================================
if flat and not finalLong and not finalShort
activeStop := na
activeTarget := na
entryPriceSeen := na
initialFillRisk := na
entryBarSeen := na
breakEvenActive := false
// ============================================================================
// SECTION 31: CLEAN CHART PLOTS - NO DASHBOARD
// ============================================================================
plot(showVWAP ? sessionVWAP : na, title="Continuous-Session VWAP", color=color.orange, linewidth=1, style=plot.style_linebr)
plot(showTradeLevels and strategy.position_size != 0 ? activeStop : na, title="Active Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showTradeLevels and strategy.position_size != 0 ? activeTarget : na, title="Active Take Profit", color=color.green, linewidth=2, style=plot.style_linebr)
plotshape(showImpulseMarkers and newLongImpulseMark, title="Bull Volume Impulse", text="RV+", style=shape.circle, location=location.belowbar, color=color.new(color.teal, 35), textcolor=color.white, size=size.tiny)
plotshape(showImpulseMarkers and newShortImpulseMark, title="Bear Volume Impulse", text="RV-", style=shape.circle, location=location.abovebar, color=color.new(color.red, 35), textcolor=color.white, size=size.tiny)
plotshape(showPullbackMarkers and longPullbackMark, title="Low-Volume Bull Pullback", text="PB+", style=shape.circle, location=location.belowbar, color=color.new(color.teal, 60), textcolor=color.white, size=size.tiny)
plotshape(showPullbackMarkers and shortPullbackMark, title="Low-Volume Bear Pullback", text="PB-", style=shape.circle, location=location.abovebar, color=color.new(color.red, 60), textcolor=color.white, size=size.tiny)
plotshape(showEntryMarkers and finalLong, title="CNPS63 LONG", text="L", style=shape.triangleup, location=location.belowbar, color=color.teal, textcolor=color.white, size=size.small)
plotshape(showEntryMarkers and finalShort, title="CNPS63 SHORT", text="S", style=shape.triangledown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small)
// ============================================================================
// CNPS63 V1 RESEARCH NOTES
// ============================================================================
// 1. Uses OHLCV relative volume, not exchange bid/ask aggressor flow.
// 2. The impulse requires both volume acceleration and price displacement.
// 3. Hybrid mode: either volume follow-through or dryback / re-acceleration.
// 4. Pullback and follow-through signals occur AFTER the impulse bar.
// 5. Market orders normally fill on the next bar, not the signal close.
// 6. Initial brackets use signal-close structure, not future fill prices.
// 7. Daily closed-loss protection blocks new trades only.
// 8. A simulated 12% margin is NOT a broker margin recommendation.
// 9. Designed for VN30F1M intraday M1/M3/M5, not verified profitable.
// 10. No dashboard / diagnostic table is plotted.
// ============================================================================
2. Những khái niệm kỹ thuật cốt lõi trong CNPS63
2.1. Khối lượng tương đối (RVOL) và Gia tốc khối lượng (Volume Acceleration)
Khác với việc chỉ nhìn khối lượng tuyệt đối, CNPS63 đo lường sự đột biến thanh khoản tương đối so với nền lịch sử gần nhất:
- Khối lượng tương đối (
rvol):volume / ta.ema(volume, 40)[1]. Việc dùng[1]giúp không tính chính cây nến hiện tại vào đường nền, tránh làm loãng độ nhạy. Ngưỡng kích hoạt xung lực mặc định làrvol >= 1.55. - Gia tốc khối lượng (
volumeAcceleration):ta.ema(volume, 4) / ta.ema(volume, 20). Điều kiện>= 1.05đảm bảo dòng tiền ngắn hạn đang thực sự mở rộng nhanh hơn trung bình trung hạn chứ không phải một nhịp nhiễu đơn lẻ.
2.2. Nến xung lực định hướng (Directional Price Impulse)
Một cây nến chỉ được ghi nhận là xung lực hợp lệ (newBullishImpulse / newBearishImpulse) khi thỏa đồng thời cả khối lượng lẫn hành động giá:
- Tỷ lệ thân nến (
bodyRatio):math.abs(close - open) / candleRange >= 0.45. - Vị trí đóng cửa (
closeLocation):(close - low) / candleRange >= 0.70đối với Long (đóng sát đỉnh nến) hoặc<= 0.30đối với Short (đóng sát đáy nến). - Biên độ chuẩn hóa theo ATR(14): Nến phải đủ mạnh nhưng không quá cực đoan (
0.65 * atr <= candleRange <= 2.70 * atr), tránh vào sau một cây nến đã quá giãn. - Phá vỡ cấu trúc vi mô: Giá đóng cửa vượt
priorMicroHigh(đỉnh cao nhất6nến trước) với Long hoặc thủngpriorMicroLow(đáy thấp nhất6nến trước) với Short.
2.3. Bộ lọc bối cảnh phiên (Session VWAP, EMA 34 và Adverse Trend Guard)
- Session VWAP: Tính tích lũy từ đầu ngày giao dịch (
cumulativePV / cumulativeVolume) chỉ trong các khung phiên liên tục. Nếu bậtuseVWAPFilter, lệnh Long chỉ hợp lệ khiclose > sessionVWAPvà Short khiclose < sessionVWAP. - EMA Trend Filter (tùy chọn): Khi bật
useTrendFilter, yêu cầu giá nằm thuận chiềuEMA(34)và độ dốc chuẩn hóa(trendEMA - trendEMA[5]) / atrđạt ngưỡngminimumTrendSlopeATR. - Adverse Trend Guard (bật mặc định): Sử dụng
ta.dmi(14, 14). Nếuadx >= 38.0đồng thời giá nằm dướiEMA(34)vàmDI > pDI, bot sẽ chặn lệnh Long; ngược lại nếuadx >= 38.0, giá trênEMA(34)vàpDI > mDI, bot sẽ chặn lệnh Short.
3. Nguyên lý hoạt động của CNPS63
Quy trình vận hành của CNPS63 trên mỗi nến đóng cửa (barstate.isconfirmed) diễn ra tuần tự qua 5 bước:
- Khởi tạo & Reset phiên: Khi bắt đầu ngày mới (
newTradingDay), đầu phiên sáng (09:00), đầu phiên chiều (13:00) hoặc tại các mốc cắt phiên (11:25,14:25), máy trạng tháisetupStateđược reset về0, đồng thời bộ đếm lệnh trong ngày và biến tích lũy VWAP được làm mới theo ngày. - Định vị xung lực (
State 0 → State 1 / -1): Khi vị thế đang phẳng (flat), nằm trong giờ giao dịch và thỏacommonEntryOK, nếu xuất hiệnnewBullishImpulsehoặcnewBearishImpulse, bot lưu lại thông số cây nến xung lực (impulseHigh,impulseLow,impulseVolume,impulseRange) và chuyển sang trạng thái chờ (1hoặc-1). Nếu chọn chế độDirect Impulse, bot phát tín hiệu vào lệnh ngay lập tức. - Theo dõi tiếp diễn hoặc điều chỉnh cạn cung (
State 1 / -1 → Lệnh hoặc State 2 / -2): Trong tối đa9nến sau xung lực (maximumSetupBars), nếu giá vượt tiếp đỉnh/đáy nến xung lực kèm RVOL đạt0.95trong giới hạn giãn2.00 * ATR, nhánhfollowThroughkích hoạt vào lệnh ngay. Ngược lại, nếu giá hồi về22% – 85%biên độ nến xung lực với volume cạn kiệt (controlledPullback), bot ghi nhận đáy/đỉnh điều chỉnh và chuyển sang trạng thái2/-2. - Xác nhận tái tăng tốc (
State 2 / -2 → Lệnh): Trong tối đa5nến sau khi tạo đáy/đỉnh điều chỉnh (maximumWaitAfterPullback), bot liên tục cập nhậtpullbackLow/pullbackHighvà chờ một nến xác nhận cóRVOL >= 0.95đóng cửa vượt đỉnh/đáy nến liền trước vàpullbackTriggercộng0.10điểm để phát tín hiệurawLong/rawShort. - Kiểm tra rủi ro & Quản trị lệnh: Tính toán SL/TP theo cấu trúc giá, kiểm tra giới hạn
1.5 – 12.0điểm và mục tiêu tối thiểu2.5điểm. Nếu đạt, bot gửi lệnhstrategy.entrykèmstrategy.exit, sau đó tiếp tục xác thực giá khớp thực tế ở nến kế tiếp và theo dõi Break Even, thời gian giữ lệnh tối đa hoặc đóng lệnh cuối phiên.
4. Điều kiện vào lệnh Long và Short của CNPS63
4.1. Điều kiện vào lệnh Long
Lệnh Long (finalLong) được kích hoạt khi thỏa mãn đầy đủ các điều kiện sau:
- Đang ở trạng thái không có vị thế (
flat),tradeDirection != "Short"và chưa vi phạmoneTradePerSide. - Thỏa bộ lọc xu hướng (
longTrendOK), VWAP (longVWAPOK) và không bị chặn bởiadverseLongTrend(adx >= 38.0khiclose < trendEMAvàmDI > pDI). - Xuất hiện tín hiệu
rawLongtừ một trong 3 nhánh củaentryMode:- Follow-Through: Giá đóng cửa
> impulseHigh + 0.10, mức giãn<= 2.00 * atr,rvol >= 0.95và nến tăng xác nhận (bodyRatio >= 0.25,closeLocation >= 0.55). - Pullback Re-Acceleration: Sau nhịp hồi
22% – 85%biên độ xung lực với khối lượng thấp (volume <= 0.85 * impulseVolumehoặcrvol <= 1.10), xuất hiện nến tăng córvol >= 0.95,close > high[1] + 0.10,close > pullbackTrigger + 0.10vàclose > impulseLow + impulseRange * 0.15. - Direct Impulse (nếu chọn): Vào ngay tại nến
newBullishImpulse.
- Follow-Through: Giá đóng cửa
- Khoảng cách rủi ro
longRisk = close - longStopCandidatenằm trong[1.50, 12.0]điểm vàlongRisk * 1.65 >= 2.50điểm.
4.2. Điều kiện vào lệnh Short
Lệnh Short (finalShort) có logic đối xứng hoàn toàn và chỉ thực thi khi not finalLong:
- Đang ở trạng thái
flat,tradeDirection != "Long"và thỏaoneTradePerSide. - Thỏa
shortTrendOK,shortVWAPOKvà không rơi vàoadverseShortTrend(adx >= 38.0,close > trendEMA,pDI > mDI). - Xuất hiện tín hiệu
rawShort:- Follow-Through: Giá đóng cửa
< impulseLow - 0.10, mức giãn<= 2.00 * atr,rvol >= 0.95và nến giảm xác nhận (bodyRatio >= 0.25,closeLocation <= 0.45). - Pullback Re-Acceleration: Sau nhịp hồi lên
22% – 85%biên độ xung lực với khối lượng thấp, xuất hiện nến giảm córvol >= 0.95,close < low[1] - 0.10,close < pullbackTrigger - 0.10vàclose < impulseHigh - impulseRange * 0.15. - Direct Impulse (nếu chọn): Vào ngay tại nến
newBearishImpulse.
- Follow-Through: Giá đóng cửa
- Khoảng cách rủi ro
shortRisk = shortStopCandidate - closenằm trong[1.50, 12.0]điểm vàshortRisk * 1.65 >= 2.50điểm.
4.3. Điều kiện kiểm soát giao dịch chung (commonEntryOK)
Mọi lệnh vào đều phải vượt qua lớp kiểm soát chung:
- Khung giờ giao dịch (UTC+7): Nằm trong phiên liên tục và thuộc khung
09:05–11:20(sáng) hoặc13:05–14:15(chiều), đồng thời thời gian đóng nến phải trước mốc cắt lệnh (beforeCutoff). - Giới hạn tần suất:
tradesToday < 5và chỉ tối đa 1 lệnh trên mỗi cây nến (oncePerBar). - Cooldown sau thoát lệnh: Khoảng cách từ
lastExitBarphải lớn hơn3nến (bar_index - lastExitBar > cooldownBars). - Giới hạn lỗ ngày: Tổng PnL đã chốt trong ngày
dailyClosedPnL > -2,400,000 VND(khi bậtuseDailyLossGuard).
5. Quản trị Stop Loss, Take Profit và Thoát lệnh
5.1. Cơ chế Stop Loss và bộ lọc Risk
CNPS63 hỗ trợ 3 chế độ đặt điểm neo dừng lỗ (stopMode):
- Recent Structure (Mặc định): Nếu vào từ Follow-Through, neo SL tại
math.min(recentStopLow, impulseHigh)(Long) hoặcmath.max(recentStopHigh, impulseLow)(Short) vớirecentStopBars = 5. Nếu vào từ Pullback Re-Acceleration, neo trực tiếp tạipullbackLowhoặcpullbackHigh. Sau đó cộng/trừ thêm khoảng đệm0.15 * ATR(14). - Impulse Extreme: Neo SL tại đáy
impulseLow(Long) hoặc đỉnhimpulseHigh(Short) cộng/trừ0.15 * ATR(14). - ATR Fixed: Đặt SL cách giá đóng cửa tín hiệu một khoảng cố định
1.30 * ATR(14).
Toàn bộ mức SL đều được làm tròn theo bước giá (math.round_to_mintick). Nếu rủi ro vượt ngoài biên [1.50, 12.0] điểm hoặc lợi nhuận kỳ vọng < 2.50 điểm, tín hiệu sẽ bị loại bỏ trước khi gửi lệnh.
5.2. Cơ chế Take Profit, Break Even và Thoát lệnh
- Take Profit cố định theo R: Tính theo công thức
close ± risk * 1.65(vớitakeProfitR = 1.65). - Xác thực khớp lệnh thực tế (
ACTUAL FILL VALIDATION): Vì lệnh thị trường khớp ở nến kế tiếp (process_orders_on_close=false), bot kiểm tra lạiinitialFillRiskdựa trênstrategy.position_avg_price. Nếu giá khớp khiến rủi ro<= syminfo.mintickhoặc TP bị ngược phía giá khớp, bot lập tức đóng vị thế (INVALID FILLED RISK). - Break Even (tùy chọn, mặc định tắt): Khi bật
useBreakEven, nếu lợi nhuận mởopenR >= 1.00, SL được kéo vềfillPrice ± 0.20điểm (chỉ dời theo hướng có lợi). - Thoát lệnh theo thời gian & cuối phiên: Đóng vị thế nếu giữ quá
45phút (MAXIMUM HOLD), ép đóng toàn bộ vị thế trước giờ nghỉ trưa (11:25) và trước phiên ATC (14:25).
5.3. Bảng tổng hợp cơ chế bảo vệ vị thế
| Cơ chế bảo vệ | Điều kiện kích hoạt | Hành động thực thi | Trạng thái mặc định |
|---|---|---|---|
| Stop Loss cấu trúc | Giá chạm activeStop | Cắt lỗ qua strategy.exit (SL Long/SL Short) | Bật (Recent Structure) |
| Take Profit theo R | Giá chạm activeTarget (1.65R) | Chốt lời qua strategy.exit (TP Long/TP Short) | Bật (1.65R, tối thiểu 2.50 điểm) |
| Xác thực khớp lệnh | initialFillRisk <= mintick hoặc TP sai phía | Đóng khẩn cấp immediately=true (INVALID FILLED RISK) | Luôn bật |
| Break Even | openR >= 1.00 | Kéo SL về fillPrice ± 0.20 điểm | Tắt (false) |
| Maximum Hold Time | Thời gian giữ lệnh >= 45 phút | Đóng lệnh thị trường (MAXIMUM HOLD) | Bật (45 phút) |
| Force Flat phiên | Nến chạm 11:25 hoặc 14:25 | Đóng toàn bộ vị thế (VN30F1M CONTINUOUS SESSION END) | Bật cả trưa & ATC |
| Daily Loss Guard | Lỗ đã chốt trong ngày >= 2,400,000 VND | Chặn toàn bộ tín hiệu mở lệnh mới trong ngày | Bật (true) |
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, chọn khung thời gian giao dịch trong ngày (khuyến nghị M1, M3 hoặc M5).
- Mở tab Pine Editor ở phía dưới màn hình, xóa code mẫu mặc định.
- 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 để chạy chiến lược lên biểu đồ.
- Vào phần Settings (biểu tượng bánh răng) của chiến lược để điều chỉnh số hợp đồng (
contracts), chế độ vào lệnh (entryMode) hoặc bật thêmshowImpulseMarkers/showPullbackMarkersnếu muốn quan sát quá trình hình thành setup.
Cách đọc bảng chẩn đoán (Diagnostics Table)
Điểm đặc biệt trong thiết kế của CNPS63 V1 là tuân thủ triết lý Clean Chart — không vẽ bảng Diagnostics (table.new) lên góc biểu đồ nhằm giữ không gian quan sát nến và khối lượng hoàn toàn thông thoáng. Thay cho bảng thông số chữ, bạn theo dõi trực tiếp trạng thái hoạt động của bot ngay trên đồ thị giá thông qua các lớp hiển thị sau:
- Đường Active Stop Loss (Đỏ) & Active Take Profit (Xanh lá): Tự động vẽ ngang khi có vị thế đang mở, giúp theo dõi trực quan vùng bảo vệ và điểm dời Break Even (nếu bật).
- Nhãn tín hiệu vào lệnh (
Lxanh ngọc /Sđỏ): Hiển thị chính xác vị trí nến xác nhận kích hoạt lệnh Long hoặc Short. - Nhãn tiền đề (tùy chọn bật trong mục
11 - Display):RV+/RV-đánh dấu nến xung lực khối lượng tương đối đạt chuẩn;PB+/PB-đánh dấu nhịp điều chỉnh cạn cung hợp lệ trước khi tái tăng tốc. - Đường Session VWAP (Cam, tùy chọn): Hiển thị giá trung bình trọng số khối lượng tính riêng cho phiên liên tục trong ngày.
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 qua ứng dụng TradingView, Telegram hoặc Webhook khi CNPS63 phát tín hiệu:
- Nhấn vào biểu tượng Alert (Đồng hồ báo thức) trên thanh công cụ TradingView.
- Tại mục Condition, chọn chiến lược
CNPS63 RELATIVE VOLUME EXPANSION V1 - VN30F1M. - Tại ô Message, xóa nội dung mặc định và nhập chính xác cú pháp:
{{strategy.order.alert_message}} - Đặt tên Alert và nhấn Create để kích hoạt theo dõi thời gian thực.
Bảng thông điệp Alert của CNPS63
| Sự kiện trong code | Lệnh / Nhãn kích hoạt | Nội dung thông điệp (alert_message / alert_profit / alert_loss) |
|---|---|---|
| Vào lệnh Long | CNPS63-L | 🟢 VÀO VỊ THẾ LONG (Relative Volume Expansion) kèm Giá vào, SL dự kiến, TP dự kiến |
| Vào lệnh Short | CNPS63-S | 🔴 VÀO VỊ THẾ SHORT (Relative Volume Expansion) kèm Giá vào, SL dự kiến, TP dự kiến |
| Chốt lời Long / Short | CNPS63-L-X / CNPS63-S-X | 💰 CHỐT LỜI LONG (TP HIT) hoặc 💰 CHỐT LỜI SHORT (TP HIT) kèm Giá chốt |
| Cắt lỗ Long / Short | CNPS63-L-X / CNPS63-S-X | 🛑 CẮT LỖ LONG (SL HIT) hoặc 🛑 CẮT LỖ SHORT (SL HIT) kèm Giá cắt |
| Chốt hòa vốn (BE) | CNPS63-L-X / CNPS63-S-X | 🛡️ HÒA VỐN LONG (BE HIT) hoặc 🛡️ HÒA VỐN SHORT (BE HIT) kèm Giá thoát |
| Khớp lệnh lỗi rủi ro | INVALID FILLED RISK | 🔄 ĐÓNG VỊ THẾ (Khớp lệnh không hợp lệ) kèm Giá đóng |
| Hết thời gian giữ lệnh | MAXIMUM HOLD | ⏱️ ĐÓNG VỊ THẾ (Hết thời gian giữ lệnh tối đa) kèm Giá đóng |
| Đóng lệnh hết phiên | VN30F1M CONTINUOUS SESSION END | ⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (Session End) kèm Giá đóng |
Kết luận
Bot CNPS63 (Relative Volume Expansion V1) mang đến một cách tiếp cận kỷ luật cho giao dịch VN30F1M dựa trên dòng tiền tương đối (RVOL) kết hợp cấu trúc hấp thụ cung cầu (Dryback). Điểm mạnh của hệ thống là không vào lệnh mù quáng theo mọi cú giật volume, mà đòi hỏi sự xác nhận của cấu trúc nến, bộ lọc xu hướng nghịch ADX và các lớp bảo vệ rủi ro chặt chẽ theo phiên giao dịch Việt Nam. Chiến lược này đặc biệt phù hợp trong các phiên thị trường có dòng tiền chủ động rõ ràng, biên độ dao động vừa phải trên khung M1–M5, và cần thận trọng khi thị trường đi ngang thanh khoản quá thấp.
Bạn có thể tham khảo thêm các hệ thống giao dịch VN30F1M khác như Bot CNPS50 - Trend Analysis V2 và Bot CNPS49 - Daily Open để đa dạng hóa góc nhìn chiến lược.
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.





