Indicator Daily-Weekly-Range-In-Price
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Maurizio-Ciullo

//@version=5
indicator("Indicatore Daily-Weekly-Range-In-Price", overlay=true)

//Inputs
input_daily_range = input.bool(defval=true)
input_weekly_range = input.bool(defval=false)

//Daily sessions and range
dailySessionDataHigh = request.security(syminfo.tickerid,"D", high)
dailySessionDataLow = request.security(syminfo.tickerid,"D", low)
dailyRangeInPrice = dailySessionDataHigh - dailySessionDataLow

plot(input_daily_range == true ? dailySessionDataHigh : na, title="weeklySessionDataHigh", color=color.blue)
plot(input_daily_range == true ? dailySessionDataLow : na, title="weeklySessionDataLow", color=color.blue)
plot(input_daily_range == true ? dailyRangeInPrice : na, style=plot.style_histogram, color=color.blue)

//Weekly sessions and range
weeklySessionDataHigh = request.security("","W", high)
weeklySessionDataLow = request.security("","W", low)
weeklyRangeInPrice = weeklySessionDataHigh - weeklySessionDataLow

plot(input_weekly_range == true ? weeklySessionDataHigh : na, title="weeklySessionDataHigh", color=color.blue)
plot(input_weekly_range == true ? weeklySessionDataLow : na, title="weeklySessionDataLow", color=color.blue)
plot(input_weekly_range == true ? weeklyRangeInPrice : na, style=plot.style_histogram, color=color.blue)


label_daily_range_text = input_daily_range == true ? str.tostring(dailyRangeInPrice) : na
label_daily_range = label.new(x=bar_index, y=na, yloc=yloc.belowbar, text=label_daily_range_text, style=label.style_label_lower_left, textcolor=color.white, size=size.normal)

label_weekly_range_text = input_weekly_range == true ? str.tostring(weeklyRangeInPrice) : na
label_weekly_range = label.new(x=bar_index, y=na, yloc=yloc.belowbar, text=label_weekly_range_text, style=label.style_label_down, textcolor=color.white, size=size.normal)

