Hi trader..
My first thought is why don’t you want to set ‘DrawOnLastBarOnly to true’.
Secondly, unless i’m mistaken, doesn’t ‘calculateOnLastBars’ just delays the start of code execution if you’ve got billion historical bars loaded. But from a displaying perspective, each new bar still add to any existing result line, so would display 300+ bars anyway.
In your later comments about having a 2nd indicator for 48bars, this would still display 48+ bars if ‘drawOnLastBarOnly = false’. Setting to true, would solve your problem , but that leads me back to my first thought!.
Regarding your 24/48 bar problem, and in addition to the other commented problems in doing it, i’ll add that to display over the last ‘n’ bars only, you need to know the last bar. Roberto’s array’s does that because the last ‘n’ entries would align up to the one’s you want. Alternatively the code below does it by looping after ‘lastBarUpdate’.
Further to ‘any timeframe’ comment, determine the timeframe; which of 48 bars, current bar is on; loop over the relevant bars/values after ‘isLastbarUpdate’; and of course, ‘drawOnLastBarOnly = true;
I’ll just say this, when you state 24,48 bars and today and tomorrow, what are you referring to. Though there are 24hrs in a day, current their are only 13 bars today at this time. So, today and tomorrow would currently equate to 37 bars, if we go by 48bars, this could cover bars over three days. not just today/tomorrow. Don’t get me started at the weekend and market close scenario’s.
It’s a 50/50 choice, next time pick ‘true’!
All the best
defparam calculateonlastbars = 50
defparam drawonlastbaronly = true
if islastbarupdate then
for i = 23 downto 1 // for (24) or 47(48) bars
drawsegment(barindex[i-1],close[i-1],barindex[i],close[i])coloured("red")
next
endif
return close style(dottedline,5)coloured(0,255,0,100)