st_market_phase
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alferow

//@version=4
study("st_market_phase", overlay = true)

p = input(24, title = 'period')

s = (lowest(low, p) + highest(high, p))*0.5

var t = 0
if s > s[1]
    t := 1
if s < s[1]
    t := 0
    
st = t == 1 ? s - 0.1*ema(s, p) : s + 0.1*ema(s, p) 

col = st < close ? color.green : color.red

p1 = plot(close)
p2 = plot(st)


fill(p1, p2, color = col)


