Chiến lược siêu xu hướng chồng chéo ba lần

Tác giả:ChaoZhang, Ngày: 2024-02-26 10:04:18
Tags:

img

Tổng quan

Đây là một chiến lược đưa ra quyết định giao dịch dựa trên ba chỉ số SuperTrend chồng chéo. Nó có thể nắm bắt các cơ hội định hướng lớn hơn trong các thị trường xu hướng.

Chiến lược logic

Chiến lược sử dụng hàm ta.supertrend() để tính toán ba chỉ số SuperTrend với các thiết lập tham số khác nhau, cụ thể là SuperTrend1 với 10 ngày và nhân 3, SuperTrend2 với 14 ngày và nhân 2, và SuperTrend3 với 20 ngày và nhân 2.5.

Chỉ số SuperTrend kết hợp chỉ số ATR để theo dõi hiệu quả các thay đổi xu hướng giá. Chiến lược của ba SuperTrends chồng chéo làm cho các tín hiệu đáng tin cậy hơn, do đó thu được lợi nhuận lớn hơn trong các thị trường xu hướng.

Ưu điểm

  1. Cơ chế lọc ba loại tránh tín hiệu sai và cải thiện chất lượng tín hiệu
  2. SuperTrend có khả năng giảm tiếng ồn tốt
  3. Nhiều sự kết hợp của các siêu tham số có thể được cấu hình để phù hợp với nhiều môi trường thị trường hơn
  4. Hiệu suất lịch sử tốt với tỷ lệ rủi ro cao

Rủi ro

  1. Nhiều tín hiệu lọc có thể bỏ lỡ một số cơ hội
  2. Không hoạt động tốt trên các thị trường khác nhau
  3. Yêu cầu tối ưu hóa các kết hợp của ba bộ siêu tham số
  4. Thời gian giao dịch tập trung dễ bị biến động đột ngột

Những điều sau đây có thể được xem xét để giảm rủi ro:

  1. Điều chỉnh các điều kiện lọc, giữ một hoặc hai SuperTrends
  2. Thêm chiến lược dừng lỗ
  3. Tối ưu hóa các siêu tham số để cải thiện tỷ lệ thắng

Hướng dẫn tối ưu hóa

  1. Kiểm tra nhiều kết hợp tham số hơn để tìm các siêu tham số tối ưu
  2. Thêm thuật toán học máy để tối ưu hóa tham số thời gian thực
  3. Thêm các chiến lược dừng lỗ để kiểm soát lỗ đơn
  4. Bao gồm các chỉ số khác để xác định xu hướng và phạm vi
  5. Mở rộng thời gian giao dịch để tránh rủi ro tại một thời điểm duy nhất

Kết luận

Chiến lược này đưa ra quyết định dựa trên ba siêu xu hướng chồng chéo, có thể xác định hiệu quả hướng xu hướng. Nó có những lợi thế như chất lượng tín hiệu cao và các thông số có thể cấu hình. Đồng thời, cũng có một số rủi ro. Các thông số và thời gian thoát cần phải được điều chỉnh để thích nghi với môi trường thị trường khác nhau. Nhìn chung, chiến lược hoạt động đặc biệt tốt và đáng để nghiên cứu và áp dụng thêm.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('Combined Supertrend Strategy - Ajit Prasad', overlay=true)

// Function to calculate Supertrend
supertrendFunc(atrLength, factor) =>
    [supertrend, direction] = ta.supertrend(factor, atrLength)
    [supertrend, direction]

// Input parameters for the first Supertrend
atrPeriod1 = input(10, 'ATR Length 1')
factor1 = input(3, 'Factor 1')

// Calculate the first Supertrend
[supertrend1, direction1] = supertrendFunc(atrPeriod1, factor1)

// Input parameters for the second Supertrend
atrPeriod2 = input(14, 'ATR Length 2') // Change values as needed
factor2 = input(2, 'Factor 2') // Change values as needed

// Calculate the second Supertrend
[supertrend2, direction2] = supertrendFunc(atrPeriod2, factor2)

// Input parameters for the third Supertrend
atrPeriod3 = input(20, 'ATR Length 3') // Change values as needed
factor3 = input(2.5, 'Factor 3') // Change values as needed

// Calculate the third Supertrend
[supertrend3, direction3] = supertrendFunc(atrPeriod3, factor3)

// Define market opening and closing times
marketOpenHour = 9
marketOpenMinute = 15
marketCloseHour = 15
marketCloseMinute = 30
exitTimeHour = 15
exitTimeMinute = 10

// Fetch historical close values using security function
histClose = request.security(syminfo.tickerid, "D", close)

// Buy condition
buyCondition = close > supertrend1 and close > supertrend2 and close > supertrend3 and close[1] <= supertrend1[1]

// Sell condition
sellCondition = close < supertrend1 and close < supertrend2 and close < supertrend3 and close[1] >= supertrend1[1]

// Exit conditions
buyExitCondition = close < supertrend1[1] or close < supertrend2[1] or close < supertrend3[1]
sellExitCondition = close > supertrend1[1] or close > supertrend2[1] or close > supertrend3[1]

// Execute orders with market timing
if true
    // Buy condition without 'and not'
    strategy.entry('Buy', strategy.long, when = buyCondition)

    // Sell condition without 'and not'
    strategy.entry('Sell', strategy.short, when = sellCondition)

    // Close conditions
    strategy.close('Buy', when = buyExitCondition )
    strategy.close('Sell', when = sellExitCondition)

// Close all trades at 3:10 pm IST
if true
    strategy.close_all()

// Plot Supertrends
plot(supertrend1, 'Supertrend 1', color=color.new(color.green, 0), style=plot.style_linebr)
plot(supertrend2, 'Supertrend 2', color=color.new(color.red, 0), style=plot.style_linebr)
plot(supertrend3, 'Supertrend 3', color=color.new(color.blue, 0), style=plot.style_linebr)

// Plot labels
plotshape(buyCondition, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.large, text='Buy Signal', textcolor=color.new(color.white, 0))
plotshape(sellCondition, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.large, text='Sell Signal', textcolor=color.new(color.white, 0))

Thêm nữa