GREEN MILE & RED SKY by Onur
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © onurenginogutcu

//@version=4
study("GREEN MILE & RED SKY by Onur" , overlay = true)

i = input(title="Periyod", type=input.integer, defval=1500, minval=10, maxval=3500)

/////////////////////////calculating fibo levels
up = highest (high , i)
down = lowest (low , i)

up1 = down + ((up - down) * 0.382)
up2 = down + ((up - down) * 0.236)
up3 = down + ((up - down) * 0.786)
up4 = down + ((up - down) * 0.618)
middle = down + ((up - down) * 0.5)


////////////////////////////labeling all fibo levels and buy/sell alert
dt = time - time[1]
if barstate.islast
    label.new(time + 3*dt, up, text = tostring (up), textcolor=color.new(color.blue,60),  style=label.style_none, xloc=xloc.bar_time)
    label.new(time + 3*dt, up4,text = tostring (up4), textcolor=color.new(color.blue,60), style=label.style_none, xloc=xloc.bar_time)
    label.new(time + 3*dt, up3,text = tostring (up3), textcolor=color.new(color.blue,60), style=label.style_none, xloc=xloc.bar_time)
    label.new(time + 3*dt, up2,text = tostring (up2), textcolor=color.new(color.blue,60),  style=label.style_none, xloc=xloc.bar_time)
    label.new(time + 3*dt, up1,text = tostring (up1), textcolor=color.new(color.blue,60), style=label.style_none, xloc=xloc.bar_time)
    label.new(time + 3*dt, down,text = tostring (down), textcolor=color.new(color.blue,60), style=label.style_none, xloc=xloc.bar_time)
    if close > up3
        label.new(time + 3*dt, close, text = "STRONG SELL AREA", textcolor=color.new(color.red,30),  style=label.style_none, xloc=xloc.bar_time)
    if close > up4
        if close <= up3
            label.new(time + 3*dt, close, text = "SELL AREA", textcolor=color.new(color.red,30),  style=label.style_none, xloc=xloc.bar_time)
    if close >= down
        if close < up2
            label.new(time + 3*dt, close, text = "STRONG BUY AREA", textcolor=color.new(color.green,30),  style=label.style_none, xloc=xloc.bar_time)
    if close >= up2
        if close < up1
            label.new(time + 3*dt, close, text = "BUY AREA", textcolor=color.new(color.green,30),  style=label.style_none, xloc=xloc.bar_time)

///////plotting buying levels of fibonacci
a = plot(up1 , color = color.new(color.green,0) )
b = plot(up2 ,  color = color.new(color.green,0) )
c = plot(down ,  color = color.new(color.green, 0) )

////////plotting %50 level of fibo
g = plot(middle , color = color.new(color.gray,0) )

//////plotting selling levels of fibonacci
d = plot(up3 , color = color.new(color.red,0) )
e = plot(up4 ,  color = color.new(color.red,0) )
f = plot(up ,  color = color.new(color.red, 0) )

//////////colouring area of buying levels
fill(a, b, color = color.new(color.green,95))
fill(b, c,  color = color.new(color.green,75))

////////colouring area of selling levels
fill(f, d, color = color.new(color.red,75))
fill(e, d,  color = color.new(color.red,95))


