I want to draw a box from the highest candle to the lowest in the last 20 candles. Each box has 4 side: top, bottom, left and right. for top and bottom i use highest() and lowest() but for left and right how can i find time for highest and lowest candle?
You can find the high using highest and low using lowest function. Then you can find the index of them using barssince function. Then you can use them to plot a box at the last bar using barstate.islast. Example below
//@version=5
indicator(title="Highest Lowest Bar", shorttitle="HLB", overlay=true)
hi=ta.highest(high,20)
lo=ta.lowest(low,20)
hiIndex=ta.barssince(high==hi)
loIndex=ta.barssince(low==lo)
var box b=na
if barstate.islast
box.delete(b)
b:=box.new(bar_index-hiIndex,hi,bar_index-loIndex,lo,bgcolor=color.new(color.blue,80),border_color=na)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments