Adding an alert to study in thinkscript

cattle trader

New member
How can i add an alert to this

Code:
input typicalLength = 5;
input haLength = 8;
input paintBars = yes;

def haOpen = (ohlc4[1] + haOpen[1]) / 2;
def haClose = (ohlc4 + haOpen + Max(high, haOpen) + Min(low, haOpen)) / 4;

plot AvgTyp = ExpAverage(hlc3, typicalLength);
plot AvgHAC = ExpAverage(haClose, haLength);


AvgTyp.SetDefaultColor(GetColor(1));
AvgHAC.SetDefaultColor(GetColor(2));
 

cattle trader

New member
That didn't work, maybe i'm doing something wrong.

Code:
input typicalLength = 5;
input haLength = 8;
input paintBars = yes;

def haOpen = (ohlc4[1] + haOpen[1]) / 2;
def haClose = (ohlc4 + haOpen + Max(high, haOpen) + Min(low, haOpen)) / 4;

plot AvgTyp = ExpAverage(hlc3, typicalLength);
plot AvgHAC = ExpAverage(haClose, haLength);


AvgTyp.SetDefaultColor(GetColor(1));
AvgHAC.SetDefaultColor(GetColor(2));
Alert(AvgTyp crosses above AvgHAC, "Cross Up", alert.bar, sound.chimes);
Alert(AvgTyp crosses below AvgHAC, "Cross Down", alert.bar, sound.chimes);
 
Last edited by a moderator:

Pensar

Well-known member
VIP
@cattle trader The alerts would be working correctly then. I dont know about SMS or email msgs, never use them. But maybe check your application settings to see if you have alerts turned on? Perhaps @BenTen knows more.

M4a2KsJ.png
 

BenTen

Administrative
Staff member
Staff
VIP
@cattle trader @Pensar Alerts implemented through the indicator's source code will not give you the option for text messages. You will only get notified via a sound alert (ex: chime). You would need to go to the MarketWatch tab and set up another alert there.

Note: not all indicators will be supported through MarketWatch.
 

nickolaustort

New member
I added this code to my study and it produce sound alert at every new bar (which I don't want) and I want to have a sound alert only when I have a signal.
Code:
#
# Alerts:
#
def alerttrigger = 1; #replace the 1 with your definition
# BLOCK CODE BELOW
input alerttext = “Alert Text”;
input UseAlerts = {false, default true};
input AlertType = {default “BAR”, “ONCE”, “TICK”};
def at=AlertType;
input AlertSound = {“Bell”, “Chimes”, default “Ding”, “NoSound”, “Ring”};
alert(alerttrigger AND UseAlerts, alerttext, if at==1 then Alert.ONCE else if at==2 then Alert.TICK else Alert.BAR, AlertSound);

When I select ONCE instead of BAR - there is no sound alert at all.
Any advice?
Thanks.
 

rad14733

Well-known member
VIP
@nickolaustort A could things I see that might help... First, you should optimize your code to either use AlertType throughout your code or rename it to at rather than selecting and then reassigning as there is no benefit at all in doing this, it just slows the parser... Second, try using yes/no instead of true/false as they are interpreted differently by the Thinkorswim parser... If I get a chance I'll test the code during trading hours today but make those changes first and report back...
 

nickolaustort

New member
@nickolaustort A could things I see that might help... First, you should optimize your code to either use AlertType throughout your code or rename it to at rather than selecting and then reassigning as there is no benefit at all in doing this, it just slows the parser... Second, try using yes/no instead of true/false as they are interpreted differently by the Thinkorswim parser... If I get a chance I'll test the code during trading hours today but make those changes first and report back...
Sorry, can you write an example of the corrected code? I tried to change yes/no instead of true/false- get errors. And I am not sure how to change AlertType too.
 

rad14733

Well-known member
VIP
Thinkorswim may be experiencing issues with the Alerts feature since the weekend updates as I'm having issues triggering even the simplest of Alerts on my system this morning... I've only had one chart alert all morning and should have received dozens...

Edited to add: Ok, Alerts are back working... I ended up logging out, deleting usergui, and restarting TOS... Odd considering how I did that just before the markets opened at 9:30...
 
Last edited:

Similar threads

Top