• Get $40 off VIP by signing up for a free account! Sign Up

Combine Studies (Indicators) In ThinkOrSwim

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
How To Combine Studies (Indicators) For ThinkOrSwim
Members combine studies to create comprehensive strategies to be able to test for multiple conditions.
If the combined study is of ToS built-in indicators and it is only needed for upper chart calculations.
It is as simple as referencing the studies:
Ruby:
def RSI = reference RSI() ;
def Vroc= reference VolumeRateOfChange();

When combining lower chart studies with the purpose of creating a combined plot:
Combining and plotting lower chart studies can be problematic. While they may look good when you overlay them in your chart. Lower chart oscillators cannot be plotted together in the same script unless they show the same SCALE on the vertical axis. While it is possible to "normalize" indicators to the same scale, this has shown to sometimes have the habit of skewing the data.

Below are the simple steps to combine as many studies as you want for the purpose of manipulating the data (not attempting to plot the data on a lower chart).
It should be noted that studies should still be used separately in the Scan Hacker, where possible. The scanner is temperamental about studies that get too complex.

Bad News: It is an excruciatingly boring detailed process so unless the studies being combined are small and simple or another member is interested enough in the results to do it for you, the requests to combine indicators tend to not be fulfilled on this forum.
Good News: Combining Indicators is a relatively easy procedure. So feel free to do this yourself! (y)
- - - - - - - - - - - - - - - - - - - - - -
Before Combining The Studies:
Review the code in each study.
Every statement in each of the studies that you want to smoosh together must have a unique identifying field names.

For example: if
StudyA has
input length =13 ;
plot ema21 = ExpAverage(close, length);
and

StudyB has
input length= 30;
def VolDayAvg = (fold index = 1 to length+ 1 with Avg = 0 do (Avg + volume(period = "DAY")[index])) / length;

The Combined Study will vomit an error when you paste them both together. Because they are both using the same named field: length .
Duplicate names are not allowed.

- - - - - - - - - - - - - - - - - - - - - -
  1. THEREFORE, EVERY NAME TO THE LEFT OF AN EQUAL SIGN MUST BE UNIQUE.
  2. Once you create a unique name THAT NEW NAME must be substituted throughout the code.
StudyA becomes:
input lengthA =13 ;
plot ema21 = ExpAverage(close, lengthA );

StudyB has
input lengthB= 30;
def VolDayAvg = (fold index = 1 to lengthB+ 1 with Avg = 0 do (Avg + volume(period = "DAY")[index])) / lengthB;

That is all there is too it. Rinse and repeat for every duplicate name.
Then copy and paste your indicators into a new combined study.

Here are the additional common errors that will need to be cleaned up:
Error: Can only have one declare statement. Fix: delete any extra declare statements​
Most Common Error: Identifier Already Used or Already assigned This means there STILL duplicate names. The error message will tell you what the duplicate name is. Go back to square one and rename the duplicates.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@MerryDay Do you know weather or not a combined study can be red by a scanner or is it better separated in that case ?
Members generally combine studies to create strategies to backtest or to get that elusive "buy me now" arrow on a chart.

However, it is generally accepted practice to scan studies separately, where possible. The scanner is temperamental about studies that get too complex.

Great question, BTW. I will add this information to the original post.
 
Hello evemryone, newbie here. I've been trying to combine the AccumDisTrVol study with the MovingAveExp to create a new study to trigger an up arrow in the chart when the former crosses the latter. Anyone has any ideas how I could make it work? They both use the Close constant so I'm not sure if that's the problem here. I can plot them separately fine on the chart but when I combine them, one or the other goes way off chart or totally flat. Thank you!
 
Hello evemryone, newbie here. I've been trying to combine the AccumDisTrVol study with the MovingAveExp to create a new study to trigger an up arrow in the chart when the former crosses the latter. Anyone has any ideas how I could make it work? They both use the Close constant so I'm not sure if that's the problem here. I can plot them separately fine on the chart but when I combine them, one or the other goes way off chart or totally flat. Thank you!
Sure...
Code:
# ########################################################
plot Indicator        = reference AccumDistPrVol() ;
plot Indicator_ma     = MovingAverage(AverageType.SIMPLE, Indicator, 30);
# ########################################################
 
Last edited:
ty, @MerryDay.....my question is, is it POSSIBLE to write a STRATEGY that uses multiple studies(indicators) that will issue AddOrder buys and sells independently of each other, so that your net position is the net long number (longs-shorts) or net short number......for instance, if 4 of the 5 indicators reflect a long position and one indicator is a short position, the net long position would be 3 long (4 longs minus 1 short).....just want to know if this is possible and if so, I will go to work on it or have someone work on it. Thanks.
 
Last edited by a moderator:
ty, @MerryDay.....my question is, is it POSSIBLE to write a STRATEGY that uses multiple studies(indicators) that will issue AddOrder buys and sells independently of each other, so that your net position is the net long number (longs-shorts) or net short number......for instance, if 4 of the 5 indicators reflect a long position and one indicator is a short position, the net long position would be 3 long (4 longs minus 1 short).....just want to know if this is possible and if so, I will go to work on it or have someone work on it. Thanks.
Yes it is possible
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
261 Online
Create Post

Similar threads

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.
Back
Top