Highest High and Lowest Low Channel Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ceyhun

//@version=5
strategy('Highest High and Lowest Low Channel Strategy', overlay=true)

length = input(20)
reverse = input(false, title='Trade reverse')
hh = ta.highest(high, length)
ll = ta.lowest(low, length)

pos = 0.0
iff_1 = close < ll[1] ? -1 : nz(pos[1], 0)
pos := close > hh[1] ? 1 : iff_1
iff_2 = reverse and pos == -1 ? 1 : pos
possig = reverse and pos == 1 ? -1 : iff_2

if possig == 1
    strategy.entry('Long', strategy.long)
if possig == -1
    strategy.entry('Short', strategy.short)
barcolor(possig == -1 ? color.red : possig == 1 ? color.green : color.blue)
plot(hh[1], color=color.new(color.green, 0), title='HH', linewidth=2)
plot(ll[1], color=color.new(color.red, 0), title='LL', linewidth=2)

