Script Stopwatch - PineCoders FAQ

This script calculates the run time of a Pine script. While its numbers are not very precise and it doesn’t work on all scripts, it will help developers calculate run times more precisely than by hand, and so provides Pine coders with an additional profiling tool to help them optimize their code.

How to use the code
• Place the code included between the up/down arrows after your script’s input() calls.
• Comment out the display modes you don’t want to use.
• Save your script, wait and look at the results.
• Results show in different colors, depending on the average time per bar:
- green for < 5 ms
- dark red for < 50 ms
- bright red for > 50 ms (the maximum allowed is 200).

How the code works
The code in this script starts by saving the value of the timenow variable on the first bar. While the time variable returns the time at the beginning of the bar, timenow returns the current time. The code then follows the progression of timenow during the script’s execution. The variable only updates every second, so in between updates the script makes an estimate of the total time elapsed by adding the last average time per bar calculated to each bar that passes until timenow increases by another 1000 because one more second has elapsed since its last update. At that point a new, current average time per bar is calculated and the cycle repeats.

The code only calculates elapsed time for the initial run. Once the realtime bar is hit, timing stops so that time spent in the realtime bar does not affect the numbers once they have been calculated on the script’s initial pass over the dataset.

• If results show zero elapsed time, it’s most probably because your script executes in less than one second, which is very good. In that case timenow hasn’t changed, so no timing can be calculated.
• The code is quirky and doesn’t work on all scripts.
• It doesn’t properly time execution of security() calls.
• The average time per bar will sometimes vary quite a bit with changes in chart resolution.
Notes de version: Updated comments.
Notes de version: More efficient label code.
Supprimer des scripts favoris Ajouter aux scripts favoris
Tools and ideas for all Pine coders:
Pine Wizards:
Our Pine FAQ & Code:
Get Pine news and tips on Telegram:


Thanks, won't get dinged on out of control loops, wonderful ;√)
+1 Répondre
Great works!
Haha megalomania, nice one!
Accueil Screener d'actions Screener Forex Screener Crypto Calendrier économique Comment ça marche Caractéristiques du graphique Prix Parrainer un ami Règles de conduite Centre d'aide Solutions site web & courtier Widgets Solutions de cartographie Bibliothèque de graphiques allégés Blog & News Twitter
Profil Paramètres du Profil Compte et Facturation Parrainer un ami Mes tickets au support Centre d'aide Idées Publiées Followers Suivi(e) Messages privés Chat Se Déconnecter