lp6970
lp6970

Reputation: 15

Pine script - Starting an indicator plotting from a date known after the starting bar has 'passed'

I searched a lot for an answer to the problem but I was not able to find one.

My problem (just an example, many similar ones exist): I need to identify the highest volume bar in a specific past quarter and plot a (custom) indicator starting from that specific bar to the last bar.

No problem to identify the bar and to calculate the indicator starting from it.

The problem is related to the plotting. Why: I know the highest volume bar (date) only after the analysis of all quarter's bars (at least based on my knowledge of Pine); so when the interesting bar/date is known, I should plot in the past, but that is not possible (at least with the 'plot' function).

Questions:

  1. Is it true that there is no way to do what I need to do using the 'plot' function (with the 'a ? b:c' operator)?
  2. Is the 'line.new' function the only workaround? It has limitations: based on documentation, total number of lines that can be drawn is limited, 50 to 500. This limit is easily exceeded if I need to go back in a quarter of some years back

What I'm thinking to do if no other solution exists is: A. Identify the interesting bar / date analyzing all the quarter (I repeat, 'quarter' is just an example, could be year, month, week, ...) B. Start plotting (with the 'plot' function and the 'a ? b:c' operator) the custom indicator at the end of the quarter C. Putting on that 'starting' bar a label with the real starting date (the 'interesting' date)

Thanks for any help. Cheers from Italy

Upvotes: 0

Views: 502

Answers (1)

vitruvius
vitruvius

Reputation: 21342

Your script is executed on each bar. So, you cannot really go back and plot something with the plot() functions.

Your only option is using line but that has its own limitations as you mentioned.

Another workaround would be, you do your analysis and identify the start bar index. Then use this as an input and only plot if bar_index > bar_index_start. This of course cannot be automated so someone has to do the analysis first and then input that to the main script.

Upvotes: 0

Related Questions