Incomplete Session Candle - Incomplete Timeframe Candle Marker 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AfnanTAjuddin
//@version=5
indicator("Incomplete Session Candle - Incomplete Timeframe Candle Marker ", shorttitle="Incomplete Session candle", overlay=true)

// Check if current timeframe is intraday
isIntraday = timeframe.isintraday

// Calculate the expected duration of the current candle in milliseconds
expectedDuration() =>
    if (timeframe.multiplier == 1 and timeframe.period == "D")
        na // If it's a daily candle, we can't determine its expected duration
    else if (timeframe.period == "S")
        timeframe.multiplier * 1000 // For seconds
    else if (timeframe.period == "M")
        timeframe.multiplier * 60 * 1000 * 60 * 24 * 30 // For months
    else if (timeframe.period == "W")
        timeframe.multiplier * 60 * 1000 * 60 * 24 * 7 // For weeks
    else
        timeframe.multiplier * 60 * 1000 // For minutes and hours

// Check if the current candle's duration is less than the expected duration
isIncompleteCandle = isIntraday and (time_close - time) < expectedDuration()

// Plot a shape above the last candle if it's incomplete
plotshape(series=isIncompleteCandle)

