Draw a stepline style plot() with no vertical lines?

Viewed 25

I'm creating a script that I want to plot a few horizontal lines on top of a chart. I'm doing this by calling plot() and passing an int that only changes monthly.

I've got it working how I'd like except for one problem. At the month transitions, I get a vertical line on my chart (as part of the step function). How can I get rid of this?

Ideas I had but can't find a means to execute:

  1. Plot "na" where I want the breaks. In the script, I can determine when I'm on the first day of the month. If I pass na here, for some reason, the plot still renders the vertical step down/up, then a gap, then the beginning of the next. I'd try providing the "na" as the last day of the month but am not sure how to determine this in the code.
  2. Somehow cause the plot function to "reinitialize" at month beginning. Somehow Pine Script keeps track of the different plot calls and knows which calls map to which existing plot. Probably by variable reference? If I could "reset" the plot method then I could effectively draw a new line and not worry about the vertical transition rendering.

Worth noting: I have a total of 15 lines being plotted any given month.

2 Answers

I ended up using the Line.new call to accomplish this. A bit of a rewrite, but Line.new can be called within function blocks unlike plot() so that cleaned the code up quite a bit.

For your first idea, instead of using plot.style_stepline, you should be using plot.style_linebr. Or, instead of providing a na value, you can set the color to na on the first day (using default line style), e.g. plot(level, color = firstday ? na : color.yellow).

Also note that line.new() doesn't work with MTF feature, in case you need it.

Related