Hide Active Candle [SteinG]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SteinG

//@version=5
//Hide Active Candle v1
// # ========================================================================= #
// #                   |  Hide Active Candle Indicator  |
// # ========================================================================= #
indicator(
 title                = "Hide Active Candle",
 shorttitle           = "",
 overlay              = true
 )
// # ========================================================================= #
// #                   |  Hide Active Candle Indicator  |
// # ========================================================================= #


//----------------------- input ----------------------
secondForCandleVisible = input.int(30, "Countdown seconds left", minval=0, step=1, tooltip="Current candle will be visible N seconds before bar being closed")
bullColor = input(color.new(#2d9682, 0), "Bull candle color")
bearColor = input(color.new(#e85048, 0), "Bear candle color")
equalColor = input(color.white, "Equal candle color")
theme = input.string("Dark", "Theme", ["Dark", "Light"])
useCustomColor = input.bool(false, "Use custom hidden color", inline="custom")
customHiddenCandleColor = input(color.new(#171923, 0), "", tooltip="Custom color only applicable if 'Use custom hidden color' is set", inline="custom")


//--------------------Calculation --------------------
normalBarColor = close > open ? bullColor : close == open ? equalColor : bearColor
normalWickColor = close > open ? bullColor : close == open ? equalColor : bearColor
hiddenColor = useCustomColor ? customHiddenCandleColor : theme == "Dark" ? color.new(#171923, 0) : color.new(#ffffff, 0)

secondsLeft = barstate.isrealtime ?
     (time_close - timenow) / 1000 :
     na
plotcandle(open, high, low, close, "History candle", editable = false, color = normalBarColor, wickcolor = normalWickColor, bordercolor = normalWickColor)

plotcandle(open, high, low, close, editable = false, 
                 color = secondsLeft <= secondForCandleVisible ? normalBarColor : hiddenColor, 
                 wickcolor = secondsLeft <= secondForCandleVisible ? normalWickColor : hiddenColor, 
                 bordercolor = secondsLeft <= secondForCandleVisible ? normalWickColor : hiddenColor, show_last = 1)

