Time Range Bar Pattern
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 
// Created by @jayallways for Tom
 
//@version=5
indicator("Time Range Bar Pattern")
bullColor         = input.color(color.white, "Bull Candle")
bearColor         = input.color(color.black, "Bear Candle")
londonColor       = input.color(color.new(color.blue, 70), "London Session Color")
newyorkColor      = input.color(color.new(color.red, 70), "New York Session Color")
timeRange1        = input.string("1000-1100", "Visible #1 Time Range")
firstCandleRange1 = input.string("1000-1005", "First Bar #1 Time Range")
timeRange2        = input.string("1630-1730", "Visible #2 Time Range")
firstCandleRange2 = input.string("1630-1635", "First Bar #2 Time Range")

var string[] dateList = array.new_string(0)
tr1 = time(timeframe.period, timeRange1)
tr2 = time(timeframe.period, timeRange2)
fcr1 = time(timeframe.period, firstCandleRange1)
fcr2 = time(timeframe.period, firstCandleRange2)

var count = bar_index
number = bar_index % 10

var float lowestX = 0
if (na(tr1) and na(tr2))
    lowestX := 0
if (not na(fcr1) or not na(fcr2))
    lowestX := low

c_open  = (na(tr1) and na(tr2)) ? 0 : open - lowestX
c_high  = (na(tr1) and na(tr2)) ? 0 : high - lowestX
c_low   = (na(tr1) and na(tr2)) ? 0 : low - lowestX
c_close = (na(tr1) and na(tr2)) ? 0 : close - lowestX

plotcandle(c_open, c_high, c_low, c_close, color = close >= open ? bullColor : bearColor)
bgcolor(not na(tr1) ? londonColor : not na(tr2) ? newyorkColor : na)
