I am working on an indicator that draws boxes in a HTF using the Up candle Top Wicks and down candle Bottom Wicks.
Right now it will draw an upBox where i want in blue and a downBox in red... but then it will end somewhere it seems randomly, and then a new one will start at the next time the situation occurs
what i need is for it to draw the box everytime, regardless of whether there is an upBox or a downBox there already or not
i really want the upBox to stop drawing when there is a new higherhigh that goes above the upHiLine, etc... but i haven't worked out how to do that yet of course either
Can anybody help?
//@version=5 indicator("Intraday wicks",overlay=true, max_bars_back = 200, max_boxes_count = 200) //Input string tfInput = input.timeframe("15", "Timeframe") // Initialize variables on bar zero only, so they preserve their values across bars. bool up = close > open bool down = close < open var upHi = float(na) var upCl = float(na) var upOp = float(na) var upLo = float(na) var downLo = float(na) var downCl = float(na) var downHi = float(na) var downOp = float(na) var line upHiLine = na var line upLoLine = na var line downHiLine = na var line downLoLine = na var box upBox = na var box downBox = na // Detect changes in timeframe. bool newTF = ta.change(time(tfInput)) if newTF if up //if new bar in HTF is Bullish var, reset values and create new lines upHi := high //collect the top of the top wick value upCl := close //collect the bottom of top wick value //up high line is the top wick of a bull candle as a line upHiLine := line.new(bar_index, upHi, bar_index, upHi, color = color.white, width = 1) //up lo line is the bottom wick of a bull candle as a line upLoLine := line.new(bar_index, upCl, bar_index, upCl, color = color.white, width = 1) //up box is a box drawn beteen the top and bottom wicks of a bull candle upBox := box.new(bar_index, upHi, bar_index,upCl, border_color = na, bgcolor = color.rgb(47, 93, 229)) else // On other bars, extend the right coordinate of lines and box. line.set_x2(upHiLine, bar_index) line.set_x2(upLoLine, bar_index) box.set_right(upBox, bar_index) int(na) if down //if new bar in HTF is Bearish var, reset values and create new lines downCl := close //collect the top of the top wick value downLo := low //collect the bottom of top wick value //up high line is the top wick of a bull candle as a line downHiLine := line.new(bar_index, downCl, bar_index, downCl, color = color.white, width = 1) //up lo line is the bottom wick of a bull candle as a line downLoLine := line.new(bar_index, downLo, bar_index, downLo, color = color.white, width = 1) //up box is a box drawn beteen the top and bottom wicks of a bull candle downBox := box.new(bar_index, downCl, bar_index,downLo, border_color = na, bgcolor = color.rgb(234, 70, 125)) else // On other bars, extend the right coordinate of lines and box. line.set_x2(downHiLine, bar_index) line.set_x2(downLoLine, bar_index) box.set_right(downBox, bar_index) int(na) 1 Answer
ok so i found one error in my code.....
box.set_right(upBox, bar_index) changed to
box.set_extend(id=upBox, extend=extend.right) [pic of new boxes][1]
