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