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!!
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.