This indicator builds a Donchian channel with midlines between the extremes, then uses Ichimoku-style logic to classify the market as trending up, trending down or ranging.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
52 lines of Pine Script v4 from Donchian Ichimoku Hybrid Channel.txt, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Donchian Ichimoku Hybrid Channel.txt
//@version=4
study("Donchian Ichimoku Hybrid",shorttitle="DIH",overlay=true)
dc_length = input(title="Length",defval=20)
length = bar_index > dc_length ? dc_length : bar_index+1
src = input(title="Source", type=input.source, defval=hl2)
system = input(title="System",options=["None","Trend","Retracement"],defval="None")
darkMode = input(title="Dark Mode",type=input.bool,defval=false)
// === DONCHIAN CHANNEL ===
donchian_channel(l)=>
t = highest(l)
b = lowest(l)
ba = avg(t,b)
tba = avg(t,ba)
bba = avg(b,ba)
[t,b,ba,tba,bba]
// == CHANNELS ===
[top,bottom,basis,top_basis,bottom_basis] = donchian_channel(length)
// === MARKET STATE ===
extreme = high == top or low == bottom
expansionUp = src > top[length] and high==top
expansionDown = src < bottom[length] and low==bottom
trend = barssince(expansionUp) < barssince(expansionDown)
trendStart = expansionUp or expansionDown
trendEnd = not trendStart and cross(src,basis)
trending = barssince(trendStart) < barssince(trendEnd or bar_index==0)
breakout = (expansionUp or expansionDown) and not trending[1]
trendFlip = (trend and not trend[1]) or (trend[1] and not trend)
rangeStart = (trendEnd and trending[1]) or (trendFlip and trending[1])
retracementTrigger = trending and (crossunder(src,top_basis) or crossover(src,bottom_basis))
retracement = retracementTrigger and not retracementTrigger[1]
// === DISPLAY STRATEGY ===
barcolor(trending and trend ? #2aa599 : trending and not trend ? #ee5451 : not trending ? color.gray : color.gray)
t = plot(top,color=#3bb3e4,linewidth=2,transp=65,title="Upper")
b = plot(bottom,color=#3bb3e4,linewidth=2,transp=65,title="Lower")
ba = plot(basis,color=#3bb3e4,transp=65,linewidth=2,title="Basis")
tba = plot(top_basis,color=#3bb3e4,linewidth=2,transp=100,title="Upper Basis")
bba = plot(bottom_basis,color=#3bb3e4,linewidth=2,transp=100,title="Lower Basis")
fill(tba,ba,transp=90,color=trend and trending ? #2aa599 : darkMode ? #191e28 : color.white,title="Upper Basis")
fill(ba,bba,transp=90,color=not trend and trending ? #ee5451 : darkMode ? #191e28: color.white,title="Lower Basis")
plotshape(system == "Retracement" and trend and retracement,style=shape.triangleup,color=color.green,size=size.small)
plotshape(system == "Retracement" and not trend and retracement,style=shape.triangledown,color=color.red,size=size.small)
plotshape(system == "Trend" and trend and trendFlip,style=shape.triangleup,color=color.green,size=size.small)
plotshape(system == "Trend" and not trend and trendFlip,style=shape.triangledown,color=color.red,size=size.small)
alertcondition(retracement,title="Retracement",message='{{ticker}} RETRACEMENT at {{close}}')
alertcondition(rangeStart,title="Range",message='{{ticker}} is RANGING at {{close}}')
alertcondition(trendFlip,title="Trend",message='TREND CHANGE on {{ticker}} at {{close}}')
Overview
Bars are coloured green, red or gray and the zones near the basis are shaded. An optional System setting plots triangle markers on trend flips or on retracements inside a trend. The length, price source and dark mode are adjustable. It draws on the price chart and includes alert conditions.
Donchian channel with upper and lower basis lines
Trend versus range bar colouring
Optional trend or retracement triangle markers
Alert conditions for retracement, range and trend change
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Length
int
20
dc_length
Source
source
hl2
src
System
string
None
system
Dark Mode
bool
false
darkMode
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
Sideway Zones Live is an overlay indicator that estimates inner and outer sideways bands from recent highs and lows with a rational quadratic kernel. It tracks swing pivots over a loopback period and counts bars that remain between the outer high and low. Afte
This indicator calculates dynamic upper and lower trendlines from pivot highs and pivot lows across a specified bar length. Trendline slopes are derived using ATR, standard deviation, or linear regression methods. It plots trendlines and breakout signal labels
This indicator detects inside candles inside larger parent candles on the price chart. It plots colored boxes around inside and parent candles, fills them with user-adjustable transparency, draws Fibonacci retracement lines and mother candle range lines, and d
This indicator maps Smart Money Concepts (SMC) market structure directly onto the price chart. It detects internal and swing structure breaks (BOS and CHoCH), tracks bullish and bearish order blocks, identifies fair value gaps (FVG), highlights equal highs and
The Market Tradability Engine calculates multi-factor tradability, balance, compression, and direction scores to evaluate market regime quality. It classifies market conditions into eight distinct states, including Balance, Compression, Ready, Breakout, Trend,
This indicator tracks swing highs and swing lows to generate trend-following trailing stop levels on the price chart. When the closing price breaks above the previous swing high, the system establishes a bullish state using the recent swing low as a trailing s