简体   繁体   中英

Loop plot? Pine Script

I have a script that looks back to a user selected [range] then calculates a simple accumulation of a specific volume based on the range and then plots them in what I would consider a "mini plot" based only on that range.

The problem I have is all the bars on a chart are a printed receipts of the current bar and can not be overwritten.

range = user input value to represent lookback period

So my solution was to calculate the volume of the desired bar back via [range] and plot that value over that bar by offsetting the plot by the same [range] and only showing that single printed bar by show_last=1.

I then repeat the plot function by moving the series forward 1 [range-1] and offsetting the new plot candle by 1 [range-1]

My issue now is given that the 'range' is selected by the user, I would like to loop the plot function for a repeated duration as defined by 'range' rather than having to write out every new plot individually in script.

My attempts at doing a for loop with plot within that have failed.

Ideas?

short_off = current_volume + past_volume
range_add = range

plot(short_off[range_add], offset= -(range_add), show_last= 1,  ...)

plot(short_off[range_add-1], offset= -(range_add-1), show_last= 1,  ...)

plot(short_off[range_add-2], offset= -(range_add-2), show_last= 1,  ...)

plot(short_off[range_add-3], offset= -(range_add-3), show_last= 1,  ...)

plot(short_off[range_add-4], offset= -(range_add-4), show_last= 1,  ...)

plot(short_off[range_add-5], offset= -(range_add-5), show_last= 1,  ...)

plot(short_off[range_add-6], offset= -(range_add-6), show_last= 1,  ...)

plot(short_off[range_add-7], offset= -(range_add-7), show_last= 1,  ...)

plot(short_off[range_add-8], offset= -(range_add-8), show_last= 1,  ...)

plot(short_off[range_add-9], offset= -(range_add-9), show_last= 1,  ...)

plot(short_off[range_add-10], offset= -(range_add-10), show_last= 1,  ...)```



So this simple code shows the same result as yours. Why don't you just use the show_last parameter?

//@version=5
indicator("My Script", overlay=true)
short_off = close*2
range_add = input(10)
plot(short_off, show_last=range_add)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM