Failed Auction
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © geneclash

//@version=5
indicator("Failed Auction",overlay=true,max_lines_count=500)

//INPUTS
hideLine = input.bool(false,title="Hide Successful Auctions")

actLines = input.bool(true,title="Lines:",inline="l1")
lineClr = input.color(color.new(color.black,80),title="",inline="l1")
lineStyle = input.string("Solid",options=["Solid","Dotted","Dashed"],inline='l1',title="")
lineWidth = input.int(1,title="",inline="l1")

StyleToEnum(s) =>
    if s == 'Solid'
        line.style_solid
    else if s == 'Dotted'
        line.style_dotted
    else
        line.style_dashed

//CALCS
var float lineValue = na
var line lineOne = na
var arrLineBarIndex = array.new_float(0)

GreenBar = close > open
FailedAuctionCond = (high == high[1] and GreenBar==false and GreenBar[1]) or (low == low[1] and GreenBar and GreenBar[1]==false)

if FailedAuctionCond
    lineValue := GreenBar ? low : high
    if actLines
        lineOne := line.new(bar_index,lineValue,bar_index+1,lineValue,color=lineClr,extend=extend.right,style=StyleToEnum(lineStyle),width=lineWidth)
        array.push(arrLineBarIndex,bar_index)
    alert(message="Failed Auction!",freq=alert.freq_once_per_bar_close)

//PLOTS
activeLines = line.all
if array.size(activeLines) > 0
	for i = 0 to array.size(activeLines) - 1
        controlValue = line.get_y1(array.get(activeLines, i))
        barIndex = line.get_x1(array.get(activeLines, i))
        bIndex = array.indexof(arrLineBarIndex, barIndex)
        
        if ((open > controlValue and low < controlValue) or (open < controlValue and high > controlValue)) and bIndex != -1 
            if hideLine
                line.delete(array.get(activeLines, i))
            else
    	        line.set_extend(array.get(activeLines, i),extend.none)
    	        line.set_x2(array.get(activeLines, i),bar_index)
	        array.remove(arrLineBarIndex,bIndex)
	        alert(message="Successful Auction!",freq=alert.freq_once_per_bar_close) 

plotshape(FailedAuctionCond and GreenBar,style=shape.square,location=location.belowbar,color=#ff03d9)
plotshape(FailedAuctionCond and GreenBar==false,style=shape.square,location=location.abovebar,color=#ff03d9)
