Daily Close on a smaller time frame: series float problem

Viewed 28

I am trying to plot the closing values of daily candles (the last 10 daily candles, including the current day candle) on a smaller timeframe chart, for example, when I am using a 4-hours chart. Please see below the code. I am not able to plot this because of the following error:

line 34: Cannot call 'plot' with argument 'series'='_1d_close'. An argument of 'float[]' type was used but a 'series float' is expected

Any idea of how to convert the float[] type to series float?

Thank you

//@version=5
indicator("Close MTF", overlay=true)



//////////////
// 1D Close //
//////////////

var int lookback = 10

daily_close = request.security(symbol=syminfo.tickerid, timeframe="1D", expression=close)

CurrentDayclose = request.security(syminfo.tickerid, '1D', close)

var float[] daily_closes = array.new_float(lookback)

if ta.change(time("1D")) != 0
    array.unshift(daily_closes, daily_close)
    array.pop(daily_closes)


_1d_close = array.new_float(0)
array.push(id=_1d_close, value=CurrentDayclose)


for i=0 to lookback-2
    array.push(id=_1d_close, value=array.get(id=daily_closes, index=i))


// plot(_1d_close, title="1D Close", color=color.new(color.green,0), linewidth=2, style=plot.style_line)
1 Answers

You need to get the array value for plot() to use. Also, when time changes, the close should be in the prior bar.

if timeframe.change("D")
    array.unshift(daily_closes, daily_close[1])
    array.pop(daily_closes)

last_close =array.get(daily_closes,0)

plot(last_close, title="1D Close", color=color.new(color.green,0), linewidth=2, style=plot.style_line)
Related