Gann High Low Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dongyun

//@version=4
strategy("Gann High Low Strategy", overlay=true)

HPeriod = input(16,"HIGH Period")
LPeriod = input(48,"LOW Period")

hsma = 0.0
lsma = 0.0

hsma := sma(high,HPeriod)
lsma := sma(low,LPeriod)

HLd = iff(close>nz(hsma[1]),1,iff(close<nz(lsma[1]),-1,0))
HLv = valuewhen(HLd!=0,HLd,0)
HiLo = iff(HLv==-1,hsma,lsma)
HLcolor = HLv == -1 ? color.maroon : color.blue

plot(HiLo, linewidth=2, color=HLcolor)

if HLv == -1
    strategy.entry("short", strategy.short)
else
    if HLv == 1
        strategy.entry("long", strategy.long)