JC - Line Break Alert_v1

Download script
Author: Juan Carlos Christensen.
JC - Line Break Alert_v1

The JC - Line Break Alert is a specialized monitoring tool designed to track specific price levels on a financial chart and notify the user immediately when those levels are breached. It functions as an automated watchdog, ensuring that you don't have to constantly watch the screen to know when a price hits your target.

Core Functionality

The script allows users to define specific price points and choose between two primary monitoring methods:

  • Line Mode: This focuses on a single price level. The script monitors the market movement and triggers an alert the moment the price crosses that specific line, whether it is moving up or down.
  • Channel Mode: This monitors two distinct price levels, effectively creating a "channel" or zone. It detects movements in both directions: it will alert you if the price breaks upward through the top level or downward through the bottom level.

Detection Logic

The tool evaluates market data in real-time based on your preference for "Tick Mode."

  • In Tick Mode, the script analyzes the very latest price updates to provide high-sensitivity alerts.
  • If disabled, it looks at the opening prices of historical candles to monitor movement on a slightly broader basis.

The logic is designed to identify the exact moment a price transition occurs (e.g., moving from below the target to above it). To prevent the system from sending repetitive notifications for the same event, it includes a "Deactivate" feature; once a breakout is detected and an alert is fired, the script can be set to ignore further crossings until the system is reset.

Notification System

When a price breach occurs, the script can communicate with you through several channels simultaneously:

  • Audio Alerts: Plays a specific sound file a designated number of times.
  • Visual Pop-ups: Displays a clear alert message on your trading platform screen, specifying the asset, timeframe, and the exact price reached.
  • Email Notifications: Sends an automated email to your registered account providing a written record of the breakout.

Visual Representation

The script draws horizontal lines directly on your chart at your specified price points, providing a clear visual reference of your targets while it performs its background monitoring.

Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each bar
Miscellaneous
Implements a curve of type %1It plays sound alertsIt issuies visual alerts to the screenIt sends emails
7 Views
0 Downloads
0 Favorites
JC - Line Break Alert_v1
//+------------------------------------------------------------------+
//|                                        JC - Line Break Alert.mq4 |
//|                                         Juan Carlos Christensen. |
//|                                     http://www.eumefinancial.com |
//+------------------------------------------------------------------+
#property copyright "Juan Carlos Christensen."
#property link      "http://www.eumefinancial.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Magenta
#property indicator_width1 2
#property indicator_width2 2

//---- input parameters
extern double Price1 = 2.0000;
extern double Price2 = 2.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;

double PRICE1[];
double PRICE2[];
bool DidBreakout = False;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  //---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,PRICE1);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,PRICE2);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   //ObjectDelete("Price1");
   //ObjectDelete("Price2");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----

   switch(Mode)
   {
      case 0:
         CrossingPrice1Only();
         break;
      case 1:
         ChannelBreakOut();
         break;
      default:
         CrossingPrice1Only();
   }
   

//----
   return(0);
  }
//+------------------------------------------------------------------+

void CrossingPrice1Only()
{
   int counted_bars =IndicatorCounted();
   int pos =Bars-counted_bars;
   
   double LastPrice;
   double CurrentPrice;
   int x;
   
   while(pos>=0)
   {
      PRICE1[pos]= Price1;
      
      pos--;
   }
   
   if(UseTickMode)
   {
      LastPrice = iClose(NULL, 0, 1);
      CurrentPrice = iClose(NULL, 0, 0);
   }
   else if(UseTickMode == False)
   {
      LastPrice = iOpen(NULL, 0, 1);
      CurrentPrice = iOpen(NULL, 0, 0);
   }

   //int counter = 0;
   
   //while(!ObjectCreate("Price1_" + counter, OBJ_HLINE, 0, 0, Price1) && counter < 100)
   //{
   //   counter++;
   //}
   
   //ObjectSet("Price1", OBJPROP_COLOR, Green);
   
   if(((LastPrice < Price1) && (CurrentPrice >= Price1)) || ((LastPrice > Price1) && (CurrentPrice <= Price1)) && !DidBreakout) 
   {
      if(DeactivateOnAlert)
      {
         DidBreakout = True;
      }
      
      if(UseSoundAlert)
      {
         for(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()
{
   int counted_bars = IndicatorCounted();
   int pos = Bars-counted_bars;
   
   double LastPrice;
   double CurrentPrice;
   int x;
   
   while(pos>=0)
   {
      PRICE1[pos]= Price1;
      PRICE2[pos]= Price2;
      
      pos--;
   }
   
   if(UseTickMode)
   {
      LastPrice = iClose(NULL, 0, 1);
      CurrentPrice = iClose(NULL, 0, 0);
   }
   else if(UseTickMode == False)
   {
      LastPrice = iOpen(NULL, 0, 1);
      CurrentPrice = iOpen(NULL, 0, 0);
   }

   //int counter = 0;
   
   //while(!ObjectCreate("Price1_" + counter, OBJ_HLINE, 0, 0, Price1) && counter < 100)
   //{
   //   counter++;
   //}
   
   //while((!ObjectCreate("Price2_" + counter, OBJ_HLINE, 0, 0, Price2)) && counter < 100)
   //{
   //   counter++;
   //}
   
   //ObjectSet("Price1", OBJPROP_COLOR, Green);
   //ObjectSet("Price2", OBJPROP_COLOR, Red);
   
   if((LastPrice < Price1) && (CurrentPrice >= Price1) && !DidBreakout) 
   {
      if(DeactivateOnAlert)
      {
         DidBreakout = True;
      }
      
      if(UseSoundAlert)
      {
         for(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 + "!");
      }
   }
}

//+------------------------------------------------------------------+

Comments