Daily Chart 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("Daily Chart Pattern")
bullColor         = input.color(color.white, "Bull Candle")
bearColor         = input.color(color.black, "Bear Candle")
timeRange1        = input.string("1000-1100", "Visible #1 Time Range")
firstCandleRange1 = input.string("1000-1005", "First Bar #1 Time Range")
isShowLabel       = input.bool(true, "Show Time Label")
oddBgColor        = input.color(color.new(color.silver, 75), "Background Color 1")
evenBgColor       = input.color(color.new(color.white, 75), "Background Color 2")
labelColor        = input.color(color.new(color.white, 100), "Label Color")

M5TimeIndex = 5 * 60 * 1000 // 5 minutes
tr1 = time(timeframe.period, timeRange1)
fcr1 = time(timeframe.period, firstCandleRange1)

var float lowestX = 0
var bool isNewDay = false
if (na(tr1))
    lowestX := 0
if (not na(fcr1))
    lowestX := low
    isNewDay := true
else
    isNewDay := false

var float[] vOpenList  = array.new_float(0)
var float[] vHighList  = array.new_float(0)
var float[] vLowList   = array.new_float(0)
var float[] vCloseList = array.new_float(0)
var string[] vTimeList = array.new_string(0)
var bool[] vNewDayList = array.new_bool(0)

if (not na(tr1))
    array.push(vOpenList, open - lowestX)
    array.push(vHighList, high - lowestX)
    array.push(vLowList, low - lowestX)
    array.push(vCloseList, close - lowestX)
    array.push(vTimeList, str.format("{0,date, y-MM-d}", time))
    array.push(vNewDayList, isNewDay)

lastXCandleIndex = array.size(vOpenList)

isStartDraw = time > timenow - (lastXCandleIndex * M5TimeIndex)
var arrIdx = -1
if (isStartDraw)
    arrIdx := arrIdx + 1

getPrice(arrayy, flagg, indexx) =>
    flagg ? array.get(arrayy,  indexx) : 0

vOpen   = isStartDraw ? array.get(vOpenList, arrIdx)   : 0
vHigh   = isStartDraw ? array.get(vHighList, arrIdx)   : 0
vLow    = isStartDraw ? array.get(vLowList, arrIdx)    : 0
vClose  = isStartDraw ? array.get(vCloseList, arrIdx)  : 0
vTime   = isStartDraw ? array.get(vTimeList, arrIdx)   : ""
vNewDay = isStartDraw ? array.get(vNewDayList, arrIdx) : false

plotcandle(vOpen, vHigh, vLow, vClose, color = vOpen > vClose ? bearColor : bullColor)

var oddBg = false
if (vNewDay)
    if (isShowLabel)
        label.new(bar_index, vHigh, text = vTime, color = labelColor)
    oddBg := not oddBg

bgcolor(isStartDraw ? oddBg ? oddBgColor : evenBgColor : na)