Chiến lược này là một chiến lược theo dõi xu hướng dựa trên 10 EMA và 50 EMA đôi chéo. Nó kết hợp 10 EMA của đường giờ làm phán đoán phụ trợ, tìm hướng xu hướng một cách động trong thị trường chuyển đổi bò và gấu, để thực hiện theo dõi dừng tự động.
Lập luận cốt lõi của chiến lược dựa trên 10 EMA và 50 EMA. Cụ thể, khi 10 EMA xuyên qua 50 EMA từ phía dưới để tạo ra một chiếc gai vàng, thị trường được đánh giá là đang trong xu hướng tăng; khi 10 EMA xuyên qua 50 EMA từ phía trên để tạo ra một chiếc gai chết, thị trường được đánh giá là đang trong xu hướng giảm.
Ngoài ra, chiến lược cũng giới thiệu 10EMA của đường giờ như là một phán đoán phụ, chỉ khi đường giờ 10EMA đang có xu hướng tăng mới mở nhiều vị trí sau đường vàng và chỉ khi đường giờ 10EMA đang có xu hướng giảm mới mở vị trí trống sau đường chết, do đó lọc một số tín hiệu giả.
Sau khi mở vị trí, chiến lược sử dụng phương thức xuất phát theo dõi dừng + giá dừng. Theo dõi dừng có thể khóa lợi nhuận và đảm bảo lợi nhuận giao dịch tối đa; Giữ giá dừng đảm bảo đóng vị trí để kiếm lợi nhuận khi giá đạt đến điểm mục tiêu.
Ưu điểm lớn nhất của chiến lược này là sử dụng EMA giao thoa để xác định hướng của xu hướng chính, đồng thời cũng giới thiệu các tín hiệu lọc chỉ số phụ, có thể lọc hiệu quả các giao thoa giả để nâng cao độ tin cậy của tín hiệu. Ngoài ra, giao thoa EMA kép kết hợp theo dõi dừng lỗ và dừng giá, có thể tối đa hóa lợi nhuận theo dõi xu hướng và kiểm soát rủi ro giao dịch hiệu quả, lợi nhuận rủi ro tổng thể tốt.
Chiến lược này có thể xác định chính xác hơn về hướng và độ rộng của xu hướng so với chiến lược chỉ số đơn. Chiến lược này sử dụng công nghệ theo dõi dừng lỗ tiên tiến hơn so với các lệnh dừng lỗ truyền thống và có thể khóa lợi nhuận tốt hơn.
Chiến lược này chủ yếu đối mặt với các rủi ro của whipsaw gián đoạn và đảo ngược xu hướng. Khi có liên tục các tín hiệu crossover giả, có thể dẫn đến chiến lược bị đánh giá. Ngoài ra, giá đảo ngược sau khi mở vị trí cũng có thể gây thiệt hại.
Để giảm rủi ro của whipsaw, chiến lược thêm các chỉ số phụ để lọc tín hiệu. Để kiểm soát rủi ro của xu hướng đảo ngược, chiến lược sử dụng một phạm vi dừng lỏng lẻo hơn, trong khi thiết lập giá dừng giới hạn cũng có thể giúp giảm rủi ro đó.
Chiến lược này có thể được tối ưu hóa theo một số hướng khác nhau: thứ nhất, bạn có thể thử nghiệm các kết hợp tham số khác nhau, chẳng hạn như chu kỳ EMA, gốc trì hoãn mở vị trí, v.v., để tìm tham số tối ưu; thứ hai, bạn có thể giới thiệu nhiều chỉ số phụ trợ, chẳng hạn như MACD, BOLL, v.v. để lọc tín hiệu và cải thiện chất lượng tín hiệu; thứ ba, bạn có thể tối ưu hóa logic dừng lỗ, chẳng hạn như sử dụng các phương thức dừng lỗ khác như dừng lỗ theo thời gian, dừng rung; thứ tư, bạn có thể kết hợp nhiều điều kiện mở chiến lược giao dịch, chẳng hạn như chỉ kích hoạt tín hiệu trong một khoảng thời gian nhất định hoặc dưới mức tăng giảm.
Chiến lược theo dõi xu hướng chéo kép 10 EMA, đánh giá hướng xu hướng hiện tại thông qua EMA golden cross và death cross, thiết lập tracking stop loss và price stop stop để khóa lợi nhuận và kiểm soát rủi ro, đồng thời kết hợp với tín hiệu lọc chỉ số phụ để cải thiện chất lượng tín hiệu, là một chiến lược giao dịch xu hướng hoàn chỉnh hơn. So với chỉ số đơn và dừng lỗ dừng truyền thống, chiến lược này có lợi thế của phán đoán chính xác, dừng lỗ tối ưu hóa, kiểm soát rủi ro đồng thời có thể thu được lợi nhuận xu hướng hiệu quả, là một chiến lược phù hợp cho tài khoản giao dịch thông thường.
/*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