JC - trial Line Break Alert

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

The JC - Line Break Alert is a specialized monitoring tool designed for traders who need real-time notifications when market prices reach specific, predefined levels. Instead of requiring you to watch the charts constantly, this script acts as an automated "watchdog" that triggers alerts based on your customized price targets.

Core Functionality

The logic operates in two distinct modes depending on your trading strategy:

1. Single Line Crossing (Line Mode) In this mode, you define one specific price point. The script monitors the market to see if the price moves from above that line to below it, or vice versa. The moment a "cross" occurs, the system registers the event and notifies you.

2. Channel Breakout (Channel Mode) This mode is designed for identifying "breakouts." You set two distinct price levels, effectively creating a corridor or channel. The script monitors for instances where the price moves outside of this boundaries:

  • Breakout Up: Triggered when the price crosses above your upper boundary.
  • Breakdown Down: Triggered when the price drops below your lower boundary.

How the Logic Works

To ensure accuracy, the script evaluates the market in the following ways:

  • Price Tracking: You can choose whether the script monitors "Ticks" (the absolute live movement of price) or "Bar Data" (the prices at the open and close of a candle). This allows you to decide if you want instant reactions or confirmation based on completed candles.
  • Notification System: When a breakout or crossing is detected, the script can perform several actions simultaneously:
    • Audio Alerts: Plays specific sound files to grab your attention immediately.
    • Pop-up Alerts: Displays a visual notification box on your trading platform containing the symbol name, timeframe, and the exact price reached.
    • Email Notifications: Optionally sends an email summary directly to your inbox (if configured).
  • Alert Management: The logic includes a "Deactivate" feature. If enabled, the script will alert you only once per breakout, preventing repeated notifications for the same movement. There is also a "Sleep" function in the channel mode to space out audio alerts, ensuring they remain clear and audible.

User Benefits

By using this script, traders can set their "danger zones" or "take-profit targets" ahead of time. The logic handles the heavy lifting of constant price surveillance, ensuring that you are notified the very second a significant market move occurs, regardless of whether you are currently looking at your screen.

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
10 Views
0 Downloads
0 Favorites
JC - trial Line Break Alert
//+------------------------------------------------------------------+
//|                                        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 Green
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2

//---- input parameters
extern double Price1 = 1.9752;
extern double Price2 = 1.9750;
extern string Modes = "0- Line; 1- Channel";
extern int Mode = 1;
extern bool UseSoundAlert = True;
//extern string SoundFile = "alert.wav";
extern int PlaySoundNTimes = 5;
extern bool UseAlertPopUp = True;
extern bool UseTickMode = True;
extern bool UseSendMail = False;
extern bool DeactivateOnAlert = False;
string PairWav = "gbpusd.wav";
string PeriodWave = "5min.wav";
string DirectionWavUp = "breakingup.wav";
string DirectionWavDown = "breakingdown.wav";
extern int sleeptime = 4000;

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(PairWav);
            PlaySound(PeriodWave);
            PlaySound(DirectionWavUp);
         }
      }
      
      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++)
         {
            Sleep(sleeptime);
            PlaySound(PairWav);
            Sleep(sleeptime);
            PlaySound(PeriodWave);
            Sleep(sleeptime);
            PlaySound(DirectionWavUp);
         }
      }
      
      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++)
         {
            Sleep(sleeptime);
            PlaySound(PairWav);
            Sleep(sleeptime);
            PlaySound(PeriodWave);
            Sleep(sleeptime);
            PlaySound(DirectionWavDown);
         }
      }
      
      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