Price above 150 ema in weekly but below in daily chart?

new_spy123

New member
Hi All,

I want to create a study alert which alerts me when price is above 150 ema on weekly chart but price below 150 ema on daily chart. How do I do this?

Here is what I have and this alerts me only when price is below 150 ema on daily chart. How do I add weekly chart condition to this?:
Code:
close is less than MovAvgExponential("length"=150)."AvgExp" True

Please note that I do programming for living, so if you can point me to any similar example or give some pointers that would be great.
 
Solution
I hope this will help to get you started.
It draws 2 lines on a chart and draws purple shading between them when close is between them.
It does have an alert function, but i can't verify it works after hours.

I used a chart setting of 2Y 1D, and used these stocks for testing. their last bar is between the lines.
SBUX , EMR , PM


you can define the data to be generated from a different time frame than what is on the chart. this is called 2nd aggregation. you can have a chart of hour bars and do calculations on data from a larger time, a 2nd aggregation.
you can define only one 2nd agg time in a formula, so create a formula for each data that will use 2nd agg. then combine those variables in another formula.

this uses 2nd agg for...
I hope this will help to get you started.
It draws 2 lines on a chart and draws purple shading between them when close is between them.
It does have an alert function, but i can't verify it works after hours.

I used a chart setting of 2Y 1D, and used these stocks for testing. their last bar is between the lines.
SBUX , EMR , PM


you can define the data to be generated from a different time frame than what is on the chart. this is called 2nd aggregation. you can have a chart of hour bars and do calculations on data from a larger time, a 2nd aggregation.
you can define only one 2nd agg time in a formula, so create a formula for each data that will use 2nd agg. then combine those variables in another formula.

this uses 2nd agg for both emas, by defining the 2nd agg time as a parameter of the price function, close.
this study can be used on a chart of 1 minute up to a day chart, assuming there is 150 weeks of data to be found.

Ruby:
#    close <  daily ema150 AND close >  weekly ema150

#----------------------------
input aggd = AggregationPeriod.DAY;
input lengthday = 150;
def ExpAvgday = ExpAverage( close( period = aggd), lengthday );

input aggw = AggregationPeriod.week;
input lengthweek = 150;
def ExpAvgweek = ExpAverage( close( period = aggw), lengthweek );


#----------------------------
# true when close is between both lines
def both_cond = (close < ExpAvgday) and (close > ExpAvgweek);


#----------------------------
# display a label when both conditions are true
addlabel(both_cond, "close < daily ema150  AND  close > weekly ema150", color.yellow);

# draw a cloud between the 2 emas when condition is true.
addcloud( (if both_cond then ExpAvgday else double.nan), ExpAvgweek, color.magenta, color.magenta);

input show_ema_lines = yes;
plot zd = if show_ema_lines then ExpAvgday else double.nan;
zd.setdefaultcolor(color.cyan);
plot zw = if show_ema_lines then ExpAvgweek else double.nan;
zw.setdefaultcolor(color.yellow);

Alert(both_cond, "between levels", alert.once, Sound.ding);
#


JWSo9qQ.jpg



study , output is line(s) , from numbers.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovAvgExponential

function , output is 1 number
can specify what type of average
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage

function
just exponential average
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/ExpAverage

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals
https://tlc.thinkorswim.com/center/...tants/AggregationPeriod/AggregationPeriod-DAY

alert info
https://readtheprospectus.wordpress...ng-alerts-using-thinkscript-in-think-or-swim/
 
Solution

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

I hope this will help to get you started.
It draws 2 lines on a chart and draws purple shading between them when close is between them.
It does have an alert function, but i can't verify it works after hours.

I used a chart setting of 2Y 1D, and used these stocks for testing. their last bar is between the lines.
SBUX , EMR , PM


you can define the data to be generated from a different time frame than what is on the chart. this is called 2nd aggregation. you can have a chart of hour bars and do calculations on data from a larger time, a 2nd aggregation.
you can define only one 2nd agg time in a formula, so create a formula for each data that will use 2nd agg. then combine those variables in another formula.

this uses 2nd agg for both emas, by defining the 2nd agg time as a parameter of the price function, close.
this study can be used on a chart of 1 minute up to a day chart, assuming there is 150 weeks of data to be found.

Ruby:
#    close <  daily ema150 AND close >  weekly ema150

#----------------------------
input aggd = AggregationPeriod.DAY;
input lengthday = 150;
def ExpAvgday = ExpAverage( close( period = aggd), lengthday );

input aggw = AggregationPeriod.week;
input lengthweek = 150;
def ExpAvgweek = ExpAverage( close( period = aggw), lengthweek );


#----------------------------
# true when close is between both lines
def both_cond = (close < ExpAvgday) and (close > ExpAvgweek);


#----------------------------
# display a label when both conditions are true
addlabel(both_cond, "close < daily ema150  AND  close > weekly ema150", color.yellow);

# draw a cloud between the 2 emas when condition is true.
addcloud( (if both_cond then ExpAvgday else double.nan), ExpAvgweek, color.magenta, color.magenta);

input show_ema_lines = yes;
plot zd = if show_ema_lines then ExpAvgday else double.nan;
zd.setdefaultcolor(color.cyan);
plot zw = if show_ema_lines then ExpAvgweek else double.nan;
zw.setdefaultcolor(color.yellow);

Alert(both_cond, "between levels", alert.once, Sound.ding);
#


JWSo9qQ.jpg



study , output is line(s) , from numbers.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovAvgExponential

function , output is 1 number
can specify what type of average
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage

function
just exponential average
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/ExpAverage

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals
https://tlc.thinkorswim.com/center/...tants/AggregationPeriod/AggregationPeriod-DAY

alert info
https://readtheprospectus.wordpress...ng-alerts-using-thinkscript-in-think-or-swim/
This is awesome. Learnt some new stuff from your code.

Only one question I have is on the Alert : Can I get this alert on my mobile? how is this alert different from the study alerts that show up in the Marketwatch?
 
This is awesome. Learnt some new stuff from your code.

Only one question I have is on the Alert : Can I get this alert on my mobile? how is this alert different from the study alerts that show up in the Marketwatch?
Commonly Asked Questions about Alerts:
There are Three Types of Alerts:
There are alerts written into studies. They only alert when the chart w/ the study is open on your screen
They cannot be sent to phone/email. They cannot have custom sounds.
There are alerts created on a chart for one specific stock that you want to alert on. The alert will only fire once. At that point, the condition has been met, the alert expires. No, this can't be changed.
There are scanned watchlist alerts which alert whenever the results of the scan changes. These alerts can be 3-7min delayed.
Alerts blinking by too fast? To see all alerts: click on the message center
Want to see a list of alerts all the time? detach the message center
TeXjiwC.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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