JC - Line Break Alert2
Download scriptOverview
The JC - Line Break Alert is a specialized monitoring tool designed for traders who need real-time notifications when market prices reach specific levels. Rather than requiring you to watch the charts constantly, this script acts as an automated sentry, watching for price movements and alerting you the moment a predefined "breakout" occurs.
Key Functionalities
1. Flexible Alert Modes
The tool offers two primary ways to monitor the market:
- Line Mode: Focuses on a single specific price point. It will notify you the moment the market crosses that specific level (either moving up through it or down through it).
- Channel Mode: Monitors a range between two different price points. This is ideal for identifying when the price "breaks out" of a corridor, moving significantly higher than the top boundary or lower than the bottom boundary.
2. Interactive Visuals
The script automatically draws visual lines on your trading chart to represent your target prices. These lines are not static; they are interactive. If you manually move the lines on your screen to adjust your targets, the script is smart enough to detect that movement and update its internal logic accordingly. It also ensures that the "higher" price is always correctly associated with the top of your range, maintaining visual and logical consistency.
3. Multi-Channel Notifications
To ensure you never miss a move, the script can communicate with you in several ways simultaneously:
- Sound Alerts: Plays a customizable warning sound on your computer.
- Pop-up Alerts: Displays a visual notification window directly on your trading platform.
- Email Alerts: Sends an automated email to your registered account, providing a written confirmation of the exact price level that was breached.
4. Smart Logic & Persistence
The script includes several "quality of life" features designed for professional consistency:
- One-Time Alerting: To prevent your computer from being flooded with constant notifications, the script can be set to "deactivate" once a breakout has occurred, ensuring you only get notified the first time the price hits your target.
- Auto-Save/Restore: The tool is designed to remember your preferences. It can automatically save your specific price levels and settings to a file, so you don't have to re-enter your data every time you restart your platform.
Summary for the User
Essentially, this tool transforms your trading chart into an active notification system. You set your boundaries, choose how you want to be notified (sound, pop-up, or email), and let the script do the heavy lifting of monitoring the price action for you 24/7.
//+------------------------------------------------------------------+
//| JC - Line Break Alert.mq4 |
//| Juan Carlos Christensen. |
//| http://www.eumefinancial.com |
//|Modified on June 8, 2007 by Hartono Setiono |
//|Movable Price Level Setting by Line |
//|Store & Restore Setting to File |
//+------------------------------------------------------------------+
#property copyright "Juan Carlos Christensen."
#property link "http://www.eumefinancial.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 2
//---- input parameters
extern double Price1 = 0.0000;
extern double Price2 = 0.0000;
extern string Modes = "0- Line; 1- Channel";
extern int Mode = 1;
extern bool UseSoundAlert = True;
extern string SoundFile = "alert.wav";
extern int PlaySoundNTimes = 1;
extern bool UseAlertPopUp = True;
extern bool UseTickMode = True;
extern bool UseSendMail = False;
extern bool DeactivateOnAlert = True;
extern color price1_color = Blue;
extern color price2_color = Red;
bool DidBreakout = False;
double LastPrice;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
if(Price1==0 && Price2==0) RestoreSetting();
LastPrice=Bid;
CreateLine("price1",price1_color,Price1);
if(Mode==1) CreateLine("price2",price2_color,Price2);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
if(Price1!=0 && Price2!=0) StoreSetting();
ObjectDelete("price1");
ObjectDelete("price2");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double aPrice1=ObjectGet("price1",OBJPROP_PRICE1);
if(GetLastError()==4202) CreateLine("price1",price1_color,Price1);
if(aPrice1!=0 && aPrice1 != Price1) {Price1=aPrice1; Print("Price1 Changed:",Price1); DidBreakout=false;}
if(Mode==1)
{
double aPrice2=ObjectGet("price2",OBJPROP_PRICE1);
if(GetLastError()==4202) CreateLine("price2",price2_color,Price2);
if(aPrice2!=0 && aPrice2 != Price2) {Price2=aPrice2; Print("Price2 Changed:",Price2); DidBreakout=false;}
}
if(Price1<Price2 && Mode==1)
{
aPrice1=Price1;
Price1=Price2;
Price2=aPrice1;
ObjectSet("price1",OBJPROP_PRICE1,Price1);
ObjectSet("price2",OBJPROP_PRICE1,Price2);
}
switch(Mode)
{
case 0:
CrossingPrice1Only();
break;
case 1:
ChannelBreakOut();
break;
default:
CrossingPrice1Only();
}
//----
return(0);
}
//+------------------------------------------------------------------+
void CrossingPrice1Only()
{
double CurrentPrice=Bid;
if(((LastPrice < Price1) && (CurrentPrice >= Price1)) || ((LastPrice > Price1) && (CurrentPrice <= Price1)) && !DidBreakout)
{
if(DeactivateOnAlert) DidBreakout = True;
if(UseSoundAlert)
for(int x=0;x<=PlaySoundNTimes;x++)
PlaySound(SoundFile);
if(UseAlertPopUp)
Alert(Symbol()," ",Period(),"Price Crossing Alert Line at ", Price1); //Symbol()," ",Period()," @ ",Bid
if(UseSendMail)
SendMail("Price Crossing Alert Line at " + Price1 + "!", "This is an email from the JC - Line Break Alert indicator. Price is crossing your alert line at " + Price1 + "!");
}
}
//+------------------------------------------------------------------+
void ChannelBreakOut()
{
double CurrentPrice=Bid;
if((LastPrice < Price1) && (CurrentPrice >= Price1) && !DidBreakout)
{
if(DeactivateOnAlert) DidBreakout = True;
if(UseSoundAlert)
for(int x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile);
if(UseAlertPopUp)
Alert(Symbol()," ",Period(),"Price Breaking Up at ", Price1);
if(UseSendMail)
SendMail("Channel Breaking Up at " + Price1 + "!", "This is an email from the JC - Line Break Alert indicator. Price broke up your channel alert line at " + Price1 + "!");
}
if((LastPrice > Price2) && (CurrentPrice <= Price2) && !DidBreakout)
{
if(DeactivateOnAlert) DidBreakout = True;
if(UseSoundAlert)
for(x=0;x<=PlaySoundNTimes;x++)
PlaySound(SoundFile);
if(UseAlertPopUp)
Alert(Symbol()," ",Period(),"Price Breaking Down at ", Price2);
if(UseSendMail)
SendMail("Channel Breaking Down at " + Price2 + "!", "This is an email from the JC - Line Break Alert indicator. Price broke down your channel alert line at " + Price2 + "!");
}
}
//+------------------------------------------------------------------+
void CreateLine(string aName, color aColor, double aPrice)
{
ObjectCreate(aName, OBJ_HLINE, 0, Time[0],aPrice);
ObjectSet(aName, OBJPROP_COLOR, aColor);
ObjectSet(aName, OBJPROP_STYLE, STYLE_DASH);
}
void StoreSetting()
{
int myhandle;
Print("Store Setting :",Symbol(),":",Price1,":",Price2,":",Mode);
myhandle=FileOpen("LineBreak_"+Symbol()+".SET", FILE_BIN|FILE_WRITE|FILE_READ);
if(myhandle>0)
{
FileSeek(myhandle,0,0);
FileWriteDouble(myhandle, Price1);
FileWriteDouble(myhandle, Price2);
FileWriteInteger(myhandle, Mode);
FileClose(myhandle);
}
}
void RestoreSetting()
{
int myhandle, aMode, err;
double aPrice1, aPrice2;
myhandle=FileOpen("LineBreak_"+Symbol()+".SET", FILE_BIN|FILE_WRITE|FILE_READ);
if(myhandle>0)
{
FileSeek(myhandle,0,0);
aPrice1=FileReadDouble(myhandle);
err=GetLastError();
if(err==0) { aPrice2=FileReadDouble(myhandle); err=GetLastError();}
if(err==0) { aMode=FileReadInteger(myhandle); err=GetLastError();}
FileClose(myhandle);
}
if(err==0){Mode=aMode; Price1=aPrice1; Price2=aPrice2;}
Print("Restore Setting :",Symbol(),":",err,":",aPrice1,":",aPrice2,":",aMode);
}
Comments