On day opening on any chart, i want first candle’s body, color and wick according to previous day close like it is a continuation from previous day.
Tried the following script but some problem is there.
Probable solutions could be
- either first candle should be transparent completely so that only indicator candle is plotted and correctly.
- indicator must override the first candle OHLC completely.
- when indicator is active chart should be hidden.
//@version=5
indicator("No gaps candles", overlay=true)
applyToDayOpenOnly = input(true, title="Apply to day open only")
dayChangeHourThreshold = input(6, title="Hour threshold to detect the day open")
showPriceLine = input(true, title="Show price line")
hoursSinceLastCandle = (time[0] - time[1]) / 1000 / 60 / 60
myOpen = open
myClose = close
myHigh = high
myLow = low
if not applyToDayOpenOnly or hoursSinceLastCandle > dayChangeHourThreshold
myOpen := close[1]
myClose := close
myHigh := high
myLow := low
candleColor = myOpen <= myClose ? color.teal : color.red
plotcandle(myOpen, myHigh, myLow, myClose, color=candleColor, bordercolor=candleColor, wickcolor=candleColor)
if barstate.islast
if showPriceLine
line.new(bar_index - 4999, close, bar_index + 500, close, color=candleColor, style=line.style_dotted, width=1)
New contributor
Harender Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.