How can I create a Donchian Channel indicator in Pine Script?

Asked by Radhesh Joshi · SOLVED
1 reply 241 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

I’m creating my own technical indicators in Pine Script and want to build a Donchian Channel from scratch instead of using a built-in indicator.

I want to understand how the upper and lower channel levels are calculated using the highest high and lowest low over a selected period.

What is the correct way to create a Donchian Channel in Pine Script?

Posted Aug 19
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    Yes sir, you can definitely create a Donchian Channel in Pine Script.

    A Donchian Channel is mainly made up of three lines:

    -> Upper Band = Highest High over the selected length
    -> Lower Band = Lowest Low over the selected length
    -> Middle Line = Average of the Upper and Lower Bands

    You can create it using:

    indicator("Custom Donchian Channel", overlay=true) 
    length = input.int(20, "Length") 
    upperBand = ta.highest(high, length) 
    lowerBand = ta.lowest(low, length) 
    middleBand = (upperBand + lowerBand) / 2 
    upperPlot = plot(upperBand, "Upper Band") 
    lowerPlot = plot(lowerBand, "Lower Band") 
    plot(middleBand, "Middle Band")
    fill(upperPlot, lowerPlot, color = color.new(color.blue, 95))

    -> ta.highest() finds the highest high within the selected period.

    -> ta.lowest() finds the lowest low within the selected period.

    -> The middle line is calculated from the average of the upper and lower bands.

    -> fill() highlights the area between the two channel boundaries.

    You can change the channel length directly from the indicator settings. The commonly used default is 20 periods.

    So that’s how you can create a basic Donchian Channel indicator from scratch in Pine Script.

    Verified Solution
      Markdown supported · ```json for code blocks · paste or drop screenshots

      Be specific and kind. Never share API keys, passwords or personal account details.

      Welcome to the community

      Log in or create your account in under a minute.

      1. 1Mobile
      2. 2E-mail
      3. 3Password
      +91

      Have a password?

      By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.