
Chiến lược này dựa trên các chỉ số kênh Đường Đông Dương trong nhiều chu kỳ để xây dựng hệ thống theo dõi xu hướng. Bằng cách phân tích sự đột phá của kênh Đường Đông Dương trong các chu kỳ thời gian khác nhau, kết hợp xu hướng chính và mối quan hệ phối hợp của xu hướng địa phương để tạo ra biểu đồ theo dạng dải xu hướng trực quan. Chiến lược sử dụng sự thay đổi màu sắc sâu sắc để hiển thị mức độ yếu của xu hướng, màu xanh lá cây đại diện cho xu hướng tăng, màu đỏ đại diện cho xu hướng giảm, màu sắc sâu hơn cho thấy xu hướng rõ ràng hơn.
Cốt lõi của chiến lược này là đánh giá xu hướng dựa trên các chỉ số của kênh Donchian. Các kênh Donchian bao gồm các kênh giá cao nhất và kênh giá thấp nhất, đánh giá xu hướng bằng cách so sánh giá hiện tại với mối quan hệ vị trí của kênh.
Chiến lược này có giá trị ứng dụng thực tế tốt thông qua các biện pháp tối ưu hóa tham số và kiểm soát rủi ro hợp lý. Người giao dịch được khuyến khích chú ý đến lựa chọn môi trường thị trường khi áp dụng thực tế và quản lý vị trí phù hợp với khả năng chịu rủi ro của mình.
/*backtest
start: 2024-06-12 00:00:00
end: 2025-02-19 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Donchian Trend Ribbon Strategy", shorttitle="DonchianTrendRibbonStrat", overlay=true, precision=0)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Parameters
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dlen = input.int(defval=20, title="Donchian Channel Period", minval=10)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Helper function to determine color
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
f_color(mainTrend, localTrend) =>
// mainTrend = 1 => uptrend, -1 => downtrend
// localTrend = 1 => local uptrend, -1 => local downtrend
// Return color based on whether local trend aligns with the main trend
color c = na
if mainTrend == 1
c := localTrend == 1 ? color.new(color.lime, 0) : color.new(color.lime, 60)
else if mainTrend == -1
c := localTrend == -1 ? color.new(color.red, 0) : color.new(color.red, 60)
else
c := na
c
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Function dchannel - determines main trend (1 or -1)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dchannel(len) =>
float hh = ta.highest(len)
float ll = ta.lowest(len)
var int tr = 0
tr := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(tr[1])
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Function dchannelalt - determines local trend and returns color
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dchannelalt(len, maintrend) =>
float hh = ta.highest(len)
float ll = ta.lowest(len)
var int tr = 0
tr := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(tr[1])
f_color(maintrend, tr)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Calculate main trend
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
maintrend = dchannel(dlen)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Plotting the Donchian Trend Ribbon
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plot( 5, color=dchannelalt(dlen - 0, maintrend), style=plot.style_columns, histbase= 0)
plot(10, color=dchannelalt(dlen - 1, maintrend), style=plot.style_columns, histbase= 5)
plot(15, color=dchannelalt(dlen - 2, maintrend), style=plot.style_columns, histbase=10)
plot(20, color=dchannelalt(dlen - 3, maintrend), style=plot.style_columns, histbase=15)
plot(25, color=dchannelalt(dlen - 4, maintrend), style=plot.style_columns, histbase=20)
plot(30, color=dchannelalt(dlen - 5, maintrend), style=plot.style_columns, histbase=25)
plot(35, color=dchannelalt(dlen - 6, maintrend), style=plot.style_columns, histbase=30)
plot(40, color=dchannelalt(dlen - 7, maintrend), style=plot.style_columns, histbase=35)
plot(45, color=dchannelalt(dlen - 8, maintrend), style=plot.style_columns, histbase=40)
plot(50, color=dchannelalt(dlen - 9, maintrend), style=plot.style_columns, histbase=45)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Trading Logic (STRATEGY)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool goLong = (maintrend == 1)
bool goShort = (maintrend == -1)
// Entry signals
if goLong
strategy.entry("Long", strategy.long)
if goShort
strategy.entry("Short", strategy.short)
// Close positions when trend changes
if strategy.position_size > 0 and goShort
strategy.close("Long")
if strategy.position_size < 0 and goLong
strategy.close("Short")