Trong bài viết này, chúng tôi sẽ giới thiệu một chiến lược định lượng sử dụng đột phá kênh để giao dịch xu hướng. Chiến lược này sử dụng kênh EMA để xác định xu hướng xu hướng, và Brin đánh giá ngược lại để hoạt động ngược lại.
A. Nguyên tắc chiến lược
Chiến lược này bao gồm các yếu tố sau:
Thiết lập đường EMA trung tâm và mở rộng các kênh lên xuống theo tỷ lệ;
Khi giá vượt qua đường dẫn trên, hãy theo dõi nhiều hơn; Khi giá vượt qua đường dẫn dưới, hãy theo dõi trống;
Khi Blink bị thu hẹp, hãy đánh giá xu hướng và thực hiện các hoạt động đảo ngược.
Thiết lập ATR để hạn chế rủi ro mất mát
Bạn có thể tùy chỉnh các tham số kênh để tìm các tham số kết hợp tốt nhất.
Chiến lược này sử dụng EMA để đánh giá xu hướng chính, và sử dụng Brin để xác định cơ hội đảo ngược và tạo thành một hệ thống xu hướng hoàn chỉnh.
2 - Lợi thế chiến lược
Lợi thế lớn nhất của chiến lược này là chỉ số được sử dụng hợp lý, EMA đánh giá chủ đạo, và Brin bắt được sự đảo ngược.
Một lợi thế khác là các thiết lập dừng lỗ có hiệu quả trực tiếp, có thể kiểm soát rủi ro.
Cuối cùng, các tham số có thể được tùy chỉnh và có thể được tối ưu hóa cho các giống khác nhau.
Ba, rủi ro tiềm ẩn
Tuy nhiên, chiến lược này cũng có những vấn đề:
Đầu tiên, cả EMA và BRI đều bị tụt hậu.
Thứ hai, cần xem xét rủi ro thất bại của việc đảo ngược.
Cuối cùng, tối ưu hóa tham số cần rất nhiều công việc để tránh quá tối ưu hóa.
Bốn nội dung, tóm tắt
Bài viết này mô tả chi tiết một chiến lược sử dụng đột phá EMA để giao dịch xu hướng. Chiến lược này có thể nhận ra xu hướng chính và thực hiện hoạt động đảo ngược tại các điểm xoay. Chiến lược này có thể đạt được lợi nhuận ổn định thông qua tối ưu hóa tham số, nhưng cũng cần kiểm soát các vấn đề như khó tối ưu hóa và chậm trễ của chỉ số.
/*backtest
start: 2023-08-15 00:00:00
end: 2023-09-14 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="[mdeacey] EMA Percentage Channel + Bollinger Band Trending Strategy", shorttitle="[mdeacey] EMA% Channel + BB Trend Strategy", overlay=true)
//EMA 200
len = input(title="EMA Length", type=input.integer, defval=100)
srce = input(title="EMA Source", type=input.source, defval=close)
ema1= ema(srce,len)
percent = input(title="Inside Channel (%)", type=input.float, defval= 1)
valuee = (percent*ema1)/100
upperbande = ema1 + valuee
lowerbande = ema1 - valuee
///2
percent2 = input(title="Outside Channel (%)", type=input.float, defval= 2)
valuee2 = (percent2*ema1)/100
upperbande2 = ema1 + valuee2
lowerbande2 = ema1 - valuee2
plot(upperbande, title='Inside Channel Upperband', color=color.black, linewidth=1, style=plot.style_line )
plot(lowerbande, title='Inside Channel Lowerband', color=color.black, linewidth=1, style=plot.style_line )
plot(upperbande2, title='Outside Channel Upperband', color=color.black, linewidth=1, style=plot.style_line )
plot(lowerbande2, title='Outside Channel Lowerband', color=color.black, linewidth=1, style=plot.style_line )
length = input(20, minval=2)
src = input(close, title="Close price")
mult = input(2.0, title="Multiplier", minval=0.001, maxval=50)
MA2 = sma(src, length)
dev = mult * stdev(src, length)
upper = MA2 + dev
lower = MA2 - dev
signalColor = crossunder(close, upper) ? color.red : crossover(close, lower) ? color.green : color.white
barcolor(color=signalColor)
nopo= strategy.position_size==0
upperBand = plot(upper, title='Upper Bollinger Band', color=color.gray, linewidth=1)
lowerBand = plot(lower, title='Lower Bollinger Band', color=color.gray, linewidth=1)
fill(upperBand, lowerBand, title='Bollinger Band', color=color.black)
strategy.entry("Long",true,when = crossover(close,lower) and close <lowerbande and close>lowerbande2)
strategy.close("Long",when = crossunder(close,lowerbande2))//crossunder(close,lowerbande) or crossunder(close,lowerbande2))
strategy.entry("Short",false,when = crossunder(close,upper) and close >upperbande and close<upperbande2)
strategy.close("Short",when = crossover(close,upperbande2) )//crossover(close,upperbande) or crossover(close,upperbande2) )
//Inputs
atrPeriod = input(defval=14, title="ATR Period",group='ATR Stoploss', type=input.integer) // Adjust this to change the ATR calculation length
multiplierPeriod = input(defval=1.75, title="ATR Multiplier",group='ATR Stoploss', type=input.float)// Adjust this to change the distance between your candles and the line
//ATR Calculation
pine_rma(x, y) =>
alpha = y
sum = 0.0
sum := (x + (alpha - 1) * nz(sum[1])) / alpha
true_range() =>
max(high - low, max(abs(high - close[1]), abs(low - close[1])))
//Long SL
plot(low - pine_rma(true_range() * multiplierPeriod, atrPeriod), "Long Stop", color=color.red, offset = 1)
// Short SL
plot(high +pine_rma(true_range() * multiplierPeriod, atrPeriod), "Short Stop", color=color.red, offset = 1)
strategy.exit("Exit","Long",limit=upper ,stop = low - pine_rma(true_range() * multiplierPeriod, atrPeriod) )
strategy.exit("Exit","Short",limit=lower ,stop =high +pine_rma(true_range() * multiplierPeriod, atrPeriod) )
/////////////////////new strategy
strategy.entry("Long",true,stop =upperbande ,when = close <upperbande and close[1] <upperbande and nopo )
strategy.close("Long",when = crossunder(close,upper) )// and close <upperbande and close>lowerbande)
strategy.entry("Short",false,stop =lowerbande ,when = close >lowerbande and close[1] >lowerbande and nopo )
strategy.close("Short",when = crossover(close, lower) )
strategy.exit("Exit","Long",stop = low - pine_rma(true_range() * multiplierPeriod, atrPeriod) )
strategy.exit("Exit","Short",stop =high +pine_rma(true_range() * multiplierPeriod, atrPeriod) )