Đây là một chiến lược giao dịch định lượng kết hợp ba xu hướng siêu, EMA và ADX. Nó sử dụng hệ thống ba xu hướng siêu để phát tín hiệu giao dịch và kết hợp EMA và ADX làm điều kiện lọc để kiểm soát tần suất giao dịch và nâng cao chất lượng tín hiệu giao dịch.
Cụ thể, điều kiện nhập cảnh dài cho ba xu hướng vượt trội đều chuyển sang bullish, giá đóng cửa cao hơn EMA, ADX cao hơn giá trị thiết lập khi mở nhiều vị trí; điều kiện nhập cảnh ngắn cho ba xu hướng vượt trội đều chuyển sang lỗ, giá đóng cửa thấp hơn EMA, ADX cao hơn giá trị thiết lập khi mở vị trí trống. Điều kiện vị trí bằng phẳng cho bất kỳ xu hướng vượt trội nào chuyển sang bằng phẳng vị trí hiện tại.
Chiến lược này cùng một lúc vẽ đường kháng cự hỗ trợ cho ba nhóm siêu xu hướng, hỗ trợ xác định hướng xu hướng.
Những rủi ro này có thể được giảm bớt bằng cách điều chỉnh các tham số, tối ưu hóa các điều kiện lọc, v.v.
Chiến lược này có thể được tối ưu hóa theo các khía cạnh sau:
Chiến lược này tận dụng tối đa lợi thế của hệ thống siêu xu hướng ba, được hỗ trợ bởi EMA và ADX lọc kép, có thể cải thiện hiệu quả chất lượng tín hiệu giao dịch, kiểm soát rủi ro. Các phương pháp như tối ưu hóa tham số, tăng điều kiện lọc, dừng động có thể tăng cường thêm sức mạnh và khả năng thích ứng của chiến lược. Kết hợp với phán đoán xu hướng, chiến lược này có thể cung cấp tín hiệu nhập cảnh và xuất cảnh hiệu quả cho giao dịch định lượng.
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ©kunjandetroja
//@version=5
strategy('Triple Supertrend with EMA and ADX', overlay=true)
m1 = input.float(1,"ATR Multi",minval = 1,maxval= 6,step=0.5,group='ST 1')
m2 = input.float(2,"ATR Multi",minval = 1,maxval= 6,step=0.5,group='ST 2')
m3 = input.float(3,"ATR Multi",minval = 1,maxval= 6,step=0.5,group='ST 3')
p1 = input.int(10,"ATR Multi",minval = 5,maxval= 25,step=1,group='ST 1')
p2 = input.int(15,"ATR Multi",minval = 5,maxval= 25,step=1,group='ST 2')
p3 = input.int(20,"ATR Multi",minval = 5,maxval= 25,step=1,group='ST 3')
len_EMA = input.int(200,"EMA Len",minval = 5,maxval= 250,step=1)
len_ADX = input.int(14,"ADX Len",minval = 1,maxval= 25,step=1)
len_Di = input.int(14,"Di Len",minval = 1,maxval= 25,step=1)
adx_above = input.float(25,"adx filter",minval = 1,maxval= 50,step=0.5)
var bool long_position = false
adx_filter = input.bool(false, "Add Adx & EMA filter")
renetry = input.bool(true, "Allow Reentry")
f_getColor_Resistance(_dir, _color) =>
_dir == 1 and _dir == _dir[1] ? _color : na
f_getColor_Support(_dir, _color) =>
_dir == -1 and _dir == _dir[1] ? _color : na
[superTrend1, dir1] = ta.supertrend(m1, p1)
[superTrend2, dir2] = ta.supertrend(m2, p2)
[superTrend3, dir3] = ta.supertrend(m3, p3)
EMA = ta.ema(close, len_EMA)
[diplus,diminus,adx] = ta.dmi(len_Di,len_ADX)
// ADX Filter
adxup = adx > adx_above and close > EMA
adxdown = adx > adx_above and close < EMA
sum_dir = dir1 + dir2 + dir3
dir_long = if(adx_filter == false)
sum_dir == -3
else
sum_dir == -3 and adxup
dir_short = if(adx_filter == false)
sum_dir == 3
else
sum_dir == 3 and adxdown
Exit_long = dir1 == 1 and dir1 != dir1[1]
Exit_short = dir1 == -1 and dir1 != dir1[1]
// BuySignal = dir_long and dir_long != dir_long[1]
// SellSignal = dir_short and dir_short != dir_short[1]
// if BuySignal
// label.new(bar_index, low, 'Long', style=label.style_label_up)
// if SellSignal
// label.new(bar_index, high, 'Short', style=label.style_label_down)
longenter = if(renetry == false)
dir_long and long_position == false
else
dir_long
shortenter = if(renetry == false)
dir_short and long_position == true
else
dir_short
if longenter
long_position := true
if shortenter
long_position := false
strategy.entry('BUY', strategy.long, when=longenter)
strategy.entry('SELL', strategy.short, when=shortenter)
strategy.close('BUY', Exit_long)
strategy.close('SELL', Exit_short)
buy1 = ta.barssince(dir_long)
sell1 = ta.barssince(dir_short)
colR1 = f_getColor_Resistance(dir1, color.red)
colS1 = f_getColor_Support(dir1, color.green)
colR2 = f_getColor_Resistance(dir2, color.orange)
colS2 = f_getColor_Support(dir2, color.yellow)
colR3 = f_getColor_Resistance(dir3, color.blue)
colS3 = f_getColor_Support(dir3, color.maroon)
plot(superTrend1, 'R1', colR1, linewidth=2)
plot(superTrend1, 'S1', colS1, linewidth=2)
plot(superTrend2, 'R1', colR2, linewidth=2)
plot(superTrend2, 'S1', colS2, linewidth=2)
plot(superTrend3, 'R1', colR3, linewidth=2)
plot(superTrend3, 'S1', colS3, linewidth=2)
// // Intraday only
// var int new_day = na
// var int new_month = na
// var int new_year = na
// var int close_trades_after_time_of_day = na
// if dayofmonth != dayofmonth[1]
// new_day := dayofmonth
// if month != month[1]
// new_month := month
// if year != year[1]
// new_year := year
// close_trades_after_time_of_day := timestamp(new_year,new_month,new_day,15,15)
// strategy.close_all(time > close_trades_after_time_of_day)