MTrendLine alert
Download scriptThis script is designed as a visual and auditory monitoring tool for traders who need to keep a close watch on specific price levels on a trading chart. It automates the creation of horizontal-style trend lines and provides real-time notifications when the market price approaches these predefined zones.
Core Functionality
The tool allows you to monitor up to four distinct price levels simultaneously. For each level, the script performs three primary actions:
- Visual Mapping: It draws specific trend lines on your chart (color-coded as Red, Blue, or Magenta). These lines act as visual anchors, helping you identify key support or resistance areas instantly.
- Dynamic Distance Tracking: Alongside the lines, the script places text labels that calculate and display the exact distance (in pips) between the current market price and the designated trend line. This allows you to see at a glance how much "room" is left before the price hits your target.
- Proximity Alerts: The most critical feature is the automated alert system. You can set a specific "buffer zone" (measured in pips) for each line. When the market price enters this specified range, the script will automatically trigger a notification based on your preferences:
- Audio: Plays a specific alert sound to grab your attention.
- Pop-up: Displays a visual alert window on your trading platform.
- Email: Sends an instant email notification to your linked account.
Customization Options
The script is highly modular, allowing you to toggle features on or off to suit your specific trading style:
- Toggle Levels: You can choose which of the four trend lines to display (e.g., you can turn off levels 3 and 4 if you only need two).
- Adjust Sensitivity: You can define exactly how many pips away from a line should trigger an alert, making it suitable for both high-frequency scalping and long-term swing trading.
- Communication Preferences: You can decide whether you want to be notified via sound, pop-ups, or emails, or use all three simultaneously.
In summary, this tool serves as an "automated lookout," providing constant monitoring of key price levels so that you don't have to watch the screen every second. It alerts you exactly when the market gets close to your areas of interest, ensuring you never miss a potential entry or exit point.
//+------------------------------------------------------------------+
//| MTrendLine alert.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
extern bool TrendLine1_Red = true ; //false true
extern bool TrendLine2_Blue = true ; //false true
extern bool TrendLine_3 = false ; //false true
extern bool TrendLine_4 = false ; //false true
extern int Alert_Red=3;
extern int Alert_Blue=3;
extern bool Sound_Alert_Red=true,Sound_Alert_Blue=true,PopupON=false;
extern bool EmailON=false;
string AlertSound="alert.wav";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("1"); ObjectDelete("2");ObjectDelete("3"); ObjectDelete("4");
// ObjectDelete("TrendLine 1"); ObjectDelete("TrendLine 2");//
// ObjectDelete("TrendLine 3"); ObjectDelete("TrendLine 4");
//ýòî èñïðàâëåíî, ÷òî áû ïðè ïåðåõîäå ñ îäíîãî òàéì ôðåéìà íà äðóãîé, òðåíä ëèíèè, íå ìåíÿëè ñâîå ìåñòî ðàñïîëîæåíèå.
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//+-----------------------------------------------------------------------------------------------
if( TrendLine1_Red) ObjectCreate("TrendLine 1", OBJ_TREND, 0, Time[12], Bid+25*Point , Time[0]+3600, Bid+25*Point );
ObjectSet("TrendLine 1", OBJPROP_COLOR, Red);
if (ObjectFind("1")==-1){ ObjectCreate("1",OBJ_TEXT, 0, 0, 0);
} ObjectSetText("1",DoubleToStr(MathAbs((NormalizeDouble(Bid,Digits)-NormalizeDouble
(ObjectGetValueByShift("Trendline "+1,0),Digits))*MathPow(10,Digits)),0),8,"Arial",Red);
ObjectSet("1",OBJPROP_PRICE1,NormalizeDouble(ObjectGetValueByShift("Trendline "+1,0),Digits));
ObjectSet("1",OBJPROP_TIME1,Time[0]) ;
//+---
double val1=ObjectGetValueByShift("Trendline 1", 0);
if (Bid-Alert_Red*Point <= val1 && Bid+Alert_Red*Point >= val1)
{ if (Sound_Alert_Red) PlaySound (AlertSound);
if (PopupON) Alert (Symbol()," price within ",Alert_Red," pips of ","Trendline 1");
if (EmailON) SendMail(Symbol()+" ",Alert_Red+" pips from "+"Trendline 1");
}
//+-----------------------------------------------------------------------------------------------
if( TrendLine2_Blue) ObjectCreate("TrendLine 2", OBJ_TREND, 0, Time[12], Bid-25*Point, Time[0]+3600, Bid-25*Point);
ObjectSet("TrendLine 2", OBJPROP_COLOR, Blue);
if (ObjectFind("2")==-1){ ObjectCreate("2",OBJ_TEXT, 0, 0, 0);
} ObjectSetText("2",DoubleToStr(MathAbs((NormalizeDouble(Bid,Digits)-NormalizeDouble
(ObjectGetValueByShift("Trendline "+2,0),Digits))*MathPow(10,Digits)),0),8,"Arial",Blue);
ObjectSet("2",OBJPROP_PRICE1,NormalizeDouble(ObjectGetValueByShift("Trendline "+2,0),Digits));
ObjectSet("2",OBJPROP_TIME1,Time[0]) ;
//----
double val2=ObjectGetValueByShift("Trendline 2", 0);
if (Bid-Alert_Blue*Point <= val2 && Bid+Alert_Blue*Point >= val2)
{ if (Sound_Alert_Blue) PlaySound (AlertSound);
if (PopupON) Alert (Symbol()," price within ",Alert_Blue," pips of ","Trendline 2");
if (EmailON) SendMail(Symbol()+" ",Alert_Blue+" pips from "+"Trendline 2");
}
//+-----------------------------------------------------------------------------------------------
if( TrendLine_3) ObjectCreate("TrendLine 3", OBJ_TREND, 0, Time[10], Bid+50*Point, Time[0]+3600, Bid+50*Point);
ObjectSet("TrendLine 3", OBJPROP_COLOR, Magenta);
if (ObjectFind("3")==-1){ ObjectCreate("3",OBJ_TEXT, 0, 0, 0);
} ObjectSetText("3",DoubleToStr(MathAbs((NormalizeDouble(Bid,Digits)-NormalizeDouble
(ObjectGetValueByShift("Trendline "+3,0),Digits))*MathPow(10,Digits)),0),8,"Arial",Magenta);
ObjectSet("3",OBJPROP_PRICE1,NormalizeDouble(ObjectGetValueByShift("Trendline "+3,0),Digits));
ObjectSet("3",OBJPROP_TIME1,Time[0]) ;
//+---
double val3=ObjectGetValueByShift("Trendline 3", 0);
if (Bid-Alert_Red*Point <= val3 && Bid+Alert_Red*Point >= val3)
{ if (Sound_Alert_Red) PlaySound (AlertSound);
if (PopupON) Alert (Symbol()," price within ",Alert_Red," pips of ","Trendline 3");
if (EmailON) SendMail(Symbol()+" ",Alert_Red+" pips from "+"Trendline 3");
}
//+-----------------------------------------------------------------------------------------------
if( TrendLine_4) ObjectCreate("TrendLine 4", OBJ_TREND, 0, Time[10],Bid-50*Point, Time[0]+3600, Bid-50*Point);
ObjectSet("TrendLine 4", OBJPROP_COLOR, Magenta);
if (ObjectFind("4")==-1){ ObjectCreate("4",OBJ_TEXT, 0, 0, 0);
} ObjectSetText("4",DoubleToStr(MathAbs((NormalizeDouble(Bid,Digits)-NormalizeDouble
(ObjectGetValueByShift("Trendline "+4,0),Digits))*MathPow(10,Digits)),0),8,"Arial",Magenta);
ObjectSet("4",OBJPROP_PRICE1,NormalizeDouble(ObjectGetValueByShift("Trendline "+4,0),Digits));
ObjectSet("4",OBJPROP_TIME1,Time[0]) ;
//----
double val4=ObjectGetValueByShift("Trendline 4", 0);
if (Bid-Alert_Blue*Point <= val4 && Bid+Alert_Blue*Point >= val4)
{ if (Sound_Alert_Blue) PlaySound (AlertSound);
if (PopupON) Alert (Symbol()," price within ",Alert_Blue," pips of ","Trendline 4");
if (EmailON) SendMail(Symbol()+" ",Alert_Blue+" pips from "+"Trendline 4");
}
//+-----------------------------------------------------------------------------------------------
return(0);
}
//+-------------------------------------------------------------------------------------------------+
Comments