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 or the price moves far away from the trendline. 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_XDIST ANCE,5);
ObjectSet(“lblTAlert”,OBJPROP_YDIST ANCE,15);
ObjectSet(“lblTAlert”,OBJPROP_CORNE R,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_PR ICE3);
if ((prevbid!=0) && (prevvalue!=0))
if (((Bid>value) && (prevbid<=prevvalue)) || ((Bid<value) && (prevbid>=prevvalue))) {
PlaySound(“alert.wav”);
SendMail(“Trendline Alert”, "Price crossed trendline "); }
ObjectSet(name,OBJPROP_PRICE3,value );
}
}
prevbid=Bid;
//----
return(0);
}
//±----------------------------------- ------------------------------+