10EMA Chiến lược theo dõi xu hướng chéo kép

Tác giả:ChaoZhang, Ngày: 2023-12-29 16:03:55
Tags:

img

Tổng quan

Chiến lược này là một chiến lược theo dõi xu hướng dựa trên đường chéo kép của 10EMA và 50EMA. Nó kết hợp 10EMA trên biểu đồ hàng giờ như một phán đoán phụ để tìm động hướng xu hướng trong thị trường bò và gấu xen kẽ và đạt được việc theo dõi dừng lỗ tự động.

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

Lý thuyết cốt lõi của chiến lược dựa trên đường chéo vàng và đường chéo chết của 10EMA và 50EMA. Cụ thể, khi 10EMA vượt qua trên 50EMA để tạo thành đường chéo vàng, nó được đánh giá là thị trường đã bước vào xu hướng tăng; khi 10EMA vượt qua dưới 50EMA để tạo thành đường chéo chết, nó được đánh giá là thị trường đã bước vào xu hướng giảm.

Mở các vị trí dài hoặc ngắn trong vòng 1-5 thanh sau đường chéo vàng hoặc đường chéo chết. Ngoài ra, chiến lược cũng giới thiệu 10EMA trên biểu đồ hàng giờ như một phán quyết phụ trợ. Các vị trí dài chỉ được mở khi 10EMA trên biểu đồ hàng giờ có xu hướng tăng sau đường chéo vàng, và các vị trí ngắn chỉ được mở khi 10EMA trên biểu đồ hàng giờ có xu hướng giảm sau đường chéo chết, do đó lọc ra một số tín hiệu sai.

Sau khi mở các vị trí, chiến lược sử dụng phương pháp lấy lợi nhuận và dừng lỗ theo dõi lệnh dừng lỗ + lệnh giới hạn. Theo dõi lệnh dừng lỗ có thể khóa lợi nhuận và tối đa hóa lợi nhuận của giao dịch; lệnh giới hạn đảm bảo rằng các vị trí được đóng khi giá đạt mục tiêu để có được lợi nhuận.

Phân tích lợi thế

Ưu điểm lớn nhất của chiến lược này là trong khi sử dụng đường EMA để đánh giá hướng xu hướng chính, nó cũng giới thiệu các chỉ số phụ để lọc tín hiệu, có thể lọc hiệu quả các đường chéo sai để cải thiện độ tin cậy tín hiệu.

So với các chiến lược chỉ số duy nhất, chiến lược này có thể đánh giá chính xác hơn hướng xu hướng và kích thước.

Phân tích rủi ro

Rủi ro chính mà chiến lược này phải đối mặt là những cú đánh đập và đảo chiều xu hướng gián đoạn. Khi các tín hiệu giao thoa sai liên tiếp xảy ra, chiến lược có thể bị hủy bỏ. Ngoài ra, sự đảo ngược giá sau khi mở các vị trí cũng có thể dẫn đến tổn thất.

Để giảm nguy cơ whipsaws, các chỉ số phụ trợ được thêm vào để lọc các tín hiệu. Để kiểm soát nguy cơ đảo ngược xu hướng, một phạm vi dừng lỗ tương đối khoan dung được áp dụng, và cài đặt lợi nhuận giới hạn cũng giúp giảm nguy cơ này. Khi dừng lỗ được kích hoạt, cũng có thể xem xét nhập lại hướng xu hướng.

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

Có một số hướng tối ưu hóa cho chiến lược này: đầu tiên, các kết hợp tham số khác nhau như thời gian EMA và thanh trì vị trí có thể được thử nghiệm để tìm các tham số tối ưu; thứ hai, nhiều chỉ số phụ trợ như MACD và BOLL có thể được giới thiệu để lọc tín hiệu để cải thiện chất lượng tín hiệu; thứ ba, logic dừng lỗ và lấy lợi nhuận có thể được tối ưu hóa, chẳng hạn như áp dụng các phương pháp dừng lỗ khác như dừng lỗ thời gian và dừng lỗ dao động; thứ tư, nhiều điều kiện thị trường có thể được kết hợp để kích hoạt các tín hiệu giao dịch chiến lược, chẳng hạn như chỉ kích hoạt các tín hiệu trong các khoảng thời gian nhất định hoặc phạm vi biến động.

Tóm lại

Chiến lược theo dõi xu hướng chéo đôi 10EMA này đánh giá hướng xu hướng hiện tại thông qua EMA đường chéo vàng và đường chéo chết, thiết lập theo dõi dừng lỗ và giới hạn lợi nhuận để khóa lợi nhuận và kiểm soát rủi ro, trong khi kết hợp các chỉ số phụ để lọc tín hiệu và cải thiện chất lượng tín hiệu. So với chỉ số duy nhất và các chiến lược dừng lỗ truyền thống, chiến lược này có những lợi thế như đánh giá chính xác, cơ chế dừng lỗ tối ưu hóa, v.v. Nó có thể nắm bắt hiệu quả lợi nhuận xu hướng trong khi kiểm soát rủi ro, làm cho nó phù hợp với các tài khoản giao dịch thông thường. Tất nhiên vẫn còn chỗ để cải thiện cho chiến lược này, chẳng hạn như tiếp tục nâng cao hiệu suất chiến lược thông qua tối ưu hóa tham số và giới thiệu nhiều chỉ số phụ hơn.


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

//@version=5
strategy("10ema Strat 9", overlay=true, format=format.price)
//#region // inputs for candles
//time
t1 = time(timeframe.period,"0930-1500") //last hour of market is not ideal for trading
// candle status
bullish = close > open and barstate.isconfirmed
bearish = open > close and barstate.isconfirmed
bullcandle = ta.valuewhen(bullish, close, 0)
bearcandle = ta.valuewhen(bearish, close, 0)
ema1 = input.int(10, minval=1, title="short ema")
ema2 = input.int(50, minval=1, title="long ema")
ema3 = input.int(200, minval=1, title="hourly 10 ema")
//@variable Input for source
src = input(close, title="Source")
offsetema = input.int(title="Offset", defval=0, minval=-500, maxval=500)
sema = ta.ema(src, ema1)//@variable Input for smaller ema1
lema = ta.ema(src, ema2)//@variable Input for longer ema2
hema = ta.ema(src, ema3)// @variable Input for hourly ema3
bullcrosscount = ta.barssince(ta.crossover(sema,lema)) //@variable Input 10/50 cross higher
bearcrosscount = ta.barssince(ta.crossunder(sema,lema)) //@variable Input 10/50 cross lower
ideallong = bullcrosscount <= 5 //number of candles after the cross
idealshort = bearcrosscount <= 5 //number of candles after the cross

emabull = (sema > lema) and bearish and close > sema and close > hema and ideallong and t1 and barstate.isconfirmed
xemabull = ta.barssince(emabull)
dbullema = emabull and emabull[1] and xemabull <=1
bullentry = if dbullema
    ta.valuewhen(emabull[1], high + 0.05, 0)
else 
    ta.valuewhen(emabull, high + 0.05, 0)
bullentryh = dbullema ? bullentry[1] : bullentry
bullentrylow = ta.valuewhen(emabull, low - 0.05, 0)
bullstop = (bullentryh - bullentrylow) <= 1.00 ? bullentryh - 1.00 : (bullentryh - bullentrylow) <= 10.40 ? bullentrylow : na
bulltarget = (bullentryh - bullstop) * 1.62 + bullentryh

// bear setup
emabear = (sema < lema) and bullish and close < sema and close < hema and idealshort and t1 and barstate.isconfirmed
xemabear = ta.barssince(emabear)
dbearema = emabear and emabear [1] and xemabear <=1
bearentry = if dbearema
    ta.valuewhen(emabear[1], low - 0.05, 0)
else
    ta.valuewhen(emabear, low - 0.05, 0)
bearentryh = dbearema ? bearentry[1] : bearentry
bearentryhigh = ta.valuewhen(emabear, high + 0.05, 0)
bearstop = (bearentryhigh - bearentryh) <= 1.00 ? bearentryh + 1.00 : (bearentryh - bearentryhigh) <= 10.40 ? bearentryhigh : na
beartarget = bearentryh - (bearstop-bearentryh) * 1.62

bullclose = (xemabull <=7) and bullish and bullcrosscount >=1 and barstate.isconfirmed //number of candles for a close above
bearclose = (xemabear <=7) and bearish and bearcrosscount >=1 and barstate.isconfirmed //number of candles for a close below
buyzone = ta.barssince(bullclose)
shortzone =  ta.barssince(bearclose)
idealbuy = close >= bullentryh and bullclose and (buyzone<=7)
idealsell = close <= bearentryh and bearclose and (shortzone<=7)

// // bull setup on chart
// if sema > lema and xemabull < 50
//     var line line_bullentry = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(0, 200, 0), style=line.style_solid, width=1)
//     if emabull
//         line.set_xy1(line_bullentry, x=bar_index, y=bullentryh)
//         line.set_xy2(line_bullentry, x=bar_index, y=bullentryh)
//         alert("EMA-bullish", alert.freq_once_per_bar_close)
//     line.set_x2(line_bullentry, x=bar_index)
//     var line line_bullstop = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(250, 0, 0), style=line.style_solid, width=1)
//     if emabull
//         line.set_xy1(line_bullstop, x=bar_index, y=bullstop)
//         line.set_xy2(line_bullstop, x=bar_index, y=bullstop)
//     line.set_x2(line_bullstop, x=bar_index)    
//     var line line_bulltarget = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(200, 100, 200), style=line.style_solid, width=1)
//     if emabull
//         line.set_xy1(line_bulltarget, x=bar_index, y=bulltarget)
//         line.set_xy2(line_bulltarget, x=bar_index, y=bulltarget)
//     line.set_x2(line_bulltarget, x=bar_index)

// //bear setup on chart
// if sema < lema and xemabear < 50
//     var line line_bearentry = line.new(bar_index, na, bar_index, na, color=color.rgb(0, 200, 0), style=line.style_solid, width=1)
//     if emabear
//         line.set_xy1(line_bearentry, x=bar_index, y=bearentryh)
//         line.set_xy2(line_bearentry, x=bar_index, y=bearentryh)
//         alert("EMA-bearish", alert.freq_once_per_bar_close)
//     line.set_x2(line_bearentry, x=bar_index)
//     var line line_bearstop = line.new(bar_index, na, bar_index, na, color=color.rgb(250, 0, 0), style=line.style_solid, width=1)
//     if emabear
//         line.set_xy1(line_bearstop, x=bar_index, y=bearstop)
//         line.set_xy2(line_bearstop, x=bar_index, y=bearstop)
//     line.set_x2(line_bearstop, x=bar_index)
//     var line line_beartarget = line.new(bar_index, na, bar_index, na, color=color.rgb(200, 100, 200), style=line.style_solid, width=1)
//     if emabear
//         line.set_xy1(line_beartarget, x=bar_index, y=beartarget)
//         line.set_xy2(line_beartarget, x=bar_index, y=beartarget)
//     line.set_x2(line_beartarget, x=bar_index)

//#endregion
//execution 
if idealbuy
    strategy.close("sell", comment=na)	
    strategy.entry("buy", strategy.long, limit=bullentryh, stop=bullstop, comment="buy")
strategy.exit("exit","buy", trail_points = low, trail_offset = 5, qty_percent=100, limit=bulltarget, stop=bullstop)

if idealsell
	strategy.close("buy",comment=na)
    strategy.entry("sell", strategy.short, limit=bearentryh, stop=bearstop, comment="sell")
strategy.exit("exit","sell", trail_points = low, trail_offset = 5, qty_percent=100, limit=beartarget, stop=bearstop)
// strategy.close_all(time == close_day) 
//#region // graphical analysis
//Plots
plotshape(emabull, location=location.belowbar, title='emabull')
plotshape(idealbuy, style=shape.circle, color=color.green, title="bull close")
plotshape(emabear, title='emabear')
plotshape(idealsell, location=location.belowbar, style=shape.circle, color=color.red, title="bear close")

// //Dashboard
// var label id = na
// label.delete(id)   // Delete last label
// i_offsetLabel = input(15, "Data Dashboard Offset") 
// offset = i_offsetLabel * (time - time[1])
// dynamicText = "= Bull Setup ="
// id := label.new(x=time + offset, y=open, xloc=xloc.bar_time, text=dynamicText, color=color.rgb(255, 255, 255), size=size.normal)
// label.set_textcolor(id, color.rgb(0, 0, 0))
// label.set_text(id=id, text=dynamicText)
// label.set_textalign(id, text.align_left)
// label.set_text(id=id, text=dynamicText)
// f_round( _val, _decimals) => 
//     _p = math.pow(10, _decimals)
//     math.round(math.abs(_val) * _p) / _p * math.sign(_val)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bulltarget,2)) + "  :Target"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bullentryh,2)) + "  :Entry"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bullstop,2)) + "  :Stop"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + "= Bear Setup ="
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bearstop,2)) + "  :Stop"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bearentryh,2)) + "  :Entry"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(beartarget,2)) + "  :Target"
// label.set_text(id=id, text=dynamicText)
// //#endregion

Thêm nữa