Indicator · Pine Script v6 · On the chart

Price Channel (PCHANNEL)

by mihakralj

The Price Channel indicator calculates and plots the dynamic highest high and lowest low over a user-defined lookback period, alongside a central midpoint line.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code64
Settings1inputs
LicenceMIT
Last update8 months ago28 Feb 2026

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

64 lines of Pine Script v6 from indicators/channels/pchannel.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

pchannel.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Price Channel (PCHANNEL)", "PCHANNEL", overlay=true)

//@function Calculates Price Channel
//@param length_param Lookback period for determining the highest high and lowest low
//@returns tuple [upperChannel, middleChannel, lowerChannel]
//@optimized Uses monotonic deque for O(1) amortized complexity per bar
pchannel(simple int length_param) =>
    if length_param <= 0
        runtime.error("Length must be greater than 0")
    var deque_hi = array.new_int(0)
    var src_buffer_hi = array.new_float(0, na)
    var int current_index_hi = 0
    var deque_lo = array.new_int(0)
    var src_buffer_lo = array.new_float(0, na)
    var int current_index_lo = 0
    if array.size(src_buffer_hi) != length_param
        src_buffer_hi := array.new_float(length_param, na)
        current_index_hi := 0
        array.clear(deque_hi)
        src_buffer_lo := array.new_float(length_param, na)
        current_index_lo := 0
        array.clear(deque_lo)
    float cv_hi = nz(high)
    array.set(src_buffer_hi, current_index_hi, cv_hi)
    float cv_lo = nz(low)
    array.set(src_buffer_lo, current_index_lo, cv_lo)
    while array.size(deque_hi) > 0 and array.get(deque_hi, 0) <= bar_index - length_param
        array.shift(deque_hi)
    while array.size(deque_lo) > 0 and array.get(deque_lo, 0) <= bar_index - length_param
        array.shift(deque_lo)
    while array.size(deque_hi) > 0
        if array.get(src_buffer_hi, array.get(deque_hi, array.size(deque_hi) - 1) % length_param) <= cv_hi
            array.pop(deque_hi)
        else
            break
    array.push(deque_hi, bar_index)
    while array.size(deque_lo) > 0
        if array.get(src_buffer_lo, array.get(deque_lo, array.size(deque_lo) - 1) % length_param) >= cv_lo
            array.pop(deque_lo)
        else
            break
    array.push(deque_lo, bar_index)
    float highestHigh = array.get(src_buffer_hi, array.get(deque_hi, 0) % length_param)
    current_index_hi := (current_index_hi + 1) % length_param
    float lowestLow = array.get(src_buffer_lo, array.get(deque_lo, 0) % length_param)
    current_index_lo := (current_index_lo + 1) % length_param
    [highestHigh, (highestHigh + lowestLow) / 2.0, lowestLow]

// ---------- Main loop ----------

// Inputs
i_length = input.int(20, "Length", minval=1)

// Calculation
[upperCh, middleCh, lowerCh] = pchannel(i_length)

// Plot
plot(middleCh, "Middle Channel", color=color.yellow, linewidth=2)
p1 = plot(upperCh, "Upper Channel", color=color.yellow, linewidth=2)
p2 = plot(lowerCh, "Lower Channel", color=color.yellow, linewidth=2)
fill(p1, p2, color=color.new(color.blue, 90), title="Band Fill")

Overview

Built using monotonic deques for optimized streaming runtime efficiency, it plots an upper channel boundary, lower channel boundary, and a middle channel line directly on the price chart with a background fill between the outer bands. Traders can modify the single lookback length setting to adjust sensitivity to price extremes.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance, Volatility & bands, Breakout

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.

Topics

pinescriptpinescript-indicatorstechnical-analysistradingview-indicators

Settings

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

SettingTypeDefaultVariable
Lengthint20i_length
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

Donchian Channels (DC)

by mihakralj
99 stars

This indicator calculates and plots Donchian Channels directly on the price chart. It determines the highest high and lowest low over a user-selected lookback period using an optimized monotonic deque algorithm, as well as a middle basis line computed as their

Indicator v6 Volatility & bandsSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of Donchian Channels (DC)
43 stars

This indicator plots Donchian channel bands and a midline on the price chart. It finds the highest and lowest values over a user-set length, then draws the upper band, lower band, and their average as the basis. The source setting chooses high and low, or the

Indicator v4 Volatility & bandsBreakout
Updated 1 year ago · None stated GitHub repository of Donchian Channels Experiment

Zen ABR Against

by Zen-Tim
29 stars

This overlay indicator measures average bar range as a simple moving average of high minus low, then draws short horizontal ticks at one to four times that range above and below the close. The user chooses which multipliers appear, their colors, and the line w

Indicator v6 Volatility & bandsSupport & resistance
Updated 2 weeks ago · MIT GitHub repository of Zen ABR Against

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 yesterday · MIT GitHub repository of Market Tradability Engine [WavesUnchained]

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

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