Hướng Dẫn Sử Dụng Bot CNPS89 - Volume-Weighted Momentum V1 cho VN30F1M
TradingviewBot CNPS89 Volume-Weighted Momentum V1 sử dụng chỉ báo xung lượng gia quyền khối lượng chuẩn hóa theo ATR kết hợp bộ lọc xu hướng EMA 50 và quản trị rủi ro SL/TP cố định cho VN30F1M.

Mục lục
Trong giao dịch hợp đồng tương lai VN30F1M, nhiều tín hiệu bứt phá giá trông có vẻ mạnh mẽ nhưng thực chất lại thiếu dòng tiền tham gia thực sự, dẫn đến tình trạng phá vỡ giả (false breakout) và quét cắt lỗ liên tục. Bên cạnh đó, việc so sánh biến động giá thuần túy giữa các giai đoạn có độ biến động (volatility) khác nhau thường làm sai lệch độ nhạy của các chỉ báo động lượng truyền thống.
CNPS89 VOLUME-WEIGHTED MOMENTUM V1 (tên đầy đủ trong mã nguồn: CNPS89 VOLUME-WEIGHTED MOMENTUM V1, tên rút gọn: CNPS89 VWM) là chiến lược giao dịch định lượng viết bằng Pine Script v6 trên TradingView nhằm giải quyết bài toán trên thông qua việc đo lường xung lượng giá có trọng số khối lượng và chuẩn hóa theo biến động thị trường (ATR).
- Xung lượng gia quyền khối lượng chuẩn hóa ATR: Kết hợp biến động giá (
close - close[1]) nhân với khối lượng (volume) và chia choATR(14)giúp chuẩn hóa cường độ dòng tiền qua mọi giai đoạn thị trường. - Xác nhận nến và gia tốc xung lượng: Chỉ vào lệnh khi nến đã đóng cửa xác nhận (
barstate.isconfirmed), xung lượng cắt qua ngưỡng và có gia tốc tiếp diễn, loại bỏ hoàn toàn hiện tượng repaint hay dùng pivot tương lai. - Hệ thống bộ lọc đa tầng linh hoạt: Tích hợp sẵn bộ lọc xu hướng
EMA(50), độ dốc EMA, cấu trúc giá, khối lượng tương đối (Relative Volume),ADX/DIvà xu hướng khung giờ lớnH1 EMA. - Quản trị rủi ro chặt chẽ theo phiên VN30F1M: Cố định Stop Loss (5.0 điểm) / Take Profit (15.0 điểm) theo bước giá
syminfo.mintick, giới hạn tối đa 2 lệnh/ngày, cooldown 3 nến sau khi thoát lệnh và tự động đóng toàn bộ vị thế lúc 14:45.
1. CNPS89 Volume-Weighted Momentum V1 là gì?
CNPS89 Volume-Weighted Momentum V1 là hệ thống giao dịch theo đà (momentum) kết hợp dòng tiền và xu hướng trong ngày (intraday) được thiết kế chuyên biệt cho phái sinh VN30F1M. Chiến lược vận hành dựa trên 4 trụ cột kỹ thuật chính:
- Động cơ xung lượng gia quyền khối lượng (Weighted Momentum Engine): Tính toán trung bình trượt đơn giản (SMA) của thay đổi giá nhân khối lượng chia cho SMA khối lượng trong chu kỳ
N = 12, sau đó chuẩn hóa theoATR(14)(và tùy chọn làm mượt bằng EMA). - Bộ lọc cấu trúc và giải phẫu nến (Signal Confirmation & Candle Anatomy): Đảm bảo nến tín hiệu có hướng đồng thuận (nến tăng cho Long, nến giảm cho Short), đồng thời hỗ trợ lọc tỷ lệ thân nến (
bodyRatio), vị trí đóng cửa (closePosition) và phá vỡ cấu trúc giáNnến trước đó. - Bộ lọc xu hướng và bối cảnh thị trường (Trend & Regime Filters): Mặc định kích hoạt bộ lọc
EMA(50)kết hợp kiểm tra độ dốc EMA trong 3 nến (emaSlopeBars = 3) và vị trí giá so với EMA; ngoài ra hỗ trợ bật/tắtRelative Volume,ADX/DIvàConfirmed H1 EMA Bias. - Kiểm soát lệnh và quản trị rủi ro (Trade Control & Risk Management): Giới hạn khung giờ vào lệnh (09:15 – 14:15 theo giờ
Asia/Ho_Chi_Minh), đóng cưỡng bức cuối phiên lúc 14:45, giới hạn số lệnh trong ngày, thời gian nghỉ (cooldown) và SL/TP cố định quy đổi raticks.
Bảng thông số mặc định
| Nhóm thông số | Tên tham số trong code | Mô tả | Giá trị mặc định |
|---|---|---|---|
| 01. Volume-Weighted Momentum | momentumLength | Chu kỳ tính VWM | 12 |
atrLength | Chu kỳ tính ATR chuẩn hóa | 14 | |
momentumThreshold | Ngưỡng xung lượng / ATR để vào lệnh | 0.10 | |
requireAcceleration | Yêu cầu xung lượng tăng tốc | true | |
accelerationLookback | Số nến so sánh gia tốc | 1 | |
useMomentumSmoothing | Bật làm mượt VWM bằng EMA | false | |
smoothingLength | Chu kỳ EMA làm mượt VWM | 3 | |
| 02. Signal Confirmation | requireCandleDirection | Yêu cầu nến tăng (Long) / giảm (Short) | true |
useBodyFilter | Lọc tỷ lệ thân nến tối thiểu | false | |
minimumBodyRatio | Tỷ lệ Thân nến / Biên độ nến tối thiểu | 0.40 | |
useCloseLocation | Lọc vị trí đóng cửa gần cực trị nến | false | |
longClosePosition | Vị trí đóng cửa tối thiểu cho Long | 0.65 | |
shortClosePosition | Vị trí đóng cửa tối đa cho Short | 0.35 | |
useStructureFilter | Yêu cầu phá vỡ đỉnh/đáy cấu trúc | false | |
structureLookback | Số nến tính cấu trúc giá trước đó | 5 | |
| 03. EMA Trend | useEMAFilter | Bật bộ lọc xu hướng EMA | true |
emaLength | Chu kỳ đường EMA xu hướng | 50 | |
emaSlopeBars | Số nến kiểm tra độ dốc EMA | 3 | |
requirePriceEMA | Yêu cầu giá đóng cửa trên/dưới EMA | true | |
| 04. Volume Filter | useVolumeFilter | Bật bộ lọc khối lượng tương đối | false |
volumeLength | Chu kỳ trung bình khối lượng | 20 | |
minimumVolumeFactor | Hệ số khối lượng tối thiểu | 1.00 | |
| 05. ADX Filter | useADXFilter | Bật bộ lọc ADX tối thiểu | false |
diLength / adxSmoothing | Chu kỳ DI / làm mượt ADX | 14 / 14 | |
minimumADX | Ngưỡng ADX tối thiểu | 18.0 | |
requireDIDirection | Yêu cầu hướng +DI / -DI đồng thuận | false | |
| 06. H1 Bias | useH1Bias | Bật lọc xu hướng khung H1 | false |
h1EMALength | Chu kỳ EMA trên khung H1 | 50 | |
| 07. Risk Management | stopLossPoints | Điểm cắt lỗ cố định (Points) | 5.0 |
takeProfitPoints | Điểm chốt lời cố định (Points) | 15.0 | |
useTimeExit | Bật thoát lệnh theo thời gian nắm giữ | false | |
maximumHoldingBars | Số nến nắm giữ tối đa | 20 | |
| 08. Trade Control | tradeDirection | Chiều giao dịch (Long, Short, Both) | "Long" |
contracts | Số hợp đồng khai báo input | 3 | |
maximumTradesPerDay | Số lệnh tối đa mỗi ngày | 2 | |
cooldownBars | Số nến nghỉ sau khi đóng lệnh | 3 | |
| 09. Trading Session | useSessionFilter | Bật bộ lọc phiên giao dịch | true |
tz | Múi giờ áp dụng | "Asia/Ho_Chi_Minh" | |
startHour / startMinute | Giờ bắt đầu nhận lệnh | 9:15 | |
lastHour / lastMinute | Giờ vào lệnh cuối cùng | 14:15 | |
endHour / endMinute | Giờ đóng toàn bộ vị thế cuối phiên | 14:45 | |
| 10. Alerts & 11. Display | disableExitAlerts | Tắt cảnh báo SL/TP | false |
showEMA, showEntryMarkers, showSLTP | Hiển thị EMA, mũi tên vào lệnh, SL/TP | true | |
showMomentumMarkers, showStructureLevels, showDiagnostics | Hiển thị chấm VWM, mức cấu trúc, bảng chẩn đoán | false |
Source Code CNPS89 Volume-Weighted Momentum 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
strategy(title="CNPS89 VOLUME-WEIGHTED MOMENTUM V1", shorttitle="CNPS89 VWM", 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)
// ============================================================================
// CNPS89 - VOLUME-WEIGHTED MOMENTUM
//
// VWM = SMA(Price Change * Volume, N)
// / SMA(Volume, N)
//
// Normalized VWM = VWM / ATR
//
// LONG:
// 1. Volume-weighted momentum crosses positive threshold.
// 2. Momentum is accelerating upward.
// 3. Bullish candle and optional price confirmation.
// 4. EMA, ADX, volume and H1 filters.
// 5. Enter LONG.
//
// SHORT: Symmetric conditions.
//
// No future pivots.
// Entry signals require confirmed candles.
// Fixed stop loss / take profit in ticks.
// ============================================================================
// ============================================================================
// 01. VOLUME-WEIGHTED MOMENTUM
// ============================================================================
gMomentum = "01. Volume-Weighted Momentum"
momentumLength = input.int(12, "Momentum Lookback", minval=2, maxval=200, group=gMomentum)
atrLength = input.int(14, "ATR Length", minval=1, maxval=200, group=gMomentum)
momentumThreshold = input.float(0.10, "Entry Threshold / ATR", minval=0.0, step=0.02, group=gMomentum)
requireAcceleration = input.bool(true, "Require Momentum Acceleration", group=gMomentum)
accelerationLookback = input.int(1, "Acceleration Lookback", minval=1, maxval=20, group=gMomentum)
useMomentumSmoothing = input.bool(false, "Smooth Weighted Momentum", group=gMomentum)
smoothingLength = input.int(3, "Momentum Smoothing Length", minval=1, maxval=50, group=gMomentum)
// ============================================================================
// 02. SIGNAL CONFIRMATION
// ============================================================================
gSignal = "02. Signal Confirmation"
requireCandleDirection = input.bool(true, "Require Bullish/Bearish Candle", group=gSignal)
useBodyFilter = input.bool(false, "Require Minimum Candle Body", group=gSignal)
minimumBodyRatio = input.float(0.40, "Minimum Body / Candle Range", minval=0.0, maxval=1.0, step=0.05, group=gSignal)
useCloseLocation = input.bool(false, "Require Close Near Candle Extreme", group=gSignal)
longClosePosition = input.float(0.65, "Minimum Long Close Position", minval=0.5, maxval=1.0, step=0.05, group=gSignal)
shortClosePosition = input.float(0.35, "Maximum Short Close Position", minval=0.0, maxval=0.5, step=0.05, group=gSignal)
useStructureFilter = input.bool(false, "Require Price Structure Break", group=gSignal)
structureLookback = input.int(5, "Structure Lookback", minval=2, maxval=100, group=gSignal)
// ============================================================================
// 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=2, maxval=300, group=gTrend)
emaSlopeBars = input.int(3, "EMA Slope Lookback", minval=1, maxval=50, group=gTrend)
requirePriceEMA = input.bool(true, "Require Close Above/Below EMA", group=gTrend)
// ============================================================================
// 04. VOLUME FILTER
// ============================================================================
gVolume = "04. Volume Filter"
useVolumeFilter = input.bool(false, "Require Relative Volume", group=gVolume)
volumeLength = input.int(20, "Volume Average Length", minval=2, maxval=200, group=gVolume)
minimumVolumeFactor = input.float(1.00, "Minimum Volume / Average", minval=0.1, step=0.1, group=gVolume)
// ============================================================================
// 05. ADX FILTER
// ============================================================================
gADX = "05. ADX Filter"
useADXFilter = input.bool(false, "Use Minimum ADX", group=gADX)
diLength = input.int(14, "DI Length", minval=2, group=gADX)
adxSmoothing = input.int(14, "ADX Smoothing", minval=2, group=gADX)
minimumADX = input.float(18.0, "Minimum ADX", minval=1.0, step=1.0, group=gADX)
requireDIDirection = input.bool(false, "Require DI Direction", group=gADX)
// ============================================================================
// 06. CONFIRMED H1 BIAS
// ============================================================================
gH1 = "06. H1 Bias"
useH1Bias = input.bool(false, "Use Confirmed H1 EMA Bias", group=gH1)
h1EMALength = input.int(50, "H1 EMA Length", minval=2, group=gH1)
// ============================================================================
// 07. RISK MANAGEMENT
// ============================================================================
gRisk = "07. 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)
maximumHoldingBars = input.int(20, "Maximum Holding Bars", minval=1, maxval=200, group=gRisk)
// ============================================================================
// 08. TRADE CONTROL
// ============================================================================
gTrade = "08. 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)
maximumTradesPerDay = input.int(2, "Maximum Trades Per Day", minval=1, maxval=20, group=gTrade)
cooldownBars = input.int(3, "Cooldown After Exit (Bars)", minval=0, maxval=100, group=gTrade)
bool allowLong = (tradeDirection == "Long" or tradeDirection == "Both")
bool allowShort = (tradeDirection == "Short" or tradeDirection == "Both")
// ============================================================================
// 09. TRADING SESSION
// ============================================================================
gSession = "09. Trading 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)
// ============================================================================
// 10. ALERTS
// ============================================================================
gAlerts = "10. Alerts"
disableExitAlerts = input.bool(false, "Disable SL/TP Alerts", group=gAlerts)
// ============================================================================
// 11. DISPLAY
// ============================================================================
gDisplay = "11. Display"
showEMA = input.bool(true, "Show EMA", group=gDisplay)
showMomentumMarkers = input.bool(false, "Show Momentum Cross Dots", group=gDisplay)
showStructureLevels = input.bool(false, "Show Structure High/Low", group=gDisplay)
showEntryMarkers = input.bool(true, "Show Entry Markers", group=gDisplay)
showSLTP = input.bool(true, "Show Active SL/TP", group=gDisplay)
showDiagnostics = input.bool(false, "Show Diagnostics", group=gDisplay)
// ============================================================================
// 12. TIME ENGINE
// ============================================================================
int openMinutes = (hour(time, tz) * 60 + minute(time, tz))
int closeMinutes = (hour(time_close, tz) * 60 + minute(time_close, tz))
int entryStartMinutes = (startHour * 60 + startMinute)
int lastEntryMinutes = (lastHour * 60 + lastMinute)
int forceCloseMinutes = (endHour * 60 + endMinute)
bool intradayOK = timeframe.isintraday
bool entrySessionOK = (not useSessionFilter or (openMinutes >= entryStartMinutes and closeMinutes <= lastEntryMinutes))
bool beforeForceClose = (closeMinutes < forceCloseMinutes)
bool forceCloseBar = (openMinutes < forceCloseMinutes and closeMinutes >= forceCloseMinutes)
// ============================================================================
// 13. DAILY COUNTER
// ============================================================================
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
// ============================================================================
// 14. ATR / EMA / VOLUME
// ============================================================================
float atr = ta.atr(atrLength)
float ema = ta.ema(close, emaLength)
float previousAverageVolume = ta.sma(volume[1], volumeLength)
float relativeVolume = (not na(previousAverageVolume) and previousAverageVolume > 0 and not na(volume) ? volume / previousAverageVolume : na)
// ============================================================================
// 15. WEIGHTED MOMENTUM ENGINE
// ============================================================================
//
// Price Change = Close - Previous Close
//
// Weighted Change = Price Change * Volume
//
// Weighted Momentum:
// SMA(Weighted Change, N) / SMA(Volume, N)
//
// Normalize by ATR.
//
// The SMA ratio equals the ratio of
// corresponding rolling sums. It avoids
// dependence on a separate sum function.
//
// A positive value represents net upward
// price change weighted by traded volume.
//
// ============================================================================
float priceChange = (close - close[1])
float weightedChange = (priceChange * volume)
float averageWeightedChange = ta.sma(weightedChange, momentumLength)
float averageMomentumVolume = ta.sma(volume, momentumLength)
float rawMomentum = (not na(averageMomentumVolume) and averageMomentumVolume > 0 ? averageWeightedChange / averageMomentumVolume : na)
float normalizedMomentum = (not na(atr) and atr > 0 ? rawMomentum / atr : na)
float smoothedMomentum = ta.ema(normalizedMomentum, smoothingLength)
float momentum = (useMomentumSmoothing ? smoothedMomentum : normalizedMomentum)
// ============================================================================
// 16. MOMENTUM CROSSOVER
// ============================================================================
float longThreshold = momentumThreshold
float shortThreshold = -momentumThreshold
bool bullishMomentumCross = ta.crossover(momentum, longThreshold)
bool bearishMomentumCross = ta.crossunder(momentum, shortThreshold)
bool longAccelerationOK = (not requireAcceleration or (not na(momentum[accelerationLookback]) and momentum > momentum[accelerationLookback]))
bool shortAccelerationOK = (not requireAcceleration or (not na(momentum[accelerationLookback]) and momentum < momentum[accelerationLookback]))
bool bullishMomentumSignal = (barstate.isconfirmed and bullishMomentumCross and longAccelerationOK)
bool bearishMomentumSignal = (barstate.isconfirmed and bearishMomentumCross and shortAccelerationOK)
// ============================================================================
// 17. CANDLE ANATOMY
// ============================================================================
float candleRange = (high - low)
float candleBody = math.abs(close - open)
float bodyRatio = (candleRange > 0 ? candleBody / candleRange : 0.0)
float closePosition = (candleRange > 0 ? (close - low) / candleRange : 0.5)
bool bullishCandle = close > open
bool bearishCandle = close < open
bool longCandleOK = (not requireCandleDirection or bullishCandle)
bool shortCandleOK = (not requireCandleDirection or bearishCandle)
bool bodyOK = (not useBodyFilter or bodyRatio >= minimumBodyRatio)
bool longCloseOK = (not useCloseLocation or closePosition >= longClosePosition)
bool shortCloseOK = (not useCloseLocation or closePosition <= shortClosePosition)
// ============================================================================
// 18. PRICE STRUCTURE
// ============================================================================
//
// Previous N bars only.
// Current breakout candle is excluded.
//
// ============================================================================
float structureHigh = ta.highest(high[1], structureLookback)
float structureLow = ta.lowest(low[1], structureLookback)
bool longStructureOK = (not useStructureFilter or (not na(structureHigh) and close > structureHigh))
bool shortStructureOK = (not useStructureFilter or (not na(structureLow) and close < structureLow))
// ============================================================================
// 19. EMA TREND
// ============================================================================
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)))
// ============================================================================
// 20. RELATIVE VOLUME FILTER
// ============================================================================
bool volumeOK = (not useVolumeFilter or (not na(relativeVolume) and relativeVolume >= minimumVolumeFactor))
// ============================================================================
// 21. ADX / DI FILTERS
// ============================================================================
[diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
bool adxOK = (not useADXFilter or (not na(adx) and adx >= minimumADX))
bool longDIOK = (not requireDIDirection or (not na(diPlus) and not na(diMinus) and diPlus > diMinus))
bool shortDIOK = (not requireDIDirection or (not na(diPlus) and not na(diMinus) and diMinus > diPlus))
// ============================================================================
// 22. 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))
// ============================================================================
// 23. 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
var int lastEntryBar = na
bool newClosedTrade = (strategy.closedtrades > nz(strategy.closedtrades[1], 0))
if newClosedTrade
lastExitBar := bar_index
bool cooldownOK = (na(lastExitBar) or bar_index - lastExitBar > cooldownBars)
bool freshEntryBar = (na(lastEntryBar) or lastEntryBar != bar_index)
// ============================================================================
// 24. BASE SIGNALS
// ============================================================================
bool longBase = (bullishMomentumSignal and longCandleOK and bodyOK and longCloseOK and longStructureOK)
bool shortBase = (bearishMomentumSignal and shortCandleOK and bodyOK and shortCloseOK and shortStructureOK)
// ============================================================================
// 25. FINAL FILTERED SIGNALS
// ============================================================================
bool rawLong = (longBase and longTrendOK and volumeOK and adxOK and longDIOK and longH1OK)
bool rawShort = (shortBase and shortTrendOK and volumeOK and adxOK and shortDIOK and shortH1OK)
// ============================================================================
// 26. ENTRY GATES
// ============================================================================
bool canTrade = (barstate.isconfirmed and intradayOK and flat and strategy.opentrades == 0 and tradesToday < maximumTradesPerDay and cooldownOK and freshEntryBar and entrySessionOK and beforeForceClose)
bool ambiguousSignal = (rawLong and rawShort)
bool enterLong = (canTrade and allowLong and rawLong and not ambiguousSignal)
bool enterShort = (canTrade and allowShort and rawShort and not ambiguousSignal)
// ============================================================================
// 27. RISK 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)
// ============================================================================
// 28. DIAGNOSTIC COUNTERS
// ============================================================================
var int bullCrossCount = 0
var int bearCrossCount = 0
var int longBaseCount = 0
var int shortBaseCount = 0
var int filteredLongCount = 0
var int filteredShortCount = 0
var int blockedLongCount = 0
var int blockedShortCount = 0
var int longEntryCount = 0
var int shortEntryCount = 0
// ============================================================================
// 29. LONG ENTRY
// ============================================================================
if enterLong
strategy.entry("Long", strategy.long, comment="VWM Momentum LONG", alert_message="🟢 VÀO VỊ THẾ LONG (CNPS89)\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
// ============================================================================
// 30. SHORT ENTRY
// ============================================================================
if enterShort
strategy.entry("Short", strategy.short, comment="VWM Momentum SHORT", alert_message="🔴 VÀO VỊ THẾ SHORT (CNPS89)\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
// ============================================================================
// 31. UPDATE DIAGNOSTICS
// ============================================================================
if barstate.isconfirmed
if bullishMomentumSignal
bullCrossCount += 1
if bearishMomentumSignal
bearCrossCount += 1
if longBase
longBaseCount += 1
if shortBase
shortBaseCount += 1
if rawLong
filteredLongCount += 1
if rawShort
filteredShortCount += 1
if rawLong and not enterLong
blockedLongCount += 1
if rawShort and not enterShort
blockedShortCount += 1
// ============================================================================
// 32. LONG SL / TP
// ============================================================================
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 (CNPS89 - TP HIT)\n🎯 Giá chốt lời: " + str.tostring(strategy.position_avg_price + effectiveTP, format.mintick), alert_loss="🛑 CẮT LỖ LONG (CNPS89 - SL HIT)\n💥 Giá cắt lỗ: " + str.tostring(strategy.position_avg_price - effectiveSL, format.mintick), disable_alert=disableExitAlerts)
// ============================================================================
// 33. SHORT SL / TP
// ============================================================================
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 (CNPS89 - TP HIT)\n🎯 Giá chốt lời: " + str.tostring(strategy.position_avg_price - effectiveTP, format.mintick), alert_loss="🛑 CẮT LỖ SHORT (CNPS89 - SL HIT)\n💥 Giá cắt lỗ: " + str.tostring(strategy.position_avg_price + effectiveSL, format.mintick), disable_alert=disableExitAlerts)
// ============================================================================
// 34. 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 >= maximumHoldingBars 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 (CNPS89 - Time Exit)\n📌 Giá đóng: " + str.tostring(close, format.mintick))
// ============================================================================
// 35. FORCE CLOSE
// ============================================================================
if (barstate.isconfirmed and forceCloseBar and strategy.position_size != 0)
strategy.close_all(immediately=true, comment="Session End", alert_message="⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (CNPS89 - Session End)\n📌 Giá đóng: " + str.tostring(close, format.mintick))
// ============================================================================
// 36. EMA PLOT
// ============================================================================
plot(showEMA ? ema : na, title="EMA Trend", color=color.orange, linewidth=2)
// ============================================================================
// 37. STRUCTURE LEVELS
// ============================================================================
plot(showStructureLevels ? structureHigh : na, title="Structure High", color=color.new(color.red, 40), linewidth=1, style=plot.style_stepline)
plot(showStructureLevels ? structureLow : na, title="Structure Low", color=color.new(color.green, 40), linewidth=1, style=plot.style_stepline)
// ============================================================================
// 38. MOMENTUM CROSS MARKERS
// ============================================================================
//
// OFF by default to keep chart clean.
//
// ============================================================================
plotshape(showMomentumMarkers and bullishMomentumSignal, title="Bullish Weighted Momentum Cross", style=shape.circle, location=location.belowbar, color=color.aqua, size=size.tiny, text="VWM")
plotshape(showMomentumMarkers and bearishMomentumSignal, title="Bearish Weighted Momentum Cross", style=shape.circle, location=location.abovebar, color=color.orange, size=size.tiny, text="VWM")
// ============================================================================
// 39. ENTRY MARKERS
// ============================================================================
plotshape(showEntryMarkers and enterLong, title="CNPS89 LONG", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="LONG", textcolor=color.white)
plotshape(showEntryMarkers and enterShort, title="CNPS89 SHORT", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="SHORT", textcolor=color.white)
// ============================================================================
// 40. 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)
// ============================================================================
// 41. DATA WINDOW
// ============================================================================
plot(momentum, title="Volume-Weighted Momentum / ATR", color=color.blue, display=display.data_window)
plot(normalizedMomentum, title="Raw Normalized Momentum", color=color.aqua, display=display.data_window)
plot(rawMomentum, title="Weighted Price Change", color=color.orange, display=display.data_window)
plot(relativeVolume, title="Relative Volume", color=color.gray, display=display.data_window)
plot(atr, title="ATR", color=color.gray, display=display.data_window)
plot(adx, title="ADX", color=color.purple, display=display.data_window)
// ============================================================================
// 42. DIAGNOSTICS
// ============================================================================
var table diagnostics = table.new(position.top_right, 2, 19, border_width=1)
if showDiagnostics and barstate.islast
table.cell(diagnostics, 0, 0, "CNPS89 V1")
table.cell(diagnostics, 1, 0, timeframe.period)
table.cell(diagnostics, 0, 1, "Weighted Momentum")
table.cell(diagnostics, 1, 1, str.tostring(momentum, "#.###"))
table.cell(diagnostics, 0, 2, "Volume Ratio")
table.cell(diagnostics, 1, 2, str.tostring(relativeVolume, "#.##"))
table.cell(diagnostics, 0, 3, "Bull Crosses")
table.cell(diagnostics, 1, 3, str.tostring(bullCrossCount))
table.cell(diagnostics, 0, 4, "Bear Crosses")
table.cell(diagnostics, 1, 4, str.tostring(bearCrossCount))
table.cell(diagnostics, 0, 5, "Long Bases")
table.cell(diagnostics, 1, 5, str.tostring(longBaseCount))
table.cell(diagnostics, 0, 6, "Short Bases")
table.cell(diagnostics, 1, 6, str.tostring(shortBaseCount))
table.cell(diagnostics, 0, 7, "Filtered Long")
table.cell(diagnostics, 1, 7, str.tostring(filteredLongCount))
table.cell(diagnostics, 0, 8, "Filtered Short")
table.cell(diagnostics, 1, 8, str.tostring(filteredShortCount))
table.cell(diagnostics, 0, 9, "Blocked Long")
table.cell(diagnostics, 1, 9, str.tostring(blockedLongCount))
table.cell(diagnostics, 0, 10, "Blocked Short")
table.cell(diagnostics, 1, 10, str.tostring(blockedShortCount))
table.cell(diagnostics, 0, 11, "Long Entries")
table.cell(diagnostics, 1, 11, str.tostring(longEntryCount))
table.cell(diagnostics, 0, 12, "Short Entries")
table.cell(diagnostics, 1, 12, str.tostring(shortEntryCount))
table.cell(diagnostics, 0, 13, "EMA Up")
table.cell(diagnostics, 1, 13, emaUp ? "YES" : "NO")
table.cell(diagnostics, 0, 14, "EMA Down")
table.cell(diagnostics, 1, 14, emaDown ? "YES" : "NO")
table.cell(diagnostics, 0, 15, "ADX")
table.cell(diagnostics, 1, 15, str.tostring(adx, "#.##"))
table.cell(diagnostics, 0, 16, "Session OK")
table.cell(diagnostics, 1, 16, entrySessionOK ? "YES" : "NO")
table.cell(diagnostics, 0, 17, "Trades Today")
table.cell(diagnostics, 1, 17, str.tostring(tradesToday) + "/" + str.tostring(maximumTradesPerDay))
table.cell(diagnostics, 0, 18, "Position")
table.cell(diagnostics, 1, 18, inLong ? "LONG" : inShort ? "SHORT" : "FLAT")
2. Những khái niệm kỹ thuật cốt lõi trong CNPS89
2.1. Xung lượng gia quyền khối lượng chuẩn hóa ATR (Normalized VWM)
Khác với ROC hay RSI chỉ nhìn vào biến động giá, CNPS89 tính toán mức thay đổi giá có trọng số khối lượng qua từng bước:
$$\text{Price Change} = \text{Close} - \text{Close}[1]$$
$$\text{Weighted Change} = \text{Price Change} \times \text{Volume}$$
$$\text{Raw VWM} = \frac{\text{SMA}(\text{Weighted Change}, N)}{\text{SMA}(\text{Volume}, N)}$$
$$\text{Normalized VWM} = \frac{\text{Raw VWM}}{\text{ATR}(\text{atrLength})}$$
Về mặt toán học, tỷ lệ giữa hai đường SMA tương đương với tỷ lệ tổng trượt (rolling sum), giúp loại bỏ sự phụ thuộc vào hàm tổng riêng biệt. Khi Normalized VWM mang giá trị dương lớn, điều đó phản ánh lực đẩy tăng giá đi kèm khối lượng giao dịch thực sự áp đảo so với biên độ dao động trung bình ATR(14). Nếu bật useMomentumSmoothing, chuỗi Normalized VWM sẽ được làm mượt thêm qua ta.ema(..., 3).
2.2. Giải phẫu nến (Candle Anatomy) và Cấu trúc giá (Price Structure)
Bot định lượng hình thái từng cây nến thông qua hai đại lượng:
bodyRatio = math.abs(close - open) / (high - low)(nếuhigh == lowtrả về0.0): Đo độ đặc của thân nến so với toàn bộ biên độ nến.closePosition = (close - low) / (high - low)(nếuhigh == lowtrả về0.5): Đo vị trí giá đóng cửa nằm ở phần trên hay phần dưới của cây nến.
Bên cạnh đó, bộ lọc cấu trúc giá (useStructureFilter) sử dụng ta.highest(high[1], structureLookback) và ta.lowest(low[1], structureLookback) — chỉ tính trên N nến trước đó và loại trừ cây nến breakout hiện tại để tránh tự tham chiếu (lookahead).
2.3. Hệ thống bộ lọc xu hướng và khung lớn (EMA, Volume, ADX, H1 Bias)
- EMA Trend (
emaLength = 50): Không chỉ kiểm tra giá nằm trên/dướiEMA(50), bot còn kiểm tra độ dốcema > ema[3](với Long) hoặcema < ema[3](với Short) để tránh giao dịch khi EMA đang đi ngang. - Relative Volume: Tính
volume / ta.sma(volume[1], 20), so sánh khối lượng nến hiện tại với trung bình 20 nến liền trước (không bao gồm nến hiện tại). - ADX / DI (
ta.dmi(14, 14)): Tùy chọn lọc độ mạnh xu hướngadx >= 18.0và hướng+DI/-DI. - Confirmed H1 Bias: Dùng
request.security(syminfo.tickerid, "60", ...[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)để lấy đúng giá đóng cửa vàEMA(50)của nến H1 đã đóng hoàn toàn gần nhất (chỉ hợp lệ trên biểu đồ intraday nhỏ hơn 60 phúttimeframe.in_seconds() < 3600).
3. Nguyên lý hoạt động của CNPS89
Quy trình vận hành của CNPS89 trên mỗi thanh nến diễn ra tuần tự theo 5 bước khép kín:
- Khởi tạo phiên và bộ đếm ngày: Xác định mốc thời gian theo múi giờ
Asia/Ho_Chi_Minh, reset biến đếmtradesToday := 0khi bước sang ngày giao dịch mới (newDay), đồng thời tính toán sẵnATR,EMA,Relative Volume,ADXvàNormalized VWM. - Phát hiện giao cắt xung lượng: Theo dõi điểm cắt lên ngưỡng
+0.10(ta.crossover(momentum, longThreshold)) hoặc cắt xuống ngưỡng-0.10(ta.crossunder(momentum, shortThreshold)), kết hợp kiểm tra gia tốc xung lượng (momentum > momentum[1]cho Long hoặcmomentum < momentum[1]cho Short) tại thời điểm nến đóng cửa (barstate.isconfirmed). - Xác nhận tín hiệu cơ sở (Base Signals): Kết hợp tín hiệu VWM với hướng nến (
bullishCandle/bearishCandle) và các tùy chọn giải phẫu nến, cấu trúc giá để hình thànhlongBasevàshortBase. - Kiểm tra bộ lọc và cổng vào lệnh (Entry Gates): Lọc qua
EMA Trend,Volume,ADX/DI,H1 Biasđể rarawLong/rawShort. Sau đó kiểm tra toàn bộ điều kiện an toàncanTrade(đang không có vị thế, chưa vượt quámaximumTradesPerDay, hếtcooldownBars, nằm trong khung giờ phiên) trước khi gửi lệnhstrategy.entry. - Quản trị và thoát lệnh: Ngay khi khớp lệnh,
strategy.exitthiết lập SL/TP cố định theoslTicksvàtpTicks. Nếu bậtuseTimeExit, bot tự đóng lệnh khi giữ đủmaximumHoldingBarsnến; và khi chạm mốc14:45(forceCloseBar), bot cưỡng bức đóng toàn bộ vị thế bằngstrategy.close_all.
4. Điều kiện vào lệnh Long và Short của CNPS89
4.1. Điều kiện vào lệnh Long
Lệnh Long (enterLong) được kích hoạt khi thỏa mãn đồng thời các điều kiện sau:
- Chiều giao dịch cho phép:
tradeDirectionlà"Long"hoặc"Both"(allowLong == true). - Tín hiệu xung lượng tăng (
bullishMomentumSignal): Nến đã xác nhận (barstate.isconfirmed),momentumcắt lên trên+momentumThreshold(+0.10) và nếu bậtrequireAccelerationthìmomentum > momentum[accelerationLookback]. - Xác nhận nến & cấu trúc (
longBase):- Nếu bật
requireCandleDirection(mặc địnhtrue): Nến tăng (close > open). - Nếu bật
useBodyFilter:bodyRatio >= minimumBodyRatio(0.40). - Nếu bật
useCloseLocation:closePosition >= longClosePosition(0.65). - Nếu bật
useStructureFilter:close > structureHigh(vượt đỉnh5nến trước).
- Nếu bật
- Bộ lọc xu hướng & bối cảnh (
rawLong):- Nếu bật
useEMAFilter(mặc địnhtrue):ema > ema[3]và (nếurequirePriceEMAlàtrue)close > ema. - Nếu bật
useVolumeFilter:relativeVolume >= 1.00. - Nếu bật
useADXFilter:adx >= 18.0; nếu bậtrequireDIDirection:diPlus > diMinus. - Nếu bật
useH1Bias: Biểu đồ< 60phút vàh1Close > h1EMA.
- Nếu bật
- Không xung đột tín hiệu:
not ambiguousSignal(tứcrawLongvàrawShortkhông cùng xảy ra đồng thời) và thỏa mãncanTrade.
4.2. Điều kiện vào lệnh Short
Lệnh Short (enterShort) hoạt động đối xứng hoàn toàn với lệnh Long:
- Chiều giao dịch cho phép:
tradeDirectionlà"Short"hoặc"Both"(allowShort == true). Lưu ý mặc định code đang đểtradeDirection = "Long", bạn cần chuyển sang"Both"hoặc"Short"nếu muốn bot đánh Short. - Tín hiệu xung lượng giảm (
bearishMomentumSignal): Nến đã xác nhận (barstate.isconfirmed),momentumcắt xuống dưới-momentumThreshold(-0.10) và nếu bậtrequireAccelerationthìmomentum < momentum[accelerationLookback]. - Xác nhận nến & cấu trúc (
shortBase):- Nếu bật
requireCandleDirection(mặc địnhtrue): Nến giảm (close < open). - Nếu bật
useBodyFilter:bodyRatio >= minimumBodyRatio(0.40). - Nếu bật
useCloseLocation:closePosition <= shortClosePosition(0.35). - Nếu bật
useStructureFilter:close < structureLow(thủng đáy5nến trước).
- Nếu bật
- Bộ lọc xu hướng & bối cảnh (
rawShort):- Nếu bật
useEMAFilter(mặc địnhtrue):ema < ema[3]và (nếurequirePriceEMAlàtrue)close < ema. - Nếu bật
useVolumeFilter:relativeVolume >= 1.00. - Nếu bật
useADXFilter:adx >= 18.0; nếu bậtrequireDIDirection:diMinus > diPlus. - Nếu bật
useH1Bias: Biểu đồ< 60phút vàh1Close < h1EMA.
- Nếu bật
- Không xung đột tín hiệu:
not ambiguousSignalvà thỏa mãncanTrade.
4.3. Điều kiện kiểm soát giao dịch chung
Biến canTrade yêu cầu toàn bộ các cổng kiểm soát sau phải đạt trạng thái hợp lệ:
- Khung thời gian & Xác nhận nến:
barstate.isconfirmedvàtimeframe.isintraday(chỉ chạy trên khung intraday). - Trạng thái vị thế Flat:
strategy.position_size == 0vàstrategy.opentrades == 0(vớipyramiding = 0, không nhồi lệnh). - Giới hạn lệnh/ngày:
tradesToday < maximumTradesPerDay(mặc định tối đa2lệnh/ngày). - Cooldown sau thoát lệnh:
bar_index - lastExitBar > cooldownBars(mặc định phải qua hơn3nến kể từ nến ghi nhận đóng lệnh trước đó) vàfreshEntryBar(không vào lại trên cùng một nến vừa vào). - Khung giờ giao dịch (
Asia/Ho_Chi_Minh): Nếu bậtuseSessionFilter(mặc địnhtrue), giờ mở nếnopenMinutes >= 09:15và giờ đóng nếncloseMinutes <= 14:15. Đồng thờicloseMinutes < 14:45(beforeForceClose).
5. Quản trị Stop Loss, Take Profit và Thoát lệnh
5.1. Cơ chế Stop Loss và quy đổi Ticks
Bot CNPS89 sử dụng cơ chế cắt lỗ cố định theo điểm và tự động quy đổi sang đơn vị tick tối thiểu của hợp đồng (syminfo.mintick, với VN30F1M là 0.1 điểm):
slTicks = math.max(1, int(math.round(stopLossPoints / syminfo.mintick)))effectiveSL = slTicks * syminfo.mintick
Với mặc định stopLossPoints = 5.0, mức cắt lỗ tương ứng là 50 ticks (5.0 điểm) tính từ giá khớp trung bình strategy.position_avg_price. Bot không sử dụng bộ lọc Min–Max Risk hay khoảng đệm ATR riêng cho SL.
5.2. Cơ chế Take Profit và Thoát lệnh theo thời gian / cuối phiên
- Take Profit cố định: Quy đổi tương tự
tpTicks = math.max(1, int(math.round(takeProfitPoints / syminfo.mintick))). Với mặc địnhtakeProfitPoints = 15.0, mức chốt lời đạt150 ticks(15.0điểm), tương ứng tỷ lệ Risk:Reward = 1:3. 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). Khi bật, nếu số nến nắm giữbarsHeld = bar_index - strategy.opentrades.entry_bar_index(0) >= maximumHoldingBars(mặc định20nến) tại nến xác nhận (và chưa đến giờforceCloseBar), bot sẽ đóng toàn bộ vị thế ngay lập tức. - Đóng cưỡng bức cuối phiên (
Force Close): Tại nến cóopenMinutes < 14:45vàcloseMinutes >= 14:45khi nến đóng cửa (barstate.isconfirmed), nếu vẫn còn vị thế mở, bot tự động gọistrategy.close_all(immediately=true, comment="Session End")để tránh giữ lệnh qua đêm (tránh rủi ro ATC và gap ATO).
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 | Công thức / Điều kiện kích hoạt | Comment trên biểu đồ |
|---|---|---|---|
| Stop Loss (SL) | Bật | Cố định 5.0 điểm (50 ticks) từ strategy.position_avg_price | SL Long / SL Short |
| Take Profit (TP) | Bật | Cố định 15.0 điểm (150 ticks) từ strategy.position_avg_price | TP Long / TP Short |
| Time Exit | Tắt (false) | barsHeld >= 20 nến tại barstate.isconfirmed (trước 14:45) | Time Exit |
| Force Close cuối phiên | Bật | Nến xác nhận vượt qua mốc 14:45 (Asia/Ho_Chi_Minh) | 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 phái sinh VN30F1M trên TradingView và chọn khung thời gian intraday phù hợp (ví dụ
M5hoặcM15). - Nhấn vào tab Pine Editor ở thanh công cụ phía dưới màn hình.
- Xóa toàn bộ mã mẫu mặc định, sao chép toàn bộ mã nguồn CNPS89 ở Mục 1 và dán vào Pine Editor.
- Nhấn Save để lưu script, sau đó nhấn Add to chart để đưa chiến lược lên biểu đồ.
- Nhấn biểu tượng bánh răng (Settings) của chiến lược
CNPS89 VWMđể tùy chỉnh chiều giao dịch (Long,Short,Both), mức SL/TP hoặc bậtShow Diagnosticsnếu muốn theo dõi bảng thống kê.
Cách đọc bảng chẩn đoán (Diagnostics Table)
Khi bật tùy chọn Show Diagnostics (showDiagnostics = true), bot sẽ hiển thị một bảng 2 cột x 19 dòng tại góc trên bên phải (position.top_right) ở nến cuối cùng (barstate.islast):
- CNPS89 V1: Hiển thị khung thời gian hiện tại của biểu đồ (
timeframe.period). - Weighted Momentum & Volume Ratio: Giá trị hiện tại của
momentum(độ lớn xung lượng chuẩn hóa ATR) vàrelativeVolume. - Bull Crosses / Bear Crosses: Tổng số lần
bullishMomentumSignalvàbearishMomentumSignalxuất hiện trong lịch sử dữ liệu. - Long Bases / Short Bases: Số tín hiệu vượt qua bước kiểm tra giải phẫu nến và cấu trúc giá.
- Filtered Long / Filtered Short: Số tín hiệu vượt qua toàn bộ các bộ lọc xu hướng (
EMA,Volume,ADX,H1). - Blocked Long / Blocked Short: Số tín hiệu hợp lệ (
rawLong/rawShort) nhưng bị chặn bởi cổng kiểm soát (canTradenhư đang có lệnh, hết lượt/ngày, cooldown hoặc ngoài giờ). - Long Entries / Short Entries: Tổng số lệnh Long và Short đã thực sự được gửi vào thị trường.
- EMA Up / EMA Down & ADX: Trạng thái độ dốc đường
EMA(50)(YES/NO) và giá trịADXhiện tại. - Session OK, Trades Today & Position: Trạng thái phiên giao dịch hiện tại (
YES/NO), số lệnh đã dùng trong ngày (x/2) và trạng thái vị thế (LONG,SHORT,FLAT).
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 bot phát sinh tín hiệu:
- Nhấn vào biểu tượng Alert (Đồng hồ báo thức) hoặc nhấn tổ hợp phím
Alt + Atrên TradingView. - Tại mục Condition, chọn chiến lược CNPS89 VOLUME-WEIGHTED MOMENTUM V1.
- Tại ô Message, xóa nội dung mặc định và thay bằng đúng cú pháp:
{{strategy.order.alert_message}}. - Đặt tên Alert, chọn phương thức nhận thông báo (Notify on app, Webhook URL…) và nhấn Create.
Bảng thông điệp Alert của CNPS89
| Sự kiện | Điều kiện kích hoạt | Nội dung thông điệp (alert_message / alert_profit / alert_loss) |
|---|---|---|
| Vào lệnh Long | enterLong | 🟢 VÀO VỊ THẾ LONG (CNPS89) kèm Giá vào, Cắt lỗ (SL) và Chốt lời (TP) |
| Vào lệnh Short | enterShort | 🔴 VÀO VỊ THẾ SHORT (CNPS89) kèm Giá vào, Cắt lỗ (SL) và Chốt lời (TP) |
| Chốt lời Long | Chạm tpTicks (khi disableExitAlerts = false) | 💰 CHỐT LỜI LONG (CNPS89 - TP HIT) kèm Giá chốt lời |
| Cắt lỗ Long | Chạm slTicks (khi disableExitAlerts = false) | 🛑 CẮT LỖ LONG (CNPS89 - SL HIT) kèm Giá cắt lỗ |
| Chốt lời Short | Chạm tpTicks (khi disableExitAlerts = false) | 💰 CHỐT LỜI SHORT (CNPS89 - TP HIT) kèm Giá chốt lời |
| Cắt lỗ Short | Chạm slTicks (khi disableExitAlerts = false) | 🛑 CẮT LỖ SHORT (CNPS89 - SL HIT) kèm Giá cắt lỗ |
| Thoát hết giờ giữ | timeExit and not forceCloseBar | ⏱️ ĐÓNG VỊ THẾ HẾT THỜI GIAN (CNPS89 - Time Exit) kèm Giá đóng |
| Đóng hết phiên | forceCloseBar lúc 14:45 | ⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (CNPS89 - Session End) kèm Giá đóng |
Kết luận
CNPS89 Volume-Weighted Momentum V1 là một hệ thống giao dịch gọn nhẹ, minh bạch và kỷ luật cao cho VN30F1M. Nhờ kết hợp biến động giá theo khối lượng chuẩn hóa ATR với bộ lọc xu hướng EMA(50) có độ dốc và tỷ lệ R:R cố định 1:3 (SL 5 điểm / TP 15 điểm), bot đặc biệt phù hợp trong các phiên thị trường có xu hướng rõ ràng và dòng tiền đồng thuận.
Bạn có thể tham khảo thêm các chiến lược khác trong cùng hệ sinh thái như Bot CNPS50 - Trend Analysis V2 và Bot CNPS49 - Daily Open để đa dạng hóa phương pháp giao dịch.
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.





