Donchian Channels System [racer8]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © racer8
//@version=4
strategy("Donchian Channels System", overlay=true)

n = input(20,"Period")
hi = highest(n)
lo = lowest(n)
cl = close
mid = 0.5*(hi + lo)

if cl>hi[1]
    strategy.entry("Buy", strategy.long)

if cl<lo[1]
    strategy.entry("Sell", strategy.short)
    
if close<mid
    strategy.close("Buy")

if close>mid
    strategy.close("Sell")

plot(hi,color=color.blue)
plot(lo,color=color.red)
plot(mid,color=color.gray)
