Thứ Tư, 02/12/202602/12/2026

Hướng Dẫn Sử Dụng Bot CNPS84 - Compression Expansion V1 cho VN30F1M

Bot CNPS84 (Compression Expansion V1) là chiến lược giao dịch VN30F1M tự động trên TradingView, chuyên bắt các pha bùng nổ biến động thoát khỏi vùng giá nén chặt với bộ lọc cấu trúc nến, xu hướng EMA 50 và quản trị rủi ro SL/TP cố định.

Hướng dẫn sử dụng Bot CNPS84 cho VN30F1M
Hướng dẫn sử dụng Bot CNPS84 cho VN30F1M
Mục lục
Mục lục

Khi giao dịch hợp đồng tương lai VN30F1M, thị trường thường xuyên trải qua những giai đoạn đi ngang tích lũy trong biên độ hẹp (nén giá) trước khi bước vào một nhịp bùng nổ biến động mạnh. Nếu vào lệnh quá sớm khi giá còn trong vùng giằng co, nhà đầu tư dễ bị quét cắt lỗ liên tục (whipsaw); ngược lại, nếu chờ quá muộn sau khi giá đã chạy xa, tỷ lệ Rủi ro/Lợi nhuận (R:R) sẽ không còn tối ưu.

Chiến lược CNPS84 COMPRESSION EXPANSION V1 (tên rút gọn: CNPS84 COMP EXP), được lập trình trên nền tảng Pine Script v6 của TradingView, giải quyết trực tiếp bài toán này bằng cách tự động phát hiện các vùng giá bị nén chặt hơn mức trung bình lịch sử và chỉ kích hoạt lệnh khi xuất hiện một cây nến xác nhận bùng nổ biến động thực sự.

Các điểm nổi bật cốt lõi của Bot CNPS84:

  • Nhận diện nén giá chuẩn hóa theo ATR: So sánh biên độ vùng giá gần nhất với đường trung bình lịch sử đã chuẩn hóa theo ATR, đảm bảo chỉ ghi nhận các pha tích lũy thực sự chặt chẽ.
  • Xác nhận giải phẫu nến bùng nổ (Breakout Candle Anatomy): Đòi hỏi nến phá vỡ phải có biên độ mở rộng, thân nến đặc (Body Ratio cao) và đóng cửa sát vùng cực trị, loại bỏ các cú phá vỡ giả (Fakeout).
  • Bộ lọc đa tầng linh hoạt: Kết hợp xu hướng EMA 50 dốc cùng chiều (mặc định bật) cùng các bộ lọc tùy chọn như ADX, Volume và xu hướng khung H1 đã xác nhận (Confirmed H1 Bias), cam kết không repaint.
  • Quản trị rủi ro chặt chẽ: Cài đặt sẵn Stop Loss 5.0 điểm, Take Profit 15.0 điểm (tỷ lệ R:R 1:3), giới hạn tối đa 2 lệnh/ngày, thời gian nghỉ (Cooldown) sau khi thoát lệnh và tự động đóng toàn bộ vị thế cuối phiên lúc 14:45.

1. CNPS84 Compression Expansion V1 là gì?

CNPS84 Compression Expansion V1 là hệ thống giao dịch theo động lượng phá vỡ (Breakout Momentum) được thiết kế chuyên biệt cho khung thời gian trong ngày (Intraday) trên phái sinh VN30F1M. Toàn bộ kiến trúc của bot xoay quanh 4 trụ cột kỹ thuật chính:

  1. Bộ phát hiện vùng nén giá (Compression Detection): Theo dõi biên độ cao – thấp của 8 cây nến liền trước (không tính nến hiện tại), chuẩn hóa theo chỉ báo ATR(14) và đối chiếu với mức nền trung bình 50 phiên gần nhất. Khi tỷ lệ nén đạt ngưỡng ≤ 0.75 lần mức nền, bot ghi nhận một vùng nén hợp lệ (Compression High và Compression Low).
  2. Cửa sổ phá vỡ và giải phẫu nến (Breakout Window & Candle Anatomy): Một thiết lập nén giá chỉ có hiệu lực trong vòng 6 cây nến tiếp theo (trong cùng một ngày giao dịch). Nến phá vỡ phải vượt qua biên vùng nén cộng thêm vùng đệm (0.10 * ATR), đồng thời thỏa mãn các tiêu chuẩn khắt khe về độ mở rộng biên độ (≥ 1.20 * ATR), tỷ lệ thân nến (≥ 0.55) và vị trí đóng cửa sát đỉnh/đáy nến.
  3. Hệ thống lọc xu hướng và xác nhận đa điều kiện: Mặc định sử dụng đường EMA 50 (yêu cầu EMA đang dốc lên/xuống so với 3 nến trước và giá nằm đúng phía so với EMA). Ngoài ra, người dùng có thể kích hoạt thêm bộ lọc sức mạnh xu hướng ADX, xác nhận dòng tiền Volume và xu hướng khung H1 đã đóng nến.
  4. Kiểm soát lệnh và quản trị rủi ro theo phiên: Quy đổi trực tiếp Stop Loss (5.0 điểm) và Take Profit (15.0 điểm) sang đơn vị tick của hợp đồng, kết hợp cơ chế giới hạn số lệnh trong ngày (2 lệnh), thời gian nghỉ (3 nến), tùy chọn thoát lệnh theo thời gian (Time Exit) và tự động tất toán trước phiên ATC lúc 14:45.

Bảng thông số mặc định

Nhóm thông sốTên tham số trong CodeGiá trị mặc địnhÝ nghĩa & Chức năng
01. CompressionCompression Lookback8Số nến liền trước (không gồm nến hiện tại) dùng đo biên độ nén
Baseline Lookback50Chu kỳ SMA tính mức biên độ chuẩn hóa nền
ATR Length14Chu kỳ tính biến động trung bình ATR
Compression Factor0.75Hệ số nén tối đa so với mức nền để xác nhận vùng nén
Require Maximum Range / ATRfalseBật/tắt giới hạn trần tuyệt đối của vùng nén theo ATR (3.0)
02. BreakoutMaximum Breakout Window6Số nến tối đa chờ phá vỡ kể từ khi thiết lập vùng nén
Require Breakout BuffertrueYêu cầu giá đóng cửa vượt biên cộng vùng đệm (0.10 * ATR)
Require Expansion CandletrueYêu cầu nến phá vỡ có biên độ tối thiểu 1.20 * ATR
Require Strong Candle BodytrueYêu cầu tỷ lệ Thân nến / Biên độ tối thiểu 0.55
Require Close Near Candle ExtremetrueĐóng cửa Long ≥ 0.70 biên độ nến; Short ≤ 0.30
03. EMA TrendUse EMA Trend FiltertrueBật/tắt bộ lọc xu hướng EMA
EMA Length / EMA Slope Lookback50 / 3Chu kỳ EMA 50 và độ dốc so với 3 nến trước
Require Price Above/Below EMAtrueBắt buộc giá đóng cửa nằm trên (Long) hoặc dưới (Short) EMA
04. Optional FiltersUse Minimum ADX FilterfalseTùy chọn lọc ADX (DI=14, Smooth=14, Min ADX=18.0)
Use Volume ConfirmationfalseTùy chọn lọc Volume (SMA=20, hệ số tối thiểu 1.20)
05. H1 BiasUse Confirmed H1 EMA BiasfalseTùy chọn lọc xu hướng EMA 50 khung H1 đã đóng nến
06. Risk ManagementStop Loss (Points)5.0Khoảng cách cắt lỗ tính bằng điểm từ giá khớp lệnh
Take Profit (Points)15.0Khoảng cách chốt lời tính bằng điểm từ giá khớp lệnh
Use Time ExitfalseTùy chọn đóng lệnh nếu giữ quá 20 nến (Maximum Holding Bars)
07. Trade ControlTrade Direction"Long"Chiều giao dịch mặc định (Long, Short, hoặc Both)
Contracts3Số lượng hợp đồng mặc định mỗi lệnh
Maximum Trades Per Day2Giới hạn số lệnh tối đa trong một ngày
Cooldown After Exit (Bars)3Số nến phải chờ sau khi đóng lệnh trước khi vào lệnh mới
08. SessionUse Entry Session FiltertrueMúi giờ Asia/Ho_Chi_Minh: vào lệnh 09:15–14:15, đóng hết lúc 14:45
09. Alerts & 10. DisplayDisable SL/TP AlertsfalseBật cảnh báo SL/TP; bảng Show Diagnostics mặc định tắt (false)

Source Code CNPS84 Compression 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
strategy(title="CNPS84 COMPRESSION EXPANSION V1", shorttitle="CNPS84 COMP EXP", 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)

// ============================================================================
// CNPS84 - COMPRESSION EXPANSION
//
// LONG:
// 1. Previous N bars form a compressed range.
// 2. Store the range high and low.
// 3. A subsequent candle closes above the range.
// 4. Breakout candle shows volatility expansion.
// 5. Optional EMA, ADX, volume and H1 confirmation.
// 6. Enter LONG.
//
// SHORT: Inverse conditions.
//
// All entries require confirmed candles.
// No future pivots or unconfirmed HTF values.
// SL / TP are measured from entry fill.
// ============================================================================
// ============================================================================
// 01. COMPRESSION DETECTION
// ============================================================================
gCompression = "01. Compression"
compressionLength = input.int(8, "Compression Lookback", minval=3, maxval=100, group=gCompression)
baselineLength = input.int(50, "Baseline Lookback", minval=10, maxval=300, group=gCompression)
atrLength = input.int(14, "ATR Length", minval=1, group=gCompression)
compressionFactor = input.float(0.75, "Compression Factor", minval=0.10, maxval=2.0, step=0.05, group=gCompression)
useAbsoluteRangeLimit = input.bool(false, "Require Maximum Range / ATR", group=gCompression)
maximumRangeATR = input.float(3.0, "Maximum Compression Range / ATR", minval=0.1, step=0.1, group=gCompression)

// ============================================================================
// 02. BREAKOUT CONFIRMATION
// ============================================================================
gBreakout = "02. Breakout"
breakoutWindow = input.int(6, "Maximum Breakout Window", minval=1, maxval=30, group=gBreakout)
useBreakoutBuffer = input.bool(true, "Require Breakout Buffer", group=gBreakout)
breakoutBufferATR = input.float(0.10, "Breakout Buffer / ATR", minval=0.0, step=0.05, group=gBreakout)
requireExpansion = input.bool(true, "Require Expansion Candle", group=gBreakout)
minimumExpansionATR = input.float(1.20, "Minimum Candle Range / ATR", minval=0.1, step=0.1, group=gBreakout)
requireBodyRatio = input.bool(true, "Require Strong Candle Body", group=gBreakout)
minimumBodyRatio = input.float(0.55, "Minimum Body / Range", minval=0.0, maxval=1.0, step=0.05, group=gBreakout)
requireClosePosition = input.bool(true, "Require Close Near Candle Extreme", group=gBreakout)
minimumLongClosePosition = input.float(0.70, "Long Minimum Close Position", minval=0.5, maxval=1.0, step=0.05, group=gBreakout)
maximumShortClosePosition = input.float(0.30, "Short Maximum Close Position", minval=0.0, maxval=0.5, step=0.05, group=gBreakout)

// ============================================================================
// 03. EMA TREND FILTER
// ============================================================================
gTrend = "03. EMA Trend"
useEMAFilter = input.bool(true, "Use EMA Trend Filter", group=gTrend)
emaLength = input.int(50, "EMA Length", minval=5, group=gTrend)
emaSlopeBars = input.int(3, "EMA Slope Lookback", minval=1, maxval=50, group=gTrend)
requirePriceEMA = input.bool(true, "Require Price Above/Below EMA", group=gTrend)

// ============================================================================
// 04. OPTIONAL FILTERS
// ============================================================================
gFilters = "04. Optional Filters"
useADXFilter = input.bool(false, "Use Minimum ADX Filter", group=gFilters)
diLength = input.int(14, "DI Length", minval=2, group=gFilters)
adxSmoothing = input.int(14, "ADX Smoothing", minval=2, group=gFilters)
minimumADX = input.float(18.0, "Minimum ADX", minval=1.0, step=1.0, group=gFilters)
useVolumeFilter = input.bool(false, "Use Volume Confirmation", group=gFilters)
volumeLength = input.int(20, "Volume Average Length", minval=2, group=gFilters)
volumeFactor = input.float(1.20, "Minimum Volume Factor", minval=0.1, step=0.1, group=gFilters)

// ============================================================================
// 05. CONFIRMED H1 BIAS
// ============================================================================
gH1 = "05. H1 Bias"
useH1Bias = input.bool(false, "Use Confirmed H1 EMA Bias", group=gH1)
h1EMALength = input.int(50, "H1 EMA Length", minval=1, group=gH1)

// ============================================================================
// 06. RISK MANAGEMENT
// ============================================================================
gRisk = "06. Risk Management"
stopLossPoints = input.float(5.0, "Stop Loss (Points)", minval=0.1, step=0.5, group=gRisk)
takeProfitPoints = input.float(15.0, "Take Profit (Points)", minval=0.1, step=0.5, group=gRisk)
useTimeExit = input.bool(false, "Use Time Exit", group=gRisk)
maximumHoldingBars = input.int(20, "Maximum Holding Bars", minval=1, maxval=200, group=gRisk)

// ============================================================================
// 07. TRADE CONTROL
// ============================================================================
gTrade = "07. Trade Control"
tradeDirection = input.string("Long", "Trade Direction", options=["Long", "Short", "Both"], group=gTrade)
contracts = input.int(3, "Contracts", minval=1, maxval=100, group=gTrade)
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")

// ============================================================================
// 08. SESSION
// ============================================================================
gSession = "08. Session"
useSessionFilter = input.bool(true, "Use Entry Session Filter", group=gSession)
tz = input.string("Asia/Ho_Chi_Minh", "Timezone", group=gSession)
startHour = input.int(9, "Entry Start Hour", minval=0, maxval=23, group=gSession)
startMinute = input.int(15, "Entry Start Minute", minval=0, maxval=59, group=gSession)
lastHour = input.int(14, "Last Entry Hour", minval=0, maxval=23, group=gSession)
lastMinute = input.int(15, "Last Entry Minute", minval=0, maxval=59, group=gSession)
endHour = input.int(14, "Force Close Hour", minval=0, maxval=23, group=gSession)
endMinute = input.int(45, "Force Close Minute", minval=0, maxval=59, group=gSession)

// ============================================================================
// 09. ALERTS
// ============================================================================
gAlerts = "09. Alerts"
disableExitAlerts = input.bool(false, "Disable SL/TP Alerts", group=gAlerts)

// ============================================================================
// 10. DISPLAY
// ============================================================================
gDisplay = "10. Display"
showEMA = input.bool(true, "Show EMA", group=gDisplay)
showCompressionMarkers = input.bool(false, "Show Compression Markers", group=gDisplay)
showCompressionLevels = input.bool(true, "Show Active Compression Levels", group=gDisplay)
showBreakoutMarkers = input.bool(false, "Show Breakout Markers", 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)

// ============================================================================
// 11. 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)

// ============================================================================
// 12. 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

// ============================================================================
// 13. ATR AND EMA
// ============================================================================
float atr = ta.atr(atrLength)
float ema = ta.ema(close, emaLength)
bool emaUp = (not na(ema[emaSlopeBars]) and ema > ema[emaSlopeBars])
bool emaDown = (not na(ema[emaSlopeBars]) and ema < ema[emaSlopeBars])
bool longTrendOK = (not useEMAFilter or (emaUp and (not requirePriceEMA or close > ema)))
bool shortTrendOK = (not useEMAFilter or (emaDown and (not requirePriceEMA or close < ema)))

// ============================================================================
// 14. COMPRESSION RANGE
// ============================================================================
//
// Exclude the current bar.
//
// Previous N bars determine the candidate
// compression high and low.
//
// ============================================================================
float recentRangeHigh = ta.highest(high[1], compressionLength)
float recentRangeLow = ta.lowest(low[1], compressionLength)
float recentRange = (recentRangeHigh - recentRangeLow)
float normalizedRange = (not na(atr[1]) and atr[1] > 0 ? recentRange / atr[1] : na)
float baselineRange = ta.sma(normalizedRange, baselineLength)
bool compressionReady = (not na(normalizedRange) and not na(baselineRange) and baselineRange > 0)
bool compressionNow = (compressionReady and normalizedRange <= baselineRange * compressionFactor and (not useAbsoluteRangeLimit or normalizedRange <= maximumRangeATR))
bool newCompression = (compressionNow and not compressionNow[1])

// ============================================================================
// 15. BREAKOUT 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 expansionOK = (not requireExpansion or (not na(atr) and candleRange >= atr * minimumExpansionATR))
bool bodyOK = (not requireBodyRatio or bodyRatio >= minimumBodyRatio)
bool longCloseOK = (not requireClosePosition or closePosition >= minimumLongClosePosition)
bool shortCloseOK = (not requireClosePosition or closePosition <= maximumShortClosePosition)

// ============================================================================
// 16. ADX AND VOLUME
// ============================================================================
[diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
float averageVolume = ta.sma(volume, volumeLength)
bool adxOK = (not useADXFilter or (not na(adx) and adx >= minimumADX))
bool volumeOK = (not useVolumeFilter or (not na(volume) and not na(averageVolume) and volume >= averageVolume * volumeFactor))

// ============================================================================
// 17. 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))

// ============================================================================
// 18. 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)

// ============================================================================
// 19. COMPRESSION STATE
// ============================================================================
//
// A compression setup stores its upper and
// lower boundaries.
//
// Only a later bar can trigger a breakout.
//
// A breakout consumes the setup.
// Expired setups cannot trigger new entries.
//
// ============================================================================
var bool pendingCompression = false
var int compressionBar = na
var int compressionDay = na
var float compressionHigh = na
var float compressionLow = na
var int compressionCount = 0
var int expiredCount = 0
var int bullBreakoutCount = 0
var int bearBreakoutCount = 0
var int longBaseCount = 0
var int shortBaseCount = 0
var int filteredLongCount = 0
var int filteredShortCount = 0
var int longEntryCount = 0
var int shortEntryCount = 0
bool validCompressionWindow = (pendingCompression and not na(compressionBar) and compressionDay == dayKey and bar_index > compressionBar and bar_index - compressionBar <= breakoutWindow)

// ============================================================================
// 20. BREAKOUT CONDITIONS
// ============================================================================
float breakoutBuffer = (useBreakoutBuffer and not na(atr) ? atr * breakoutBufferATR : 0.0)
bool bullishBreak = (barstate.isconfirmed and validCompressionWindow and not na(compressionHigh) and close > compressionHigh + breakoutBuffer)
bool bearishBreak = (barstate.isconfirmed and validCompressionWindow and not na(compressionLow) and close < compressionLow - breakoutBuffer)
bool longBase = (bullishBreak and bullishCandle and expansionOK and bodyOK and longCloseOK)
bool shortBase = (bearishBreak and bearishCandle and expansionOK and bodyOK and shortCloseOK)

// ============================================================================
// 21. FINAL FILTERED SIGNALS
// ============================================================================
bool rawLong = (longBase and longTrendOK and adxOK and volumeOK and longH1OK)
bool rawShort = (shortBase and shortTrendOK and adxOK and volumeOK and shortH1OK)

// ============================================================================
// 22. 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)

// ============================================================================
// 23. RISK MANAGEMENT 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)

// ============================================================================
// 24. LONG ENTRY
// ============================================================================
if enterLong
    strategy.entry("Long", strategy.long, comment="Compression Expansion LONG", alert_message="🟢 VÀO VỊ THẾ LONG (CNPS84)\\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

// ============================================================================
// 25. SHORT ENTRY
// ============================================================================
if enterShort
    strategy.entry("Short", strategy.short, comment="Compression Expansion SHORT", alert_message="🔴 VÀO VỊ THẾ SHORT (CNPS84)\\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

// ============================================================================
// 26. UPDATE COMPRESSION STATE
// ============================================================================
//
// Important:
// Entry signals above use saved levels.
//
// The state update is performed afterwards.
// This prevents using the current breakout bar
// as a newly created compression setup.
//
// ============================================================================
if barstate.isconfirmed
    if newCompression
        compressionCount += 1
    if bullishBreak
        bullBreakoutCount += 1
    if bearishBreak
        bearBreakoutCount += 1
    if longBase
        longBaseCount += 1
    if shortBase
        shortBaseCount += 1
    if rawLong
        filteredLongCount += 1
    if rawShort
        filteredShortCount += 1
    bool setupExpired = (pendingCompression and not na(compressionBar) and bar_index - compressionBar > breakoutWindow)
    bool breakoutResolved = (bullishBreak or bearishBreak)

    // Reset state at the start of each day.
    if newDay or setupExpired or breakoutResolved
        if setupExpired
            expiredCount += 1
        pendingCompression := false
        compressionBar := na
        compressionDay := na
        compressionHigh := na
        compressionLow := na

    // Register a new compression setup.
    //
    // Only when flat and inside entry hours.
    //
    // Do not immediately re-arm on the
    // same bar that resolved a breakout.
    bool canRegister = (intradayOK and flat and entrySessionOK and beforeForceClose and not breakoutResolved and not enterLong and not enterShort)
    if (canRegister and compressionNow and not pendingCompression)
        pendingCompression := true
        compressionBar := bar_index
        compressionDay := dayKey
        compressionHigh := recentRangeHigh
        compressionLow := recentRangeLow

// ============================================================================
// 27. 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 (CNPS84 - TP HIT)\\n🎯 Giá chốt lời: " + str.tostring(strategy.position_avg_price + effectiveTP, format.mintick), alert_loss="🛑 CẮT LỖ LONG (CNPS84 - SL HIT)\\n💥 Giá cắt lỗ: " + str.tostring(strategy.position_avg_price - effectiveSL, format.mintick), disable_alert=disableExitAlerts)

// ============================================================================
// 28. 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 (CNPS84 - TP HIT)\\n🎯 Giá chốt lời: " + str.tostring(strategy.position_avg_price - effectiveTP, format.mintick), alert_loss="🛑 CẮT LỖ SHORT (CNPS84 - SL HIT)\\n💥 Giá cắt lỗ: " + str.tostring(strategy.position_avg_price + effectiveSL, format.mintick), disable_alert=disableExitAlerts)

// ============================================================================
// 29. 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 (CNPS84 - Time Exit)\\n📌 Giá đóng: " + str.tostring(close, format.mintick))

// ============================================================================
// 30. 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 (CNPS84 - Session End)\\n📌 Giá đóng: " + str.tostring(close, format.mintick))

// ============================================================================
// 31. EMA PLOT
// ============================================================================
plot(showEMA ? ema : na, title="EMA Trend", color=color.orange, linewidth=2)

// ============================================================================
// 32. COMPRESSION LEVELS
// ============================================================================
plot(showCompressionLevels and pendingCompression ? compressionHigh : na, title="Compression High", color=color.aqua, linewidth=2, style=plot.style_linebr)
plot(showCompressionLevels and pendingCompression ? compressionLow : na, title="Compression Low", color=color.fuchsia, linewidth=2, style=plot.style_linebr)

// ============================================================================
// 33. COMPRESSION MARKER
// ============================================================================
plotshape(showCompressionMarkers and newCompression, title="New Compression", style=shape.circle, location=location.belowbar, color=color.gray, size=size.tiny, text="CP")

// ============================================================================
// 34. BREAKOUT MARKERS
// ============================================================================
plotshape(showBreakoutMarkers and bullishBreak, title="Bullish Compression Breakout", style=shape.circle, location=location.belowbar, color=color.aqua, size=size.tiny, text="BO")
plotshape(showBreakoutMarkers and bearishBreak, title="Bearish Compression Breakout", style=shape.circle, location=location.abovebar, color=color.orange, size=size.tiny, text="BO")

// ============================================================================
// 35. ENTRY MARKERS
// ============================================================================
plotshape(showEntryMarkers and enterLong, title="CNPS84 LONG", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="LONG", textcolor=color.white)
plotshape(showEntryMarkers and enterShort, title="CNPS84 SHORT", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="SHORT", textcolor=color.white)

// ============================================================================
// 36. 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)

// ============================================================================
// 37. DATA WINDOW
// ============================================================================
plot(normalizedRange, title="Compression Range / ATR", color=color.blue, display=display.data_window)
plot(baselineRange, title="Average Compression Range", color=color.gray, display=display.data_window)
plot(bodyRatio, title="Expansion Body Ratio", color=color.orange, 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)

// ============================================================================
// 38. DIAGNOSTICS TABLE
// ============================================================================
var table diagnostics = table.new(position.top_right, 2, 17, border_width=1)
if showDiagnostics and barstate.islast
    table.cell(diagnostics, 0, 0, "CNPS84 V1")
    table.cell(diagnostics, 1, 0, timeframe.period)
    table.cell(diagnostics, 0, 1, "Range / ATR")
    table.cell(diagnostics, 1, 1, str.tostring(normalizedRange, "#.###"))
    table.cell(diagnostics, 0, 2, "Baseline")
    table.cell(diagnostics, 1, 2, str.tostring(baselineRange, "#.###"))
    table.cell(diagnostics, 0, 3, "Compression Now")
    table.cell(diagnostics, 1, 3, compressionNow ? "YES" : "NO")
    table.cell(diagnostics, 0, 4, "Compression Events")
    table.cell(diagnostics, 1, 4, str.tostring(compressionCount))
    table.cell(diagnostics, 0, 5, "Bull Breakouts")
    table.cell(diagnostics, 1, 5, str.tostring(bullBreakoutCount))
    table.cell(diagnostics, 0, 6, "Bear Breakouts")
    table.cell(diagnostics, 1, 6, str.tostring(bearBreakoutCount))
    table.cell(diagnostics, 0, 7, "Long Bases")
    table.cell(diagnostics, 1, 7, str.tostring(longBaseCount))
    table.cell(diagnostics, 0, 8, "Short Bases")
    table.cell(diagnostics, 1, 8, str.tostring(shortBaseCount))
    table.cell(diagnostics, 0, 9, "Filtered Long")
    table.cell(diagnostics, 1, 9, str.tostring(filteredLongCount))
    table.cell(diagnostics, 0, 10, "Filtered Short")
    table.cell(diagnostics, 1, 10, str.tostring(filteredShortCount))
    table.cell(diagnostics, 0, 11, "Pending Setup")
    table.cell(diagnostics, 1, 11, pendingCompression ? "YES" : "NO")
    table.cell(diagnostics, 0, 12, "Expired Setups")
    table.cell(diagnostics, 1, 12, str.tostring(expiredCount))
    table.cell(diagnostics, 0, 13, "Long Entries")
    table.cell(diagnostics, 1, 13, str.tostring(longEntryCount))
    table.cell(diagnostics, 0, 14, "Short Entries")
    table.cell(diagnostics, 1, 14, str.tostring(shortEntryCount))
    table.cell(diagnostics, 0, 15, "Trades Today")
    table.cell(diagnostics, 1, 15, str.tostring(tradesToday) + "/" + str.tostring(maximumTradesPerDay))
    table.cell(diagnostics, 0, 16, "Position")
    table.cell(diagnostics, 1, 16, inLong ? "LONG" : inShort ? "SHORT" : "FLAT")

2. Những khái niệm kỹ thuật cốt lõi trong CNPS84

2.1. Đo lường vùng nén giá chuẩn hóa (Normalized Compression Range)

Thay vì dùng một mức điểm cố định (dễ lỗi thời khi chỉ số VN30 biến động mạnh hoặc yếu theo từng giai đoạn), CNPS84 chuẩn hóa biên độ vùng tích lũy theo biến động thị trường (ATR(14)):

  • Biên độ vùng nén (recentRange): Lấy ta.highest(high[1], 8) - ta.lowest(low[1], 8), tức là hoàn toàn loại trừ cây nến hiện tại để tránh hiện tượng tự tham chiếu.
  • Biên độ chuẩn hóa (normalizedRange): recentRange / atr[1].
  • Đường nền lịch sử (baselineRange): ta.sma(normalizedRange, 50).
  • Điều kiện nén (compressionNow): Giá trị normalizedRange <= baselineRange * 0.75 (tức vùng giá hiện tại hẹp hơn ít nhất 25% so với mức trung bình 50 nến trước đó). Nếu bật thêm useAbsoluteRangeLimit, bot yêu cầu thêm normalizedRange <= 3.0.

2.2. Giải phẫu nến bùng nổ (Breakout Candle Anatomy)

Để phân biệt cú phá vỡ thật với bẫy tăng/giảm giá (Fakeout), CNPS84 kiểm tra đồng thời 4 đặc tính của cây nến phá vỡ:

  • Vùng đệm phá vỡ (breakoutBuffer): atr * 0.10. Giá đóng cửa phải vượt qua hẳn compressionHigh + breakoutBuffer (với Long) hoặc compressionLow - breakoutBuffer (với Short).
  • Độ mở rộng biên độ (expansionOK): Toàn bộ biên độ nến (high - low) phải đạt tối thiểu 1.20 * atr.
  • Tỷ lệ thân nến (bodyRatio): math.abs(close - open) / (high - low) >= 0.55, đảm bảo lực mua/bán áp đảo, không phải nến Doji hay nến rút chân mạnh.
  • Vị trí đóng cửa (closePosition): Tính bằng (close - low) / (high - low). Nến Long phải đóng cửa ở 30% phía trên (>= 0.70), còn nến Short phải đóng cửa ở 30% phía dưới (<= 0.30).

2.3. Hệ thống lọc xu hướng EMA 50 và các bộ lọc tùy chọn

  • Bộ lọc EMA Trend (Bật mặc định): Tính ta.ema(close, 50). Chiều Long yêu cầu ema > ema[3] (EMA đang dốc lên) và close > ema; chiều Short yêu cầu ema < ema[3] và close < ema.
  • Bộ lọc ADX & Volume (Tùy chọn): Người dùng có thể bật useADXFilter (yêu cầu ADX(14,14) >= 18.0) và useVolumeFilter (yêu cầu khối lượng nến breakout >= 1.20 * SMA(volume, 20)).
  • Confirmed H1 Bias (Tùy chọn): Sử dụng request.security(..., "60", ...[1], lookahead=barmerge.lookahead_on) để lấy EMA 50 và close của cây nến H1 đã đóng hoàn toàn, đảm bảo không bao giờ nhìn trước tương lai (non-repainting) và chỉ hoạt động trên biểu đồ nhỏ hơn 1 giờ (timeframe.in_seconds() < 3600).

3. Nguyên lý hoạt động của CNPS84

Quy trình vận hành khép kín của Bot CNPS84 diễn ra tuần tự qua 5 bước trên mỗi cây nến đã đóng (barstate.isconfirmed):

  1. Khởi tạo phiên và đếm lệnh ngày: Khi bước sang ngày giao dịch mới (newDay), bộ đếm tradesToday được đặt lại về 0 và mọi trạng thái vùng nén cũ chưa kích hoạt đều bị xóa bỏ.
  2. Đánh giá tín hiệu phá vỡ từ vùng nén đang chờ (pendingCompression): Nếu trước đó đã ghi nhận một vùng nén hợp lệ (cùng ngày và còn nằm trong cửa sổ breakoutWindow tối đa 6 nến), bot kiểm tra xem nến vừa đóng có phá vỡ biên trên/dưới kèm theo tiêu chuẩn nến bùng nổ (longBase / shortBase) và vượt qua các bộ lọc (EMA, ADX, Volume, H1) hay không.
  3. Kiểm tra cổng vào lệnh (canTrade) và gửi lệnh: Nếu thỏa mãn trạng thái không có vị thế (flat), chưa chạm giới hạn 2 lệnh/ngày, hết thời gian nghỉ (cooldownBars), và nằm trong khung giờ 09:15–14:15, bot thực thi strategy.entry(...).
  4. Cập nhật trạng thái vùng nén (sau khi xử lý lệnh): Nếu một thiết lập nén bị quá hạn (bar_index - compressionBar > 6) hoặc vừa xảy ra phá vỡ (breakoutResolved), bot xóa trạng thái cũ. Ngược lại, nếu đang flat, trong giờ giao dịch, và xuất hiện vùng nén mới (compressionNow), bot lưu compressionHigh và compressionLow để chờ phá vỡ ở các nến tiếp theo. Lưu ý: bot không tự động tạo lại thiết lập nén ngay trên chính cây nến vừa phá vỡ.
  5. Quản trị và đóng vị thế: Ngay khi khớp lệnh, strategy.exit tự động đặt sẵn mức SL/TP theo tick. Nếu bật Time Exit và giữ lệnh đủ 20 nến, hoặc khi chạm mốc 14:45 (forceCloseBar), bot gọi strategy.close_all(immediately=true) để đóng toàn bộ vị thế.

4. Điều kiện vào lệnh Long và Short của CNPS84

4.1. Điều kiện vào lệnh Long

Lệnh Long (enterLong) chỉ được kích hoạt khi thỏa mãn đồng thời tất cả các điều kiện sau trên cây nến đã đóng (barstate.isconfirmed):

  • Chiều giao dịch tradeDirection là "Long" hoặc "Both".
  • Đang có vùng nén hợp lệ (validCompressionWindow): cùng ngày, 1 <= bar_index - compressionBar <= 6.
  • Phá vỡ biên trên: close > compressionHigh + breakoutBuffer (với breakoutBuffer = 0.10 * atr nếu bật).
  • Nến tăng bùng nổ (longBase): Nến xanh (close > open), biên độ high - low >= 1.20 * atr, tỷ lệ thân nến >= 0.55, và vị trí đóng cửa >= 0.70.
  • Bộ lọc xu hướng & tùy chọn: ema > ema[3] và close > ema (khi bật useEMAFilter); thỏa mãn adx >= 18.0, volume >= 1.20 * averageVolume, và h1Close > h1EMA (nếu các bộ lọc tùy chọn này được bật).
  • Không có xung đột tín hiệu hai chiều (not ambiguousSignal) và thỏa mãn cổng kiểm soát chung (canTrade).

4.2. Điều kiện vào lệnh Short

Lệnh Short (enterShort) sử dụng logic đối xứng hoàn toàn so với chiều Long:

  • Chiều giao dịch tradeDirection là "Short" hoặc "Both" (lưu ý: mặc định trong code đang để "Long", người dùng cần chuyển sang "Short" hoặc "Both" nếu muốn bot đánh Short).
  • Đang có vùng nén hợp lệ (validCompressionWindow).
  • Phá vỡ biên dưới: close < compressionLow - breakoutBuffer.
  • Nến giảm bùng nổ (shortBase): Nến đỏ (close < open), biên độ high - low >= 1.20 * atr, tỷ lệ thân nến >= 0.55, và vị trí đóng cửa <= 0.30.
  • Bộ lọc xu hướng & tùy chọn: ema < ema[3] và close < ema (khi bật useEMAFilter); thỏa mãn adx, volume và h1Close < h1EMA (nếu được bật).
  • Thỏa mãn not ambiguousSignal và cổng kiểm soát chung (canTrade).

4.3. Điều kiện kiểm soát giao dịch chung

Biến canTrade đóng vai trò chốt chặn an toàn cho mọi lệnh vào:

  • Khung thời gian: Biểu đồ bắt buộc là khung Intraday (timeframe.isintraday) và nến đã đóng (barstate.isconfirmed).
  • Trạng thái vị thế (flat): strategy.position_size == 0 và strategy.opentrades == 0 (không nhồi lệnh, pyramiding=0).
  • Giới hạn lệnh ngày: tradesToday < 2 (maximumTradesPerDay = 2).
  • Thời gian nghỉ (Cooldown): bar_index - lastExitBar > 3 (cooldownBars = 3), nghĩa là sau khi đóng lệnh, phải qua ít nhất 3 cây nến mới được phép vào lệnh kế tiếp; đồng thời không vào 2 lệnh trên cùng 1 cây nến (freshEntryBar).
  • Khung giờ giao dịch (Asia/Ho_Chi_Minh): Thời gian mở nến >= 09:15, thời gian đóng nến <= 14:15 (entrySessionOK), và phải trước giờ đóng cửa bắt buộc 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 Tick

Bot CNPS84 không dùng SL động theo cấu trúc đỉnh/đáy mà sử dụng khoảng cắt lỗ cố định theo điểm, được quy đổi chính xác sang bước giá nhỏ nhất (syminfo.mintick) của VN30F1M (0.1 điểm/tick):

  • slTicks = math.max(1, int(math.round(stopLossPoints / syminfo.mintick))) → Với stopLossPoints = 5.0, slTicks = 50 ticks (effectiveSL = 5.0 điểm).
  • Mức SL thực tế: Tính từ giá khớp lệnh trung bình (strategy.position_avg_price):
    • Long: strategy.position_avg_price - effectiveSL
    • Short: strategy.position_avg_price + effectiveSL

5.2. Cơ chế Take Profit, Time Exit và Force Close

  • Take Profit cố định: Tương tự SL, tpTicks = math.max(1, int(math.round(takeProfitPoints / syminfo.mintick))) → Với takeProfitPoints = 15.0, tpTicks = 150 ticks (effectiveTP = 15.0 điểm), đạt tỷ lệ R:R 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 (Time Exit): Mặc định tắt (useTimeExit = false). Khi bật, nếu số nến nắm giữ vị thế barsHeld >= 20 trên nến đã đóng (và không trùng nến Force Close), bot chủ động đóng toàn bộ vị thế bằng strategy.close_all(immediately=true).
  • Đóng vị thế cuối phiên (Force Close): Tự động kích hoạt tại cây nến giao cắt qua mốc 14:45 (openMinutes < 14:45 và closeMinutes >= 14:45), đảm bảo tài khoản luôn về trạng thái FLAT trước phiên ATC, tránh rủi ro qua đêm.

5.3. Bảng tổng hợp cơ chế bảo vệ vị thế

Cơ chế thoát lệnhTrạng thái mặc địnhĐiều kiện kích hoạtHành động thực thi
Stop Loss (Cắt lỗ)Bật (5.0 điểm)Giá chạm entry ± effectiveSLThoát lệnh qua strategy.exit (SL Long / SL Short)
Take Profit (Chốt lời)Bật (15.0 điểm)Giá chạm entry ± effectiveTPThoát lệnh qua strategy.exit (TP Long / TP Short)
Time Exit (Hết thời gian)Tắt (false)Giữ vị thế >= 20 nếnĐóng toàn bộ lệnh (strategy.close_all)
Session End (Hết phiên)Bật (14:45)Nến đóng chạm mốc 14:45Đóng toàn bộ lệnh (strategy.close_all) trước ATC

6. Hướng dẫn cài đặt và đọc bảng Diagnostics trên TradingView

Các bước cài đặt

  1. Mở biểu đồ hợp đồng tương lai VN30F1M trên TradingView (khuyến nghị khung thời gian Intraday như M5 hoặc M15; nếu bật H1 Bias bắt buộc dùng khung dưới H1).
  2. Nhấp vào tab Pine Editor ở thanh công cụ phía dưới màn hình.
  3. Xóa toàn bộ code 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.
  4. Nhấn Save (Lưu) đặt tên là CNPS84 COMPRESSION EXPANSION V1, sau đó nhấn Add to chart (Thêm vào biểu đồ).
  5. Vào biểu tượng bánh răng Settings (Cài đặt) để điều chỉnh Trade Direction (chuyển sang "Both" nếu muốn đánh cả 2 chiều), Contracts và bật Show Diagnostics nế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 Show Diagnostics = true, một bảng gồm 17 dòng sẽ hiển thị ở góc trên bên phải (position.top_right) tại cây nến cuối cùng (barstate.islast):

  • CNPS84 V1 / timeframe.period: Tên phiên bản bot và khung thời gian biểu đồ đang chạy.
  • Range / ATR & Baseline: Tỷ lệ biên độ vùng nén hiện tại so với ATR và mức trung bình nền 50 phiên.
  • Compression Now & Pending Setup: Trạng thái YES/NO cho biết hiện tại có đang trong pha nén giá hay đang có một vùng nén chờ breakout hay không.
  • Compression Events & Expired Setups: Tổng số lần phát hiện vùng nén và số vùng nén bị hết hạn do quá 6 nến mà không có phá vỡ.
  • Bull Breakouts / Bear Breakouts: Số lần giá vượt qua biên trên / biên dưới (chưa xét giải phẫu nến).
  • Long Bases / Short Bases: Số lần thỏa mãn cả breakout lẫn điều kiện giải phẫu nến bùng nổ.
  • Filtered Long / Filtered Short: Số tín hiệu vượt qua toàn bộ bộ lọc (EMA, ADX, Volume, H1).
  • Long Entries / Short Entries: Tổng số lệnh Long / Short thực tế đã vào được qua cổng canTrade.
  • Trades Today & Position: Số lệnh đã giao dịch trong ngày hiện tại trên tổng hạn mức (ví dụ 1/2) và trạng thái vị thế hiện tại (LONG, SHORT, hoặc 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 Telegram, Email hoặc Webhook khi Bot CNPS84 phát sinh tín hiệu, bạn thực hiện theo các bước sau:

  1. Nhấn vào biểu tượng Alert (Cảnh báo - hình đồng hồ báo thức) trên thanh công cụ bên phải TradingView.
  2. Tại mục Condition (Điều kiện), chọn đúng tên chiến lược CNPS84 COMPRESSION EXPANSION V1.
  3. Tại ô Message (Thông điệp), xóa nội dung mặc định và nhập duy nhất cú pháp biến động: {{strategy.order.alert_message}}
  4. Chọn phương thức nhận thông báo (Notify in app, Webhook URL…) và nhấn Create. (Lưu ý: Nếu không muốn nhận thông báo khi chạm SL/TP, bạn có thể tích chọn Disable SL/TP Alerts trong phần cài đặt bot).

Bảng thông điệp Alert của CNPS84

Sự kiệnĐiều kiện kích hoạtNội dung thông điệp (alert_message / alert_profit / alert_loss)
Vào lệnh LongenterLong🟢 VÀO VỊ THẾ LONG (CNPS84)\n🎯 Giá vào: <giá>\n🛑 Cắt lỗ (SL): <giá SL>\n💰 Chốt lời (TP): <giá TP>
Vào lệnh ShortenterShort🔴 VÀO VỊ THẾ SHORT (CNPS84)\n🎯 Giá vào: <giá>\n🛑 Cắt lỗ (SL): <giá SL>\n💰 Chốt lời (TP): <giá TP>
Chốt lời LongChạm TP Long💰 CHỐT LỜI LONG (CNPS84 - TP HIT)\n🎯 Giá chốt lời: <giá TP>
Cắt lỗ LongChạm SL Long🛑 CẮT LỖ LONG (CNPS84 - SL HIT)\n💥 Giá cắt lỗ: <giá SL>
Chốt lời ShortChạm TP Short💰 CHỐT LỜI SHORT (CNPS84 - TP HIT)\n🎯 Giá chốt lời: <giá TP>
Cắt lỗ ShortChạm SL Short🛑 CẮT LỖ SHORT (CNPS84 - SL HIT)\n💥 Giá cắt lỗ: <giá SL>
Hết thời gian giữ lệnhtimeExit (nếu bật)⏱️ ĐÓNG VỊ THẾ HẾT THỜI GIAN (CNPS84 - Time Exit)\n📌 Giá đóng: <giá>
Đóng hết phiênforceCloseBar (14:45)⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (CNPS84 - Session End)\n📌 Giá đóng: <giá>

Kết luận

Bot CNPS84 Compression Expansion V1 là một hệ thống giao dịch kỷ luật, kết hợp chặt chẽ giữa cấu trúc nén – mở rộng biến động (Volatility Compression & Expansion) và giải phẫu nến thực chiến. Nhờ cơ chế chỉ vào lệnh khi nến đã đóng cửa, không repaint dữ liệu đa khung thời gian và luôn đóng sạch vị thế trước phiên ATC lúc 14:45, bot đặc biệt phù hợp với thị trường phái sinh VN30F1M trong những giai đoạn thị trường có các nhịp tích lũy rồi bứt phá rõ ràng theo xu hướng EMA 50.

Bạn có thể tham khảo thêm các hệ thống giao dịch tự động khác trên phaisinh.online như Bot CNPS50 - Trend Analysis V2 để tối ưu điểm vào lại theo xu hướng hoặc Bot CNPS49 - Daily Open cho chiến lược giao dịch theo giá mở cửa phiên.

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.

Đinh Mạnh Đạt

Nhà nghiên cứu định lượng, chuyên sâu về dữ liệu Open Interest và quản trị vị thế.

Bản tin phái sinh mỗi phiên
Nhận bản tin mỗi phiên + Dự báo Nhịp đập phái sinh

Giao dịch & cuộc sống

Xem tất cả →
Cộng đồng