Bar Magnifier
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
//                                       ░▒             
//                                  ▒▒▒   ▒▒      
//                              ▒▒▒▒▒     ▒▒      
//                      ▒▒▒▒▒▒▒░     ▒     ▒▒          
//                  ▒▒▒▒▒▒           ▒     ▒▒          
//             ▓▒▒▒       ▒        ▒▒▒▒▒▒▒▒▒▒▒  
//   ▒▒▒▒▒▒▒▒▒▒▒ ▒        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒         
//   ▒  ▒       ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░        
//   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒         
//   ▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒                       
//    ▒▒▒▒▒         ▒▒▒▒▒▒▒                            
//                 ▒▒▒▒▒▒▒▒▒                           
//                ▒▒▒▒▒ ▒▒▒▒▒                          
//               ░▒▒▒▒   ▒▒▒▒▓      ████████╗██████╗ ███████╗███╗   ██╗██████╗  ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗
//              ▓▒▒▒▒     ▒▒▒▒      ╚══██╔══╝██╔══██╗██╔════╝████╗  ██║██╔══██╗██╔═══██╗██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝
//              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒        ██║   ██████╔╝█████╗  ██╔██╗ ██║██║  ██║██║   ██║███████╗██║     ██║   ██║██████╔╝█████╗ 
//             ▒▒▒▒▒       ▒▒▒▒▒       ██║   ██╔══██╗██╔══╝  ██║╚██╗██║██║  ██║██║   ██║╚════██║██║     ██║   ██║██╔═══╝ ██╔══╝  
//            ▒▒▒▒▒         ▒▒▒▒▒      ██║   ██║  ██║███████╗██║ ╚████║██████╔╝╚██████╔╝███████║╚██████╗╚██████╔╝██║     ███████╗
//             ▒▒             ▒                        
//@version=5
indicator("Bar Magnifier", max_lines_count = 500, max_boxes_count = 250)

barTime = input.time(0, title="Select Bar", confirm = true)
lowerTimeframe = input.timeframe("1", 'Lower Timeframe')

type ohlc
    float o
    float h
    float l
    float c

getOhlc()=>ohlc.new(open, high, low, close)

array<ohlc> ohlcArray = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, getOhlc(), true) 

bgcolor(time == barTime?color.aqua:na)

var int l = na
var int r = na
var float t = na
var float b = na
if(time == barTime)
    lastClose = close[1]
    
    for [i, ohlcValue] in ohlcArray
        left = bar_index-3*(array.size(ohlcArray)-i)
        right = left + 2
        mid = left + 1
        borderColor = ohlcValue.c > lastClose? color.green : color.red
        lastClose := ohlcValue.c
        bgcolor = ohlcValue.c > ohlcValue.o? na: borderColor
        ocMax = math.max(ohlcValue.o, ohlcValue.c)
        ocMin = math.min(ohlcValue.o, ohlcValue.c)
        box.new(left, ocMax, right, ocMin, borderColor, 1, bgcolor=bgcolor)
        line.new(mid, ocMax, mid, ohlcValue.h, color=borderColor)
        line.new(mid, ocMin, mid, ohlcValue.l, color=borderColor)
    leftMost = bar_index-3*(array.size(ohlcArray))
    rightMost = bar_index
    borderColor = close > close[1]? color.green : color.red
    bodyColor = color.new(borderColor, 90)
   
    box.new(leftMost, math.max(open, close), rightMost, math.min(open, close), borderColor, 0, line.style_dotted, extend.none, xloc.bar_index, bodyColor)
