Here is the trendline alert which I want to sent me an email, along with the alert sound. I added the sendmail line right after the play sound and it sends e-mails but it won't stop sending them on every tick until I delete the indicator from the chart. Is there any way to make it send only one text per bar? Here is the code below, thanks for any help.
//+------------------------------------------------------------------+
//| TrendLine Alert.mq4 |
//| |
//| Plays sound when Bid price crosses any trendline or |
//| horizontal line. Feel free to modify if needed. |
//| |
//+------------------------------------------------------------------+
#property copyright "Gustavs"
#property indicator_chart_window
double prevbid=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
for (int i=0;i<ObjectsTotal();i++) {
string name=ObjectName(i);
if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) {
ObjectSet(name,OBJPROP_PRICE3,0);
}
}
if (ObjectFind("lblTAlert")<0) ObjectCreate("lblTAlert",OBJ_LABEL,0,0,0);
ObjectSet("lblTAlert",OBJPROP_XDISTANCE,5);
ObjectSet("lblTAlert",OBJPROP_YDISTANCE,15);
ObjectSet("lblTAlert",OBJPROP_CORNER,0);
ObjectSetText("lblTAlert","TAlert",10,"Times New Roman",Lime);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("lblTAlert");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double value,prevvalue;
//----
for (int i=0;i<ObjectsTotal();i++) {
string name=ObjectName(i);
if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) {
if (ObjectType(name)==OBJ_TREND) {value=ObjectGetValueByShift(name,0);} else {
value=ObjectGet(name,OBJPROP_PRICE1);
}
prevvalue=ObjectGet(name,OBJPROP_PRICE3);
if ((prevbid!=0) && (prevvalue!=0))
if (((Bid>value) && (prevbid<=prevvalue)) || ((Bid<value) && (prevbid>=prevvalue))) {
PlaySound("alert.wav");
SendMail("Trendline Alert", "Price crossed trendline ");[/size] }
ObjectSet(name,OBJPROP_PRICE3,value);
}
}
prevbid=Bid;
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TrendLine Alert.mq4 |
//| |
//| Plays sound when Bid price crosses any trendline or |
//| horizontal line. Feel free to modify if needed. |
//| |
//+------------------------------------------------------------------+
#property copyright "Gustavs"
#property indicator_chart_window
double prevbid=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
for (int i=0;i<ObjectsTotal();i++) {
string name=ObjectName(i);
if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) {
ObjectSet(name,OBJPROP_PRICE3,0);
}
}
if (ObjectFind("lblTAlert")<0) ObjectCreate("lblTAlert",OBJ_LABEL,0,0,0);
ObjectSet("lblTAlert",OBJPROP_XDISTANCE,5);
ObjectSet("lblTAlert",OBJPROP_YDISTANCE,15);
ObjectSet("lblTAlert",OBJPROP_CORNER,0);
ObjectSetText("lblTAlert","TAlert",10,"Times New Roman",Lime);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("lblTAlert");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double value,prevvalue;
//----
for (int i=0;i<ObjectsTotal();i++) {
string name=ObjectName(i);
if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) {
if (ObjectType(name)==OBJ_TREND) {value=ObjectGetValueByShift(name,0);} else {
value=ObjectGet(name,OBJPROP_PRICE1);
}
prevvalue=ObjectGet(name,OBJPROP_PRICE3);
if ((prevbid!=0) && (prevvalue!=0))
if (((Bid>value) && (prevbid<=prevvalue)) || ((Bid<value) && (prevbid>=prevvalue))) {
PlaySound("alert.wav");
SendMail("Trendline Alert", "Price crossed trendline ");[/size] }
ObjectSet(name,OBJPROP_PRICE3,value);
}
}
prevbid=Bid;
//----
return(0);
}
//+------------------------------------------------------------------+