Chiến lược theo dõi xu hướng Dynamic Squeeze Breakout

Tác giả:ChaoZhang, Ngày: 2023-11-13 17:46:01
Tags:

img

Tổng quan

Chiến lược này dựa trên chỉ số Squeeze Momentum của LazyBear, kết hợp Bollinger Bands và Keltner Channels để xác định sự đột phá giá từ nén kênh và mở rộng để xác định hướng xu hướng tiềm năng của giá, và áp dụng cách tiếp cận theo xu hướng để quyết định hướng nhập cảnh.

Chiến lược logic

  1. Tính toán dải giữa, dải trên và dải dưới của Bollinger Bands. Dải giữa là trung bình di chuyển đơn giản n ngày của giá đóng, dải trên và dải dưới là dải giữa cộng/từ m lần lệch chuẩn n ngày của giá đóng.

  2. Tính toán đường giữa, đường trên và đường dưới của Keltner Channels.

  3. Xác định giá có vượt qua dải trên hoặc dưới của Bollinger Bands và Keltner Channels để hình thành các mô hình nén và mở rộng không.

  4. Tính toán giá trị của đường cong hồi quy tuyến tính như một chỉ số động lực.

  5. Kết hợp các mô hình nén / mở rộng, hướng động lực, lọc trung bình và các điều kiện khác để xác định tín hiệu giao dịch cuối cùng.

Ưu điểm của Chiến lược

  1. Sử dụng lọc đôi các dải Bollinger và kênh Keltner để xác định các mô hình nén và mở rộng chất lượng.

  2. Chỉ số động lực có thể nắm bắt kịp thời sự đảo ngược xu hướng giá, bổ sung cho các chỉ số kênh.

  3. Cho phép nhập cảnh sớm để tăng cơ hội lợi nhuận.

  4. Adopt multiple condition judgment to avoid over-trading during ranging markets (Phát nhận quyết định nhiều điều kiện để tránh giao dịch quá mức trong các thị trường khác nhau).

  5. Các tham số chỉ số kỹ thuật có thể tùy chỉnh, thích nghi với các sản phẩm và kết hợp tham số khác nhau.

  6. Khung thời gian backtest có thể được thiết lập để tối ưu hóa trong các khoảng thời gian cụ thể.

Rủi ro của chiến lược

  1. Các chiến lược theo xu hướng có xu hướng thua lỗ khi xu hướng đảo ngược.

  2. Cài đặt tham số không chính xác có thể dẫn đến giao dịch quá mức hoặc chất lượng tín hiệu kém.

  3. Việc dựa vào dữ liệu lịch sử không thể đảm bảo lợi nhuận ổn định trong tương lai.

  4. Không thể xử lý biến động thị trường và biến động giá mạnh do các sự kiện thiên nga đen.

  5. Cài đặt cửa sổ thời gian backtest không chính xác có thể dẫn đến quá tải.

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

  1. Tối ưu hóa các thông số của Bollinger Bands và Keltner Channels để tìm kết hợp tốt nhất.

  2. Kiểm tra thêm stop loss để kiểm soát lỗ tối đa cho mỗi giao dịch.

  3. Cố gắng tối ưu hóa thêm cho các sản phẩm cụ thể và kết hợp thời gian / tham số.

  4. Khám phá việc tích hợp các mô hình học máy để xác định sự đảo ngược xu hướng.

  5. Kiểm tra các chiến lược thứ tự nhập và kích thước vị trí khác nhau.

  6. Nghiên cứu làm thế nào để xác định các tín hiệu đảo ngược xu hướng và thoát khỏi thời gian.

Tóm lại

This strategy integrates multiple technical indicators to judge price trend direction and follow the trend, having relatively strong adaptability. By customizing parameters and using multiple condition filters, it can effectively control trading frequency and improve signal quality. But reversal trades and black swan events should still be watched out for.


/*backtest
start: 2022-11-06 00:00:00
end: 2023-11-12 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//Strategy based on LazyBear Squeeze Momentum Indicator
//I added some custom feature and filters
//
// @author LazyBear
// List of all my indicators:
// https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
// v2 - fixed a typo, where BB multipler was always stuck at 1.5. [Thanks @ucsgears]
//
strategy(shorttitle = "SQZMOM_LB", title="Strategy for Squeeze Momentum Indicator [LazyBear]", overlay=false, calc_on_every_tick=true, pyramiding=0,default_qty_type=strategy.percent_of_equity,default_qty_value=100,currency=currency.USD)

length = input(14, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(16, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
 
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)

//FILTERS
useExtremeOrders  = input(false, title="Early entry on momentum change", type=bool)
useMomAverage = input(false, title="Filter for Momenutum value", type=bool)
MomentumMin = input(20, title="Min for momentum")

// Calculate BB
src = close
basis = sma(src, length)
dev = mult * stdev(src, length)
upperBB = basis + dev
lowerBB = basis - dev
 
// Calculate KC
ma = sma(src, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
 
sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)
 
val = linreg(src  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)
 
bcolor = iff( val > 0,            iff( val > nz(val[1]), lime, green),            iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : aqua
plot(val, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)

//LOGIC
//momentum filter
filterMom=useMomAverage?abs(val)>(MomentumMin/100000)?true:false:true

//standard condition
longCondition = scolor[1]!=aqua and scolor==aqua and bcolor==lime and filterMom
exitLongCondition = bcolor==green and not useExtremeOrders
shortCondition = scolor[1]!=aqua and scolor==aqua and bcolor==red and filterMom
exitShortCondition = bcolor==maroon and not useExtremeOrders

//early entry
extremeLong= useExtremeOrders and scolor==aqua and bcolor==maroon and bcolor[1]!=bcolor[0] and filterMom
exitExtLong = scolor==black or bcolor==red
extremeShort = useExtremeOrders and scolor==aqua and bcolor==green and bcolor[1]!=bcolor[0] and filterMom
exitExtShort = scolor==black or bcolor==lime

//STRATEGY

strategy.entry("SQ_Long", strategy.long, when = longCondition)
strategy.close("SQ_Long",when = exitLongCondition )

strategy.entry("SQ_Long_Ext", strategy.long, when = extremeLong)
strategy.close("SQ_Long_Ext",when = exitExtLong)
//strategy.exit("exit Long", "SQ_Long", when = exitLongCondition)

strategy.entry("SQ_Short", strategy.short, when = shortCondition)
strategy.close("SQ_Short",when = exitShortCondition)

strategy.entry("SQ_Short_Ext", strategy.short, when = extremeShort)
strategy.close("SQ_Short_Ext",when = exitExtShort)
//strategy.exit("exit Short", "SQ_Short", when = exitShortCondition)



// // === Backtesting Dates === thanks to Trost

// testPeriodSwitch = input(true, "Custom Backtesting Dates")
// testStartYear = input(2018, "Backtest Start Year")
// testStartMonth = input(1, "Backtest Start Month")
// testStartDay = input(1, "Backtest Start Day")
// testStartHour = input(0, "Backtest Start Hour")
// testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,testStartHour,0)
// testStopYear = input(2018, "Backtest Stop Year")
// testStopMonth = input(12, "Backtest Stop Month")
// testStopDay = input(14, "Backtest Stop Day")
// testStopHour = input(23, "Backtest Stop Hour")
// testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,testStopHour,0)
// testPeriod() =>
//     time >= testPeriodStart and time <= testPeriodStop ? true : false
// isPeriod = testPeriodSwitch == true ? testPeriod() : true
// // === /END

// if not isPeriod
//     strategy.cancel_all()
//     strategy.close_all()
        



Thêm nữa