How efficient is Thinkscript code?

Thane313

New member
I was looking into volume labels for my watcher charts which are pretty small since I have one old 55" screen to work with. Saw in one script that they calculated the daily average volume for 30 days by summing each day individually, / by 30. Versus getting 4 weekly values, or one month. Perhaps this is a bad example if monthly and weekly values refer to real weeks and months. But ignoring that for the sake of argument, it wouldn't be worth considering at all if Thinkorswim is programmed to check on whether or not each value is going to change again. The daily volume values from the past aren't going to change, so it wouldn't need to recheck for updates from the servers or locally. But does it? Every frame? If so, ouch.

Just curious: How about plots? After getting beyond the portion of the plot which is going to see additional changes, ToS "could" just store those finalized values. Does anyone know if it constantly recalculates the whole plot?
 
Solution
I was looking into volume labels for my watcher charts which are pretty small since I have one old 55" screen to work with. Saw in one script that they calculated the daily average volume for 30 days by summing each day individually, / by 30. Versus getting 4 weekly values, or one month. Perhaps this is a bad example if monthly and weekly values refer to real weeks and months. But ignoring that for the sake of argument, it wouldn't be worth considering at all if Thinkorswim is programmed to check on whether or not each value is going to change again. The daily volume values from the past aren't going to change, so it wouldn't need to recheck for updates from the servers or locally. But does it? Every frame? If so, ouch.

Just...

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
I was looking into volume labels for my watcher charts which are pretty small since I have one old 55" screen to work with. Saw in one script that they calculated the daily average volume for 30 days by summing each day individually, / by 30. Versus getting 4 weekly values, or one month. Perhaps this is a bad example if monthly and weekly values refer to real weeks and months. But ignoring that for the sake of argument, it wouldn't be worth considering at all if Thinkorswim is programmed to check on whether or not each value is going to change again. The daily volume values from the past aren't going to change, so it wouldn't need to recheck for updates from the servers or locally. But does it? Every frame? If so, ouch.

Just curious: How about plots? After getting beyond the portion of the plot which is going to see additional changes, ToS "could" just store those finalized values. Does anyone know if it constantly recalculates the whole plot?
The answer is that "it depends".

When using Range All functions, (highestall, inertiaall, etc...) The entire plot 'used to' recalculate on every tick.
Recently, TDA changed that:
https://usethinkscript.com/threads/...-range-lagging-issues-due-to-tos-update.8794/
Those functions now re-plot the entire line, once per bar.

For plots with static values, only the current bar is updated.
 
Last edited:
Solution

Thane313

New member
I wonder if its advantageous to combine scripts that have elements that compute the same info or if TOS automatically tracks duplicate operations across indicators which i doubt but could be possible.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
I wonder if its advantageous to combine scripts that have elements that compute the same info or if TOS automatically tracks duplicate operations across indicators which i doubt but could be possible.
The ToS platform performs whatever calculations are called for, for every line in the script, individually. If you use the same information multiple times in the same script or multiple scripts each line is individually resourced.

A common method members use to conserve resources within studies is to create holding variables:
price = close ;
h = high;
ema44 = expAverage(volume,44);
Creating variables for expressions such as above for elements that are used multiple times in a study, reduces how often ToS has to calculate these items.
 
Last edited:

Joshua

Well-known member
VIP
All bars within the largest forward offset present in the script will be reevaluated every tick.

This should help you visualize it:

Code:
input ForwardOffset = 25;
def x = random() * 10;
assignpriceColor(getcolor(x[-ForwardOffset]));

Run it on something that's trading though, like futures at the moment.

It wont function on closed markets.
 

Thane313

New member
Wow. Ouch. I guess in the future ....well after I figure out a strategy that gets to my $50/day monthly expense goal.... I will likely spend some time creating combined indicator sets if possible so all the computations for ATR and volume and relative strength etc can be done as few times as possible.
 
Last edited by a moderator:

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top