0

I'm new here, and still learning to write pine. I have a very simple idea I'm trying to code that's been kicking my backside for weeks!

I want the background color for the last five bars to change only a condition has been met in the last 5 bars - the background color change is just to alert me "Hey, this is condition is new - give it a look" - like a visual alert. I don't want the background to be changed on any of the older bars to the left. If the condition was met > 6 bars ago I don't want the background changed anywhere on the chart. I've tried subtracting 60k (milliseconds) * 5 from timenow and it won't work. Any help will be SUPER appreciated!!! Many thanks, -Daniel

D-Auburn
  • 41
  • 4

1 Answers1

0

Hard to say without the exact condition you're considering, but this code will only show the background if the condition is true on one of the last 5 bars:

//@version=4
study("", "", true)
bgcolor(high > highest(5)[1] ? color.green : na, show_last = 5)

enter image description here

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
  • OMG!!! I knew it was a simple answer, but I didn't know it was THAT simple!! I'd never seen the "show_last" command bgcolor. Thank you >>THANK YOU!!!!!!<< -Daniel – D-Auburn Apr 28 '20 at 23:35