Before add your script, you must remember that all the elements showed in the chart (bars, candles, indicators…) will be generated from left to right in a only one time.
After the execution of your script (continuing with real time) it will generate the next bars one by one adding to the painted graphic.
Pinescripts.