Naked Bar Upward Reversal
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MrDevDevy

//@version=5
indicator("Naked Bar Upward Reversal", overlay=true, max_lines_count=500)

Text            = input.string( defval="NBUR",      title="Text above bar",     group="Settings")
BoundaryColor   = input.color(  defval=color.blue,  title="Bounding Box Color", group="Settings")

// A Naked Bar is one that closes BELOW the previous LOW and is a down bar.
// Rules for the inside bar are as follows: Must follow the Naked Bar with an OPEN GREATER than the Naked Bar CLOSE.

bool IsNaked    = ( close[1] < low[2]   and close[1] < open[1])   ? true : false
bool IsInside   = ( (high[0] < high[1]) and (low[0] > low[1]) and (open[0] > close[1]) ) ? true : false

if(IsNaked and IsInside)

    TopBound = math.max(high[0],    high[1],    high[2]) 
    LowBound = math.min(low[0],     low[1],     low[2])
    
    label.new(bar_index[1], TopBound, style=label.style_none, text=Text)
    
    //top boundary
    line.new(bar_index[2], TopBound,    bar_index,      TopBound,   color=BoundaryColor)
    //bottom boundary
    line.new(bar_index[2], LowBound,    bar_index,      LowBound,   color=BoundaryColor)
    //left boundary
    line.new(bar_index[2], TopBound,     bar_index[2],   LowBound,     color=BoundaryColor)
    //right boundary
    line.new(bar_index[0], TopBound,     bar_index[0],   LowBound,     color=BoundaryColor)