
이 전략은 다중 주기의 돈치안 통로 지표를 기반으로 트렌드 추적 시스템을 구축한다. 다양한 시간 주기의 돈치안 통로 돌파를 분석하여 주 트렌드와 지역 트렌드의 조화 관계를 결합하여 시각적으로 직관적인 트렌드 띠 모양의 그래프를 형성한다. 전략은 트렌드의 강도 약도를 표시하기 위해 색상의 심층 변화를 사용합니다. 녹색은 상승 추세를 나타내고, 빨간색은 하락 추세를 나타냅니다. 색상이 더 깊으면 추세가 더 분명합니다.
전략의 핵심은 돈치안 채널 (Donchian Channel) 지표에 기초하여 트렌드를 판단하는 것이다. 돈치안 채널은 최고 가격 채널과 최저 가격 채널로 구성되어 있으며, 현재 가격과 채널의 위치 관계를 비교하여 트렌드를 판단한다. 주로 다음과 같은 몇 가지 핵심 구성 요소를 포함한다:
이 전략은 다중 주기 동치안 통로의 혁신적인 응용을 통해, 시각적 효과에 돋보이는, 논리적으로 명확한 트렌드 추적 거래 시스템을 구축한다. 이 전략의 핵심 장점은 복잡한 트렌드 분석 과정을 시각화하여 거래자가 시장 움직임을 직관적으로 파악하는 데 있습니다. 합리적인 매개 변수 최적화 및 위험 제어 조치를 통해 이 전략은 실전 응용 가치있다.
/*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")