
Эта стратегия основана на показателях тончайского канала с несколькими циклами для построения системы отслеживания тенденций. Анализируя прорывы тончайского канала в разные периоды времени, в сочетании с основными тенденциями и локальными тенденциями, формируется визуально интуитивно понятный график трендовых полос.
В основе стратегии лежит определение трендов на основе показателей Доньчжанского канала. Доньчжанский канал состоит из каналов наивысшей цены и каналов наименьшей цены, и тенденции определяются путем сравнения текущей цены с отношением позиций каналов.
Стратегия использует инновационное применение многоциклических каналов Тунцзяна для создания выделенной визуально и логически четкой системы отслеживания трендов. Основная преимущество стратегии заключается в том, что она визуализирует сложный процесс анализа трендов, что позволяет трейдерам визуально понимать движение рынка. Благодаря разумной оптимизации параметров и мерам контроля риска, стратегия имеет хорошую ценность для реальных применений.
/*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")