OHLC [TFO]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeforopp

//@version=5
indicator("OHLC [TFO]", "OHLC [TFO]", true)

var g1 = "Settings"
tf = input.timeframe("D", "Timeframe", group = g1)
bar_offset = input.int(20, "OHLC Bar Offset", minval = 0, maxval = 100, group = g1)
bar_width = input.int(30, "OHLC Bar Width", minval = 0, maxval = 100, group = g1)

var g2 = "Style"
up_color = input.color(color.green, "Up Color", group = g2)
down_color = input.color(color.red, "Down Color", group = g2)
wick_color = input.color(color.gray, "Wick Color", group = g2)
border_color = input.color(color.gray, "Border Color", group = g2)
body_width = input.int(10, "Body Border Width", group = g2)
wick_width = input.int(5, "Wick Border Width", group = g2)

[d_o, d_h, d_l, d_c] = request.security(syminfo.tickerid, tf, [open, high, low, close], barmerge.gaps_off, barmerge.lookahead_on)

up_candle = d_c > d_o
wick_start = bar_offset + math.floor(bar_width / 2 - 1)
wick_end = bar_offset + math.ceil(bar_width / 2 + 1)

var box candle_wick = box.new(na, na, na, na, border_color = wick_color, bgcolor = wick_color, border_width = wick_width)
var box candle_body = box.new(na, na, na, na, border_color = border_color, bgcolor = wick_color, border_width = body_width)

box.set_lefttop(candle_wick, bar_index + wick_start, d_h)
box.set_rightbottom(candle_wick, bar_index + wick_end, d_l)

box.set_lefttop(candle_body, bar_index + bar_offset, up_candle ? d_c : d_o)
box.set_rightbottom(candle_body, bar_index + bar_offset + bar_width, up_candle ? d_o : d_c)

if up_candle
    box.set_bgcolor(candle_body, up_color)
else
    box.set_bgcolor(candle_body, down_color)