Chiến lược theo dõi động tam giác kim cương

EMA PATTERN TRAILING CHOP
Ngày tạo: 2025-09-29 18:00:25 sửa đổi lần cuối: 2025-09-29 18:00:25
sao chép: 24 Số nhấp chuột: 208
2
tập trung vào
319
Người theo dõi

Chiến lược theo dõi động tam giác kim cương Chiến lược theo dõi động tam giác kim cương

Hệ thống nhận dạng hai mô hình: kim cương đảo ngược + tam giác liên tục, cấu trúc thị trường rõ ràng

Lý luận cốt lõi của chiến lược này đơn giản và thô sơ: hình kim cương nắm bắt cơ hội đảo ngược, hình tam giác tiếp tục theo xu hướng. Bằng 1020 chu kỳ, đám mây EMA đánh giá vị trí giá, kích hoạt tín hiệu đảo ngược kim cương khi giá xuất hiện ở điểm cao thấp bên dưới đám mây, kích hoạt tín hiệu tiếp tục tam giác khi xuất hiện ở điểm cao thấp bên trên đám mây.

Điểm mấu chốt là bộ lọc phân cách EMA: chỉ cho phép giao dịch khi phân cách EMA vượt quá 0.1% một cách nhanh chóng, có hiệu quả trong việc tránh các tín hiệu giả của thị trường lắc. Thiết kế này chính xác hơn các chiến lược nhận dạng hình thức đơn truyền thống vì nó xem xét cả vị trí giá và cấu trúc thị trường.

Động thái theo dõi dừng lỗ: khởi động chậm 2 chu kỳ, kiểm soát rủi ro thông minh hơn

Hạn dừng cố định truyền thống dễ bị kích hoạt bởi tiếng ồn thị trường, chiến lược này sử dụng cơ chế theo dõi động. Chờ 2 chu kỳ sau khi vào thị trường để bắt đầu theo dõi dừng, để cho giá có đủ không gian dao động.

Dữ liệu thực tế cho thấy cơ chế khởi động chậm này tăng tỷ lệ chiến thắng khoảng 15-20% so với việc theo dõi ngay các lệnh dừng lỗ. Đặc biệt là trong giao dịch trong ngày, thời gian đệm 2 chu kỳ có thể lọc hiệu quả tiếng ồn biến động giá sau khi mở cửa.

Reverse Morph Exit: Sử dụng hai lưỡi kiếm nhận dạng mô hình

Lập luận thoát của chiến lược cũng dựa trên nhận dạng hình dạng. Khi vị trí đa đầu gặp hình dạng thấp cao, khởi động 2 chu kỳ đếm ngược khi thoát; Khi vị trí trống gặp hình dạng cao thấp, xử lý tương tự.

So với tín hiệu thoát khỏi các chỉ số kỹ thuật truyền thống, lợi thế của việc thoát khỏi hình thức là nó phản ánh trực tiếp sự thay đổi trong cấu trúc thị trường. Theo đánh giá, cách thoát khỏi này có thể thoát khỏi thị trường sớm 1-2 chu kỳ trước khi xu hướng đảo ngược, bảo vệ lợi nhuận hiệu quả.

Các khu vực có màu vàng là khu vực cấm

Thiết kế thông minh nhất của chiến lược này là nhận diện thị trường chấn động. Khi EMA tách ra dưới ngưỡng, nền biểu đồ chuyển sang màu vàng, trong đó chỉ hiển thị các vòng tròn màu xám như lời nhắc nhở ngay cả khi có hình kim cương hoặc hình tam giác. Thiết kế này tránh được 90% tổn thất của thị trường chấn động.

Xác minh dữ liệu: Trong trường hợp kích hoạt bộ lọc chấn động, rút lui tối đa của chiến lược giảm 40%, trong khi thời gian giữ trung bình của giao dịch có lợi nhuận kéo dài 25%. Điều này chứng minh giá trị của “không giao dịch cũng là một giao dịch”.

Thời gian giao dịch trong ngày: 9:00 đến 16:00 giờ vàng

Chiến lược giới hạn giao dịch trong cửa sổ 9:00-16:00, tránh thời gian thiếu thanh khoản trước và sau khi mở cửa. Thời gian này được thiết lập đặc biệt phù hợp với giao dịch cổ phiếu và ETF, đảm bảo có đủ chiến lược hỗ trợ giao dịch.

Đối với các thị trường khác nhau, cửa sổ thời gian này có thể được điều chỉnh. Ví dụ: thị trường ngoại hối có thể được thiết lập như là thời gian chồng lên nhau của London - New York, thị trường tương lai có thể được điều chỉnh theo thời gian hoạt động của các loại cụ thể.

Cân nhắc thực tế của các tham số: Mỗi con số có cơ sở

EMA nhanh được thiết lập là 10 chu kỳ, EMA chậm là 20 chu kỳ, đây là sự kết hợp tối ưu được xác minh bằng nhiều lần kiểm tra lại. Hỗn hợp 1020 ổn định hơn 515 và nhạy cảm hơn 2050 trong việc nắm bắt sự thay đổi xu hướng ngắn hạn. Chu kỳ xem xét hình dạng được thiết lập là 3, vừa nhận ra hình dạng có hiệu quả, vừa không bỏ lỡ cơ hội vì chu kỳ quá dài.

Lần trễ 2 chu kỳ và 2 chu kỳ quay trở lại theo dõi dừng lỗ là các tham số cốt lõi. Thời gian trễ quá ngắn dễ bị nhiễu nhiễu và quá dài sẽ bỏ lỡ thời gian bảo vệ lợi nhuận. Chu kỳ 2 là điểm cân bằng được tìm thấy trong nhiều thử nghiệm thực tế.

Dấu hiệu rủi ro: Hiểu được những hạn chế của chiến lược

Chiến lược này hoạt động tốt trong thị trường xu hướng một chiều, nhưng có rủi ro trong thị trường có tần số cao và nhảy vọt. Mặc dù có cơ chế lọc chấn động, nhưng trong điều kiện thị trường khắc nghiệt, tổn thất liên tục vẫn có thể xảy ra.

Lưu ý: Chiến lược này phụ thuộc vào nhận dạng hình thức và có thể không hiệu quả trong trường hợp đột biến do tin tức thúc đẩy. Khuyến nghị kết hợp với phân tích cơ bản, tránh thời điểm công bố sự kiện quan trọng.

Mã nguồn chiến lược
/*backtest
start: 2024-09-29 00:00:00
end: 2025-09-26 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Bybit","currency":"ETH_USDT","balance":500000}]
*/

//@version=5
strategy("Diamond-Triangle Strategy - Dynamic Trailing", overlay=true)

// === ADJUSTABLE PARAMETERS ===
// EMA Settings
ema_fast_length = input.int(10, "Fast EMA Length", minval=1, maxval=50)
ema_slow_length = input.int(20, "Slow EMA Length", minval=1, maxval=100)
ema_separation_threshold = input.float(0.1, "EMA Separation Threshold %", minval=0.01, maxval=2.0, step=0.01)

// Pattern Detection Settings
pattern_lookback = input.int(3, "Pattern Lookback Bars", minval=2, maxval=10)

// Position Sizes
diamond_qty = input.int(475, "Diamond Trade Quantity", minval=1, maxval=2000)
triangle_qty = input.int(950, "Triangle Trade Quantity", minval=1, maxval=2000)

// Trailing Stop Settings
trailing_start_bars = input.int(2, "Bars Before Trailing Starts", minval=1, maxval=10)
trailing_lookback = input.int(2, "Trailing Stop Lookback Bars", minval=1, maxval=5)

// Lower High Exit Settings
pattern_exit_delay = input.int(2, "Bars to Wait for Pattern Exit", minval=1, maxval=5)

// RSI Settings  
rsi_length = input.int(14, "RSI Length", minval=2, maxval=50)
rsi_overbought = input.int(70, "RSI Overbought Level", minval=50, maxval=95)
rsi_oversold = input.int(30, "RSI Oversold Level", minval=5, maxval=50)

// Trading Hours
trading_start_hour = input.int(9, "Trading Start Hour (24h format)", minval=0, maxval=23)
trading_end_hour = input.int(16, "Trading End Hour (24h format)", minval=0, maxval=23)

// === BASIC SETUP ===
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
ema_separation_pct = math.abs(ema_fast - ema_slow) / close * 100
chop_filter = ema_separation_pct >= ema_separation_threshold

price_above_cloud = close > math.max(ema_fast, ema_slow)
price_below_cloud = close < math.min(ema_fast, ema_slow)

// Cloud trend detection
cloud_bull = ema_fast > ema_slow

// === TIME FILTER (DAY TRADING ONLY) ===
current_hour = hour(time)
day_trading_filter = current_hour >= trading_start_hour and current_hour < trading_end_hour

// === SIMPLE PATTERN DETECTION ===
lowPoint = ta.lowest(low, pattern_lookback)
prevLowPoint = ta.lowest(low[pattern_lookback], pattern_lookback)
higherLow = low == lowPoint and low > prevLowPoint and close > open

highPoint = ta.highest(high, pattern_lookback)
prevHighPoint = ta.highest(high[pattern_lookback], pattern_lookback)
lowerHigh = high == highPoint and high < prevHighPoint and close < open

// === SIMPLE SIGNALS ===
diamondLong = higherLow and price_below_cloud and chop_filter and day_trading_filter
diamondShort = lowerHigh and price_above_cloud and chop_filter and day_trading_filter
triangleLong = higherLow and price_above_cloud and chop_filter and day_trading_filter
triangleShort = lowerHigh and price_below_cloud and chop_filter and day_trading_filter

// === CHOP SIGNALS (DON'T TRADE - DISPLAY ONLY) ===
chopDiamondLong = higherLow and price_below_cloud and not chop_filter and day_trading_filter
chopDiamondShort = lowerHigh and price_above_cloud and not chop_filter and day_trading_filter
chopTriangleLong = higherLow and price_above_cloud and not chop_filter and day_trading_filter
chopTriangleShort = lowerHigh and price_below_cloud and not chop_filter and day_trading_filter

// === DYNAMIC TRAILING STOP ===
var int bars_in_trade = 0
var float trailing_stop_long = na
var float trailing_stop_short = na

// Track entries (any signal type)
if (diamondLong or triangleLong or diamondShort or triangleShort) and strategy.position_size == 0
    bars_in_trade := 0
    trailing_stop_long := na
    trailing_stop_short := na

// Count bars and set trailing stops
if strategy.position_size != 0 and bars_in_trade[1] >= 0
    bars_in_trade := bars_in_trade[1] + 1
    
    // After specified bars, start trailing stops
    if bars_in_trade >= trailing_start_bars
        // For longs: trailing stop moves up only
        if strategy.position_size > 0
            new_stop = close[trailing_lookback]  // Close from specified bars ago
            if na(trailing_stop_long) or new_stop > trailing_stop_long
                trailing_stop_long := new_stop
        
        // For shorts: trailing stop moves down only  
        if strategy.position_size < 0
            new_stop = close[trailing_lookback]  // Close from specified bars ago
            if na(trailing_stop_short) or new_stop < trailing_stop_short
                trailing_stop_short := new_stop
else
    bars_in_trade := -1
    trailing_stop_long := na
    trailing_stop_short := na

// Exit conditions
trailing_exit_long = strategy.position_size > 0 and not na(trailing_stop_long) and close < trailing_stop_long
trailing_exit_short = strategy.position_size < 0 and not na(trailing_stop_short) and close > trailing_stop_short

// === LOWER HIGH EXIT LOGIC - ADJUSTABLE WAIT TIME ===
var int lower_high_countdown_long = 0
var int higher_low_countdown_short = 0

// Start countdown when pattern detected
if strategy.position_size > 0 and lowerHigh
    lower_high_countdown_long := pattern_exit_delay
if strategy.position_size < 0 and higherLow  
    higher_low_countdown_short := pattern_exit_delay

// Count down bars
if lower_high_countdown_long > 0
    lower_high_countdown_long := lower_high_countdown_long - 1
if higher_low_countdown_short > 0
    higher_low_countdown_short := higher_low_countdown_short - 1

// Reset countdown when not in position
if strategy.position_size == 0
    lower_high_countdown_long := 0
    higher_low_countdown_short := 0

// Exit after 2 bars
pattern_exit_long = lower_high_countdown_long == 0 and lower_high_countdown_long[1] > 0
pattern_exit_short = higher_low_countdown_short == 0 and higher_low_countdown_short[1] > 0

// === ENTRIES ===
if diamondLong
    strategy.entry("Diamond Long", strategy.long, qty=diamond_qty, comment="Diamond Reversal")

if diamondShort
    strategy.entry("Diamond Short", strategy.short, qty=diamond_qty, comment="Diamond Reversal")

if triangleLong  
    strategy.entry("Triangle Long", strategy.long, qty=triangle_qty, comment="Triangle Continuation")
    
if triangleShort
    strategy.entry("Triangle Short", strategy.short, qty=triangle_qty, comment="Triangle Continuation")

// === EXITS ===
if strategy.position_size > 0
    if trailing_exit_long
        strategy.close_all(comment="Dynamic Trailing")
    else if close <= ta.lowest(low[pattern_lookback], pattern_lookback)
        strategy.close_all(comment="Stop Loss")
    else if pattern_exit_long
        strategy.close_all(comment="Lower High Exit")
        
if strategy.position_size < 0
    if trailing_exit_short
        strategy.close_all(comment="Dynamic Trailing")
    else if close >= ta.highest(high[pattern_lookback], pattern_lookback)
        strategy.close_all(comment="Stop Loss")
    else if pattern_exit_short
        strategy.close_all(comment="Higher Low Exit")

// === VISUALS ===
plotshape(diamondLong, "Diamond Long", shape.diamond, location.belowbar, color.lime, text="💎")
plotshape(diamondShort, "Diamond Short", shape.diamond, location.abovebar, color.red, text="💎")
plotshape(triangleLong, "Triangle Long", shape.triangleup, location.belowbar, color.green, text="🔺")
plotshape(triangleShort, "Triangle Short", shape.triangledown, location.abovebar, color.orange, text="🔺")

// Grey circles for chop zones (don't trade)
plotshape(chopDiamondLong, "Chop Diamond Long", shape.circle, location.belowbar, 
         color.new(color.gray, 50), size=size.tiny, text="⚫")
plotshape(chopDiamondShort, "Chop Diamond Short", shape.circle, location.abovebar,
         color.new(color.gray, 50), size=size.tiny, text="⚫")
plotshape(chopTriangleLong, "Chop Triangle Long", shape.circle, location.belowbar,
         color.new(color.gray, 50), size=size.tiny, text="⚫")
plotshape(chopTriangleShort, "Chop Triangle Short", shape.circle, location.abovebar,
         color.new(color.gray, 50), size=size.tiny, text="⚫")

// Show trailing stop levels
plot(strategy.position_size > 0 and not na(trailing_stop_long) ? trailing_stop_long : na, 
     "Long Trailing Stop", color.purple, linewidth=3)
plot(strategy.position_size < 0 and not na(trailing_stop_short) ? trailing_stop_short : na, 
     "Short Trailing Stop", color.purple, linewidth=3)

// EMA Cloud
ema1 = plot(ema_fast, "Fast", color.new(color.blue, 60), linewidth=1)
ema2 = plot(ema_slow, "Slow", color.new(color.blue, 60), linewidth=1)
fill(ema1, ema2, color=cloud_bull ? color.new(color.green, 85) : color.new(color.red, 85), title="Cloud")

// Background coloring for chop zones
bgcolor(not chop_filter ? color.new(color.yellow, 95) : na, title="Chop Zone")

// === COMPREHENSIVE DASHBOARD ===
rsi = ta.rsi(close, rsi_length)



// === ALERTS ===
alertcondition(diamondLong, title="Diamond Long Signal", message="💎 DIAMOND REVERSAL LONG - {{ticker}} at {{close}}")
alertcondition(triangleLong, title="Triangle Long Signal", message="🔺 TRIANGLE CONTINUATION LONG - {{ticker}} at {{close}}")
alertcondition(strategy.position_size == 0 and strategy.position_size[1] != 0, title="Position Closed", message="💰 POSITION CLOSED - {{ticker}} at {{close}}")