Combine 2 Custom Indicators?

switchfire

Member
Hello,

This is my first post so please go easy ;) . I've done some googling but it's difficult to find specific information regarding thinkscript.

So I've created 2 studies (indicators) that mark the chart with arrows. They are essentially opposites in their design (buy and sell) and I'm trying to figure out how I can combine them into a single study.

Thanks for any insight regarding my noob question!

-Switch
 

switchfire

Member
But where are the code?

Sorry Ben, I wrongly assumed it was a general enough question. Here's the Code:

## Switch_Up_ES_78 code created by Switchfire
TTM_Squeeze()."Histogram" from -5 bars ago crosses above TTM_Squeeze()."VolComp" from -5 bars ago within 10 bars and MACD("fast length" = 21, "slow length" = 31, "macd length" = 8)."Diff" crosses above MACD("fast length" = 21, "slow length" = 31, "macd length" = 8)."ZeroLine" within 10 bars and CCI()."CCI" crosses CCI()."OverSold" within 10 bars
## End Code

##Switch_Down_ES_78 created by Switchfire
TTM_Squeeze()."Histogram" from -5 bars ago crosses below TTM_Squeeze()."VolComp" from -5 bars ago within 10 bars and MACD("fast length" = 21, "slow length" = 31, "macd length" = 8)."Diff" crosses below MACD("fast length" = 21, "slow length" = 31, "macd length" = 8)."ZeroLine" within 10 bars and CCI()."CCI" crosses CCI()."OverBought" within 10 bars
## End Code
 

switchfire

Member
I built it using the "Condition Wizard" and then when i go to edit settings, i change the plot to boolean with arrows. So essentially "if those conditions are true, then plot an arrow".
 

tomsk

Well-known member
VIP
@switchfire Let's discuss your request from several angles shall we?

Firstly, as several readers have pointed out, the code you provided are scan codes. You'll typically place those codes directly in the scanner to determine if there are any signals matching your conditions. Using a daily aggregation, I scanned against the S&P 500 and the NASDAQ Composite and was unable to obtain any signals for either your Switch Up condition or Switch Down condition. That usually means that your scan conditions are so restrictive that you'll not find any signals. Hence you'll need to relax some of the conditions of your scan code.

That said, your scan code pertains to three standard TOS studies - TTM Squeeze, MACD and CCI. Assuming you fix the issues described above and are able to generate signals and now wish to combine all three studies into one study, the biggest hurdle is that the code for TTM Squeeze is not available to the general public.

If you decide to exclude the TTM Squeeze component from the combined study, you are then left with the MACD and CCI. The MACD is an oscillator that has values running from -10 to +10 while the CCI has values ranging from -200 to +200. What you'll need to do is to first normalize the scales in both these studies. Once that is completed then you can combine the MACD and CCI.

My assessment at this point is that the most realistic course of action is to first combine MACD and CCI and see if that resulting study makes sense from your point of view. If so then you can then think of layering on top of that other indicators you deem fit.

These are just some of my high level thoughts from a first pass assessment. Hope that is helpful
 

switchfire

Member
@tomsk Thanks for that explanation! I primarily built these indicators for use in futures (/es) utilizing the 78min chart. You also need to modify the settings to plot boolean with arrows and sometimes it resets :( . I'll look into breaking out the indicators and building it to plot from base code (not condition wizard)
 

switchfire

Member
Yep, that would be a good start. BTW, since 78 min is a non standard aggregation, this would not be an acceptable aggregation in the scanner. All the best as you proceed with these plans

Hey Tom, thanks for all your help thus far here! I'm trying write my original code into standard thinkscript, and it's proving to be difficult. If you happen to have time, could you help get me started? Maybe just plotting an arrow on the chart for macd crossover with adjustable settings? Then I'd try to take it from there? If this is too much to ask then i completely understand and no worries! Thanks!!
* edit * sorry this is too much to ask! I should stick with indicators already built and try to learn what they are doing and maybe modify from there.
 
Last edited:

tomsk

Well-known member
VIP
@switchfire Sounds like you're new to ThinkScript. No problem, happy to help - Here's a real simple MACD crossover study that plots signals when the MACD value line crosses ABOVE the MACD Avg line. It's a real simple example and you can take it apart, add bells and whistles, etc Have fun!

Code:
# MACD Crossover Arrows

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

plot Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(Color.CYAN);
Avg.SetDefaultColor(Color.PINK);
ZeroLine.SetDefaultColor(Color.WHITE);

plot UpArrow = if Value crosses above Avg then Avg else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
UpArrow.AssignValueColor(Color.YELLOW);
 

switchfire

Member
@switchfire Yep it is a simple starter script. Don't hesitate to come back if you get stuck. It takes a while to get up to speed, and I'm sure you'll be a whizz in almost no time
Hopefully 😁 I know very basic SQL, so that helps a little.

I'm assuming the Double.NaN is the same as "if x then y else ' ' " so like a null? (Without the space, because that's not a null lol, but for visual reasons)
 

tomsk

Well-known member
VIP
It's essentially a TOS quirk. Double.NaN is used when you want a return of nothing in a variable. For example if a variable has a value of 0, there may be times when you want a variable to not return anything. That's the time to use Double.NaN. In the MACD example above, if there is no crossover, nothing is plotted. Simple as that
 

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