Search code examples
pine-scriptcryptocurrencypine-script-v4forex

pine script : color the current candle different color


i wanna to color all candles , all down candles will be red ,, all up candle will be green and the current candle will be black (if not closed yet)

this is for example

//@version=4
study("color all except current candle", overlay=true)

this_is_current_candle_function = ?????????????

redbar = close < open
greenbar = close > open

barcolor(not this_is_current_candle_function and redbar ? color.red:color.black)
barcolor(not this_is_current_candle_function and greenbar ? color.green:color.black)

Solution

  • you use barstate.isconfirmedfunction

        //@version=5
        indicator("barcolor example", overlay=true)
        barcolor(barstate.isconfirmed ? na : color.black)