Chiến lược đột phá xu hướng


Ngày tạo: 2023-09-28 15:54:32 sửa đổi lần cuối: 2023-09-28 15:54:32
sao chép: 1 Số nhấp chuột: 701
1
tập trung vào
1617
Người theo dõi

Tổng quan

Chiến lược này nhằm mục đích nắm bắt xu hướng mạnh mẽ trong thị trường tiền điện tử, sử dụng nhiều kênh và đường trung bình di chuyển để xác định các tín hiệu hình thành xu hướng, và kết hợp các chỉ số có thể lọc các đợt phá vỡ giả mạo, đồng thời sử dụng các điểm dừng thích ứng để khóa lợi nhuận, có thể đạt được lợi nhuận trong thị trường xu hướng.

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

Chiến lược này sử dụng kết hợp của các kênh nhanh, kênh chậm và đường trung bình di chuyển nhanh để xác định xu hướng. Cài đặt tham số kênh nhanh nhạy hơn, được sử dụng để nắm bắt biến động giá trong thời gian ngắn; tham số kênh chậm chậm hơn, được sử dụng để đánh giá xu hướng lớn; tham số trung bình di chuyển nhanh nằm giữa hai thứ này và tạo ra tín hiệu giao dịch khi nó phá vỡ kênh.

Cụ thể, nó đầu tiên tính toán đường đua lên xuống của kênh nhanh, và trung bình di chuyển. Khi giá phá vỡ đường đua lên, nếu đường đua dưới của kênh chậm cũng nằm trên trung bình di chuyển, nó sẽ tạo ra một tín hiệu nhiều; ngược lại, khi phá vỡ đường đua xuống để xác định liệu đường đua trên của kênh chậm có nằm dưới trung bình di chuyển hay không, nó sẽ tạo ra một tín hiệu trống.

Ngoài ra, nó cũng phát hiện hình dạng K-line, yêu cầu một số K-line được sắp xếp theo thứ tự để lọc các đột phá giả mạo; và tính toán chỉ số biến động giá để tránh bị mắc kẹt trong các biến động trong kênh; thêm chỉ số khối lượng giao dịch để đảm bảo rằng thời gian đột phá có thể theo dõi.

Đối với Stop Loss, chiến lược này sử dụng Stop Loss thích ứng. Động thái điều chỉnh Stop Loss theo biến động trong khoảng thời gian gần đây. Điều này có thể truy lại càng nhiều càng tốt trong khi đảm bảo Stop Loss.

Phân tích lợi thế

Ưu điểm lớn nhất của chiến lược này là các quy tắc phán đoán hình thành tín hiệu giao dịch khá nghiêm ngặt, có thể lọc hiệu quả các đột phá giả không có xu hướng, thực sự bắt được điểm biến đổi xu hướng trên thị trường. Cụ thể, có một số khía cạnh chính như sau:

  1. Sự kết hợp của nhiều kênh và trung bình di chuyển, tiêu chuẩn phán đoán nghiêm ngặt, có thể làm giảm khả năng sai lầm.

  2. K-đường được sắp xếp theo thứ tự để tránh tín hiệu sai của K-đường đơn lẻ.

  3. Kết hợp với chỉ số biến động giá, bạn có thể đánh giá xem có phải bạn đang vào đợt cân bằng hay không, và tránh bỏ lỡ cơ hội đảo ngược.

  4. Thêm chỉ số năng lượng định lượng, chỉ khi số lượng xuất hiện cùng với giá sẽ tạo ra tín hiệu, tránh phá vỡ không hiệu quả.

  5. Cơ chế tự điều chỉnh dừng lỗ, có thể khóa tối đa lợi nhuận theo xu hướng trong trường hợp đảm bảo dừng lỗ.

Do đó, chiến lược này có các đặc điểm như tối ưu hóa cấu hình, quyết định nghiêm ngặt, tự thích ứng với tổn thất, rất phù hợp để nắm bắt xu hướng.

Phân tích rủi ro

Mặc dù chiến lược này đã được tối ưu hóa rất nhiều trong việc lọc các xu hướng đột nhập và chặn giả mạo, nhưng vẫn có một số rủi ro cần lưu ý:

  1. Thiết lập tham số quá phức tạp, kết hợp các tham số khác nhau có hiệu quả khác nhau, cần phải thử nghiệm rất nhiều để tìm tham số tối ưu, thiết lập không đúng có thể tạo ra quá nhiều tín hiệu sai.

  2. Các đường trung bình nhanh và các khoảng cách qua giờ có thể tạo ra các vị trí mở và đóng thường xuyên, không có lợi cho xu hướng theo dõi lâu dài.

  3. Mức dừng lỗ của cơ chế tự điều chỉnh được tính dựa trên chênh lệch chuẩn đơn giản, có thể dừng lỗ quá nhỏ đối với các tình huống cực đoan.

  4. Nó là một trong những yếu tố quan trọng trong sự thay đổi cơ bản của nền kinh tế.

  5. Chiến lược này thuộc chiến lược theo dõi xu hướng và hoạt động kém hơn trong thị trường biến động.

Đối với những rủi ro này, các biện pháp sau đây được đề xuất để kiểm soát:

  1. Đánh giá lại đầy đủ để xác định các tham số tốt nhất, cũng có thể xem xét các phương pháp tối ưu hóa tham số bằng cách sử dụng học máy.

  2. Việc mở rộng khoảng cách kênh thích hợp, chu kỳ chuyển trung bình cũng có thể được kéo dài thích hợp, giảm tần suất mở kho không cần thiết.

  3. Các mô hình tính toán tỷ lệ dao động tiên tiến hơn như quỹ bảo hiểm có thể được xem xét.

  4. Hãy tham khảo thông tin cơ bản khi cần thiết và tránh giao dịch chỉ dựa trên chỉ số kỹ thuật.

  5. Tăng khả năng đánh giá thị trường, tạm dừng giao dịch trong một thị trường bất ổn.

Hướng tối ưu hóa

Chiến lược này có thể được tối ưu hóa thêm như sau:

  1. Thêm thuật toán học máy để thực hiện tối ưu hóa tham số tự động. Có thể ghi lại hiệu suất tham số trong các môi trường thị trường khác nhau, tạo bảng truy vấn, tối ưu hóa động.

  2. Tăng khả năng đánh giá tình trạng thị trường, chẳng hạn như tăng khả năng đánh giá xu hướng hay biến động, tạm dừng giao dịch trong thị trường biến động để tránh tổn thất không cần thiết.

  3. Tối ưu hóa chiến lược dừng lỗ, bạn có thể xem xét các phương pháp dừng lỗ khác như theo dõi dừng lỗ, dừng tỷ lệ.

  4. Thêm các yếu tố cơ bản, phát ra cảnh báo khi xảy ra sự kiện cơ bản quan trọng, tránh thiệt hại chỉ với chỉ số kỹ thuật.

  5. Tối ưu hóa danh mục, kết hợp chiến lược này với các danh mục chiến lược khác không liên quan, có thể làm phân tán rủi ro hơn nữa.

  6. Tham gia vào khung giao dịch định lượng, tự động thực hiện tín hiệu và kiểm soát rủi ro nghiêm ngặt.

Tóm tắt

Nói chung, chiến lược này rất phù hợp để nắm bắt cơ hội xu hướng trong thị trường tiền điện tử. Nó sử dụng nhiều kênh và trung bình di chuyển để tạo tín hiệu giao dịch và lọc hiệu quả tiếng ồn phá vỡ giả, thành công trong việc khóa lợi nhuận xu hướng. Tuy nhiên, vẫn cần chú ý đến các vấn đề như tối ưu hóa tham số, cách dừng lỗ và đánh giá tình trạng thị trường.

Mã nguồn chiến lược
/*backtest
start: 2022-09-21 00:00:00
end: 2023-09-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Extremely Overfit", overlay=true, commission_type=strategy.commission.percent, commission_value=.16, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding = 1)
price = close

goLong = input(title="go long?", type=input.bool, defval=true)
goShort = input(title="go short?", type=input.bool, defval=true)
//trendRestrict = input(title="basic trend restriction?", type=input.bool, defval=false)
dynamicRestrict = true //input(title="dynamic trend restriction?", type=input.bool, defval=true)
longtrendimpt = true //input(title="additional weight on long-term trends?", type=input.bool, defval=true)
volRestrict = true //input(title="volume restriction?", type=input.bool, defval=true)
conservativeClose = false //input(title="conservative order closing?", type=input.bool, defval=false)

Restrictiveness = input ( -40,step=10,title ="Restrictiveness (higher = make fewer trades)")
volatilityImportance = 3.2 //input( 3.2, step = 0.1, minval = 0)
fastChannelLength = input( 6 )
fastChannelMargin = input ( 3.2, step = 0.1, minval = 0)
slowChannelLength = input ( 6, step = 1, minval = 0)
slowChannelMargin = input ( 1.5, step = 0.1, minval = 0)
fastHMAlength = input (4, step = 1, minval = 0)
stopLoss = input( 3, step = 0.1, minval = 0)
//altClosePeriod = input( 27, step = 1, minval = 1)
//altCloseFactor = input( 4.9, step = 0.1)
stopLossFlexibility = 50 //input(50, step=10, title="effect of volatility on SL?")
volumeMAlength = 14 //input ( 14, step = 1, minval = 1)
volumeVolatilityCutoff = 3.8 // ( 3.8, step = 1, minval = 0)
trendSensitivity = 3.8 //input ( 3.8, step = 0.1)
obvLookback = 10 //input(10, step = 10, minval = 10)
obvCorrThreshold = 0.89 //input(0.89, step = 0.01)
ROClength = 80 //input( 80, step = 10)
ROCcutoff = 5.6 //input( 5.6, step=0.1)

trendRestrict = false
//trendLookback = input ( 360, step = 10, minval = 10)
//longTrendLookback = input(720, step = 10, minval = 10)
//longTrendImportance = input(1.5, step = 0.05)
trendLookback = 360
longTrendLookback = 720
longTrendImportance = 1.5

//conservativeness = input( 2.4, step = 0.1)
conservativeness = 0
//trendPower = input( 0, step=1)
trendPower = 0
//conservativenessLookback = input( 650, step = 10, minval = 0)
conservativenessLookback = 10
//consAffectFactor = input( 0.85,step=0.01)
consAffectFactor = 0.85
//volatilityLookback = input(50, step=1, minval=2)
volatilityLookback = int(50)
recentVol = stdev(price,volatilityLookback)/sqrt(volatilityLookback)

//price channel

fastChannel = ema(price, fastChannelLength)
fastChannelUB = fastChannel * (1 + (float(fastChannelMargin) / 1000)) + (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
fastChannelLB = fastChannel * (1 - (float(fastChannelMargin) / 1000)) - (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
fchU = ((fastChannelUB < open) and (fastChannelUB < close))
fchL = ((fastChannelLB > open) and (fastChannelLB > close))
//plot(fastChannelUB)
//plot(fastChannelLB)

//slow channel
//slowChannelLBmargin = input ( 2, step = 0.1, minval = 0 )
slowChannel = ema(ema(price,slowChannelLength),slowChannelLength)
slowChannelUB = slowChannel * (1 + (float(slowChannelMargin) / 2000)) + (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
slowChannelLB = slowChannel * (1 - (float(slowChannelMargin) / 2000)) - (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
schU = ((slowChannelUB < close))
schL = ((slowChannelLB > close))
cschU = (((slowChannelUB * (1 + conservativeness)) < close))
cschL = (((slowChannelUB * (1 - conservativeness)) > close))
//plot(slowChannel,color = #00FF00)
//plot(slowChannelUB,color = #00FF00)
//plot(slowChannelLB,color = #00FF00)


fastHMA = hma(price,fastHMAlength)
fastAboveUB = (fastHMA > slowChannelUB)
fastBelowLB = (fastHMA < slowChannelLB)
//plot(fastHMA, color = 	#FF0000, linewidth = 2)

//consecutive candles
//consecutiveCandlesReq = input(1, step = 1, minval = 1, maxval = 4)
consecutiveCandlesReq = 1
consecutiveBullReq = float(consecutiveCandlesReq)
consecutiveBearReq = float(consecutiveCandlesReq)
cbull = ((close[0] > close[1]) and (consecutiveBullReq == 1)) or (((close[0] > close[1]) and (close[1] > close[2])) and consecutiveBullReq == 2) or (((close[0] > close[1]) and (close[1] > close[2]) and (close[2] > close[3])) and consecutiveBullReq == 3) or (((close[0] > close[1]) and (close[1] > close[2]) and (close[2] > close[3]) and (close[3] > close[4])) and consecutiveBullReq == 4)
cbear = ((close[0] < close[1]) and (consecutiveBearReq == 1)) or (((close[0] < close[1]) and (close[1] < close[2])) and consecutiveBearReq == 2) or (((close[0] < close[1]) and (close[1] < close[2]) and (close[2] < close[3])) and consecutiveBearReq == 3) or (((close[0] < close[1]) and (close[1] < close[2]) and (close[2] < close[3]) and (close[3] < close[4])) and consecutiveBearReq == 4)

//trend detection
//trendCutoff = input(0, step = 0.1)
trendCutoff = 0
trendDetectionPct = float(trendCutoff/100)
trendVal = float((close[0] - close[trendLookback])/close[0])
trendUp = (trendVal > (0 + trendDetectionPct))
trendDown = (trendVal < (0 - trendDetectionPct))
//plot(trendVal+36.5,linewidth=2)

// peak indicators
peakHigh = ((fastHMA > fastChannelUB) and (fastChannelLB > slowChannelUB))
peakLow = ((fastHMA < fastChannelLB) and (fastChannelUB < slowChannelLB))
TpeakHigh = (fastHMA > fastChannelUB) and (fastChannelUB > slowChannelUB)
TpeakLow = (fastHMA < fastChannelUB) and (fastChannelLB < slowChannelLB)
//TpeakHigh = (fastHMA > fastChannelUB) and (fastChannelLB > avg(slowChannelUB,slowChannelLB))
//TpeakLow = (fastHMA < fastChannelUB) and (fastChannelUB < avg(slowChannelLB,slowChannelUB))
//TpeakHigh = ((crossover(fastHMA,fastChannelUB)) and (fastChannelLB > slowChannelUB))
//TpeakLow = ((crossover(fastChannelLB,fastHMA)) and (fastChannelUB < slowChannelLB))
//TpeakHigh = (fastHMA > (fastChannelUB * (1 + (trendPower/800)))) and (fastChannelUB > (slowChannelUB * (1 + (trendPower/800))))
//TpeakLow = (fastHMA < (fastChannelUB * (1 - (trendPower/800)))) and (fastChannelLB < (slowChannelLB * (1 - (trendPower/800))))
//TpeakHigh = (fastHMA > (fastChannelUB * (1 + (trendPower/800)))) and (avg(fastChannelUB,fastChannelLB) > (slowChannelUB * (1 + (trendPower/800))))
//TpeakLow = (fastHMA < (fastChannelUB * (1 - (trendPower/800)))) and (avg(fastChannelLB,fastChannelUB) < (slowChannelLB * (1 - (trendPower/800))))
//plot(fastChannelUB * (1 + (trendPower/700)), color=#FF69B4)

// and for closing...
closeLong = (crossover(fastHMA,fastChannelUB) and (fastChannelLB > slowChannelUB))
closeShort = (crossover(fastChannelLB,fastHMA) and (fastChannelUB < slowChannelLB))
//closeLong = (crossover(fastHMA,fastChannelUB) and (fastChannelLB > slowChannelUB)) or (roc(price,altClosePeriod) > altCloseFactor)
//closeShort = (crossover(fastChannelLB,fastHMA) and (fastChannelUB < slowChannelLB))  or (roc(price,altClosePeriod) < (altCloseFactor) * -1)
//closeLong = (crossover(fastHMA,fastChannelUB) and (fastChannelLB > slowChannelUB)) or (((price - fastChannelUB) > (altCloseFactor * abs(((fastChannelUB - fastChannelLB)/2) - ((slowChannelUB - slowChannelLB)/2)))) and (fastChannelLB > slowChannelUB))
//closeShort = (crossover(fastChannelLB,fastHMA) and (fastChannelUB < slowChannelLB)) or (((fastChannelLB - price) > (altCloseFactor * abs(((fastChannelUB - fastChannelLB)/2) - ((slowChannelUB - slowChannelLB)/2)))) and (fastChannelUB < slowChannelLB))
//closeLong = crossover(fastHMA,fastChannelUB) and ((fastChannelLB[0] - fastChannelLB[1]) < (slowChannelUB[0] - slowChannelUB[1]))
//closeShort = crossover(fastChannelLB,fastHMA) and ((fastChannelUB[0] - fastChannelUB[1]) > (slowChannelLB[0] - slowChannelLB[1]))


//stop-loss
priceDev = stdev(price,trendLookback) * (1 + stopLossFlexibility/5)
stopLossMod = stopLoss * (1 + (priceDev/price))
//longStopPrice  = strategy.position_avg_price * (1 - (stopLoss/100))
//shortStopPrice = strategy.position_avg_price * (1 + (stopLoss/100))
longStopPrice  = strategy.position_avg_price * (1 - (stopLossMod/100))
shortStopPrice = strategy.position_avg_price * (1 + (stopLossMod/100))


// volume
volumeMA = ema(volume,volumeMAlength)
volumeDecrease = ((not volRestrict ) or (volumeMA[0] < ema(volumeMA[1] * (1 - (volumeVolatilityCutoff/100)),5)))
volumeCutoff = ema(volumeMA[1] * (1 - (volumeVolatilityCutoff/100)),5)
//plot(volumeMA)
//plot(volumeCutoff)

// detect volatility
//trendinessLookback = input ( 600, step = 10, minval = 0)
trendinessLookback = trendLookback
trendiness = (stdev(price,trendinessLookback)/price) * (1 - (Restrictiveness/100))
longtermTrend = ((price - price[longTrendLookback])/price)
//dynamicTrendDetected = (dynamicRestrict and (abs(trendiness * 100) < trendSensitivity))
dynamicTrendDetected = (longtrendimpt and (dynamicRestrict and (abs(trendiness * 100) < (trendSensitivity+(longtermTrend * longTrendImportance))))) or (not longtrendimpt and ((dynamicRestrict and (abs(trendiness * 100) < trendSensitivity))))

// adapt conservativeness to volatility

//consVal = sma(((stdev(price,conservativenessLookback))/price)*100,25)
consVal = sma(((stdev(price,conservativenessLookback))/price)*100,25)
cVnorm = sma(avg(consVal,3),60)
cVal = consVal - cVnorm

//conservativenessMod = conservativeness * (cVal * consAffectFactor)
conservativenessMod = conservativeness * (consVal * consAffectFactor)
//plot(consVal,linewidth=4)
//plot(cVnorm,color = #00FF00)
//plot(cVal,linewidth=2)

// ROC cutoff (for CLOSING)
//rocCloseLong = (ema(roc(price,ROClength),10) > ROCcutoff)
//rocCloseShort = (ema(roc(price,ROClength),10) < (ROCcutoff * -1))
ROCval = roc(price,ROClength)
ROCema = ema(ROCval,30)
ROCabs = abs(ROCema)
ROCallow = ROCabs < ROCcutoff
ROCallowLong = (ROCabs < ROCcutoff)  or ((ROCabs >= ROCcutoff) and ((fastChannelLB < slowChannelLB) and (fastHMA < fastChannelLB)))
ROCallowShort = (ROCabs < ROCcutoff) or ((ROCabs >= ROCcutoff) and ((fastChannelUB > slowChannelUB) and (fastHMA > fastChannelUB)))
//plot(ROCallow)

// obv
evidence_obv = (correlation(price,obv[0],obvLookback))
obvAllow = evidence_obv > obvCorrThreshold


//if (not na(vrsi))
if trendRestrict or dynamicTrendDetected
    //if (strategy.position_size == 0)
    if not (strategy.position_size < 0)
        if trendUp
        	//if cbear and schL and fchL and trendUp and goLong
        	if cbear and TpeakLow and volumeDecrease and ROCallow and goLong and obvAllow
        	//if cbear and peakLow and rocHigh and volumeDecrease and goLong
        		strategy.entry("Long", strategy.long, comment="Long")
    if not (strategy.position_size > 0)
        if trendDown
        	//if cbull and schU and fchU and trendDown and goShort
        	if cbull and TpeakHigh and volumeDecrease and ROCallow and goShort and obvAllow
        	//if cbull and peakHigh and rocLow and volumeDecrease and goShort
        		strategy.entry("Short", strategy.short, comment="Short")
else
    //if (strategy.position_size == 0)
    if not (strategy.position_size < 0)
        //if cbear and peakLow and goLong
    	//if cbear and peakLow and volumeDecrease and ROCallow and goLong
    	if TpeakLow and goLong and obvAllow
    		strategy.entry("Long", strategy.long, comment="Long")
    if not (strategy.position_size > 0)
        //if cbull and peakHigh and goShort
    	//if cbull and peakHigh and volumeDecrease and ROCallow and goShort
    	if TpeakHigh and goShort and obvAllow
    		strategy.entry("Short", strategy.short, comment="Short")

if conservativeClose
    //pkHigh = ((fastHMA > fastChannelUB) and (fastChannelUB > (slowChannelUB * (1 + conservativeness/1000))))
    //pkLow = ((fastHMA < fastChannelLB) and (fastChannelLB < (slowChannelLB * (1 - conservativeness/1000))))
    //pkHigh = ((fastHMA > fastChannelUB) and (fastChannelUB > (slowChannelUB * (1 + conservativenessMod/1000))))
    //pkLow = ((fastHMA < fastChannelLB) and (fastChannelLB < (slowChannelLB * (1 - conservativenessMod/1000))))
    pkHigh = ((fastHMA > fastChannelUB) and (fastChannelUB > (slowChannelUB * (1 + ((conservativenessMod/1000) * (1 - Restrictiveness/100))))))
    pkLow = ((fastHMA < fastChannelLB) and (fastChannelLB < (slowChannelLB * (1 - ((conservativenessMod/1000) * (1 - Restrictiveness/100))))))
    
    if (strategy.position_size > 0)
        //if fastAboveUB
        //if pkHigh and closeLong
        if closeLong
    		strategy.close("Long", comment="closeLong")
    if (strategy.position_size < 0)
        //if fastBelowLB
        //if pkLow and closeShort
        if closeShort
    		strategy.close("Short", comment="closeShort")
else
    if (strategy.position_size > 0)
        //if fastAboveUB
        if peakHigh
    		strategy.close("Long", comment="closeLong")
    if (strategy.position_size < 0)
        //if fastBelowLB
        if peakLow
    		strategy.close("Short", comment="closeShort")

if (strategy.position_size > 0)
    strategy.exit(id="Long", stop=longStopPrice, comment="stopLong")

if (strategy.position_size < 0)
    strategy.exit(id="Short", stop=shortStopPrice, comment="stopShort")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)