How to plot only when is in London and New York sessions

How to show the fractal only when is in London or New York session?

That’s how I’m showing the fractal

plotshape(filteredtopf, title=”Top Fractals”, style=shape.triangledown, location=location.abovebar, color=color.new(color.white, 0), offset=-2, display = display.all – display.price_scale – display.status_line)

That’s what I tried

session_time = input.session(“1200-1500”, “Session”)
is_in_session = time(timeframe.period, session_time + “:1234567”)

if is_in_session
plotshape(filteredtopf, title=”Top Fractals”, style=shape.triangledown, location=location.abovebar, color=color.new(color.white, 0), offset=-2, display = display.all – display.price_scale – display.status_line)

You can use time() and pass your session strings to it to figure out if your are in a given session. Then simply and them.

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

london_sess = input.session("0700-1600", "London")
newyork_sess = input.session("1300-2200", "New York")

is_in_london = time(timeframe.period, london_sess)
is_in_newyork = time(timeframe.period, newyork_sess)
is_in_both = is_in_london and is_in_newyork

bgcolor(is_in_london ? color.new(color.white, 85) : na)
bgcolor(is_in_newyork ? color.new(color.yellow, 85) : na)
bgcolor(is_in_both ? color.new(color.green, 85) : na)

Background color is white when in London session and yellow when in New York session. It will be green if the current bar is in both sessions.

enter image description here

Leave a Comment