'Pine script - How to identify price of the last bar
I'm drawing support and resistance boxes in TradingView using pinescript. Currently all the boxes that I draw are just of one/same color. I want to mark all boxes above the current ask/bid price as Red and the ones that are below the current ask/bid price as Green. Any ideas?
These are the values for drawing the box currently.
boxLeft := bar_index-1
boxTop := open[1]
boxBottom := close[1]
boxRight := bar_index +25 // extending the box up to 25 candles from starting position
box.new(boxLeft, boxTop, boxRight, boxBottom, bgcolor=color.rgb(56,79,67,50), border_color=color.rgb(150,200,150,10))
I need to dynamically change the bgcolor based on the current ask/bid, and this should be applicable for all the drawings on the chart.
Solution 1:[1]
you may try with the code below:
colorr = boxBottom > close ? color.green : boxTop < close ? color.red : color.blue
box.new(boxLeft, boxTop, boxRight, boxBottom, bgcolor=colorr, border_color=colorr)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | You Hang |
