0
time_selection_1 = input.time(timestamp("Jun 01 2023 10:00:00 UTC+3"), 'Date/Time')
time_selection_2 = input.time(timestamp("Jun 02 2023 10:00:00 UTC+3"), 'Date/Time')

var bool highlight_date = na

if time_selection_1 == time 
    highlight_date := true 
else 
    highlight_date := false

if time_selection_2 == time 
    highlight_date := true 
else 
    highlight_date := false

All of the selected date/time in the input dialog needs to be highlighted in the chart. Currently, the first time_selection_1 is highlighted but the second time_selection_2 is not shown in the chart. Any ideas as to why this is happening?

x945
  • 27
  • 6

1 Answers1

1

You are overwriting the flag.

Just go from top to bottom and you will see.

You first check if it is time_selection_1. If it is, then you set your flag to true. But then you check if it is time_selection_2. And if it is not, you set your flag to false. So, you modify your flag twice in an execution.

You can just use two different variables and or them.

//@version=5
indicator("My script", overlay=true)

time_selection_1 = input.time(timestamp("Jun 01 2023 10:00:00 UTC+3"), 'Date/Time')
time_selection_2 = input.time(timestamp("Jun 02 2023 10:00:00 UTC+3"), 'Date/Time')

var is_sel_1 = false
var is_sel_2 = false

if time_selection_1 == time 
    is_sel_1 := true 
else 
    is_sel_1 := false

if time_selection_2 == time 
    is_sel_2 := true 
else 
    is_sel_2 := false

highlight_date = is_sel_1 or is_sel_2

bgcolor(highlight_date ? color.new(color.blue, 85) : na)

enter image description here

vitruvius
  • 15,740
  • 3
  • 16
  • 26