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

Alerts for Moving Avg Cross or else Premarket Movers

EnV-T

New member
VIP
GOOD AFTERNOON CODERS,


I have the current code that I'm looking to change so that it displays "Bullish" when price is above the 50ema on the 10 min time frame and "Bearish" when price is below the 10 min time frame. In addition to that, I would like an alert sent when these two conditions are met. I will put the code below.



input EMA_1_Length = 50; #exponential
input EMA_1_closeType = ohlc4;
def EMA_1_avg = ExpAverage(EMA_1_closeType, EMA_1_Length);

def pricevs50ema = ( 100 * (close - EMA_1_avg) / EMA_1_avg);
plot pricev50ema = If (IsNaN(EMA_1_avg), 0 , pricevs50ema);


pricev50ema.AssignValueColor(Color.BLACK );

AssignBackgroundColor(if pricevs50ema > 0 then createcolor(177,213,242) else createcolor(255,234,202) );
 
your actual request implies the PRICE CLOSE is above/below... i answered what your actual written request was.

for future reference, aside from the label, the scan you wanted could have been done with the built in "condition wizard" inside of thinkorswim. some sime 15-30min videos on you tube show how easy "condition wizard" scan is to use. however i made the code for you below.

* REMEMBER TO SET AGGREGATION TO 10 minutes (many tutorials online and on youtube)*

Alerts are made using the alert feature on thinkorswim. (many tutorials also available online on youtube)


here you go as a scan:

Bullish scan
Code:
declare lower;
input price = close;
input length = 50;
input displace = 0;
def AvgExp1 = ExpAverage(price[-displace], length);
plot scan = close >AvgExp1;

Bearish Scan
Code:
declare lower;
input price = close;
input length = 50;
input displace = 0;
def AvgExp1 = ExpAverage(price[-displace], length);
plot scan = close <AvgExp1;

here you go as a column:

Code:
declare lower;
input price = close;
input length = 50;
input displace = 0;
def AvgExp1 = ExpAverage(price[-displace], length);

AddLabel(yes, if close>AvgExp1 then  "Bullish " else if close<Avgexp1 then "Bearish" else "Neither", if close>AvgExp1 then  color.green else if close<Avgexp1 then color.red else color.gray );
 
Last edited by a moderator:

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

your actual request implies the PRICE CLOSE is above/below... i answered what your actual written request was.

for future reference, aside from the label, the scan you wanted could have been done with the built in "condition wizard" inside of thinkorswim. some sime 15-30min videos on you tube show how easy "condition wizard" scan is to use. however i made the code for you below.

* REMEMBER TO SET AGGREGATION TO 10 minutes (many tutorials online and on youtube)*

Alerts are made using the alert feature on thinkorswim. (many tutorials also available online on youtube)


here you go as a scan:

Bullish scan
Code:
declare lower;
input price = close;
input length = 50;
input displace = 0;
def AvgExp1 = ExpAverage(price[-displace], length);
plot scan = close >AvgExp1;

Bearish Scan
Code:
declare lower;
input price = close;
input length = 50;
input displace = 0;
def AvgExp1 = ExpAverage(price[-displace], length);
plot scan = close <AvgExp1;

here you go as a column:

Code:
declare lower;
input price = close;
input length = 50;
input displace = 0;
def AvgExp1 = ExpAverage(price[-displace], length);

AddLabel(yes, if close>AvgExp1 then  "Bullish " else if close<Avgexp1 then "Bearish" else "Neither", if close>AvgExp1 then  color.green else if close<Avgexp1 then color.red else color.gray );


Awesome work. Thank you so much. Do these scans send immediately when price closes above the 10 min 50EMA?
 
Awesome work. Thank you so much. Do these scans send immediately when price closes above the 10 min 50EMA?
Scans update every 3 to 4 minutes.
The above scan code is set to trigger for all results of close above moving average.
NO, it does not scan for close crossing above moving average.

If that is your intent.
Replace this:
plot scan = close >AvgExp1;
With this:
plot scan = close crosses above AvgExp1;
 
Awesome work. Thank you so much. Do these scans send immediately when price closes above the 10 min 50EMA?
you asked for when price is above, you didnt ask for when price crosses above, however Usethinkscript has the solution for what you want. as a watch list its scans every 1-4 minutes depending on server load balancing. if you scan manually using stock hacker then it gives up to date results.
 
you asked for when price is above, you didnt ask for when price crosses above, however Usethinkscript has the solution for what you want. as a watch list its scans every 1-4 minutes depending on server load balancing. if you scan manually using stock hacker then it gives up to date results.
I definitely should've specified that instead of what I initially stated. Thank you again. Coding is very interesting.
 
I would like a code to show when price is above the 20 sma Color yellow and when price is below 20 sma color red

you didn't say WHAT you want to see change color?

i made a guess and made this.
it changes the color of the average line

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

#input avg1_type = AverageType.exponential;
input avg1_type = AverageType.Simple;
input avg1_length = 20;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

plot z = avg1;
z.AssignValueColor(if close > avg1 then color.yellow else color.red);
#z.SetDefaultColor(Color.cyan);
z.setlineweight(2);
z.hidebubble();
#
 
Hello,
Need help in setting an Alert if the stock moves / crosses above or below 50-EMA within a 5 min bar. also an Alert if the stock moves above premarket high or below premarket low. your help is much appreciated
 
Last edited:
Hello,
Need help in setting an Alert if the stock moves / crosses above or below 50-EMA within a 5 min bar. also an Alert if the stock moves above premarket high or below premarket low. your help is much appreciated

Moved your question here. It should answer your question.
If you need more help, yell!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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