Fast EMA Above/Below Long EMA Alerts Help

Sparky47

New member
Hello All,

Apologies for asking what I'm sure is a simple question. I haven't programmed in thirty years and just started looking at thinkscript a couple of days ago. I'm sure I could figure it out in a couple of weeks but this is something I would like to get in production in the next couple of days.

I would like to add the option for audio alerts to a pre-existing piece of thinkscript.

The code block as is-
Code:
input Show8 = yes;

def EMA3 = ExpAverage(close, 3);
def EMA8 = ExpAverage(close, 8);

def state_8 = {default flat, long, short};
switch (state_8[1])
{
case flat: state_8 = if EMA3 > EMA8 and low[1] > EMA3 and low <= EMA3 and low >= EMA8 then state_8.long else if EMA8 > EMA3 and high[1] < EMA3 and high >= EMA3 and high <= EMA8 then state_8.short else state_8.flat;
case long: state_8 = if low <= EMA8 then state_8.flat else state_8.long;
case short: state_8 = if high >= EMA8 then state_8.flat else state_8.short;
}

plot BuyDots8 = if Show8 then (if state_8 == state_8.long or (state_8 == state_8.flat and state_8[1] == state_8.long) then EMA8 else Double.NaN) else double.nan;
BuyDots8.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyDots8.SetLineWeight(2);
BuyDots8.SetDefaultColor(Color.downtick);
BuyDots8.HideBubble();

plot SellDots8 = if Show8 then (if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan;
SellDots8.SetPaintingStrategy(PaintingStrategy.POINTS);
SellDots8.SetLineWeight(2);
SellDots8.SetDefaultColor(Color.downtick);
SellDots8.HideBubble();


This code is intended to paints dots above or below a 34 EMA line. I can see the logic where it's deciding if the 3 EMA is above or below the 8 EMA and deciding whether to paint a dot above or below.

I know that the general format for an alert (from thinkscript learning center) is Alert ( IDataHolder condition , String text , int alert type , String sound );

The only place I'm not sure what to insert is the condition part. I would like it to sound a bell on every bar. I'm thinking the alert statements will look something like this-

Code:
#Bell sound if 3EMA is above 8EMA
alert(if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan), "3 EMA above 8 EMA", Alert.BAR, Sound.Bell);

#Bell sound if 3EMA is below 8EMA
alert( if Show8 then (if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan ), "3 EMA below 8 EMA", Alert.BAR, Sound.Bell);

If an experienced thinkscripter would take a look and tell me if my alert statements are right or wrong and where to place them I would appreciate it :)
 
Last edited by a moderator:
Solution
Hello All,

Apologies for asking what I'm sure is a simple question. I haven't programmed in thirty years and just started looking at thinkscript a couple of days ago. I'm sure I could figure it out in a couple of weeks but this is something I would like to get in production in the next couple of days.

I would like to add the option for audio alerts to a pre-existing piece of thinkscript.

The code block as is-
Code:
input Show8 = yes;

def EMA3 = ExpAverage(close, 3);
def EMA8 = ExpAverage(close, 8);

def state_8 = {default flat, long, short};
switch (state_8[1])
{
case flat: state_8 = if EMA3 > EMA8 and low[1] > EMA3 and low <= EMA3 and low >= EMA8 then state_8.long else if EMA8 > EMA3 and high[1] < EMA3 and high >= EMA3 and high <=...
Hello All,

Apologies for asking what I'm sure is a simple question. I haven't programmed in thirty years and just started looking at thinkscript a couple of days ago. I'm sure I could figure it out in a couple of weeks but this is something I would like to get in production in the next couple of days.

I would like to add the option for audio alerts to a pre-existing piece of thinkscript.

The code block as is-
Code:
input Show8 = yes;

def EMA3 = ExpAverage(close, 3);
def EMA8 = ExpAverage(close, 8);

def state_8 = {default flat, long, short};
switch (state_8[1])
{
case flat: state_8 = if EMA3 > EMA8 and low[1] > EMA3 and low <= EMA3 and low >= EMA8 then state_8.long else if EMA8 > EMA3 and high[1] < EMA3 and high >= EMA3 and high <= EMA8 then state_8.short else state_8.flat;
case long: state_8 = if low <= EMA8 then state_8.flat else state_8.long;
case short: state_8 = if high >= EMA8 then state_8.flat else state_8.short;
}

plot BuyDots8 = if Show8 then (if state_8 == state_8.long or (state_8 == state_8.flat and state_8[1] == state_8.long) then EMA8 else Double.NaN) else double.nan;
BuyDots8.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyDots8.SetLineWeight(2);
BuyDots8.SetDefaultColor(Color.downtick);
BuyDots8.HideBubble();

plot SellDots8 = if Show8 then (if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan;
SellDots8.SetPaintingStrategy(PaintingStrategy.POINTS);
SellDots8.SetLineWeight(2);
SellDots8.SetDefaultColor(Color.downtick);
SellDots8.HideBubble();


This code is intended to paints dots above or below a 34 EMA line. I can see the logic where it's deciding if the 3 EMA is above or below the 8 EMA and deciding whether to paint a dot above or below.

I know that the general format for an alert (from thinkscript learning center) is Alert ( IDataHolder condition , String text , int alert type , String sound );

The only place I'm not sure what to insert is the condition part. I would like it to sound a bell on every bar. I'm thinking the alert statements will look something like this-

Code:
#Bell sound if 3EMA is above 8EMA
alert(if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan), "3 EMA above 8 EMA", Alert.BAR, Sound.Bell);

#Bell sound if 3EMA is below 8EMA
alert( if Show8 then (if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan ), "3 EMA below 8 EMA", Alert.BAR, Sound.Bell);

If an experienced thinkscripter would take a look and tell me if my alert statements are right or wrong and where to place them I would appreciate it :)

hello and welcome
i was in my 50s when i started looking at thinkscript. you will get it.
...actually if you are tackling state variables, you are doing great.


if something doesnt work, put each parameter on a new line. its easier to look at.
you have an extra double nan and an extra )

alert(
if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan)
, "3 EMA above 8 EMA"
, Alert.BAR
, Sound.Bell);


fixed
Code:
alert(if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN , "3 EMA above 8 EMA", Alert.BAR, Sound.Bell);


these are the 2 alerts sounds i use, for longs and shorts
alert(a, "up" ,alert.BAR, sound.DING);
alert(a, "down" ,alert.BAR, sound.bell);


------------------------------

i think, using state variables is complicating things. i don't use them.
i would remove the switch case and create 3 variables ,
flat =
long =
short =
and assign the proper conditions to each.
 
Last edited:
Solution
Hello All,

Apologies for asking what I'm sure is a simple question. I haven't programmed in thirty years and just started looking at thinkscript a couple of days ago. I'm sure I could figure it out in a couple of weeks but this is something I would like to get in production in the next couple of days.

I would like to add the option for audio alerts to a pre-existing piece of thinkscript.

The code block as is-
Code:
input Show8 = yes;

def EMA3 = ExpAverage(close, 3);
def EMA8 = ExpAverage(close, 8);

def state_8 = {default flat, long, short};
switch (state_8[1])
{
case flat: state_8 = if EMA3 > EMA8 and low[1] > EMA3 and low <= EMA3 and low >= EMA8 then state_8.long else if EMA8 > EMA3 and high[1] < EMA3 and high >= EMA3 and high <= EMA8 then state_8.short else state_8.flat;
case long: state_8 = if low <= EMA8 then state_8.flat else state_8.long;
case short: state_8 = if high >= EMA8 then state_8.flat else state_8.short;
}

plot BuyDots8 = if Show8 then (if state_8 == state_8.long or (state_8 == state_8.flat and state_8[1] == state_8.long) then EMA8 else Double.NaN) else double.nan;
BuyDots8.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyDots8.SetLineWeight(2);
BuyDots8.SetDefaultColor(Color.downtick);
BuyDots8.HideBubble();

plot SellDots8 = if Show8 then (if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan;
SellDots8.SetPaintingStrategy(PaintingStrategy.POINTS);
SellDots8.SetLineWeight(2);
SellDots8.SetDefaultColor(Color.downtick);
SellDots8.HideBubble();


This code is intended to paints dots above or below a 34 EMA line. I can see the logic where it's deciding if the 3 EMA is above or below the 8 EMA and deciding whether to paint a dot above or below.

I know that the general format for an alert (from thinkscript learning center) is Alert ( IDataHolder condition , String text , int alert type , String sound );

The only place I'm not sure what to insert is the condition part. I would like it to sound a bell on every bar. I'm thinking the alert statements will look something like this-

Code:
#Bell sound if 3EMA is above 8EMA
alert(if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan), "3 EMA above 8 EMA", Alert.BAR, Sound.Bell);

#Bell sound if 3EMA is below 8EMA
alert( if Show8 then (if state_8 == state_8.short or (state_8 == state_8.flat and state_8[1] == state_8.short) then EMA8 else Double.NaN) else double.nan ), "3 EMA below 8 EMA", Alert.BAR, Sound.Bell);

If an experienced thinkscripter would take a look and tell me if my alert statements are right or wrong and where to place them I would appreciate it :)
Try this:

Code:
#Bell sound if 3EMA is above 8EMA
alert((EMA3 > EMA8), "3 EMA above 8 EMA", Alert.BAR, Sound.Bell);

#Bell sound if 3EMA is below 8EMA
alert((EMA3 < EMA8), "3 EMA below 8 EMA", Alert.BAR, Sound.Bell);
 

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