Question about efficient code execution "under the hood" - is data still calculated in variable definitions even if that data is never plotted?
I'm working on a script that plots SPX contract volumes at specific strikes. The strikes are represented by horizontal lines at those price levels on the chart. The volumes are represented by colors surrounding those horizontal line plots.
The study by default will show 0dte volumes of all these strikes for each bar on the chart. However, instead of using highestall to make the levels extend back through the entire chart time span,I have written the line plot code that marks the strike levels on the chart to only extend back for 1990 bars. I did this to conserve processing power.
However, it's not clear to me how much that is helping, thus my question:
If I have a bunch of variables called "def calculate_contract_volume_strike_1 = ..." etc. and they pull out the volumes for a bunch of different strikes from the SPX options chain, is that heavy lifting being done for every bar on the entire chart (which would be over ten thousand bars on a 1min 30 day chart); or do those variable definitions only execute the process of pulling the volumes from the strikes where"plot contract_volume_strike_1 = ..." etc. are painting something?
If the former case is true, instead of the latter, then it means that setting the strike levels to only paint back 1990 bars is only helping the script run faster by saving the power of painting more, but that still does NOT avoid the waste of calculating the strike volumes for the thousands of bars that are more than 1990 bars back.
If I want to make the script efficient, is it therefore necessary to not merely stop the strike line plots from appearing more than X bars back, but also to write each of the variable definitions in a way that checks if the current bar is more than X days back from the last close bar and returns double.nan if it's not recent enough instead of accessing the options chain volumes?
Basically I want the amount of processing power and bandwidth the script uses to be nearly the same whether my chart span is set to two days or thirty days. But it's not clear if stopping the plots from appearing more than two days back actually accomplishes that. Many thanks if anyone who understands the underlying guts of how thinkscript works can help clear this up for me.
I'm working on a script that plots SPX contract volumes at specific strikes. The strikes are represented by horizontal lines at those price levels on the chart. The volumes are represented by colors surrounding those horizontal line plots.
The study by default will show 0dte volumes of all these strikes for each bar on the chart. However, instead of using highestall to make the levels extend back through the entire chart time span,I have written the line plot code that marks the strike levels on the chart to only extend back for 1990 bars. I did this to conserve processing power.
However, it's not clear to me how much that is helping, thus my question:
If I have a bunch of variables called "def calculate_contract_volume_strike_1 = ..." etc. and they pull out the volumes for a bunch of different strikes from the SPX options chain, is that heavy lifting being done for every bar on the entire chart (which would be over ten thousand bars on a 1min 30 day chart); or do those variable definitions only execute the process of pulling the volumes from the strikes where"plot contract_volume_strike_1 = ..." etc. are painting something?
If the former case is true, instead of the latter, then it means that setting the strike levels to only paint back 1990 bars is only helping the script run faster by saving the power of painting more, but that still does NOT avoid the waste of calculating the strike volumes for the thousands of bars that are more than 1990 bars back.
If I want to make the script efficient, is it therefore necessary to not merely stop the strike line plots from appearing more than X bars back, but also to write each of the variable definitions in a way that checks if the current bar is more than X days back from the last close bar and returns double.nan if it's not recent enough instead of accessing the options chain volumes?
Basically I want the amount of processing power and bandwidth the script uses to be nearly the same whether my chart span is set to two days or thirty days. But it's not clear if stopping the plots from appearing more than two days back actually accomplishes that. Many thanks if anyone who understands the underlying guts of how thinkscript works can help clear this up for me.
Last edited by a moderator: