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:
Solution
How can I add Buy/Sell arrows?

Needing a down arrow to print when price closes below the ema3 and a buy arrow when price closes above the ema1. Each time i've tried to add the arrow coding, the ema lines dissappear.
What is your definition of price?
There are many choices for definition of price: Open Close High Low hl2 hlc3 ohlc4. With today's volatility, all these definitions can miss the mark.

FYI
This thread was started because price crosses average isn't a thing found on the forum.
This is because the standard is moving average crossing another moving average.
Using a moving average w/ a length of 2 or 3 bars provides a clearer signal than attempting to apply one of the above seven definitions of price.
That is why there...
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:
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);
 
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!
 
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:
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);
 
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
 
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);
 
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
 
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);
 
I’m trying to create an alert that lets me know when price crosses the 21 SMA on a 1600 tick chart but have no idea where to start. Is it even possible to create in Think or Swim?
Ruby:
input length  = 21;
input avgtype = AverageType.SIMPLE ;
plot ema1 = MovingAverage(avgtype, close, length);

Alert(close crosses above ema1, "ding", alert.tick, Sound.ding);
AddLabel(yes, length, if close > ema1 then Color.GREEN else Color.RED);
 
Last edited:
Simple MA labels that show if price is above or below 5 Standard Ma's

Code:
#ChatGPTMadethis
# Moving Averages
input ma9 = 9;
input ma20 = 20;
input ma50 = 50;
input ma100 = 100;
input ma200 = 200;

# Current Price
def price = close;

# Moving Average Values
def ma9value = MovingAverage(AverageType.SIMPLE, price, ma9);
def ma20value = MovingAverage(AverageType.SIMPLE, price, ma20);
def ma50value = MovingAverage(AverageType.SIMPLE, price, ma50);
def ma100value = MovingAverage(AverageType.SIMPLE, price, ma100);
def ma200value = MovingAverage(AverageType.SIMPLE, price, ma200);

# Labels
AddLabel(yes, "MA9: " + ma9value, if price > ma9value then Color.GREEN else Color.RED);
AddLabel(yes, "MA20: " + ma20value, if price > ma20value then Color.GREEN else Color.RED);
AddLabel(yes, "MA50: " + ma50value, if price > ma50value then Color.GREEN else Color.RED);
AddLabel(yes, "MA100: " + ma100value, if price > ma100value then Color.GREEN else Color.RED);
AddLabel(yes, "MA200: " + ma200value, if price > ma200value then Color.GREEN else Color.RED);
 
Looking for close breaking above moving average.

provide a wedge or bubble or signal each time a candle Price closes above 20 ema until
10 ema is crosses above 20 ema which would have an arrow
Here is the example1 for multiple breaks and cross over.
yhdWzSw.png



shared chart link: https://tos.mx/!JsSInFf2
Uai1ZR4.png

This chart uses 40 EMA. Doesn't matter what is used for the longer EMA. It is adjustable.
 
Last edited by a moderator:
Looking for close breaking above moving average.

provide a wedge or bubble or signal each time a candle Price closes above 20 ema until
10 ema is crosses above 20 ema which would have an arrow
Here is the example1 for multiple breaks and cross over.

shared chart link: https://tos.mx/!JsSInFf2

This chart uses 40 EMA. Doesn't matter what is used for the longer EMA. It is adjustable.

this draws wedges and arrows

Code:
#average_2xcrossings

#https://usethinkscript.com/threads/close-crosses-above-moving-average.19037/
#close crosses above moving average
# wedge each time a candle Price closes above 20 ema 
#10 ema is crosses above 20 ema which would have an arrow

def na = double.nan;
def bn = barnumber();
def data = close;

input avg1_type = AverageType.exponential;
input avg1_length = 10;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

input avg2_type = AverageType.exponential;
input avg2_length = 30;
def avg2 = MovingAverage(avg2_type, data, avg2_length );

input show_avg1_line = yes;
input show_avg2_line = yes;

plot zavg1 = if show_avg1_line then avg1 else na;
plot zavg2 = if show_avg2_line then avg2 else na;
zavg1.SetDefaultColor(Color.yellow);
zavg1.setlineweight(1);
zavg1.hidebubble();
zavg2.SetDefaultColor(Color.gray);
zavg2.setlineweight(1);
zavg2.hidebubble();

def xup = avg1 crosses above avg2;
def xdwn = avg1 crosses below avg2;

def bodytop = max(open,close);
def bodybot = min(open,close);

def xupavg1 = (bodytop[1] < avg1[1] and bodytop[0] > avg1[0]);
def xdwnavg1 = (bodytop[1] > avg1[1] and bodytop[0] < avg1[0]);
 
plot zxup1 = if xupavg1 then 1 else 0;
zxup1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zxup1.SetDefaultColor(Color.cyan);
zxup1.setlineweight(2);
zxup1.hidebubble();

plot zxup = if xup then low*0.999 else na;
zxup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
zxup.SetDefaultColor(Color.cyan);
zxup.setlineweight(2);
zxup.hidebubble();

plot zxdwn1 = if xdwnavg1 then 1 else 0;
zxdwn1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zxdwn1.SetDefaultColor(Color.yellow);
zxdwn1.setlineweight(2);
zxdwn1.hidebubble();

plot zxdwn = if xdwn then high*1.001 else na;
zxdwn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
zxdwn.SetDefaultColor(Color.yellow);
zxdwn.setlineweight(2);
zxdwn.hidebubble();
#
 

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
240 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