All free tools

Trend indicator

Donchian Channels Calculator

Compute the upper, middle, and lower Donchian Channels from the highest high and lowest low of your lookback period. The idea, a channel that simply tracks the recent price extremes, is the part worth understanding.

Upper channel
114.00
Middle channel
109.40
Lower channel
104.80
Channel width
9.20

What Donchian Channels are

Donchian Channels were developed by Richard Donchian and plot the highest high and the lowest low of the last N bars as an upper and a lower band. A middle line sits halfway between them.

The formulas are direct: the upper channel is the highest high over N periods, the lower channel is the lowest low over N periods, and the middle channel is their average. The common default is 20 periods. Unlike Bollinger Bands or Keltner Channels, there is no moving average or volatility measure involved, so the bands move in steps whenever a new extreme enters or leaves the window.

Why Donchian Channels are used

Donchian Channels are used to frame the recent trading range and to study breakouts, where price closes beyond the prior upper or lower band. The width of the channel also gives a simple view of how wide the recent range has been.

The 20 period default is a convention, and the right length depends on the market and timeframe. How you read price against the channel is entirely your own decision.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

This calculator gives you one set of channel values. On a chart the three lines recalculate every bar. Pine Script builds them from ta.highest and ta.lowest in a few lines, but the plotting, fills, and any breakout logic around them still need to be written.

Pine Script v6
//@version=6
indicator("Donchian Channels", overlay=true)

length = input.int(20, "Length", minval=1)

upper  = ta.highest(high, length)
lower  = ta.lowest(low, length)
middle = math.avg(upper, lower)

plot(middle, "Middle", color=color.orange)
p1 = plot(upper, "Upper", color=color.blue)
p2 = plot(lower, "Lower", color=color.blue)
fill(p1, p2, color=color.new(color.blue, 90))

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

Related free calculators

From the blog

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.