price approaching moving average alert in ThinkorSwim

mgnichols

New member
Request help setting up an alert in TOS that will identify when a specific stocks price is approaching a specified EMA.
Approaching could be identified as price or percentage, such as price within $.50 of the EMA or price within 1% of EMA.

Attempting to set an alert in TOS to help me identify when stocks on my watch list have price approaching the 10EMA on the daily chart.
But would like to be flexible to set on other time frames.

Thanks for your assistance!
 
Solution
Request help setting up an alert in TOS that will identify when a specific stocks price is approaching a specified EMA.
Approaching could be identified as price or percentage, such as price within $.50 of the EMA or price within 1% of EMA.

Attempting to set an alert in TOS to help me identify when stocks on my watch list have price approaching the 10EMA on the daily chart.
But would like to be flexible to set on other time frames.

Thanks for your assistance!


find when an average line is near a candle. (within the tolerance lines)

..choose tolerance type , dollars or percent of close price
....enter values for dollars and percent
..choose price points, high and low or close
....the tolance amount is added and subtracted to...
Request help setting up an alert in TOS that will identify when a specific stocks price is approaching a specified EMA.
Approaching could be identified as price or percentage, such as price within $.50 of the EMA or price within 1% of EMA.

Attempting to set an alert in TOS to help me identify when stocks on my watch list have price approaching the 10EMA on the daily chart.
But would like to be flexible to set on other time frames.

Thanks for your assistance!


find when an average line is near a candle. (within the tolerance lines)

..choose tolerance type , dollars or percent of close price
....enter values for dollars and percent
..choose price points, high and low or close
....the tolance amount is added and subtracted to the these points, to create tolerance lines.

clouds appear when average line is near, within the tolerances of a candle
alert goes off when average line is near


Code:
# near_ema_price_per

#https://usethinkscript.com/threads/alert-for-price-approaching-moving-average-in-thinkorswim.17865/
#Alert for price approaching moving average

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

input tolerance_type = { default price , percent };
input tolerance_price = 0.50;
input tolerance_percent = 1.0;

def tol;
def tol_x;
switch(tolerance_type) {
case price:
  tol = tolerance_price;
  tol_x = 1;
case percent:
  tol = close * tolerance_percent/100;
  tol_x = 2;
}

input near_type = { default "high_low" , "close" };
def near_top;
def near_bot;
def near_x;
switch(near_type) {
case "high_low":
  near_top = high + tol;
  near_bot = low - tol;
  near_x = 1;
case "close":
  near_top = close + tol;
  near_bot = close - tol;
  near_x = 2;
}

input show_tolerance_lines = no;
plot z2 = if show_tolerance_lines then near_top else na;
plot z3 = if show_tolerance_lines then near_bot else na;
z2.SetDefaultColor(Color.magenta);
z3.SetDefaultColor(Color.magenta);


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

input show_average_line = yes;
plot zavg1 = if show_average_line then avg1 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();

def near = near_top >= avg1 and near_bot <= avg1;
#def near = near_top crosses avg1 or near_bot crosses avg1;

input show_clouds = yes;
def cld_top = if near then near_top else na;
addcloud(cld_top, near_bot, color.light_gray);

alert(near, "near" ,alert.BAR, sound.DING);

input show_labels = yes;
addlabel(show_labels, (if near_x == 1 then "high_low" else "close"), color.yellow);
addlabel(show_labels, (if tol_x == 1 then "price" else "percent"), color.yellow);
addlabel(show_labels, "$ " + tol, color.yellow);


input test1_vert = no;
addverticalline(test1_vert and near, "-");
#

purple tolerance lines are on
cyan average line is on
clouds appear when average line is within the tolerance $ of a candle
 

Attachments

  • img1.JPG
    img1.JPG
    83.7 KB · Views: 186
Solution

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

find when an average line is near a candle. (within the tolerance lines)

..choose tolerance type , dollars or percent of close price
....enter values for dollars and percent
..choose price points, high and low or close
....the tolance amount is added and subtracted to the these points, to create tolerance lines.

clouds appear when average line is near, within the tolerances of a candle
alert goes off when average line is near


Code:
# near_ema_price_per

#https://usethinkscript.com/threads/alert-for-price-approaching-moving-average-in-thinkorswim.17865/
#Alert for price approaching moving average

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

input tolerance_type = { default price , percent };
input tolerance_price = 0.50;
input tolerance_percent = 1.0;

def tol;
def tol_x;
switch(tolerance_type) {
case price:
  tol = tolerance_price;
  tol_x = 1;
case percent:
  tol = close * tolerance_percent/100;
  tol_x = 2;
}

input near_type = { default "high_low" , "close" };
def near_top;
def near_bot;
def near_x;
switch(near_type) {
case "high_low":
  near_top = high + tol;
  near_bot = low - tol;
  near_x = 1;
case "close":
  near_top = close + tol;
  near_bot = close - tol;
  near_x = 2;
}

input show_tolerance_lines = no;
plot z2 = if show_tolerance_lines then near_top else na;
plot z3 = if show_tolerance_lines then near_bot else na;
z2.SetDefaultColor(Color.magenta);
z3.SetDefaultColor(Color.magenta);


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

input show_average_line = yes;
plot zavg1 = if show_average_line then avg1 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();

def near = near_top >= avg1 and near_bot <= avg1;
#def near = near_top crosses avg1 or near_bot crosses avg1;

input show_clouds = yes;
def cld_top = if near then near_top else na;
addcloud(cld_top, near_bot, color.light_gray);

alert(near, "near" ,alert.BAR, sound.DING);

input show_labels = yes;
addlabel(show_labels, (if near_x == 1 then "high_low" else "close"), color.yellow);
addlabel(show_labels, (if tol_x == 1 then "price" else "percent"), color.yellow);
addlabel(show_labels, "$ " + tol, color.yellow);


input test1_vert = no;
addverticalline(test1_vert and near, "-");
#

purple tolerance lines are on
cyan average line is on
clouds appear when average line is within the tolerance $ of a candle
Omg lol

@halcyonguy I think this is what I have been looking for finally!

I didn’t know you had to be specific in looking for price and moving averages. This should be bumped to the top so people won’t get confused between price and moving averages intersecting.
 
I’m looking for something like this for HMA and would like to be able to scan also. When the script says 1%, percent of what is this referring to?

the percent is applied to close. then added to the high and subtracted from the low, to create a range to look for the average
tol = close * tolerance_percent/100;

change the type, from exponential, to hull
 
Did anyone try this code? I am not able to user percent option. Only price option is working.
Also, when i try to deactivate the clouds in the properties window, the study is still showing clouds in the chart. Not sure what am I missing here.
I am just looking for an alert on the chart if the candle crosses above the Moving Average.

Thanks!
 
Did anyone try this code? I am not able to user percent option. Only price option is working.
Also, when i try to deactivate the clouds in the properties window, the study is still showing clouds in the chart. Not sure what am I missing here.
I am just looking for an alert on the chart if the candle crosses above the Moving Average.

Thanks!
no one knows the code from what post you used and if you made the extra changes referenced later.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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