Indicator · Pine Script v4 · On the chart

Donchian Ichimoku Hybrid

by rocketbrainsurgeon

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.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code52
Settings4inputs
LicenceGPL-3.0
Last update5 years ago24 Jun 2021

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

rocketbrainsurgeon on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Breakout, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lengthint20dc_length
Sourcesourcehl2src
SystemstringNonesystem
Dark ModeboolfalsedarkMode
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.

Similar Pine Scripts

Sideway Zones Live

by dearvn
257 stars

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

Indicator v5 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Sideway Zones Live
56 stars

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

Indicator v5 TrendSupport & resistance Repaints
Updated 2 months ago · None stated GitHub repository of Trendlines With Breaks [LUX]

Reversal Breakout System

by TamaraKGreen
46 stars

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

Indicator v6 Candlestick patternsBreakout
Updated 7 weeks ago · None stated GitHub repository of Reversal Breakout System
24 stars

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

Indicator v5 SMC / ICT / price actionSupport & resistance Repaints
Updated 11 days ago · Custom licence GitHub repository of Smart Money Concepts [LuxAlgo] Test B

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,

Indicator v6 TrendVolatility & bands
Updated 2 days ago · MIT GitHub repository of Market Tradability Engine [WavesUnchained]

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

Indicator v4 TrendBreakout
Updated 4 years ago · None stated GitHub repository of Accurate Swing Trading System

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers