Chiến lược giao dịch kim tự tháp động siêu xu hướng đa giai đoạn

ATR ST SL
Ngày tạo: 2025-01-06 17:02:35 sửa đổi lần cuối: 2025-01-06 17:02:35
sao chép: 0 Số nhấp chuột: 460
1
tập trung vào
1617
Người theo dõi

Chiến lược giao dịch kim tự tháp động siêu xu hướng đa giai đoạn

Tổng quan

Đây là chiến lược giao dịch kim tự tháp dựa trên nhiều chỉ báo Supertrend. Công cụ này xác định các cơ hội giao dịch có xác suất cao bằng cách thiết lập chỉ báo Supertrend với ba giai đoạn và hệ số nhân khác nhau. Chiến lược này áp dụng phương pháp thêm vị thế kim tự tháp động, cho phép tối đa ba mục nhập và kết hợp lệnh dừng lỗ động và điều kiện thoát lệnh linh hoạt để tối đa hóa lợi nhuận và kiểm soát rủi ro.

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

Chiến lược này sử dụng chỉ báo Supertrend với ba cài đặt thông số khác nhau: nhanh, trung bình và chậm. Tín hiệu vào lệnh dựa trên giao điểm của ba chỉ báo này và hướng xu hướng, sử dụng kiểu kim tự tháp ba lớp để thêm các vị thế: lớp đầu tiên vào lệnh khi chỉ báo nhanh đi xuống, chỉ báo trung bình đi lên và chỉ báo chậm chỉ báo hướng xuống; lớp thứ hai vào thị trường khi chỉ báo nhanh hướng lên. Vào thị trường thông qua đột phá khi chỉ báo tốc độ trung bình và chỉ báo tốc độ trung bình cùng di chuyển xuống; cấp độ thứ ba là vào thị trường thông qua đột phá khi thị trường đạt đến mức cao mới. Lối thoát áp dụng nhiều cơ chế như dừng lỗ động, dừng lỗ giá trung bình và đảo ngược xu hướng chung.

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

  1. Cơ chế xác nhận nhiều lần cải thiện độ chính xác của giao dịch
  2. Kim tự tháp có thể làm tăng đáng kể lợi nhuận trong các thị trường có xu hướng
  3. Cơ chế dừng lỗ động bảo vệ lợi nhuận trong khi vẫn tạo đủ không gian cho xu hướng phát triển
  4. Cơ chế thoát hiểm linh hoạt có thể ứng phó tốt hơn với các môi trường thị trường khác nhau
  5. Sử dụng kiểm soát vị thế phần trăm để thích ứng với các quy mô quỹ khác nhau

Rủi ro chiến lược

  1. Tín hiệu sai thường xuyên có thể xảy ra trong thị trường biến động
  2. Kim tự tháp có thể dẫn đến sự sụt giảm lớn hơn khi xu hướng đột nhiên đảo ngược
  3. Nhiều chỉ báo có thể gây ra độ trễ tín hiệu
  4. Tối ưu hóa tham số có nguy cơ quá khớp Nên áp dụng biện pháp quản lý tiền chặt chẽ và kiểm tra ngược để kiểm soát những rủi ro này.

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

  1. Thêm cơ chế lọc môi trường thị trường để điều chỉnh các thông số một cách linh hoạt trong các môi trường biến động khác nhau
  2. Tối ưu hóa khoảng thời gian giữa việc thêm vị trí và tỷ lệ phân bổ vị trí
  3. Giới thiệu thêm các chỉ báo kỹ thuật để lọc ra các tín hiệu sai
  4. Phát triển các cơ chế tham số thích ứng để thích ứng với những thay đổi của thị trường
  5. Cải thiện cơ chế thoát, bạn có thể cân nhắc thêm mục tiêu lợi nhuận và thời gian dừng lỗ

Tóm tắt

Chiến lược này nắm bắt các cơ hội xu hướng thông qua nhiều chỉ báo Supertrend và phương pháp thêm kim tự tháp, đồng thời kiểm soát rủi ro bằng cơ chế dừng lỗ động và thoát lệnh linh hoạt. Mặc dù có một số hạn chế nhất định, nhưng thông qua quá trình tối ưu hóa liên tục và kiểm soát rủi ro chặt chẽ, chiến lược này có giá trị ứng dụng thực tế tốt.

Mã nguồn chiến lược
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy('4Vietnamese 3x Supertrend', overlay=true, max_bars_back=1000, initial_capital = 10000000000, slippage = 2, commission_type = strategy.commission.percent, commission_value = 0.013, default_qty_type=strategy.percent_of_equity, default_qty_value = 33.33, pyramiding = 3, margin_long = 0, margin_short = 0)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Inputs

// Supertrend Settings
STATRLENGTH1 = input.int(10, title='Fast Supertrend ATR Length', group='SUPERTREND SETTINGS')
STATRMULT1 = input.float(1, title='Fast Supertrend ATR Multiplier', group='SUPERTREND SETTINGS')
STATRLENGTH2 = input.int(11, title='Medium Supertrend ATR Length', group='SUPERTREND SETTINGS')
STATRMULT2 = input.float(2, title='Medium Supertrend ATR Multiplier', group='SUPERTREND SETTINGS')
STATRLENGTH3 = input.int(12, title='Slow Supertrend ATR Length', group='SUPERTREND SETTINGS')
STATRMULT3 = input.float(3, title='Slow Supertrend ATR Multiplier', group='SUPERTREND SETTINGS')

isUseHighestOf2RedCandleSetup = input.bool(false, group = "Setup Filters")


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculations 
[superTrend1, dir1] = ta.supertrend(STATRMULT1, STATRLENGTH1)
[superTrend2, dir2] = ta.supertrend(STATRMULT2, STATRLENGTH2)
[superTrend3, dir3] = ta.supertrend(STATRMULT3, STATRLENGTH3)

// directionST1 = dir1 == 1 and dir1[1] == 1 ? false : dir1 == -1 and dir1[1] == -1 ? true : false
// directionST2 = dir2 == 1 and dir2[1] == 1 ? false : dir2 == -1 and dir2[1] == -1 ? true : false
// directionST3 = dir3 == 1 and dir3[1] == 1 ? false : dir3 == -1 and dir3[1] == -1 ? true : false


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate highest from supertrend1 uptrend
var float highestGreen = 0
if dir1 < 0 and highestGreen == 0 and (isUseHighestOf2RedCandleSetup ? close < open : true)
    highestGreen := high
if highestGreen > 0 and (isUseHighestOf2RedCandleSetup ? close < open : true)
    if high > highestGreen
        highestGreen := high
if dir1 >= 0
    highestGreen := 0


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Entry SL
var entrySL4Long1 = false
var entrySL4Long2 = false
var entrySL4Long3 = false

isUseEntrySL = input.bool(true, group = "Entry SL Option")
dataToCalculate = input.source(low, group = "Entry SL Option")

if isUseEntrySL and (dir1 > 0 and dir2 < 0 and dir3 < 0)
    if strategy.opentrades >= 1
        if dataToCalculate > strategy.opentrades.entry_price(0)
            entrySL4Long1 := true
        else 
            entrySL4Long1 := false

        if entrySL4Long1 and close > strategy.opentrades.entry_price(0)
            strategy.exit('exit1', from_entry = 'long1', stop = strategy.opentrades.entry_price(0))

    if strategy.opentrades >= 2 
        if dataToCalculate > strategy.opentrades.entry_price(1)
            entrySL4Long2 := true
        else 
            entrySL4Long2 := false
    
        if entrySL4Long2 and close > strategy.opentrades.entry_price(1)
            strategy.exit('exit2', from_entry = 'long2', stop = strategy.opentrades.entry_price(1))   

    if strategy.opentrades >= 3 
        if dataToCalculate > strategy.opentrades.entry_price(2) 
            entrySL4Long3 := true
        else 
            entrySL4Long3 := false
    
        if entrySL4Long3 and close >  strategy.opentrades.entry_price(2)
            strategy.exit('exit3', from_entry = 'long3', stop = strategy.opentrades.entry_price(2))

if strategy.closedtrades > strategy.closedtrades[1]
    if strategy.closedtrades.exit_id(strategy.closedtrades-1) == 'exit3'
        entrySL4Long3 := false
    if strategy.closedtrades.exit_id(strategy.closedtrades-1) == 'exit2'
        entrySL4Long2 := false
    if strategy.closedtrades.exit_id(strategy.closedtrades-1) == 'exit1'
        entrySL4Long1 := false

    
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Entry
if dir3 < 0
    if dir2 > 0 and dir1 < 0
        strategy.entry('long1', strategy.long)
    else if dir2 < 0
        strategy.entry('long2', strategy.long, stop=superTrend1)
else
    if dir1 < 0 and highestGreen > 0
        strategy.entry('long3', strategy.long, stop=highestGreen)


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Exit
isUseAllDowntrendExit = input.bool(true, group = "Exit Type")
if isUseAllDowntrendExit and dir3 > 0 and dir2 > 0 and dir1 > 0 and close < open
    strategy.close_all()

isUseAvgPriceInLoss = input.bool(true, group = "Exit Type")
if isUseAvgPriceInLoss and strategy.position_avg_price > close //and strategy.position_avg_price <= close[1]
    //  and (dir1 > 0 or dir2 > 0 or dir3 > 0)
    //  and strategy.opentrades >= 1  
    //  and strategy.opentrades >= 3  
    strategy.close_all()

isUseAllPositionsInLoss = input.bool(false, group = "Exit Type")
if isUseAllPositionsInLoss
      and (
       false
         or (strategy.opentrades == 1 and ((not na(strategy.opentrades.entry_price(0))) and strategy.opentrades.entry_price(0) > close))

         or (strategy.opentrades == 1 and ((not na(strategy.opentrades.entry_price(0))) and strategy.opentrades.entry_price(0) > close)
             and ((not na(strategy.opentrades.entry_price(1))) and strategy.opentrades.entry_price(1) > close))

         or (strategy.opentrades == 1 and ((not na(strategy.opentrades.entry_price(0))) and strategy.opentrades.entry_price(0) > close)
             and ((not na(strategy.opentrades.entry_price(1))) and strategy.opentrades.entry_price(1) > close)
             and ((not na(strategy.opentrades.entry_price(2))) and strategy.opentrades.entry_price(2) > close))
         )
    strategy.close_all()


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Plot
plot(superTrend1, title='Fast Supertrend',      color=dir1 == 1 and dir1[1] == 1 ? color.red : dir1 == -1 and dir1[1] == -1 ? color.green : na)
plot(superTrend2, title='Medium Supertrend',    color=dir2 == 1 and dir2[1] == 1 ? color.red : dir2 == -1 and dir2[1] == -1 ? color.green : na)
plot(superTrend3, title='Slow Supertrend',      color=dir3 == 1 and dir3[1] == 1 ? color.red : dir3 == -1 and dir3[1] == -1 ? color.green : na)