Open Price v5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © feibilanceon

//@version=5
indicator("Open Price v5", shorttitle="OP_v5", overlay=true)
len = input(60, "Length")

yearly_open = request.security(syminfo.tickerid, '12M', open, lookahead=barmerge.lookahead_on)
monthly_open = request.security(syminfo.tickerid, 'M', open, lookahead=barmerge.lookahead_on)
weekly_open = request.security(syminfo.tickerid, 'W', open, lookahead=barmerge.lookahead_on)

if weekly_open != weekly_open[1]
    var weekly_line = line.new(time,close,time,close, xloc=xloc.bar_time)
    // line.delete(weekly_line)
    weekly_line := line.new(time, weekly_open, time + 1000*60*60*24*7, weekly_open, xloc=xloc.bar_time, color=color.green)

if monthly_open != monthly_open[1]
    var monthly_line = line.new(time,close,time,close, xloc=xloc.bar_time)
    // line.delete(monthly_line)
    monthly_line := line.new(time, monthly_open, time + 1000*60*60*24*31, monthly_open, xloc=xloc.bar_time, color=color.orange)

if yearly_open != yearly_open[1]
    var yearly_line = line.new(time,close,time,close, xloc=xloc.bar_time)
    // line.delete(yearly_line)
    yearly_line := line.new(time, yearly_open, time + 1000*60*60*24*365, yearly_open, xloc=xloc.bar_time, color=color.aqua)
    

color statusColor = color.green

switch
    close > yearly_open and close > monthly_open and close > weekly_open => statusColor := color.new(color.green, 80)
    close > yearly_open and close > monthly_open and close < weekly_open => statusColor := color.new(color.green, 85)
    close > yearly_open and close < monthly_open and close > weekly_open => statusColor := color.new(color.green, 90)
    close > yearly_open and close < monthly_open and close < weekly_open => statusColor := color.new(color.green, 95)
    
    close < yearly_open and close > monthly_open and close > weekly_open => statusColor := color.new(color.red, 95)
    close < yearly_open and close > monthly_open and close < weekly_open => statusColor := color.new(color.red, 90)
    close < yearly_open and close < monthly_open and close > weekly_open => statusColor := color.new(color.red, 85)
    close < yearly_open and close < monthly_open and close < weekly_open => statusColor := color.new(color.red, 80)

bgcolor(statusColor)