Alerter_snd

Download script
Alerter_snd

This tool is designed to provide automated price monitoring and notifications directly on your trading charts. It acts as a "watchdog" that scans the objects you place on your screen—such as horizontal lines or trend lines—to notify you when the market price reaches specific zones you have defined.

How it Works

The script constantly monitors every object on your active chart to see if it qualifies for an alert. For an object to trigger a notification, it must meet three specific criteria:

  1. Object Type: The tool specifically looks for horizontal lines or trend lines.
  2. Custom Description: You designate an "alert zone" by adding a specific tag to the object's description (e.g., Alert_50). This number tells the script exactly how many pips away from the line it should trigger the notification.
  3. Price Proximity: The script calculates the distance between the current live market price and the price level of your drawn line.

Notification Process

When the market price moves within the "pips distance" you defined in the object's description, the tool performs the following actions:

  • Visual & Audio Alerts: It triggers a popup window on your screen and plays a sound file to grab your immediate attention.
  • Email Notifications: If enabled, it sends an automated email alert containing the current price and the specific name of the object that was hit.
  • Auto-Reset: To prevent the alarm from firing repeatedly (which could result in spamming your inbox), the tool automatically clears the alert tag from that object's description once the notification has been sent.

User Interface

When you load this script, it creates a visible status label on your chart corner. This label provides a quick glance at your current settings, showing whether your Email and Popup alerts are currently turned ON or OFF.

In summary, this tool allows you to set "tripwires" on your charts; once the market price touches those wires within your specified range, the system handles the notification automatically so you don't have to watch the screen every second.

13 Views
0 Downloads
0 Favorites
Alerter_snd
#define			OBJNAME_LABEL		"Alerter Label"
#define			OBJDESC_PATTERN		"Alert_"

#property indicator_chart_window

extern bool		EmailAlert	= true;
extern bool		PopupAlert	= true;
extern string SoundAlert = "alert.wav";
int init() {
	createIndicatorLabel(OBJNAME_LABEL);
}

int deinit() {
	ObjectDelete(OBJNAME_LABEL);
}

int start() {

	// Iterate over objects on this chart
	for (int i=ObjectsTotal()-1;i>=0;i--) {
		string	sObjName 	= ObjectName(i);
		double	dObjPrice;
		int		iObjAlert;
		int		iProximity;
		string	sMessage;
		
		// Can we get a price for this object?  If not, continue iteration
		dObjPrice = getObjectPrice(sObjName);
		if (dObjPrice == -1) continue;
		
		// Is there an alert on this object?  If not, continue iteration
		iObjAlert = getObjectAlert(sObjName);
		if (iObjAlert == -1) continue;
		
		// Is the line within alert proximity?  If not, continue iteration
		iProximity = MathAbs(Bid - dObjPrice) / Point;
		if (iProximity > iObjAlert) continue;

		// Fire the alert and clear alert from description
		sMessage = "Alert triggered: " + Symbol() + "@" + DoubleToStr(Bid,Digits)  +"."
			+ "  " + iProximity + " pips from " + sObjName + ".";
		if (PopupAlert) {
		Alert(sMessage);
		PlaySound(SoundAlert);
		}
		if (EmailAlert) SendMail("Alert on " + Symbol(), sMessage);
		
		// Clear the alert from the object description
		clearObjectAlert(sObjName);
	}

	return(0);
}

double getObjectPrice(string sObjName) {

	int iObjType = ObjectType(sObjName);
	
	// if it's a horizontal line...
	if (iObjType == OBJ_HLINE)
		return(ObjectGet(sObjName,OBJPROP_PRICE1));
	
	// if it's a trend line...
	if (iObjType == OBJ_TREND)
		return(ObjectGetValueByShift(sObjName,0));
	
	// otherwise...
	return(-1);
}


int getObjectAlert(string sObjName) {

	// looking for pattern "alert_##" at end of obj description
	string 	sObjectDesc		= ObjectDescription(sObjName);
	int 	iPatternOffset 	= StringFind(sObjectDesc,OBJDESC_PATTERN);
	int		iPatternLength	= StringLen(OBJDESC_PATTERN);

	// if pattern not found, no alert for this object
	if (iPatternOffset == -1) 
		return(-1);
	
	// return value after the pattern as number
	//Print("Alert: ", StringSubstr(sObjectDesc,iPatternOffset+iPatternLength));
	return(StrToInteger(StringSubstr(sObjectDesc,iPatternOffset+iPatternLength)));
}

void clearObjectAlert(string sObjName) {

	// strip "alert_*" from end of obj description
	string 	sObjDesc 		= ObjectDescription(sObjName);
	int 	iSubStrOffset 	= StringFind(sObjDesc,"Alert_");
	
	// if found at start of description, clear description
	if (iSubStrOffset == 0) {
		ObjectSetText(sObjName,"");
		return;
	}
	
	// if found further on in desc, strip it from description
	if (iSubStrOffset > 0) {
		ObjectSetText(sObjName,StringSubstr(sObjDesc,0,iSubStrOffset));
		return;
	}
}

void createIndicatorLabel(string sObjName) {
	
	// Set the text
	string sObjText = "Alerter:";
	if (EmailAlert) sObjText = sObjText + "  Emails Alerts ON.";
	else            sObjText = sObjText + "  Emails Alerts OFF.";
	if (PopupAlert) sObjText = sObjText + "  Popup Alerts ON.";
	else			sObjText = sObjText + "  Popup Alerts OFF.";
	
	// Create and position the label
	ObjectCreate(sObjName,OBJ_LABEL,0,0,0);
	ObjectSetText(sObjName,sObjText,8,"Arial",Yellow);
	ObjectSet(sObjName,OBJPROP_XDISTANCE,5);
	ObjectSet(sObjName,OBJPROP_YDISTANCE,5);
	ObjectSet(sObjName,OBJPROP_CORNER,1);
	
}
	

Comments