βœ–

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

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

  • Author
    Posts
    • 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?

    • 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.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top