Extended Hour Candle
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fyntrade
// Version 1.1.2 - 23 Sep 2023

//@version=5
indicator("Extended Hour Candle", overlay = true, shorttitle = "Ext")

i_col_up = input.color(defval = #26a69a, title = "Up Color", group = "Colors")
i_col_down = input.color(defval = #ef5350, title = "Down Color", group = "Colors")

ext_close = array.last(request.security_lower_tf(ticker.new(syminfo.prefix, syminfo.ticker, session.extended), "30", close))
ext_session = array.last(request.security_lower_tf(ticker.new(syminfo.prefix, syminfo.ticker, session.extended), "30", session.ismarket == false))
ext_high = request.security_lower_tf(ticker.new(syminfo.prefix, syminfo.ticker, session.extended), "30", session.ismarket == false ? high : na)
ext_low = request.security_lower_tf(ticker.new(syminfo.prefix, syminfo.ticker, session.extended), "30", session.ismarket == false ? low : na)
hh = array.max(ext_high)
ll = array.min(ext_low)

type bar
    array<box>  body
    array<line> wick

bi = bar_index
var plot_bar = bar.new(array.new<box>(1), array.new<line>(1))

method candle(bar b)=>
    int dist = 1 //distance to last bar
    int bb = ext_close > close ? 1 : ext_close < close ? -1 : 0 //bull or bear
    top = bb > 0 ? ext_close : close
    bot = bb > 0 ? close : ext_close
    col = bb == 1 ? i_col_up : bb == -1 ? i_col_down : chart.fg_color
    b.body.set(0, box.new(bi + dist, top, bi + dist + 2, bot, na, bgcolor = col))
    b.wick.set(0, line.new(bi + dist + 1, hh , bi + dist + 1, ll, color = col))


if barstate.islast and timeframe.isdaily and ext_session
    plot_bar.candle()
