JC - Line Break Alert3
Download scriptThis script is a specialized trading tool designed to monitor market price movements and provide immediate notifications when the price crosses specific thresholds. It allows traders to define "boundary" levels on a chart, ensuring they don't have to watch the screen constantly to know when a significant price movement has occurred.
Core Functionality
The logic operates in two distinct modes depending on your trading strategy:
1. Single Line Crossing (Mode 0) In this mode, you set one specific price level. The script monitors the live market and detects whenever the price moves from above that line to below it, or vice versa. Once the crossing occurs, the system triggers your preferred notifications.
2. Channel Breakout (Mode 1) This mode utilizes two price levels to create a "channel" or "zone." It monitors for breakouts in two directions:
- Upward Breakout: Triggered when the price moves from below the upper boundary to above it.
- Downward Breakout: Triggered when the price moves from above the lower boundary to below it.
Intelligent Monitoring Features
To ensure a smooth user experience, the script includes several sophisticated logic behaviors:
- Dynamic Interaction: If you manually move the lines on your chart, the script automatically detects these changes and updates its internal memory. It also contains "smart sorting" logic to ensure that the upper boundary of a channel is always correctly identified as the higher value, even if you swap their positions visually.
- Notification Management: To prevent the system from sending constant alerts (spamming) every time a price flickers near a line, the script includes a "Breakout" memory. Once a breach is detected, it can deactivate itself for that specific move until a new threshold is crossed or the setting is refreshed.
- Multi-Channel Alerts: You can customize how you receive these alerts based on your preferences:
- Audio: Play a specific sound file a set number of times.
- Visual: Display a pop-up alert window on your trading platform.
- Email: Send a direct notification to your registered email address (if configured).
Automated Memory & Setup
The script is designed for convenience and persistence. It includes an automated "Store and Restore" system that saves your custom price levels and mode selections into a file. This means that when you restart your platform or switch between different currency pairs, the tool remembers your specific settings for each asset, eliminating the need for manual reconfiguration.
//+------------------------------------------------------------------+
//| 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