Price crossing Moving Average For ThinkOrSwim

nheminism21

New member
Moving Average Label
Hello Y'all..I'm trying to create a label that display the current value of the 21ema on the chart in thinkorswim. I would also like the label to be colored green if the last bar is over the 21ema or red if the last bar is below the 21ema. I'm not much of a programmer, so I would appreciate any help you can help me with this..thank you in advance
 
Last edited by a moderator:

eugchen

Member
im looking for a simple thinkscript to shade the chart below a value. so for instance, on AAPL, the current price is 138.88. lets say i want to set another price of 130, and i want the area on the TOS chart 130 and below to be shaded a light blue. is this possible?

Looking for something like this. i just drew a rectangle manually to create this.


Screenshot-2022-11-03-150330.jpg
 
Last edited:

SleepyZ

Well-known member
VIP
Lifetime
im looking for a simple thinkscript to shade the chart below a value. so for instance, on AAPL, the current price is 138.88. lets say i want to set another price of 130, and i want the area on the TOS chart 130 and below to be shaded a light blue. is this possible?

Looking for something like this. i just drew a rectangle manually to create this.


Screenshot-2022-11-03-150330.jpg

Try this

Screenshot-2022-11-03-162244.png
Ruby:
input Data = 130;
AddCloud(Data, Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
 

eugchen

Member
sleepz, this worked amazing well, but 130 shows up on all charts.

is there anyway to specify this code for AAPL only? for AMZN, i want another price level, for GOOGL, another level, etc. thanks!
 

SleepyZ

Well-known member
VIP
Lifetime
sleepz, this worked amazing well, but 130 shows up on all charts.

is there anyway to specify this code for AAPL only? for AMZN, i want another price level, for GOOGL, another level, etc. thanks!

You could do this and for each one you create, only that one will appear when viewing that symbol's chart.

You could also create a formula that would not require you to enter the values often. For example,
Code:
def AAPL = close("AAPL",period=aggregationperiod.day)[1] - 5;
instead of the input AAPL code.

Ruby:
input AAPL = 130;
AddCloud(if getsymbol()=="AAPL" then AAPL else double.nan,
Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
input META = 90;
AddCloud(if getsymbol()=="META" then META else double.nan,
Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
input TSLA = 207;
AddCloud(if getsymbol()=="TSLA" then TSLA else double.nan,
Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
 
Last edited:

eugchen

Member
This is EXACTLY what i wanted. THANKS!!!!!!!!!!!!!!

Ruby:
nput AAPL = 130;
AddCloud(if getsymbol()=="AAPL" then AAPL else double.nan,
Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
input META = 90;
AddCloud(if getsymbol()=="META" then META else double.nan,
Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
input TSLA = 207;
AddCloud(if getsymbol()=="TSLA" then TSLA else double.nan,
Double.NEGATIVE_INFINITY, Color.CYAN, Color.CYAN, showBorder = Yes);
 

METAL

Active member
Can someone create a label that is customizable to whichever ema is input and the label will show the ema as well as be green if price is above or show red is price is below? for example: If 200 ema is selected/input the the label will display 200 and be green if price is above the 200 ema.
Let me know if this is enough explanation. Thanks
 

SleepyZ

Well-known member
VIP
Lifetime
Can someone create a label that is customizable to whichever ema is input and the label will show the ema as well as be green if price is above or show red is price is below? for example: If 200 ema is selected/input the the label will display 200 and be green if price is above the 200 ema.
Let me know if this is enough explanation. Thanks

Try this

Code:
input length  = 200;
input avgtype = AverageType.EXPONENTIAL;
def ema1 = MovingAverage(avgtype, close, length);
AddLabel(1, length, if close > ema1 then Color.GREEN else Color.RED);
 

SleepyZ

Well-known member
VIP
Lifetime
Is there a way to calculate how far the price is from 200Exponential the price difference. If price above 200Exponential Bullish under Bearish and assign colors. Thank you

Try this

Screenshot-2022-11-23-170005.png

Ruby:
input length   = 200;
input avgtype  = AverageType.EXPONENTIAL;
input price    = close;
input hide_ema = no;
plot ema  = MovingAverage(avgtype, price, length);
ema.SetHiding(hide_ema);
def diff  = price - ema;
AddLabel(1, "$Diff:  Price - EMA: " + AsDollars(diff) , if price > ema then Color.GREEN else Color.RED);
 

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