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

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


p = input(600, title = 'period range')
n = input(20.0, title = 'divisions')

h = highest(high, p)
l = lowest(low, p)

d = h - l
f = d/n

var r = l
var g = l + f

for i = 1 to n
    if ohlc4 > l + f*i
        r := l + f*i
        g := l + f*(i + 1)
        if ohlc4 < l + f*i
            r := l + f * (i - 1)
            g := l + f*i

var a = 0
if r < r[1]
    a := 1
if r > r[1]
    a := 0
p1 =  plot(r, color = color.green, linewidth = 2)
p2 =  plot(g, color = color.red, linewidth = 2)
fill(p1, p2, color = a == 1 ? color.red : color.green, transp = 70)


