changing color of indicator based on certain market criteria

spectastic

New member
I'd like to modify the stocks above 50 MA breath indicator to be color coded where it's one color when qqq 10 MA is above the 20 MA, and another color when it's below. New to thinkscript, but any ideas how to execute this?
 
Solution
I don't know what the 50 MA breadth indicator is, but I've subbed in a simple moving average to illustrate:
Code:
def qqq_Close = close(symbol = "QQQ");
def qqq_ma_10 = SimpleMovingAvg(price = qqq_Close, length = 10);
def qqq_ma_20 = SimpleMovingAvg(price = qqq_Close, length = 20);
def qqq_10_above_20 = if qqq_ma_10 > qqq_ma_20 then 1 else 0;
plot indicator = SimpleMovingAvg(CLOSE, 50);
indicator.AssignValueColor(if qqq_10_above_20 == 1 then color.green else color.red);
Explanation:
First, we define a qqq_close by using the symbol attribute. Then we can create series of the qqq moving average. Once we have the two moving averages, we compare them and assign 1 to qqq_10_above_20 if it is true, and zero if it is not. I like to be...
I don't know what the 50 MA breadth indicator is, but I've subbed in a simple moving average to illustrate:
Code:
def qqq_Close = close(symbol = "QQQ");
def qqq_ma_10 = SimpleMovingAvg(price = qqq_Close, length = 10);
def qqq_ma_20 = SimpleMovingAvg(price = qqq_Close, length = 20);
def qqq_10_above_20 = if qqq_ma_10 > qqq_ma_20 then 1 else 0;
plot indicator = SimpleMovingAvg(CLOSE, 50);
indicator.AssignValueColor(if qqq_10_above_20 == 1 then color.green else color.red);
Explanation:
First, we define a qqq_close by using the symbol attribute. Then we can create series of the qqq moving average. Once we have the two moving averages, we compare them and assign 1 to qqq_10_above_20 if it is true, and zero if it is not. I like to be explicit in code and not rely on implicit true and false. Just the way I roll.
Once we have that value, we can plot any indicator and use the AssignValueColor() property of the plot to set the color based on the current value of the qq_10_abote_20 series. if it is 1, then the 10 is above the 20 and we plot the indicator in green. If it is not 1 (then it is 0) then we plot the indicator line in red.

Hope that helps.

-mashume
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
308 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