0

enter image description hereTrying to box for every 2:00 PM candle candle generated in trading view between any 2 dates and extend it left & right. Have written a code but it draws for last 2 days only not for all the specified dates and extended it completely left & right of chart


indicator("14:00 PM Candles", overlay=true)
leftExtension = input(500, "Left Extension")
rightExtension = input(500, "Right Extension")

var float high_225 = na
var float low_225 = na


startDate = timestamp(2023, 01, 01, 00, 00)
endDate = timestamp(2023, 06, 30, 23, 59)

h = input.int(14, "Hour", minval=0, maxval=59)
m = input.int(20, "Hour", minval=0, maxval=59)

is225Candle = (hour == h) and (minute == m) and time >= startDate and time <= endDate

//is225Candle = ta.time(hour, minute) == ta.time(9, 30) and time >= startDate and time <= endDate
if is225Candle
    high_225 := high
    low_225 := low
plotshape(is225Candle, title="14:00 PM Candle", color=color.green, style=shape.labelup, text="14:00", location=location.belowbar, size=size.small)
box.new(left=bar_index - leftExtension, top=high_225, right=bar_index + rightExtension, bottom=low_225, border_color=color.rgb(215, 165, 217), border_width=1, bgcolor=color.rgb(209, 156, 198))

Was expecting something as per attached image the green ones are missing, my code is just taking back 2 days only.

1 Answers1

0

There are two things here:

  1. You are calling box.new() on EVERY bar without any condition. You probably wanto to do that in your if block.

  2. By default the number of boxes you can draw are limited to 50. If you want to see more boxes, you should add max_boxes_count=500 to your indicator() call.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • Thanks a lot, it works like charm, but there is one more thing the areas where there is overlapping is not getting dark colored, want to darken the shade as per number of overlaps. – Techie man Jun 29 '23 at 11:51
  • You might need to treat those cases separately. – vitruvius Jun 29 '23 at 12:52
  • Thank You for your response, have been trying since past 7 days but not able to find the exact code , can you help me how to achieve the goal – Techie man Jun 29 '23 at 13:07