0

I'm fairly new to the pine script and working on a slightly complex indicator with multiple parameters. I want my indicator to change bar colour up to last 500 bars only starting from bar index. It will change colour of the bar depending on the parameters. I couldn't find any solution to make this happen. I need my indicator to detect the last 500 bars automatically from 1st bar and draw accordingly but I couldn't find any function where I can set the limit of 500 bars.

I searched on stack overflow too and I found the following answer

Limit number of bars in your study

In this answer the calculations are in time format and they used input.time to set the timeframe of the indicator. I need the calculations in bar index format and I want to set bar limit of 500 automatically without any user input. If anyone knows how to solve this issue it will be of great help.

Thank You!!

1 Answers1

0

Your script will be executed on each bar starting from the very first bar. You cannot go 500 bars back from the last bar and call barcolor() on those bars.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • Hey @virtruvius thanks for looking into my query and apologies for replying late, I got caught up with some other work. Thank you for clearing that up, I did some research too, and also tried using some combinations of ">" and "<" with "na" function and "if" statements but it didn't work. Anyways thanks a lot for helping me with this! – Sanket Kolte Feb 16 '23 at 13:54