Chiến lược đột phá giá định lượng theo mô hình E9 Shark 32


Ngày tạo: 2024-11-12 14:51:17 sửa đổi lần cuối: 2024-11-12 14:51:17
sao chép: 1 Số nhấp chuột: 422
1
tập trung vào
1617
Người theo dõi

Chiến lược đột phá giá định lượng theo mô hình E9 Shark 32

Tổng quan

Chiến lược này là một hệ thống giao dịch định lượng dựa trên nhận dạng hình dạng giá, cốt lõi là nhận dạng và sử dụng hình dạng K-line đặc biệt của “Square 32” để giao dịch. Chiến lược này phân tích sự thay đổi liên tục của các điểm cao và thấp, thiết lập mức giá quan trọng sau khi xác nhận hình dạng và giao dịch khi phá vỡ các mức này.

Nguyên tắc chiến lược

Cốt lõi của chiến lược là xác định hình dạng “Squid 32”, một hình dạng cần đáp ứng các điều kiện sau: Cấp thấp của hai đường K trước liên tục đi xuống, trong khi cao liên tục đi lên. Khi hình dạng được xác nhận, chiến lược sẽ khóa các điểm cao và thấp của đường K bắt đầu hình dạng như mức giá quan trọng. Hệ thống mở vị trí khi giá vượt qua các mức giá quan trọng này: Làm nhiều khi giá trị tài khoản phá vỡ mức cao bị khóa, làm trống khi phá vỡ mức thấp bị khóa.

Lợi thế chiến lược

  1. Tính xác định hình dạng chính xác: nhận dạng hình dạng thông qua định nghĩa toán học nghiêm ngặt, tránh phán đoán chủ quan
  2. Quản lý rủi ro tốt: bao gồm mục tiêu dừng lỗ và lợi nhuận rõ ràng
  3. Trả lời trực quan rõ ràng: sử dụng các đường và nền khác nhau màu sắc để đánh dấu hình dạng và tín hiệu giao dịch
  4. Bộ lọc tín hiệu lặp lại: mỗi hình thức chỉ cho phép thực hiện một giao dịch, tránh giao dịch quá mức
  5. Đặt mục tiêu hợp lý: đặt mục tiêu lợi nhuận dựa trên tỷ lệ biến động hình dạng, có tỷ lệ lợi nhuận rủi ro tốt

Rủi ro chiến lược

  1. Rủi ro thị trường chấn động: có thể tạo ra các tín hiệu phá vỡ giả thường xuyên trong thị trường chấn động ngang
  2. Rủi ro trượt: Có thể có trượt lớn trong điều kiện nhanh
  3. Sự phụ thuộc vào một hình thức: Sự phụ thuộc quá nhiều vào một hình thức có thể làm mất cơ hội giao dịch khác
  4. Nhận thức tham số: thiết lập tham số cho mục tiêu dừng lỗ và lợi nhuận có ảnh hưởng lớn đến hiệu suất chiến lược

Hướng tối ưu hóa chiến lược

  1. Thêm xác nhận khối lượng giao dịch: có thể kết hợp sự thay đổi khối lượng giao dịch để xác nhận tính hiệu quả của đột phá
  2. Tiếp tục giới thiệu bộ lọc môi trường thị trường: tăng các chỉ số cường độ xu hướng để lọc môi trường thị trường bất lợi
  3. Cách tối ưu hóa dừng lỗ: Có thể xem xét sử dụng dừng động để tăng khả năng thích ứng của chiến lược
  4. Thêm bộ lọc thời gian: Thêm bộ lọc thời gian giao dịch để tránh biến động trong một khoảng thời gian cụ thể
  5. Cải thiện quản lý tài chính: thêm mô-đun quản lý vị trí để tối ưu hóa hiệu quả sử dụng tài chính

Tóm tắt

Chiến lược phá vỡ giá định lượng hình dạng cá sấu E9 là một hệ thống giao dịch có cấu trúc, logic rõ ràng. Nó xây dựng một chiến lược giao dịch có thể thực hiện được bằng cách xác định hình dạng nghiêm ngặt và các quy tắc giao dịch rõ ràng. Hệ thống quản lý rủi ro của chiến lược được hoàn thiện, phản hồi trực quan rõ ràng, dễ hiểu và thực hiện bởi các nhà giao dịch.

Mã nguồn chiến lược
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
//║                                                                                                             ║
//║ ░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓██████▓▒░░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░   ░▒▓████████▓▒░▒▓██████▓▒░  ║
//║    ░▒▓█▓▒░   ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░░▒▓█▓▒   ░▒▓█▓▒░     ░▒▓█▓▒░░▒▓█▓▒░ ║
//║    ░▒▓█▓▒░   ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░░▒▓█▓▒.  ░▒▓█▓▒░     ░▒▓█▓▒░░▒▓█▓▒░ ║
//║    ░▒▓█▓▒░   ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓██████▓▒░ ░▒▓███████▓▒░.  ░▒▓██████▓▒░ ░▒▓███████▓▒░ ║
//║    ░▒▓█▓▒░   ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░░▒▓█▓▒.  ░▒▓█▓▒░            ░▒▓█▓▒░ ║
//║    ░▒▓█▓▒░   ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░░▒▓█▓▒.  ░▒▓█▓▒░            ░▒▓█▓▒░ ║
//║    ░▒▓█▓▒░   ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒.  ░▒▓████████▓▒░▒▓██████▓▒░  ║
//║                                                                                                             ║
//╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════╝

//@version=5
strategy("E9 Shark-32 Pattern Strategy with Target Lines", shorttitle="E9 Shark-32 Strategy", overlay=true)

// Inputs for background color settings
bgcolorEnabled = input(true, title="Enable Background Color")
bgcolorColor = input.color(color.new(color.blue, 90), title="Background Color")

// Inputs for bar color settings
barcolorEnabled = input(true, title="Enable Bar Color")
barcolorColor = input.color(color.rgb(240, 241, 154), title="Bar Color")

// Inputs for target lines settings
targetLinesEnabled = input(true, title="Enable Target Lines")
targetLineColor = input.color(color.white, title="Target Line Color")
targetLineThickness = input.int(1, title="Target Line Thickness", minval=1, maxval=5)

// Define Shark-32 Pattern
shark32 = low[2] < low[1] and low[1] < low and high[2] > high[1] and high[1] > high

// Initialize color variables for bars
var color barColorCurrent = na
var color barColor1 = na
var color barColor2 = na

// Update color variables based on Shark-32 pattern
barColorCurrent := barcolorEnabled and (shark32 or shark32[1] or shark32[2]) ? barcolorColor : na
barColor1 := barcolorEnabled and (shark32[1] or shark32[2]) ? barcolorColor : na
barColor2 := barcolorEnabled and shark32[2] ? barcolorColor : na

// Apply the bar colors to the chart
barcolor(barColorCurrent, offset=-2, title="Shark-32 Confirmed Current")
barcolor(barColor1, offset=-3, title="Shark-32 Confirmed Previous Bar 1")
barcolor(barColor2, offset=-4, title="Shark-32 Confirmed Previous Bar 2")

// Variables for locking the high and low of confirmed Shark-32
var float patternHigh = na
var float patternLow = na
var float upperTarget = na
var float lowerTarget = na

// Once Shark-32 pattern is confirmed, lock the patternHigh, patternLow, and target lines
if shark32
    patternHigh := high[2]  // The high of the first bar in Shark-32 pattern
    patternLow := low[2]    // The low of the first bar in Shark-32 pattern

    // Calculate the upper and lower white target lines
    upperTarget := patternHigh + (patternHigh - patternLow)  // Dotted white line above
    lowerTarget := patternLow - (patternHigh - patternLow)   // Dotted white line below

// Initialize variables for the lines
var line greenLine = na
var line redLine = na
var line upperTargetLine = na
var line lowerTargetLine = na

// Draw the lines based on the locked patternHigh, patternLow, and target lines
// if shark32
//     future_bar_index_lines = bar_index + 10

//     // Draw lines based on locked patternHigh and patternLow
//     greenLine := line.new(x1=bar_index[2], y1=patternHigh, x2=future_bar_index_lines, y2=patternHigh, color=color.green, width=2, extend=extend.none)
//     redLine := line.new(x1=bar_index[2], y1=patternLow, x2=future_bar_index_lines, y2=patternLow, color=color.red, width=2, extend=extend.none)

//     // Draw dotted white lines if targetLinesEnabled is true
//     if targetLinesEnabled
//         upperTargetLine := line.new(x1=bar_index[2], y1=upperTarget, x2=future_bar_index_lines, y2=upperTarget, color=targetLineColor, width=targetLineThickness, style=line.style_dotted, extend=extend.none)
//         lowerTargetLine := line.new(x1=bar_index[2], y1=lowerTarget, x2=future_bar_index_lines, y2=lowerTarget, color=targetLineColor, width=targetLineThickness, style=line.style_dotted, extend=extend.none)

//     // Create a box to fill the background between the red and green lines
//     if bgcolorEnabled
//         box.new(left=bar_index[2], top=patternHigh, right=future_bar_index_lines, bottom=patternLow, bgcolor=bgcolorColor)

// -------------------------------------------------------------------------
// Strategy Entry and Exit Parameters
// -------------------------------------------------------------------------

// Input parameters for stop loss
longStopLoss = input.float(1.0, title="Long Stop Loss (%)", minval=0.1)  // Percentage-based stop loss for long
shortStopLoss = input.float(1.0, title="Short Stop Loss (%)", minval=0.1)  // Percentage-based stop loss for short

// Variable to track if a trade has been taken
var bool tradeTaken = false

// Reset the flag when a new Shark-32 pattern is confirmed
if shark32
    tradeTaken := false

// Entry conditions only trigger after the Shark-32 is confirmed
longCondition = ta.crossover(close, patternHigh) and not tradeTaken  // Long entry when close crosses above locked patternHigh
shortCondition = ta.crossunder(close, patternLow) and not tradeTaken  // Short entry when close crosses below locked patternLow

// Trigger long and short trades based on the crossover conditions
if (longCondition)
    label.new(bar_index, high, "Long Trigger", style=label.style_label_down, color=color.green, textcolor=color.white, size=size.small)
    strategy.entry("Shark-32 Long", strategy.long)
    tradeTaken := true  // Set the flag to true after a trade is taken

if (shortCondition)
    label.new(bar_index, low, "Short Trigger", style=label.style_label_up, color=color.red, textcolor=color.white, size=size.small)
    strategy.entry("Shark-32 Short", strategy.short)
    tradeTaken := true  // Set the flag to true after a trade is taken

// Exit long trade based on the upper target line (upper white dotted line) as take profit
if strategy.position_size > 0
    strategy.exit("Take Profit Long", "Shark-32 Long", limit=upperTarget, stop=close * (1 - longStopLoss / 100))

// Exit short trade based on the lower target line (lower white dotted line) as take profit
if strategy.position_size < 0
    strategy.exit("Take Profit Short", "Shark-32 Short", limit=lowerTarget, stop=close * (1 + shortStopLoss / 100))