0

Example Chart In the picture above, the left windows is in D timeframe, the right is in 4H timeframe, on the Daily chart only plot the previous 12 days, doesnt plot the vertical lines more than thoses days,on the right chart allow me to plot box shape more than thoses 12 days, but not the lines


    //@version=5
indicator("Daily Bias", overlay=true)

// Get the daily open, high, and low prices
dailyOpen = request.security(syminfo.tickerid, "D", open, lookahead=barmerge.lookahead_on)
dailyHigh = request.security(syminfo.tickerid, "D", high, lookahead=barmerge.lookahead_on)
dailyLow = request.security(syminfo.tickerid, "D", low, lookahead=barmerge.lookahead_on)

// Function to check if a new day has started
isNewDay() =>
    not na(dailyOpen) and na(dailyOpen[1]) or (dayofweek != dayofweek[1])

// Plot vertical and horizontal lines at the start of each new day
var line hline = na
var line dailyHighline = na
var line dailyLowline = na
var box bearish = na 
var box area = na 
if isNewDay()
    vline = line.new(x1=bar_index, y1=low, x2=bar_index, y2=high, color=color.rgb(109, 114, 117, 70), width=1, extend=extend.both)
    hline := line.new(x1=bar_index, y1=dailyOpen, x2=bar_index, y2=dailyOpen, color=color.rgb(68, 163, 218), width=2)
    dailyHighline := line.new(x1=bar_index, y1=dailyHigh, x2=bar_index, y2=dailyHigh, color=color.rgb(215, 47, 13), width=1)
    dailyLowline := line.new(x1=bar_index, y1=dailyLow, x2=bar_index, y2=dailyLow, color=color.rgb(25, 179, 94), width=1)
    area := box.new(bar_index, dailyHigh,bar_index,dailyOpen,border_color = color.new(color.black,90),border_style = line.style_solid )
if isNewDay() == false
    line.set_x2(hline, bar_index + 1)
    line.set_x2(dailyHighline, bar_index + 1)
    line.set_x2(dailyLowline, bar_index + 1)
    if close > dailyOpen
        box.set_right(area,bar_index + 1)
        box.set_top(area, dailyOpen)
        box.set_bottom(area, dailyLow)
        box.set_bgcolor(area, color = color.new(color.green,70))
    if close < dailyOpen
        box.set_right(area,bar_index + 1)
        box.set_top(area, dailyHigh)
        box.set_bottom(area, dailyOpen)
        box.set_bgcolor(area, color = color.new(color.red,70))
    

1 Answers1

0

The number of lines you can have on your chart is limited. You can add max_lines_count=500 to your indicator() call.

The main problem is, you are creating a new line on every bar. This leads to reaching to the maximum line count I was talking about.

dailyOpenLine := line.new(x1=bar_index - dailyBar, y1=dailyOpen, x2=bar_index + 1 - dailyBar, y2=dailyOpen, color=color.rgb(61, 56, 192), width=2)
dailyHighLine := line.new(x1=bar_index - dailyBar, y1=dailyHigh, x2=bar_index + 1 - dailyBar, y2=dailyHigh, color=color.rgb(255, 0, 0), width=2, style=line.style_dashed)
dailyLowLine :=  line.new(x1=bar_index - dailyBar, y1=dailyLow, x2=bar_index + 1 - dailyBar, y2=dailyLow, color=color.rgb(0, 255, 0), width=2, style=line.style_dashed)

These three lines will be executed on every bar and each will create a new line.

You only need to create those lines when it is a new day and modify their x and y intraday with line.set_*() functions.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • i have edited the question, and uploaded the code, the indicators now works as i want, but still having the same problem with the max vertical and horizontal lines that can be plotted on the chart, with the box shape doesn't have that problem – Rainner Lopez Jul 31 '23 at 02:43
  • solved the problem adding the max_lines_count parameter to my indicator call... thanks @Vitruvius – Rainner Lopez Jul 31 '23 at 02:45