Donchian Trend Ribbon For ThinkOrSwim

halcyonguy

Moderator - Expert
VIP
Lifetime
Donchian Trend Ribbon

someone asked for this to be converted from tradingview.

the source tradingview code was someone elses' attempt to create the ribbon in tradingview, so i am unsure if it correct.
https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
i converted his code to thinkscript.

each row uses a different length to determine an up or down trend.
this is compared to a trend using the length , dlen ( default 20).

instead of using clouds for shading, i decided to go a simple way and use PaintingStrategy.SQUARES.
i set the size to 4 and it seems to look good. (on a scale of 1 to 5)

i defined the 5 colors, so they can be changed in 1 place not 10.
can change the row spacing and square size.


Ruby:
# donchian_trend_ribbon_0c
# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
    
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

#   colors    
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
#----------------------------------------

input rowstart = 0;
input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
plot row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));
row01.SetPaintingStrategy(PaintingStrategy.SQUARES);
row01.setlineweight(square_size);
row01.hidebubble();
row01.AssignValueColor(
if c01 == 2 then GlobalColor("up2")
else if c01 == 1 then GlobalColor("up1")
else if c01 == -1 then GlobalColor("dwn1")
else if c01 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c02 = dchannelalt(dlen - 1, maintrend);
plot row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));
row02.SetPaintingStrategy(PaintingStrategy.SQUARES);
row02.setlineweight(square_size);
row02.hidebubble();
row02.AssignValueColor(
if c02 == 2 then GlobalColor("up2")
else if c02 == 1 then GlobalColor("up1")
else if c02 == -1 then GlobalColor("dwn1")
else if c02 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c03 = dchannelalt(dlen - 2, maintrend);
plot row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));
row03.SetPaintingStrategy(PaintingStrategy.SQUARES);
row03.setlineweight(square_size);
row03.hidebubble();
row03.AssignValueColor(
if c03 == 2 then GlobalColor("up2")
else if c03 == 1 then GlobalColor("up1")
else if c03 == -1 then GlobalColor("dwn1")
else if c03 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c04 = dchannelalt(dlen - 3, maintrend);
plot row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));
row04.SetPaintingStrategy(PaintingStrategy.SQUARES);
row04.setlineweight(square_size);
row04.hidebubble();
row04.AssignValueColor(
if c04 == 2 then GlobalColor("up2")
else if c04 == 1 then GlobalColor("up1")
else if c04 == -1 then GlobalColor("dwn1")
else if c04 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c05 = dchannelalt(dlen - 4, maintrend);
plot row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));
row05.SetPaintingStrategy(PaintingStrategy.SQUARES);
row05.setlineweight(square_size);
row05.hidebubble();
row05.AssignValueColor(
if c05 == 2 then GlobalColor("up2")
else if c05 == 1 then GlobalColor("up1")
else if c05 == -1 then GlobalColor("dwn1")
else if c05 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c06 = dchannelalt(dlen - 5, maintrend);
plot row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));
row06.SetPaintingStrategy(PaintingStrategy.SQUARES);
row06.setlineweight(square_size);
row06.hidebubble();
row06.AssignValueColor(
if c06 == 2 then GlobalColor("up2")
else if c06 == 1 then GlobalColor("up1")
else if c06 == -1 then GlobalColor("dwn1")
else if c06 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c07 = dchannelalt(dlen - 6, maintrend);
plot row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));
row07.SetPaintingStrategy(PaintingStrategy.SQUARES);
row07.setlineweight(square_size);
row07.hidebubble();
row07.AssignValueColor(
if c07 == 2 then GlobalColor("up2")
else if c07 == 1 then GlobalColor("up1")
else if c07 == -1 then GlobalColor("dwn1")
else if c07 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c08 = dchannelalt(dlen - 7, maintrend);
plot row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));
row08.SetPaintingStrategy(PaintingStrategy.SQUARES);
row08.setlineweight(square_size);
row08.hidebubble();
row08.AssignValueColor(
if c08 == 2 then GlobalColor("up2")
else if c08 == 1 then GlobalColor("up1")
else if c08 == -1 then GlobalColor("dwn1")
else if c08 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c09 = dchannelalt(dlen - 8, maintrend);
plot row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));
row09.SetPaintingStrategy(PaintingStrategy.SQUARES);
row09.setlineweight(square_size);
row09.hidebubble();
row09.AssignValueColor(
if c09 == 2 then GlobalColor("up2")
else if c09 == 1 then GlobalColor("up1")
else if c09 == -1 then GlobalColor("dwn1")
else if c09 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c10 = dchannelalt(dlen - 9, maintrend);
plot row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));
row10.SetPaintingStrategy(PaintingStrategy.SQUARES);
row10.setlineweight(square_size);
row10.hidebubble();
row10.AssignValueColor(
if c10 == 2 then GlobalColor("up2")
else if c10 == 1 then GlobalColor("up1")
else if c10 == -1 then GlobalColor("dwn1")
else if c10 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

# -----------------------------
# pine code
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © LonesomeTheBlue

#//@version=4
#study("Donchian Trend Ribbon", precision = 0)
#dlen = input(defval = 20, title = "Donchian Channel Period", minval = 10)

#dchannel(len)=>
#    float hh = highest(len)
#    float ll = lowest(len)
    
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
    
#dchannelalt(len, maintrend)=>
#    float hh = highest(len)
#    float ll = lowest(len)
    
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])

# last 2 digits are opacity of the color. if a trend, then dark,  else pale color ( i think)
#    maintrend == 1  ? trend == 1  ? #00FF00ff :  #00FF009f :
#     maintrend == -1 ? trend == -1 ? #FF0000ff :  #FF00009f :
#     na

#maintrend = dchannel(dlen)

#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)
#


TTWO 15min
10 rows,
.top row has the shortest length(len - 9)
.bottom row has longest length(len)
p1P7YOc.jpg
 
Donchian Trend Ribbon

someone asked for this to be converted from tradingview.

the source tradingview code was someone elses' attempt to create the ribbon in tradingview, so i am unsure if it correct.
https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
i converted his code to thinkscript.

each row uses a different length to determine an up or down trend.
this is compared to a trend using the length , dlen ( default 20).

instead of using clouds for shading, i decided to go a simple way and use PaintingStrategy.SQUARES.
i set the size to 4 and it seems to look good. (on a scale of 1 to 5)

i defined the 5 colors, so they can be changed in 1 place not 10.
can change the row spacing and square size.


Ruby:
# donchian_trend_ribbon_0c
# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
   
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

#   colors   
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
#----------------------------------------

input rowstart = 0;
input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
plot row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));
row01.SetPaintingStrategy(PaintingStrategy.SQUARES);
row01.setlineweight(square_size);
row01.hidebubble();
row01.AssignValueColor(
if c01 == 2 then GlobalColor("up2")
else if c01 == 1 then GlobalColor("up1")
else if c01 == -1 then GlobalColor("dwn1")
else if c01 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c02 = dchannelalt(dlen - 1, maintrend);
plot row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));
row02.SetPaintingStrategy(PaintingStrategy.SQUARES);
row02.setlineweight(square_size);
row02.hidebubble();
row02.AssignValueColor(
if c02 == 2 then GlobalColor("up2")
else if c02 == 1 then GlobalColor("up1")
else if c02 == -1 then GlobalColor("dwn1")
else if c02 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c03 = dchannelalt(dlen - 2, maintrend);
plot row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));
row03.SetPaintingStrategy(PaintingStrategy.SQUARES);
row03.setlineweight(square_size);
row03.hidebubble();
row03.AssignValueColor(
if c03 == 2 then GlobalColor("up2")
else if c03 == 1 then GlobalColor("up1")
else if c03 == -1 then GlobalColor("dwn1")
else if c03 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c04 = dchannelalt(dlen - 3, maintrend);
plot row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));
row04.SetPaintingStrategy(PaintingStrategy.SQUARES);
row04.setlineweight(square_size);
row04.hidebubble();
row04.AssignValueColor(
if c04 == 2 then GlobalColor("up2")
else if c04 == 1 then GlobalColor("up1")
else if c04 == -1 then GlobalColor("dwn1")
else if c04 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c05 = dchannelalt(dlen - 4, maintrend);
plot row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));
row05.SetPaintingStrategy(PaintingStrategy.SQUARES);
row05.setlineweight(square_size);
row05.hidebubble();
row05.AssignValueColor(
if c05 == 2 then GlobalColor("up2")
else if c05 == 1 then GlobalColor("up1")
else if c05 == -1 then GlobalColor("dwn1")
else if c05 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c06 = dchannelalt(dlen - 5, maintrend);
plot row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));
row06.SetPaintingStrategy(PaintingStrategy.SQUARES);
row06.setlineweight(square_size);
row06.hidebubble();
row06.AssignValueColor(
if c06 == 2 then GlobalColor("up2")
else if c06 == 1 then GlobalColor("up1")
else if c06 == -1 then GlobalColor("dwn1")
else if c06 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c07 = dchannelalt(dlen - 6, maintrend);
plot row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));
row07.SetPaintingStrategy(PaintingStrategy.SQUARES);
row07.setlineweight(square_size);
row07.hidebubble();
row07.AssignValueColor(
if c07 == 2 then GlobalColor("up2")
else if c07 == 1 then GlobalColor("up1")
else if c07 == -1 then GlobalColor("dwn1")
else if c07 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c08 = dchannelalt(dlen - 7, maintrend);
plot row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));
row08.SetPaintingStrategy(PaintingStrategy.SQUARES);
row08.setlineweight(square_size);
row08.hidebubble();
row08.AssignValueColor(
if c08 == 2 then GlobalColor("up2")
else if c08 == 1 then GlobalColor("up1")
else if c08 == -1 then GlobalColor("dwn1")
else if c08 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c09 = dchannelalt(dlen - 8, maintrend);
plot row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));
row09.SetPaintingStrategy(PaintingStrategy.SQUARES);
row09.setlineweight(square_size);
row09.hidebubble();
row09.AssignValueColor(
if c09 == 2 then GlobalColor("up2")
else if c09 == 1 then GlobalColor("up1")
else if c09 == -1 then GlobalColor("dwn1")
else if c09 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

def c10 = dchannelalt(dlen - 9, maintrend);
plot row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));
row10.SetPaintingStrategy(PaintingStrategy.SQUARES);
row10.setlineweight(square_size);
row10.hidebubble();
row10.AssignValueColor(
if c10 == 2 then GlobalColor("up2")
else if c10 == 1 then GlobalColor("up1")
else if c10 == -1 then GlobalColor("dwn1")
else if c10 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));

# -----------------------------
# pine code
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © LonesomeTheBlue

#//@version=4
#study("Donchian Trend Ribbon", precision = 0)
#dlen = input(defval = 20, title = "Donchian Channel Period", minval = 10)

#dchannel(len)=>
#    float hh = highest(len)
#    float ll = lowest(len)
   
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
   
#dchannelalt(len, maintrend)=>
#    float hh = highest(len)
#    float ll = lowest(len)
   
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])

# last 2 digits are opacity of the color. if a trend, then dark,  else pale color ( i think)
#    maintrend == 1  ? trend == 1  ? #00FF00ff :  #00FF009f :
#     maintrend == -1 ? trend == -1 ? #FF0000ff :  #FF00009f :
#     na

#maintrend = dchannel(dlen)

#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)
#


TTWO 15min
10 rows,
.top row has the shortest length(len - 9)
.bottom row has longest length(len)
p1P7YOc.jpg
Love it! Goes great with my other strategy.
 
here is a second version

the 10 rows can be turned on/off.
create an overall trend number, by adding up all 10 color numbers, colorsum.
added a histogram chart, based on colorsum.
histogram can be turned on/off.


Ruby:
# donchian_trend_ribbon_0d

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# add histogram of sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;


script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
    
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

#   colors    
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
plot row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));
row01.SetPaintingStrategy(PaintingStrategy.SQUARES);
row01.setlineweight(square_size);
row01.hidebubble();
row01.AssignValueColor(
if c01 == 2 then GlobalColor("up2")
else if c01 == 1 then GlobalColor("up1")
else if c01 == -1 then GlobalColor("dwn1")
else if c01 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row01.SetHiding(!show_data_rows);

def c02 = dchannelalt(dlen - 1, maintrend);
plot row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));
row02.SetPaintingStrategy(PaintingStrategy.SQUARES);
row02.setlineweight(square_size);
row02.hidebubble();
row02.AssignValueColor(
if c02 == 2 then GlobalColor("up2")
else if c02 == 1 then GlobalColor("up1")
else if c02 == -1 then GlobalColor("dwn1")
else if c02 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row02.SetHiding(!show_data_rows);

def c03 = dchannelalt(dlen - 2, maintrend);
plot row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));
row03.SetPaintingStrategy(PaintingStrategy.SQUARES);
row03.setlineweight(square_size);
row03.hidebubble();
row03.AssignValueColor(
if c03 == 2 then GlobalColor("up2")
else if c03 == 1 then GlobalColor("up1")
else if c03 == -1 then GlobalColor("dwn1")
else if c03 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row03.SetHiding(!show_data_rows);

def c04 = dchannelalt(dlen - 3, maintrend);
plot row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));
row04.SetPaintingStrategy(PaintingStrategy.SQUARES);
row04.setlineweight(square_size);
row04.hidebubble();
row04.AssignValueColor(
if c04 == 2 then GlobalColor("up2")
else if c04 == 1 then GlobalColor("up1")
else if c04 == -1 then GlobalColor("dwn1")
else if c04 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row04.SetHiding(!show_data_rows);

def c05 = dchannelalt(dlen - 4, maintrend);
plot row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));
row05.SetPaintingStrategy(PaintingStrategy.SQUARES);
row05.setlineweight(square_size);
row05.hidebubble();
row05.AssignValueColor(
if c05 == 2 then GlobalColor("up2")
else if c05 == 1 then GlobalColor("up1")
else if c05 == -1 then GlobalColor("dwn1")
else if c05 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row05.SetHiding(!show_data_rows);

def c06 = dchannelalt(dlen - 5, maintrend);
plot row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));
row06.SetPaintingStrategy(PaintingStrategy.SQUARES);
row06.setlineweight(square_size);
row06.hidebubble();
row06.AssignValueColor(
if c06 == 2 then GlobalColor("up2")
else if c06 == 1 then GlobalColor("up1")
else if c06 == -1 then GlobalColor("dwn1")
else if c06 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row06.SetHiding(!show_data_rows);

def c07 = dchannelalt(dlen - 6, maintrend);
plot row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));
row07.SetPaintingStrategy(PaintingStrategy.SQUARES);
row07.setlineweight(square_size);
row07.hidebubble();
row07.AssignValueColor(
if c07 == 2 then GlobalColor("up2")
else if c07 == 1 then GlobalColor("up1")
else if c07 == -1 then GlobalColor("dwn1")
else if c07 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row07.SetHiding(!show_data_rows);

def c08 = dchannelalt(dlen - 7, maintrend);
plot row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));
row08.SetPaintingStrategy(PaintingStrategy.SQUARES);
row08.setlineweight(square_size);
row08.hidebubble();
row08.AssignValueColor(
if c08 == 2 then GlobalColor("up2")
else if c08 == 1 then GlobalColor("up1")
else if c08 == -1 then GlobalColor("dwn1")
else if c08 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row08.SetHiding(!show_data_rows);

def c09 = dchannelalt(dlen - 8, maintrend);
plot row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));
row09.SetPaintingStrategy(PaintingStrategy.SQUARES);
row09.setlineweight(square_size);
row09.hidebubble();
row09.AssignValueColor(
if c09 == 2 then GlobalColor("up2")
else if c09 == 1 then GlobalColor("up1")
else if c09 == -1 then GlobalColor("dwn1")
else if c09 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row09.SetHiding(!show_data_rows);

def c10 = dchannelalt(dlen - 9, maintrend);
plot row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));
row10.SetPaintingStrategy(PaintingStrategy.SQUARES);
row10.setlineweight(square_size);
row10.hidebubble();
row10.AssignValueColor(
if c10 == 2 then GlobalColor("up2")
else if c10 == 1 then GlobalColor("up1")
else if c10 == -1 then GlobalColor("dwn1")
else if c10 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row10.SetHiding(!show_data_rows);

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 ); 

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
plot zc = if show_sum_histo then (absvalue(colorsum)) else na;
zc.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
zc.AssignValueColor( if colorsum == (2*10) then color.green
else if colorsum > 0 then color.cyan
else if colorsum == (-2*10) then color.red
 else if colorsum < 0 then color.yellow
 else color.gray);
zc.SetHiding(!show_sum_histo);

# -----------------------------

# pine code

#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © LonesomeTheBlue

#//@version=4
#study("Donchian Trend Ribbon", precision = 0)
#dlen = input(defval = 20, title = "Donchian Channel Period", minval = 10)

#dchannel(len)=>
#    float hh = highest(len)
#    float ll = lowest(len)
    
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
    
#dchannelalt(len, maintrend)=>
#    float hh = highest(len)
#    float ll = lowest(len)
    
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])

# last 2 digits are opacity of the color. if a trend, then dark,  else pale color ( i think)
#    maintrend == 1  ? trend == 1  ? #00FF00ff :  #00FF009f :
#     maintrend == -1 ? trend == -1 ? #FF0000ff :  #FF00009f :
#     na

#maintrend = dchannel(dlen)

#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)
#

Yg0vNO7.jpg
 
here is a second version

the 10 rows can be turned on/off.
create an overall trend number, by adding up all 10 color numbers, colorsum.
added a histogram chart, based on colorsum.
histogram can be turned on/off.


Ruby:
# donchian_trend_ribbon_0d

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# add histogram of sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;


script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
   
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

#   colors   
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
plot row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));
row01.SetPaintingStrategy(PaintingStrategy.SQUARES);
row01.setlineweight(square_size);
row01.hidebubble();
row01.AssignValueColor(
if c01 == 2 then GlobalColor("up2")
else if c01 == 1 then GlobalColor("up1")
else if c01 == -1 then GlobalColor("dwn1")
else if c01 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row01.SetHiding(!show_data_rows);

def c02 = dchannelalt(dlen - 1, maintrend);
plot row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));
row02.SetPaintingStrategy(PaintingStrategy.SQUARES);
row02.setlineweight(square_size);
row02.hidebubble();
row02.AssignValueColor(
if c02 == 2 then GlobalColor("up2")
else if c02 == 1 then GlobalColor("up1")
else if c02 == -1 then GlobalColor("dwn1")
else if c02 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row02.SetHiding(!show_data_rows);

def c03 = dchannelalt(dlen - 2, maintrend);
plot row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));
row03.SetPaintingStrategy(PaintingStrategy.SQUARES);
row03.setlineweight(square_size);
row03.hidebubble();
row03.AssignValueColor(
if c03 == 2 then GlobalColor("up2")
else if c03 == 1 then GlobalColor("up1")
else if c03 == -1 then GlobalColor("dwn1")
else if c03 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row03.SetHiding(!show_data_rows);

def c04 = dchannelalt(dlen - 3, maintrend);
plot row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));
row04.SetPaintingStrategy(PaintingStrategy.SQUARES);
row04.setlineweight(square_size);
row04.hidebubble();
row04.AssignValueColor(
if c04 == 2 then GlobalColor("up2")
else if c04 == 1 then GlobalColor("up1")
else if c04 == -1 then GlobalColor("dwn1")
else if c04 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row04.SetHiding(!show_data_rows);

def c05 = dchannelalt(dlen - 4, maintrend);
plot row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));
row05.SetPaintingStrategy(PaintingStrategy.SQUARES);
row05.setlineweight(square_size);
row05.hidebubble();
row05.AssignValueColor(
if c05 == 2 then GlobalColor("up2")
else if c05 == 1 then GlobalColor("up1")
else if c05 == -1 then GlobalColor("dwn1")
else if c05 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row05.SetHiding(!show_data_rows);

def c06 = dchannelalt(dlen - 5, maintrend);
plot row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));
row06.SetPaintingStrategy(PaintingStrategy.SQUARES);
row06.setlineweight(square_size);
row06.hidebubble();
row06.AssignValueColor(
if c06 == 2 then GlobalColor("up2")
else if c06 == 1 then GlobalColor("up1")
else if c06 == -1 then GlobalColor("dwn1")
else if c06 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row06.SetHiding(!show_data_rows);

def c07 = dchannelalt(dlen - 6, maintrend);
plot row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));
row07.SetPaintingStrategy(PaintingStrategy.SQUARES);
row07.setlineweight(square_size);
row07.hidebubble();
row07.AssignValueColor(
if c07 == 2 then GlobalColor("up2")
else if c07 == 1 then GlobalColor("up1")
else if c07 == -1 then GlobalColor("dwn1")
else if c07 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row07.SetHiding(!show_data_rows);

def c08 = dchannelalt(dlen - 7, maintrend);
plot row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));
row08.SetPaintingStrategy(PaintingStrategy.SQUARES);
row08.setlineweight(square_size);
row08.hidebubble();
row08.AssignValueColor(
if c08 == 2 then GlobalColor("up2")
else if c08 == 1 then GlobalColor("up1")
else if c08 == -1 then GlobalColor("dwn1")
else if c08 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row08.SetHiding(!show_data_rows);

def c09 = dchannelalt(dlen - 8, maintrend);
plot row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));
row09.SetPaintingStrategy(PaintingStrategy.SQUARES);
row09.setlineweight(square_size);
row09.hidebubble();
row09.AssignValueColor(
if c09 == 2 then GlobalColor("up2")
else if c09 == 1 then GlobalColor("up1")
else if c09 == -1 then GlobalColor("dwn1")
else if c09 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row09.SetHiding(!show_data_rows);

def c10 = dchannelalt(dlen - 9, maintrend);
plot row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));
row10.SetPaintingStrategy(PaintingStrategy.SQUARES);
row10.setlineweight(square_size);
row10.hidebubble();
row10.AssignValueColor(
if c10 == 2 then GlobalColor("up2")
else if c10 == 1 then GlobalColor("up1")
else if c10 == -1 then GlobalColor("dwn1")
else if c10 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row10.SetHiding(!show_data_rows);

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
plot zc = if show_sum_histo then (absvalue(colorsum)) else na;
zc.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
zc.AssignValueColor( if colorsum == (2*10) then color.green
else if colorsum > 0 then color.cyan
else if colorsum == (-2*10) then color.red
 else if colorsum < 0 then color.yellow
 else color.gray);
zc.SetHiding(!show_sum_histo);

# -----------------------------

# pine code

#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © LonesomeTheBlue

#//@version=4
#study("Donchian Trend Ribbon", precision = 0)
#dlen = input(defval = 20, title = "Donchian Channel Period", minval = 10)

#dchannel(len)=>
#    float hh = highest(len)
#    float ll = lowest(len)
   
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
   
#dchannelalt(len, maintrend)=>
#    float hh = highest(len)
#    float ll = lowest(len)
   
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])

# last 2 digits are opacity of the color. if a trend, then dark,  else pale color ( i think)
#    maintrend == 1  ? trend == 1  ? #00FF00ff :  #00FF009f :
#     maintrend == -1 ? trend == -1 ? #FF0000ff :  #FF00009f :
#     na

#maintrend = dchannel(dlen)

#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)
#

Yg0vNO7.jpg
Looks good! Thanks!
 
Looks good! Thanks!
The colors should be
Code:
DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.red);
DefineGlobalColor("dwn2", color.Dark_red);

Lighter colors going up, Darker colors going down. Just my opinion.
 
EDIT - 4/8 3pm
added code near top to draw a line at 0.
without this, the histogram doesn't show the full height. only from the top down to the lowest value.

------------------------------------

3rd version
can change the secondary colors, from dark shades to yellow. yellow is default.


Ruby:
# donchian_trend_ribbon_0e

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# 00e
# can chg secondary colors ( 1 , -1) to yellow or diff shades

# 00d
# add histogram , sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;

input secondary_colors = { default yellow , green_red };
input show_full_height_of_histogram = yes;
plot z = if show_full_height_of_histogram and !isnan(close) then 0 else na;
z.setdefaultcolor(color.dark_gray);

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
   
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

# ---------------------------------

# input secondary_colors = { default yellow , green_red };
def seccolor;
switch (secondary_colors) {
case yellow:
  seccolor = 1;
case green_red:
  seccolor = 2;
}

#   colors   
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
DefineGlobalColor("alt1", color.yellow);
# GlobalColor("alt1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
plot row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));
row01.SetPaintingStrategy(PaintingStrategy.SQUARES);
row01.setlineweight(square_size);
row01.hidebubble();
row01.AssignValueColor(
if c01 == 2 then GlobalColor("up2")
# up1, dwn1 , if seccolor = 1 then GlobalColor("alt1") else if  seccolor = 2 then ....
else if c01 == 1 and seccolor == 1 then GlobalColor("alt1") else if c01 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c01 == -1 and seccolor == 1 then GlobalColor("alt1") else if c01 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c01 == -1 then GlobalColor("dwn1")
else if c01 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row01.SetHiding(!show_data_rows);

def c02 = dchannelalt(dlen - 1, maintrend);
plot row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));
row02.SetPaintingStrategy(PaintingStrategy.SQUARES);
row02.setlineweight(square_size);
row02.hidebubble();
row02.AssignValueColor(
if c02 == 2 then GlobalColor("up2")
#else if c02 == 1 then GlobalColor("up1")
else if c02 == 1 and seccolor == 1 then GlobalColor("alt1") else if c02 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c02 == -1 and seccolor == 1 then GlobalColor("alt1") else if c02 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c02 == -1 then GlobalColor("dwn1")
else if c02 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row02.SetHiding(!show_data_rows);

def c03 = dchannelalt(dlen - 2, maintrend);
plot row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));
row03.SetPaintingStrategy(PaintingStrategy.SQUARES);
row03.setlineweight(square_size);
row03.hidebubble();
row03.AssignValueColor(
if c03 == 2 then GlobalColor("up2")
#else if c03 == 1 then GlobalColor("up1")
else if c03 == 1 and seccolor == 1 then GlobalColor("alt1") else if c03 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c03 == -1 and seccolor == 1 then GlobalColor("alt1") else if c03 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c03 == -1 then GlobalColor("dwn1")
else if c03 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row03.SetHiding(!show_data_rows);

def c04 = dchannelalt(dlen - 3, maintrend);
plot row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));
row04.SetPaintingStrategy(PaintingStrategy.SQUARES);
row04.setlineweight(square_size);
row04.hidebubble();
row04.AssignValueColor(
if c04 == 2 then GlobalColor("up2")
#else if c04 == 1 then GlobalColor("up1")
else if c04 == 1 and seccolor == 1 then GlobalColor("alt1") else if c04 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c04 == -1 and seccolor == 1 then GlobalColor("alt1") else if c04 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c04 == -1 then GlobalColor("dwn1")
else if c04 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row04.SetHiding(!show_data_rows);

def c05 = dchannelalt(dlen - 4, maintrend);
plot row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));
row05.SetPaintingStrategy(PaintingStrategy.SQUARES);
row05.setlineweight(square_size);
row05.hidebubble();
row05.AssignValueColor(
if c05 == 2 then GlobalColor("up2")
#else if c05 == 1 then GlobalColor("up1")
else if c05 == 1 and seccolor == 1 then GlobalColor("alt1") else if c05 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c05 == -1 and seccolor == 1 then GlobalColor("alt1") else if c05 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c05 == -1 then GlobalColor("dwn1")
else if c05 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row05.SetHiding(!show_data_rows);

def c06 = dchannelalt(dlen - 5, maintrend);
plot row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));
row06.SetPaintingStrategy(PaintingStrategy.SQUARES);
row06.setlineweight(square_size);
row06.hidebubble();
row06.AssignValueColor(
if c06 == 2 then GlobalColor("up2")
#else if c06 == 1 then GlobalColor("up1")
else if c06 == 1 and seccolor == 1 then GlobalColor("alt1") else if c06 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c06 == -1 and seccolor == 1 then GlobalColor("alt1") else if c06 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c06 == -1 then GlobalColor("dwn1")
else if c06 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row06.SetHiding(!show_data_rows);

def c07 = dchannelalt(dlen - 6, maintrend);
plot row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));
row07.SetPaintingStrategy(PaintingStrategy.SQUARES);
row07.setlineweight(square_size);
row07.hidebubble();
row07.AssignValueColor(
if c07 == 2 then GlobalColor("up2")
#else if c07 == 1 then GlobalColor("up1")
else if c07 == 1 and seccolor == 1 then GlobalColor("alt1") else if c07 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c07 == -1 and seccolor == 1 then GlobalColor("alt1") else if c07 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c07 == -1 then GlobalColor("dwn1")
else if c07 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row07.SetHiding(!show_data_rows);

def c08 = dchannelalt(dlen - 7, maintrend);
plot row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));
row08.SetPaintingStrategy(PaintingStrategy.SQUARES);
row08.setlineweight(square_size);
row08.hidebubble();
row08.AssignValueColor(
if c08 == 2 then GlobalColor("up2")
#else if c08 == 1 then GlobalColor("up1")
else if c08 == 1 and seccolor == 1 then GlobalColor("alt1") else if c08 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c08 == -1 and seccolor == 1 then GlobalColor("alt1") else if c08 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c08 == -1 then GlobalColor("dwn1")
else if c08 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row08.SetHiding(!show_data_rows);

def c09 = dchannelalt(dlen - 8, maintrend);
plot row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));
row09.SetPaintingStrategy(PaintingStrategy.SQUARES);
row09.setlineweight(square_size);
row09.hidebubble();
row09.AssignValueColor(
if c09 == 2 then GlobalColor("up2")
#else if c09 == 1 then GlobalColor("up1")
else if c09 == 1 and seccolor == 1 then GlobalColor("alt1") else if c09 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c09 == -1 and seccolor == 1 then GlobalColor("alt1") else if c09 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c09 == -1 then GlobalColor("dwn1")
else if c09 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row09.SetHiding(!show_data_rows);

def c10 = dchannelalt(dlen - 9, maintrend);
plot row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));
row10.SetPaintingStrategy(PaintingStrategy.SQUARES);
row10.setlineweight(square_size);
row10.hidebubble();
row10.AssignValueColor(
if c10 == 2 then GlobalColor("up2")
#else if c10 == 1 then GlobalColor("up1")
else if c10 == 1 and seccolor == 1 then GlobalColor("alt1") else if c10 == 1 and seccolor == 2 then GlobalColor("up1")
#else if c01 == 1 then GlobalColor("up1")
else if c10 == -1 and seccolor == 1 then GlobalColor("alt1") else if c10 == -1 and seccolor == 2 then GlobalColor("dwn1")
#else if c10 == -1 then GlobalColor("dwn1")
else if c10 == -2 then GlobalColor("dwn2")
else GlobalColor("none"));
row10.SetHiding(!show_data_rows);

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
plot zc = if show_sum_histo then (absvalue(colorsum)) else na;
zc.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
zc.AssignValueColor( if colorsum == (2*10) then color.green
#else if colorsum > 0 then color.cyan
#else if colorsum > 0 then color.yellow
else if colorsum > 0 and seccolor == 1 then GlobalColor("alt1") else if colorsum > 0 and seccolor == 2 then
GlobalColor("up1")
else if colorsum == (-2*10) then color.red
# else if colorsum < 0 then color.yellow
else if colorsum < 0 and seccolor == 1 then GlobalColor("alt1") else if colorsum < 0 and seccolor == 2 then
GlobalColor("dwn1")
 else color.gray);
zc.SetHiding(!show_sum_histo);


# -----------------------------

# pine code

#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © LonesomeTheBlue

#//@version=4
#study("Donchian Trend Ribbon", precision = 0)
#dlen = input(defval = 20, title = "Donchian Channel Period", minval = 10)

#dchannel(len)=>
#    float hh = highest(len)
#    float ll = lowest(len)
   
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
   
#dchannelalt(len, maintrend)=>
#    float hh = highest(len)
#    float ll = lowest(len)
   
#    int trend = 0
#    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])

# last 2 digits are opacity of the color. if a trend, then dark,  else pale color ( i think)
#    maintrend == 1  ? trend == 1  ? #00FF00ff :  #00FF009f :
#     maintrend == -1 ? trend == -1 ? #FF0000ff :  #FF00009f :
#     na

#maintrend = dchannel(dlen)

#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)
#
 
Last edited:
Thank you so much, just great. I do have a request for you. Being a scalper, I'd like reduce the period of study from the default to like 4 or 5. I tried doing that by adjusting the period on the study, but it doesnt seem to have any effect. Looks like you're setting the minimum period to 10, with this
"
input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
"
and using the 9 lower periods to estimate the trend direction. I tried changing this particular line of code to "def dlen = if Donchian_Channel_Period < 10 then 5" , but it doesnt plot anything when I do that.
I'm not much familiar with thinkscript coding, would you kindly make this a truly customizable study, where we can adjust the periods or what do I need to do to edit the code.
Thanks!
 
@halcyonguy How do you set this up for the scanner? I was trying to set it up for buy signal (all green bar on the donchian) but I can't figure it out
Add the below code to the bottom of your script:
Ruby:
def AllGreen = row01>0 and row02>0 and row03>0 and row04>0 and row05>0 and row06>0 and row07>0 and row08>0 and row09>0 and row10>0 ;
plot scan = AllGreen and !AllGreen[1];
     scan.hide();

In Scan Hacker, type in the name of your study. Filter on scan is true
 
This indicator is great!

What code would need to be added to include a "ding" alert on a confirmed color change?

@halcyonguy
Add the below code to the bottom of your script:
Ruby:
def AllGreen = row01>0 and row02>0 and row03>0 and row04>0 and row05>0 and row06>0 and row07>0 and row08>0 and row09>0 and row10>0 ;
plot scan = AllGreen and !AllGreen[1];
      scan.hide();
Alert(scan, "AllGreen", Alert.Bar, Sound.ding);
 
Is it possible to create a custom watchlist column that displays the buy/sell/weakbuy/weaksell signals coming in?

dSgwTkc.png
 
Is it possible to create a custom watchlist column that displays the buy/sell/weakbuy/weaksell signals coming in?

dSgwTkc.png
I gave your request my best shot, but the watchlist script throws an error:
com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data.

Donchian Trend with the 10 lines summarized is just too complex for use in a watchlist column script.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
292 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top