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.