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

Hướng Dẫn Sử Dụng Bot CNPS77 - Connors RSI Trend Pullback V3 cho VN30F1M

Bot CNPS77 kết hợp chỉ báo Connors RSI (CRSI) bắt nhịp hồi ngắn hạn thuận theo xu hướng EMA 50, xác nhận hành động giá trong cửa sổ 2 nến và quản trị SL/TP cố định theo tick cho VN30F1M.

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

Trong giao dịch hợp đồng tương lai chỉ số VN30F1M, việc bắt đáy hoặc bắt đỉnh ngược xu hướng chính thường dẫn đến rủi ro bị cuốn theo đà giảm/tăng mạnh, trong khi mua đuổi khi giá đã đi quá xa đường trung bình lại dễ gặp nhịp điều chỉnh ngay sau khi khớp lệnh. Giải pháp hiệu quả là tìm kiếm các nhịp hồi ngắn hạn (pullback) đã cạn lực và có dấu hiệu đảo chiều quay lại đúng hướng của xu hướng chủ đạo.

CNPS77 CONNORS RSI TREND PULLBACK V3 (tên rút gọn: CNPS77 CRSI V3) là chiến lược giao dịch tự động viết bằng Pine Script v6 trên TradingView, kết hợp chỉ báo Connors RSI (CRSI) với bộ lọc xu hướng EMA và xác nhận hành động giá. Những điểm nổi bật cốt lõi của bot gồm:

  • Bắt nhịp hồi bằng Connors RSI (CRSI) đa thành phần: Kết hợp RSI giá (3 kỳ), RSI chuỗi nến tăng/giảm (2 kỳ) và phân vị phần trăm biến động 1 nến (100 kỳ) để phát hiện chính xác trạng thái quá mua/quá bán ngắn hạn.
  • Cơ chế Setup chờ xác nhận (Confirmation Window): Sau khi CRSI cắt lên khỏi vùng quá bán (15) hoặc cắt xuống khỏi vùng quá mua (85), bot mở cửa sổ chờ tối đa 2 nến để yêu cầu nến xác nhận hướng và phá vỡ đỉnh/đáy nến liền trước, tránh vào lệnh sớm khi giá chưa thực sự đảo chiều.
  • Lọc xu hướng và khoảng cách giá theo ATR: Chỉ giao dịch thuận theo độ dốc đường EMA 50 (slopeLookback = 5) và yêu cầu giá không nằm quá xa EMA (trong phạm vi 2.5 × ATR), kết hợp tùy chọn lọc ADX, Volume và xu hướng khung H1.
  • Quản trị rủi ro chuẩn xác theo Tick: Chốt lời (10 điểm) và cắt lỗ (5 điểm) được quy đổi sang tick dựa trên giá khớp lệnh thực tế (strategy.position_avg_price), đi kèm giới hạn số lệnh/ngày, thời gian nghỉ (cooldown) và tự động đóng toàn bộ vị thế trước phiên ATC.

1. CNPS77 Connors RSI Trend Pullback V3 là gì?

CNPS77 Connors RSI Trend Pullback V3 là hệ thống giao dịch theo mô hình Trend Pullback (vào lệnh theo nhịp hồi trong xu hướng). Chiến lược vận hành dựa trên 4 trụ cột kỹ thuật chính:

  1. Tín hiệu đảo chiều ngắn hạn từ Connors RSI: Bot sử dụng CRSI với ngưỡng quá bán mặc định 15.0 và quá mua 85.0. Tín hiệu khởi phát (bullReentry / bearReentry) xuất hiện khi CRSI cắt lên trên 15.0 hoặc cắt xuống dưới 85.0.
  2. Xác nhận hành động giá trong cửa sổ chờ: Một tín hiệu CRSI chưa đủ để vào lệnh ngay. Bot ghi nhận trạng thái chờ (pendingLong / pendingShort) trong tối đa 2 nến (confirmationBars) và yêu cầu nến xác nhận phải đóng cửa thuận chiều (close > open với Long, close < open với Short) đồng thời phá vỡ high[1] / low[1].
  3. Bộ lọc chế độ thị trường (Trend & Regime Filters): Mặc định bot kiểm tra độ dốc EMA 50 (ema > ema[5] cho Long, ema < ema[5] cho Short) và khoảng cách giá tới EMA (|close - ema| <= 2.5 × ATR(14)). Ngoài ra, người dùng có thể bật thêm bộ lọc ADX tối đa, đột biến khối lượng (Volume Spike) và xu hướng xác nhận trên khung H1.
  4. Kiểm soát phiên & Quản trị lệnh theo Tick: Giới hạn khung giờ vào lệnh từ 09:15 đến 14:15, đóng cưỡng bức lúc 14:45 (giờ Asia/Ho_Chi_Minh), tối đa 2 lệnh/ngày, nghỉ 5 nến sau mỗi lần thoát lệnh, cùng cặp lệnh Bracket SL/TP tính theo tick từ giá khớp thực tế.

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

Nhóm thông sốTên biến / Nhãn trong CodeGiá trị mặc địnhÝ nghĩa
01. Connors RSIpriceRSILength (Price RSI Length)3Chu kỳ RSI tính theo giá đóng cửa
streakRSILength (Streak RSI Length)2Chu kỳ RSI tính trên chuỗi nến tăng/giảm liên tiếp
rankLength (Percent Rank Length)100Số nến quá khứ dùng để xếp hạng phần trăm biến động 1 nến
oversold / overbought15.0 / 85.0Ngưỡng quá bán và quá mua của CRSI
02. Price ConfirmationconfirmationBars2Số nến tối đa cho cửa sổ chờ xác nhận giá
requireCandletrueYêu cầu nến xanh (close > open) với Long / đỏ (close < open) với Short
requirePriceBreaktrueYêu cầu đóng cửa vượt high[1] (Long) / thủng low[1] (Short)
longCRSIMax / shortCRSIMin70.0 / 30.0Giới hạn CRSI tối đa khi vào Long và tối thiểu khi vào Short
03. Trend RegimeuseTrendFiltertrueBật bộ lọc xu hướng theo độ dốc EMA
emaLength / slopeLookback50 / 5Chu kỳ EMA và số nến lùi để đo độ dốc EMA
useDistanceFiltertrueYêu cầu giá nằm gần EMA
atrLength / maxDistanceATR14 / 2.5Chu kỳ ATR và hệ số khoảng cách tối đa từ giá đến EMA
04. ADXuseADXFilterfalseTùy chọn bật lọc ADX tối đa
diLength / adxSmoothing / maxADX14 / 14 / 35.0Thông số DMI/ADX và ngưỡng ADX trần
05. VolumeuseVolumeFilterfalseTùy chọn bật lọc đột biến khối lượng
volumeLength / volumeFactor20 / 1.1Chu kỳ SMA khối lượng và hệ số nhân tối thiểu
06. H1 BiasuseH1Bias / h1EMALengthfalse / 50Tùy chọn lọc theo giá đóng cửa và EMA 50 khung H1 đã xác nhận
07. Risk ManagementstopLossPoints / takeProfitPoints5.0 / 10.0Mức cắt lỗ và chốt lời (tính bằng điểm, quy đổi ra tick)
useTimeExit / maximumHoldingBarsfalse / 20Tùy chọn đóng lệnh khi giữ đủ số nến tối đa
08. Trade ControltradeDirection"Long"Chiều giao dịch cho phép ("Long", "Short", "Both")
contracts3Tham số số hợp đồng trong nhóm Trade Control
maximumTradesPerDay / cooldownBars2 / 5Số lệnh tối đa/ngày và số nến nghỉ sau khi đóng lệnh
09. SessionuseSessionFilter / strategyTimezonetrue / "Asia/Ho_Chi_Minh"Bật lọc phiên giao dịch theo múi giờ Việt Nam
startHour:startMinute09:15Thời điểm bắt đầu cho phép vào lệnh
lastHour:lastMinute / endHour:endMinute14:15 / 14:45Giờ vào lệnh cuối cùng và giờ đóng cưỡng bức toàn bộ vị thế
10. Alerts & 11. DisplaydisableExitAlertsfalseCho phép gửi cảnh báo SL/TP
showEMA / showEntryMarkers / showSLTPtrue / true / trueHiển thị đường EMA, mũi tên vào lệnh và đường SL/TP
showReentryMarkers / showDiagnosticsfalse / falseHiển thị chấm tròn CRSI Re-entry và bảng chẩn đoán

Source Code CNPS77 Connors RSI Trend Pullback V3

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="CNPS77 CONNORS RSI TREND PULLBACK V3", shorttitle="CNPS77 CRSI V3", 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)

// ============================================================================
// CNPS77 V3 - CONNORS RSI TREND PULLBACK
//
// CORE:
// Trade CRSI reversal signals in the direction
// of the prevailing EMA trend.
//
// LONG:
// EMA slope positive
// CRSI crosses up through oversold
// Bullish price confirmation
//
// SHORT:
// EMA slope negative
// CRSI crosses down through overbought
// Bearish price confirmation
//
// Exits use profit/loss in TICKS measured
// from the actual strategy entry fill.
//
// IMPORTANT:
// Backtest before using real capital.
// ============================================================================
// ============================================================================
// 01. CONNORS RSI
// ============================================================================
groupCRSI = "01. Connors RSI"
priceRSILength = input.int(3, "Price RSI Length", minval=2, group=groupCRSI)
streakRSILength = input.int(2, "Streak RSI Length", minval=2, group=groupCRSI)
rankLength = input.int(100, "Percent Rank Length", minval=5, maxval=300, group=groupCRSI)
oversold = input.float(15.0, "Oversold Level", minval=1, maxval=49, group=groupCRSI)
overbought = input.float(85.0, "Overbought Level", minval=51, maxval=99, group=groupCRSI)

// ============================================================================
// 02. CONFIRMATION
// ============================================================================
groupConfirm = "02. Price Confirmation"
confirmationBars = input.int(2, "Confirmation Window (Bars)", minval=0, maxval=20, group=groupConfirm)
requireCandle = input.bool(true, "Require Bullish / Bearish Candle", group=groupConfirm)
requirePriceBreak = input.bool(true, "Require Previous High / Low Break", group=groupConfirm)
longCRSIMax = input.float(70.0, "Maximum CRSI At Long Entry", minval=20, maxval=100, group=groupConfirm)
shortCRSIMin = input.float(30.0, "Minimum CRSI At Short Entry", minval=0, maxval=80, group=groupConfirm)

// ============================================================================
// 03. TREND REGIME
// ============================================================================
groupTrend = "03. Trend Regime"
useTrendFilter = input.bool(true, "Require EMA Trend", group=groupTrend)
emaLength = input.int(50, "EMA Length", minval=5, group=groupTrend)
slopeLookback = input.int(5, "EMA Slope Lookback", minval=1, maxval=50, group=groupTrend)
atrLength = input.int(14, "ATR Length", minval=1, group=groupTrend)
maxDistanceATR = input.float(2.5, "Maximum Distance From EMA / ATR", minval=0.1, step=0.1, group=groupTrend)
useDistanceFilter = input.bool(true, "Require Price Near EMA", group=groupTrend)

// ============================================================================
// 04. ADX REGIME
// ============================================================================
groupADX = "04. ADX"
useADXFilter = input.bool(false, "Use Maximum ADX Filter", group=groupADX)
diLength = input.int(14, "DI Length", minval=2, group=groupADX)
adxSmoothing = input.int(14, "ADX Smoothing", minval=2, group=groupADX)
maxADX = input.float(35.0, "Maximum ADX", minval=1, step=1, group=groupADX)

// ============================================================================
// 05. VOLUME
// ============================================================================
groupVolume = "05. Volume"
useVolumeFilter = input.bool(false, "Require Volume Spike", group=groupVolume)
volumeLength = input.int(20, "Volume Average Length", minval=2, group=groupVolume)
volumeFactor = input.float(1.1, "Volume Factor", minval=0.1, step=0.1, group=groupVolume)

// ============================================================================
// 06. CONFIRMED H1 BIAS
// ============================================================================
groupH1 = "06. H1 Bias"
useH1Bias = input.bool(false, "Require Confirmed H1 Trend", group=groupH1)
h1EMALength = input.int(50, "H1 EMA Length", minval=1, group=groupH1)

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

// ============================================================================
// 08. TRADE CONTROL
// ============================================================================
groupTrade = "08. Trade Control"
tradeDirection = input.string("Long", "Trade Direction", options=["Long", "Short", "Both"], group=groupTrade)
contracts = input.int(3, "Contracts", minval=1, maxval=100, group=groupTrade)
maximumTradesPerDay = input.int(2, "Maximum Trades Per Day", minval=1, maxval=20, group=groupTrade)
cooldownBars = input.int(5, "Cooldown After Exit (Bars)", minval=0, maxval=100, group=groupTrade)
bool allowLong = (tradeDirection == "Long" or tradeDirection == "Both")
bool allowShort = (tradeDirection == "Short" or tradeDirection == "Both")

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

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

// ============================================================================
// 11. DISPLAY
// ============================================================================
groupDisplay = "11. Display"
showEMA = input.bool(true, "Show EMA", group=groupDisplay)
showReentryMarkers = input.bool(false, "Show CRSI Re-entry", group=groupDisplay)
showEntryMarkers = input.bool(true, "Show Entry Markers", group=groupDisplay)
showSLTP = input.bool(true, "Show SL/TP", group=groupDisplay)
showDiagnostics = input.bool(false, "Show Diagnostics", group=groupDisplay)

// ============================================================================
// 12. TIME
// ============================================================================
int barOpenMinutes = (hour(time, strategyTimezone) * 60 + minute(time, strategyTimezone))
int barCloseMinutes = (hour(time_close, strategyTimezone) * 60 + minute(time_close, strategyTimezone))
int sessionStart = (startHour * 60 + startMinute)
int sessionLast = (lastHour * 60 + lastMinute)
int sessionEnd = (endHour * 60 + endMinute)
bool validEntryTime = (not useSessionFilter or (barOpenMinutes >= sessionStart and barCloseMinutes <= sessionLast))
bool beforeForceClose = (barCloseMinutes < sessionEnd)
bool sessionEndBar = (barOpenMinutes < sessionEnd and barCloseMinutes >= sessionEnd)

// ============================================================================
// 13. DAILY LIMIT
// ============================================================================
int dayKey = (year(time, strategyTimezone) * 10000 + month(time, strategyTimezone) * 100 + dayofmonth(time, strategyTimezone))
bool newDay = (na(dayKey[1]) or dayKey != dayKey[1])
var int tradesToday = 0
if newDay
    tradesToday := 0

// ============================================================================
// 14. PRICE RSI
// ============================================================================
float priceRSI = ta.rsi(close, priceRSILength)

// ============================================================================
// 15. STREAK
// ============================================================================
var float streak = 0.0
if bar_index > 0
    float previousStreak = nz(streak[1], 0.0)
    if close > close[1]
        streak := (previousStreak > 0 ? previousStreak + 1 : 1)
    else if close < close[1]
        streak := (previousStreak < 0 ? previousStreak - 1 : -1)
    else
        streak := 0.0

// ============================================================================
// 16. STREAK RSI
// ============================================================================
float streakRSI = ta.rsi(streak, streakRSILength)

// ============================================================================
// 17. ONE-BAR RETURN
// ============================================================================
float oneBarReturn = (not na(close[1]) and close[1] != 0 ? 100.0 * (close / close[1] - 1.0) : na)

// ============================================================================
// 18. HISTORICAL PERCENT RANK
// ============================================================================
//
// Compare current return with N prior returns.
//
// Strict less-than comparison.
// The current bar is excluded from the sample.
//
// ============================================================================
float percentRank = na
if (not na(oneBarReturn) and bar_index >= rankLength + 1)
    int lowerCount = 0
    int validCount = 0
    for i = 1 to rankLength
        float pastReturn = oneBarReturn[i]
        if not na(pastReturn)
            validCount += 1
            if pastReturn < oneBarReturn
                lowerCount += 1
    if validCount == rankLength
        percentRank := (100.0 * lowerCount / rankLength)

// ============================================================================
// 19. CONNORS RSI
// ============================================================================
bool crsiReady = (not na(priceRSI) and not na(streakRSI) and not na(percentRank))
float crsi = (crsiReady ? (priceRSI + streakRSI + percentRank) / 3.0 : na)
bool bullReentry = ta.crossover(crsi, oversold)
bool bearReentry = ta.crossunder(crsi, overbought)

// ============================================================================
// 20. EMA TREND
// ============================================================================
float ema = ta.ema(close, emaLength)
float atr = ta.atr(atrLength)
bool trendUp = (not na(ema[slopeLookback]) and ema > ema[slopeLookback])
bool trendDown = (not na(ema[slopeLookback]) and ema < ema[slopeLookback])
bool longTrendOK = (not useTrendFilter or trendUp)
bool shortTrendOK = (not useTrendFilter or trendDown)
bool distanceOK = (not useDistanceFilter or (not na(atr) and atr > 0 and math.abs(close - ema) <= atr * maxDistanceATR))

// ============================================================================
// 21. ADX
// ============================================================================
[diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
bool adxOK = (not useADXFilter or (not na(adx) and adx <= maxADX))

// ============================================================================
// 22. VOLUME
// ============================================================================
float averageVolume = ta.sma(volume, volumeLength)
bool volumeOK = (not useVolumeFilter or (not na(volume) and not na(averageVolume) and volume >= averageVolume * volumeFactor))

// ============================================================================
// 23. CONFIRMED H1 EMA
// ============================================================================
float confirmedH1EMA = request.security(syminfo.tickerid, "60", ta.ema(close, h1EMALength)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
float confirmedH1Close = 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(confirmedH1EMA) and not na(confirmedH1Close) and confirmedH1Close > confirmedH1EMA))
bool shortH1OK = (not useH1Bias or (validH1Chart and not na(confirmedH1EMA) and not na(confirmedH1Close) and confirmedH1Close < confirmedH1EMA))

// ============================================================================
// 24. PRICE CONFIRMATION
// ============================================================================
bool bullCandleOK = (not requireCandle or close > open)
bool bearCandleOK = (not requireCandle or close < open)
bool bullBreakOK = (not requirePriceBreak or close > high[1])
bool bearBreakOK = (not requirePriceBreak or close < low[1])
bool longPriceConfirmed = (bullCandleOK and bullBreakOK and not na(crsi) and crsi > oversold and crsi <= longCRSIMax)
bool shortPriceConfirmed = (bearCandleOK and bearBreakOK and not na(crsi) and crsi < overbought and crsi >= shortCRSIMin)

// ============================================================================
// 25. PENDING SETUPS
// ============================================================================
var bool pendingLong = false
var bool pendingShort = false
var int pendingLongBar = na
var int pendingShortBar = na
var int bullReentryCount = 0
var int bearReentryCount = 0
var int longBaseCount = 0
var int shortBaseCount = 0
var int filteredLongCount = 0
var int filteredShortCount = 0
var int lastProcessedBar = na
bool processState = (barstate.isconfirmed and (na(lastProcessedBar) or lastProcessedBar != bar_index))
if processState
    lastProcessedBar := bar_index
    if newDay
        pendingLong := false
        pendingShort := false
        pendingLongBar := na
        pendingShortBar := na

    // Expire setups after the confirmation window.
    if pendingLong and not na(pendingLongBar)
        if bar_index - pendingLongBar > confirmationBars
            pendingLong := false
            pendingLongBar := na
    if pendingShort and not na(pendingShortBar)
        if bar_index - pendingShortBar > confirmationBars
            pendingShort := false
            pendingShortBar := na

    // Cancel a failed re-entry.
    if pendingLong and crsi < oversold
        pendingLong := false
        pendingLongBar := na
    if pendingShort and crsi > overbought
        pendingShort := false
        pendingShortBar := na

    // Register fresh CRSI reversals.
    if bullReentry
        pendingLong := true
        pendingLongBar := bar_index
        pendingShort := false
        pendingShortBar := na
        bullReentryCount += 1
    if bearReentry
        pendingShort := true
        pendingShortBar := bar_index
        pendingLong := false
        pendingLongBar := na
        bearReentryCount += 1

// ============================================================================
// 26. VALID SETUPS
// ============================================================================
bool validLongSetup = (pendingLong and not na(pendingLongBar) and bar_index - pendingLongBar <= confirmationBars)
bool validShortSetup = (pendingShort and not na(pendingShortBar) and bar_index - pendingShortBar <= confirmationBars)
bool longBase = (validLongSetup and longPriceConfirmed)
bool shortBase = (validShortSetup and shortPriceConfirmed)

// ============================================================================
// 27. FILTERED SIGNALS
// ============================================================================
bool rawLongSignal = (longBase and longTrendOK and distanceOK and adxOK and volumeOK and longH1OK)
bool rawShortSignal = (shortBase and shortTrendOK and distanceOK and adxOK and volumeOK and shortH1OK)

// ============================================================================
// 28. POSITION AND COOLDOWN
// ============================================================================
bool flat = strategy.position_size == 0
bool inLong = strategy.position_size > 0
bool inShort = strategy.position_size < 0
var int lastExitBar = na
bool tradeClosed = (strategy.closedtrades > nz(strategy.closedtrades[1], 0))
if tradeClosed
    lastExitBar := bar_index
bool cooldownOK = (na(lastExitBar) or bar_index - lastExitBar > cooldownBars)

// ============================================================================
// 29. ENTRY GATES
// ============================================================================
var int lastEntryBar = na
bool freshEntryBar = (na(lastEntryBar) or bar_index != lastEntryBar)
bool canTrade = (flat and strategy.opentrades == 0 and tradesToday < maximumTradesPerDay and cooldownOK and validEntryTime and beforeForceClose and freshEntryBar and barstate.isconfirmed)
bool ambiguousSignal = (rawLongSignal and rawShortSignal)
bool enterLong = (canTrade and allowLong and rawLongSignal and not ambiguousSignal)
bool enterShort = (canTrade and allowShort and rawShortSignal and not ambiguousSignal)

// ============================================================================
// 30. DIAGNOSTIC COUNTERS
// ============================================================================
var int longEntryCount = 0
var int shortEntryCount = 0
if processState
    if longBase
        longBaseCount += 1
    if shortBase
        shortBaseCount += 1
    if rawLongSignal
        filteredLongCount += 1
    if rawShortSignal
        filteredShortCount += 1

// ============================================================================
// 31. RISK IN TICKS
// ============================================================================
//
// strategy.exit profit/loss arguments use ticks.
//
// They are calculated relative to the actual
// entry fill price, not the signal candle close.
//
// ============================================================================
int slTicks = math.max(1, int(math.round(stopLossPoints / syminfo.mintick)))
int tpTicks = math.max(1, int(math.round(takeProfitPoints / syminfo.mintick)))
float effectiveSLPoints = (slTicks * syminfo.mintick)
float effectiveTPPoints = (tpTicks * syminfo.mintick)

// ============================================================================
// 32. LONG ENTRY
// ============================================================================
if enterLong
    strategy.entry("Long", strategy.long, comment="CRSI V3 Trend Long", alert_message="🟢 VÀO VỊ THẾ LONG (CNPS77 CRSI V3 Trend)\\n🎯 Giá vào: " + str.tostring(close, format.mintick) + "\\n🛑 Cắt lỗ (SL): " + str.tostring(close - effectiveSLPoints, format.mintick) + "\\n💰 Chốt lời (TP): " + str.tostring(close + effectiveTPPoints, format.mintick))
    tradesToday += 1
    longEntryCount += 1
    lastEntryBar := bar_index
    pendingLong := false
    pendingLongBar := na

// ============================================================================
// 33. SHORT ENTRY
// ============================================================================
if enterShort
    strategy.entry("Short", strategy.short, comment="CRSI V3 Trend Short", alert_message="🔴 VÀO VỊ THẾ SHORT (CNPS77 CRSI V3 Trend)\\n🎯 Giá vào: " + str.tostring(close, format.mintick) + "\\n🛑 Cắt lỗ (SL): " + str.tostring(close + effectiveSLPoints, format.mintick) + "\\n💰 Chốt lời (TP): " + str.tostring(close - effectiveTPPoints, format.mintick))
    tradesToday += 1
    shortEntryCount += 1
    lastEntryBar := bar_index
    pendingShort := false
    pendingShortBar := na

// ============================================================================
// 34. LONG BRACKET
// ============================================================================
//
// An exit order is submitted for the entry ID.
// This avoids delaying bracket creation until
// strategy.position_size updates.
//
// ============================================================================
strategy.exit("Long Exit", from_entry="Long", profit=tpTicks, loss=slTicks, comment_profit="TP Long", comment_loss="SL Long", alert_profit="💰 CHỐT LỜI LONG (TP HIT)\\n🎯 Giá chốt: " + str.tostring(strategy.position_avg_price + effectiveTPPoints, format.mintick), alert_loss="🛑 CẮT LỖ LONG (SL HIT)\\n🎯 Giá cắt: " + str.tostring(strategy.position_avg_price - effectiveSLPoints, format.mintick), disable_alert=disableExitAlerts)

// ============================================================================
// 35. SHORT BRACKET
// ============================================================================
strategy.exit("Short Exit", from_entry="Short", profit=tpTicks, loss=slTicks, comment_profit="TP Short", comment_loss="SL Short", alert_profit="💰 CHỐT LỜI SHORT (TP HIT)\\n🎯 Giá chốt: " + str.tostring(strategy.position_avg_price - effectiveTPPoints, format.mintick), alert_loss="🛑 CẮT LỖ SHORT (SL HIT)\\n🎯 Giá cắt: " + str.tostring(strategy.position_avg_price + effectiveSLPoints, format.mintick), disable_alert=disableExitAlerts)

// ============================================================================
// 36. OPTIONAL TIME EXIT
// ============================================================================
int holdingBars = (strategy.opentrades > 0 ? bar_index - strategy.opentrades.entry_bar_index(0) : 0)
bool timeExit = (useTimeExit and strategy.position_size != 0 and holdingBars >= maximumHoldingBars and barstate.isconfirmed)
if timeExit and not sessionEndBar
    strategy.close_all(immediately=true, comment="Time Exit", alert_message="⏱️ ĐÓNG VỊ THẾ HẾT THỜI GIAN GIỮ (Time Exit)\\n🎯 Giá đóng: " + str.tostring(close, format.mintick))

// ============================================================================
// 37. FORCE CLOSE
// ============================================================================
if (sessionEndBar and strategy.position_size != 0)
    strategy.close_all(immediately=true, comment="Session End", alert_message="⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (Session End)\\n🎯 Giá đóng: " + str.tostring(close, format.mintick))

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

// ============================================================================
// 39. ENTRY MARKERS
// ============================================================================
plotshape(showReentryMarkers and bullReentry, title="CRSI Bull Reentry", style=shape.circle, location=location.belowbar, color=color.aqua, size=size.tiny, text="CRSI")
plotshape(showReentryMarkers and bearReentry, title="CRSI Bear Reentry", style=shape.circle, location=location.abovebar, color=color.orange, size=size.tiny, text="CRSI")
plotshape(showEntryMarkers and enterLong, title="V3 Long Entry", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="LONG", textcolor=color.white)
plotshape(showEntryMarkers and enterShort, title="V3 Short Entry", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="SHORT", textcolor=color.white)

// ============================================================================
// 40. ACTIVE PRICE LEVELS
// ============================================================================
float activeLongSL = (inLong ? strategy.position_avg_price - effectiveSLPoints : na)
float activeLongTP = (inLong ? strategy.position_avg_price + effectiveTPPoints : na)
float activeShortSL = (inShort ? strategy.position_avg_price + effectiveSLPoints : na)
float activeShortTP = (inShort ? strategy.position_avg_price - effectiveTPPoints : na)
plot(showSLTP ? activeLongSL : na, title="Long SL", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showSLTP ? activeLongTP : na, title="Long TP", color=color.green, linewidth=2, style=plot.style_linebr)
plot(showSLTP ? activeShortSL : na, title="Short SL", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showSLTP ? activeShortTP : na, title="Short TP", color=color.green, linewidth=2, style=plot.style_linebr)

// ============================================================================
// 41. DATA WINDOW
// ============================================================================
plot(crsi, title="Connors RSI", color=color.purple, display=display.data_window)
plot(priceRSI, title="Price RSI", color=color.blue, display=display.data_window)
plot(streakRSI, title="Streak RSI", color=color.orange, display=display.data_window)
plot(percentRank, title="Percent Rank", color=color.gray, display=display.data_window)
plot(adx, title="ADX", color=color.gray, display=display.data_window)

// ============================================================================
// 42. DIAGNOSTICS TABLE
// ============================================================================
var table diagnostics = table.new(position.top_right, 2, 17, border_width=1)
if showDiagnostics and barstate.islast
    string positionText = (inLong ? "LONG" : inShort ? "SHORT" : "FLAT")
    string trendText = (trendUp ? "UP" : trendDown ? "DOWN" : "FLAT")
    table.cell(diagnostics, 0, 0, "CNPS77 V3")
    table.cell(diagnostics, 1, 0, timeframe.period)
    table.cell(diagnostics, 0, 1, "Connors RSI")
    table.cell(diagnostics, 1, 1, str.tostring(crsi, "#.##"))
    table.cell(diagnostics, 0, 2, "EMA Trend")
    table.cell(diagnostics, 1, 2, trendText)
    table.cell(diagnostics, 0, 3, "ADX")
    table.cell(diagnostics, 1, 3, str.tostring(adx, "#.##"))
    table.cell(diagnostics, 0, 4, "Distance OK")
    table.cell(diagnostics, 1, 4, distanceOK ? "YES" : "NO")
    table.cell(diagnostics, 0, 5, "ADX OK")
    table.cell(diagnostics, 1, 5, adxOK ? "YES" : "NO")
    table.cell(diagnostics, 0, 6, "Bull Reentries")
    table.cell(diagnostics, 1, 6, str.tostring(bullReentryCount))
    table.cell(diagnostics, 0, 7, "Bear Reentries")
    table.cell(diagnostics, 1, 7, str.tostring(bearReentryCount))
    table.cell(diagnostics, 0, 8, "Long Bases")
    table.cell(diagnostics, 1, 8, str.tostring(longBaseCount))
    table.cell(diagnostics, 0, 9, "Short Bases")
    table.cell(diagnostics, 1, 9, str.tostring(shortBaseCount))
    table.cell(diagnostics, 0, 10, "Filtered Long")
    table.cell(diagnostics, 1, 10, str.tostring(filteredLongCount))
    table.cell(diagnostics, 0, 11, "Filtered Short")
    table.cell(diagnostics, 1, 11, str.tostring(filteredShortCount))
    table.cell(diagnostics, 0, 12, "Pending Long")
    table.cell(diagnostics, 1, 12, pendingLong ? "YES" : "NO")
    table.cell(diagnostics, 0, 13, "Pending Short")
    table.cell(diagnostics, 1, 13, pendingShort ? "YES" : "NO")
    table.cell(diagnostics, 0, 14, "Long Entries")
    table.cell(diagnostics, 1, 14, str.tostring(longEntryCount))
    table.cell(diagnostics, 0, 15, "Short Entries")
    table.cell(diagnostics, 1, 15, str.tostring(shortEntryCount))
    table.cell(diagnostics, 0, 16, "Trades Today")
    table.cell(diagnostics, 1, 16, str.tostring(tradesToday) + " / " + str.tostring(maximumTradesPerDay))

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

2.1. Chỉ báo Connors RSI (CRSI)

Khác với RSI truyền thống chỉ đo lường biên độ tăng/giảm của giá đóng cửa, Connors RSI trong CNPS77 được tính bằng trung bình cộng của 3 thành phần:

$$\text{CRSI} = \frac{\text{PriceRSI}(3) + \text{StreakRSI}(2) + \text{PercentRank}(100)}{3}$$

Trong đó:

  • priceRSI (ta.rsi(close, 3)): RSI ngắn hạn 3 nến trên giá đóng cửa, rất nhạy với các nhịp co giật nhanh.
  • streakRSI (ta.rsi(streak, 2)): Biến streak đếm số nến tăng liên tiếp (+1, +2,…) hoặc giảm liên tiếp (-1, -2,…), đưa về 0.0 nếu close == close[1]. Sau đó áp dụng RSI 2 kỳ lên chuỗi streak này.
  • percentRank (Historical Percent Rank): Tính tỷ suất sinh lời 1 nến oneBarReturn = 100.0 * (close / close[1] - 1.0), rồi đếm trong 100 nến liền trước (không tính nến hiện tại) có bao nhiêu nến có mức tăng thấp hơn hẳn (pastReturn < oneBarReturn), quy ra phần trăm 100.0 * lowerCount / rankLength.

2.2. Cửa sổ xác nhận giá (Pending Setup & Price Confirmation)

Thay vì vào lệnh ngay tại nến CRSI cắt ngưỡng quá bán/quá mua, CNPS77 tách quy trình làm 2 bước:

  • Setup chờ (pendingLong / pendingShort): Khi ta.crossover(crsi, 15.0) hoặc ta.crossunder(crsi, 85.0) xảy ra trên nến đã đóng, bot kích hoạt trạng thái chờ trong confirmationBars = 2 nến (tức hợp lệ khi bar_index - pendingBar <= 2). Nếu quá 2 nến chưa xác nhận, hoặc CRSI quay ngược trở lại dưới 15.0 (với Long) / trên 85.0 (với Short), hoặc sang ngày giao dịch mới (newDay), setup chờ sẽ tự động bị hủy.
  • Xác nhận hành động giá (longPriceConfirmed / shortPriceConfirmed): Trong thời gian setup còn hiệu lực, nến hiện tại phải thỏa đồng thời: nến đúng màu (close > open cho Long, close < open cho Short), đóng cửa vượt đỉnh/đáy nến trước (close > high[1] / close < low[1]), và CRSI vẫn nằm trong vùng an toàn (15.0 < crsi <= 70.0 cho Long; 30.0 <= crsi < 85.0 cho Short) để tránh mua/bán khi động lượng đã đi quá xa.

2.3. Bộ lọc Xu hướng EMA, Khoảng cách ATR và Các bộ lọc mở rộng

  • EMA Trend (longTrendOK / shortTrendOK): Đo độ dốc đường EMA(50) so với 5 nến trước (ema > ema[5] cho Long và ema < ema[5] cho Short).
  • Distance Filter (distanceOK): Giới hạn khoảng cách từ giá đóng cửa đến đường EMA không vượt quá 2.5 × ATR(14) (math.abs(close - ema) <= atr * maxDistanceATR), giúp loại bỏ các tín hiệu khi giá đang bị kéo dãn quá mức.
  • Các bộ lọc tùy chọn (mặc định false):
    • ADX Filter (adxOK): Khi bật, yêu cầu adx <= 35.0 (ta.dmi(14, 14)) để tránh thị trường quá nóng.
    • Volume Filter (volumeOK): Khi bật, yêu cầu volume >= ta.sma(volume, 20) * 1.1.
    • Confirmed H1 Bias (longH1OK / shortH1OK): Khi bật trên khung thời gian dưới 1 giờ, dùng request.security(..., "60", ...[1], lookahead=barmerge.lookahead_on) để kiểm tra giá đóng cửa nến H1 đã hoàn tất nằm trên/dưới EMA(50) khung H1.

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

Quy trình xử lý của CNPS77 trên mỗi nến được thực thi tuần tự theo 5 bước:

  1. Khởi tạo phiên và reset bộ đếm ngày: Xác định dayKey theo múi giờ Asia/Ho_Chi_Minh. Khi sang ngày mới (newDay), bot đưa biến đếm tradesToday về 0 và xóa toàn bộ trạng thái pendingLong / pendingShort còn sót từ phiên trước.
  2. Tính toán chỉ báo và cập nhật Setup chờ: Tính priceRSI, streakRSI, percentRank để ra crsi. Chỉ khi nến đã đóng (processState = barstate.isconfirmed và chưa xử lý bar_index này), bot mới cập nhật hết hạn setup cũ, hủy setup thất bại và ghi nhận bullReentry / bearReentry mới.
  3. Xác nhận tín hiệu cơ sở và qua bộ lọc: Kết hợp validLongSetup với longPriceConfirmed tạo ra longBase (tương tự shortBase). Sau đó đưa qua các màng lọc xu hướng EMA, khoảng cách ATR, ADX, Volume và H1 Bias để hình thành rawLongSignal / rawShortSignal.
  4. Kiểm tra cổng vào lệnh (canTrade) & Gửi lệnh: Đảm bảo tài khoản đang 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, nằm trong khung giờ 09:15–14:15, trước giờ đóng phiên 14:45 và không có xung đột tín hiệu (ambiguousSignal). Nếu đạt, bot gửi lệnh strategy.entry (kèm thông báo Alert) và tăng tradesToday.
  5. Gắn Bracket SL/TP và Đóng vị thế cuối phiên: Ngay lập tức gửi lệnh strategy.exit theo số tick cố định gắn với ID lệnh "Long" hoặc "Short". Trong quá trình giữ lệnh, bot theo dõi điều kiện useTimeExit (nếu bật) và luôn kích hoạt strategy.close_all tại nến chạm 14:45 (sessionEndBar).

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

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

Lệnh Long (enterLong) được kích hoạt khi canTrade == true, allowLong == true (mặc định "Long"), không xảy ra xung đột ambiguousSignal và thỏa mãn đồng thời:

  • Setup CRSI hợp lệ (validLongSetup): Đã xuất hiện ta.crossover(crsi, 15.0) trong vòng tối đa 2 nến trở lại đây và crsi chưa rơi ngược xuống dưới 15.0.
  • Xác nhận giá tăng (longPriceConfirmed):
    • Nếu requireCandle = true: Nến tăng (close > open).
    • Nếu requirePriceBreak = true: Giá đóng cửa vượt đỉnh nến trước (close > high[1]).
    • Chỉ số CRSI nằm trong vùng 15.0 < crsi <= 70.0.
  • Xu hướng & Khoảng cách (longTrendOK & distanceOK): ema > ema[5] (khi bật useTrendFilter) và |close - ema| <= 2.5 × ATR(14) (khi bật useDistanceFilter).
  • Bộ lọc mở rộng (nếu được bật): adx <= 35.0, volume >= SMA(volume, 20) * 1.1, và trên khung < H1 có giá đóng cửa H1 đã xác nhận lớn hơn H1 EMA(50).

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

Lệnh Short (enterShort) được kích hoạt khi canTrade == true, allowShort == true (cần chỉnh tradeDirection sang "Short" hoặc "Both"), không có ambiguousSignal và thỏa mãn đồng thời:

  • Setup CRSI hợp lệ (validShortSetup): Đã xuất hiện ta.crossunder(crsi, 85.0) trong vòng tối đa 2 nến trở lại đây và crsi chưa tăng ngược lên trên 85.0.
  • Xác nhận giá giảm (shortPriceConfirmed):
    • Nếu requireCandle = true: Nến giảm (close < open).
    • Nếu requirePriceBreak = true: Giá đóng cửa thủng đáy nến trước (close < low[1]).
    • Chỉ số CRSI nằm trong vùng 30.0 <= crsi < 85.0.
  • Xu hướng & Khoảng cách (shortTrendOK & distanceOK): ema < ema[5] (khi bật useTrendFilter) và |close - ema| <= 2.5 × ATR(14) (khi bật useDistanceFilter).
  • Bộ lọc mở rộng (nếu được bật): adx <= 35.0, volume >= SMA(volume, 20) * 1.1, và trên khung < H1 có giá đóng cửa H1 đã xác nhận nhỏ hơn H1 EMA(50).

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

Biến canTrade đóng vai trò cổng kiểm soát an toàn trước mọi lệnh vào:

  • Trạng thái rỗng (flat & strategy.opentrades == 0): Chỉ giữ tối đa 1 vị thế tại một thời điểm (pyramiding=0).
  • Giới hạn lệnh trong ngày: tradesToday < 2 (maximumTradesPerDay = 2).
  • Thời gian nghỉ sau thoát lệnh (cooldownOK): Khoảng cách từ nến đóng lệnh gần nhất (lastExitBar) phải lớn hơn 5 nến (bar_index - lastExitBar > 5).
  • Khung giờ giao dịch (validEntryTime & beforeForceClose): Giờ mở nến >= 09:15, giờ đóng nến <= 14:15, và giờ đóng nến < 14:45 theo múi giờ Asia/Ho_Chi_Minh.
  • Chống trùng nến & Chờ đóng nến: freshEntryBar đảm bảo không vào lại cùng nến vừa vào, và barstate.isconfirmed đảm bảo chỉ khớp khi nến đã đóng cửa hoàn toàn.

5. Quản trị Stop Loss, Take Profit và Thoát lệnh

5.1. Cơ chế Stop Loss và quy đổi sang Tick

CNPS77 không đặt SL theo đỉnh/đáy nến mà sử dụng khoảng cắt lỗ cố định theo điểm (stopLossPoints = 5.0), sau đó quy đổi chính xác sang đơn vị tick của hợp đồng VN30F1M (syminfo.mintick = 0.1):

  • slTicks = math.max(1, int(math.round(stopLossPoints / syminfo.mintick))) (mặc định 5.0 / 0.1 = 50 ticks).
  • effectiveSLPoints = slTicks * syminfo.mintick.
  • Lệnh cắt lỗ được tính từ giá khớp lệnh thực tế (strategy.position_avg_price) thông qua tham số loss=slTicks trong strategy.exit, tránh sai lệch do trượt giá giữa giá đóng nến tín hiệu và giá khớp thực tế.

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

  • Take Profit cố định theo Tick: tpTicks = math.max(1, int(math.round(takeProfitPoints / syminfo.mintick))) (mặc định 10.0 điểm = 100 ticks, tỷ lệ R:R = 1:2), gắn trực tiếp vào profit=tpTicks trong strategy.exit.
  • Không sử dụng Break Even hay Trailing Stop: Mã nguồn của CNPS77 giữ nguyên mức SL và TP cố định theo Bracket ban đầu trong suốt thời gian nắm giữ, không dời SL về hòa vốn và không trailing theo giá.
  • Time Exit (tùy chọn, mặc định tắt): Nếu bật useTimeExit = true, khi số nến nắm giữ holdingBars >= 20 (trên nến đã đóng và chưa phải nến kết phiên), bot gọi strategy.close_all(immediately=true, comment="Time Exit").
  • Force Close cuối phiên: Khi xuất hiện sessionEndBar (barOpenMinutes < 14:45 và barCloseMinutes >= 14:45) mà vẫn còn vị thế mở, bot lập tức đóng toàn bộ bằng strategy.close_all(immediately=true, comment="Session End") để tránh rủi ro qua đêm hoặc kẹt phiên ATC.

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

Cơ chế bảo vệTham số chínhGiá trị mặc địnhCơ chế thực thi trong code
Cắt lỗ (Stop Loss)stopLossPoints5.0 điểm (50 ticks)strategy.exit(..., loss=slTicks) tính từ strategy.position_avg_price
Chốt lời (Take Profit)takeProfitPoints10.0 điểm (100 ticks)strategy.exit(..., profit=tpTicks) tính từ strategy.position_avg_price
Break Even / TrailingKhông cóKhông áp dụngGiữ nguyên Bracket SL/TP cố định
Thoát lệnh theo thời gianuseTimeExit / maximumHoldingBarsfalse / 20 nếnstrategy.close_all khi giữ đủ số nến (nếu bật)
Đóng cưỡng bức cuối phiênendHour:endMinute14:45strategy.close_all tại sessionEndBar để không giữ lệnh qua 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 giao dịch trong ngày như M5 hoặc M15).
  2. Nhấp vào tab Pine Editor ở thanh công cụ phía dưới màn hình.
  3. Xóa mã 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 script, sau đó nhấn Add to chart để gắn chiến lược lên biểu đồ.
  5. Vào phần Settings (Cài đặt) của chiến lược để điều chỉnh hướng giao dịch (Long, Short hoặc Both), bật/tắt các bộ lọc (ADX, Volume, H1 Bias) 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 showDiagnostics = true, bot vẽ một bảng gồm 17 dòng ở góc trên bên phải (position.top_right) trên nến cuối cùng (barstate.islast) để giúp người dùng kiểm tra luồng lọc tín hiệu:

  • Thông tin thị trường & chỉ báo (Dòng 0–3): Tên bot (CNPS77 V3) và khung thời gian hiện tại; giá trị Connors RSI hiện tại; hướng EMA Trend (UP / DOWN / FLAT); giá trị ADX.
  • Trạng thái bộ lọc (Dòng 4–5): Distance OK (YES/NO) và ADX OK (YES/NO) cho biết nến hiện tại có đang vượt qua hai bộ lọc này hay không.
  • Bộ đếm phễu tín hiệu lịch sử (Dòng 6–11): Lần lượt thống kê số lần xuất hiện tín hiệu CRSI gốc (Bull Reentries, Bear Reentries), số lần qua bước xác nhận giá (Long Bases, Short Bases), và số lần qua toàn bộ bộ lọc (Filtered Long, Filtered Short).
  • Trạng thái chờ & thống kê khớp lệnh (Dòng 12–16): Cho biết có đang trong cửa sổ chờ hay không (Pending Long, Pending Short), tổng số lệnh đã vào (Long Entries, Short Entries) và số lệnh đã giao dịch trong ngày hôm nay (Trades Today, ví dụ 1 / 2).

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:

  1. Nhấn vào biểu tượng Alert (Cảnh báo) (hoặc phím tắt Alt + A) trên biểu đồ đã gắn CNPS77 CRSI V3.
  2. Ở mục Condition, chọn đúng tên chiến lược CNPS77 CONNORS RSI TREND PULLBACK V3.
  3. Ở ô Message, xóa nội dung mặc định và điền duy nhất biến sau để TradingView tự động lấy nội dung thông điệp từ code: {{strategy.order.alert_message}}
  4. Nhấn Create để kích hoạt. Lưu ý giữ disableExitAlerts = false nếu bạn muốn nhận cả cảnh báo khi chạm SL hoặc TP.

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

Sự kiện kích hoạtThuộc tính trong codeNội dung thông điệp Alert
Vào lệnh Longstrategy.entry(..., alert_message=...)🟢 VÀO VỊ THẾ LONG (CNPS77 CRSI V3 Trend) kèm Giá vào, SL và TP
Vào lệnh Shortstrategy.entry(..., alert_message=...)🔴 VÀO VỊ THẾ SHORT (CNPS77 CRSI V3 Trend) kèm Giá vào, SL và TP
Chốt lời Longstrategy.exit(..., alert_profit=...)💰 CHỐT LỜI LONG (TP HIT) kèm Giá chốt
Cắt lỗ Longstrategy.exit(..., alert_loss=...)🛑 CẮT LỖ LONG (SL HIT) kèm Giá cắt
Chốt lời Shortstrategy.exit(..., alert_profit=...)💰 CHỐT LỜI SHORT (TP HIT) kèm Giá chốt
Cắt lỗ Shortstrategy.exit(..., alert_loss=...)🛑 CẮT LỖ SHORT (SL HIT) kèm Giá cắt
Hết thời gian giữstrategy.close_all(..., alert_message=...)⏱️ ĐÓNG VỊ THẾ HẾT THỜI GIAN GIỮ (Time Exit) kèm Giá đóng
Đóng hết phiênstrategy.close_all(..., alert_message=...)⏰ ĐÓNG VỊ THẾ HẾT PHIÊN (Session End) kèm Giá đóng

Kết luận

CNPS77 Connors RSI Trend Pullback V3 là một hệ thống giao dịch kỷ luật, giải quyết tốt bài toán bắt nhịp hồi thuận xu hướng trên VN30F1M nhờ sự kết hợp chặt chẽ giữa độ nhạy của Connors RSI, cửa sổ xác nhận hành động giá 2 nến, bộ lọc xu hướng EMA 50 và khoảng cách ATR. Cơ chế SL/TP cố định quy đổi theo tick từ giá khớp thực tế cùng giới hạn 2 lệnh/ngày và đóng lệnh trước ATC giúp kiểm soát rủi ro chặt chẽ trong các phiên giao dịch có xu hướng rõ ràng (Trending Pullback).

Bạn có thể tham khảo thêm các hệ thống giao dịch phái sinh khác như Bot CNPS50 - Trend Analysis V2 và Bot CNPS49 - Daily Open.

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