Author: WYF - Trendline break alert
qsxyj

This tool is designed to serve as an automated monitoring system for traders who use trendlines to identify market structure. Its primary purpose is to provide real-time notifications whenever the price "breaks" through a specific trendline, signaling a potential shift in market direction.

Core Functionality

The script continuously scans your trading chart to identify specific trendlines that have been labeled with a designated prefix (by default, "Tr"). When it detects one of these lines, it monitors the relationship between the current market price and the line's position.

How It Works

  • Trendline Detection: The system automatically looks for all trendline objects on your chart. If a line matches the required naming convention, the tool begins tracking its data points at the most recent price intervals.
  • Breakout Identification: The logic specifically looks for two scenarios:
    • Upside Break: If the previous candle closed below the line and the current candle closes above it, the system recognizes an upward break.
    • Downside Break: If the previous candle closed above the line and the current candle closes below it, the system recognizes a downward break.
  • Alert Mechanisms: When a break is confirmed, the script can trigger several types of notifications based on your preferences:
    • Audio: It can play a standard alert sound.
    • Pop-up Windows: It can generate a visual alert window on your screen showing whether the break was "UP" or "DOWN."
    • On-Screen Labels: It places a temporary text notification directly on the chart (e.g., "This Currency Breaks UP") to provide an immediate visual cue.

Management Features

To ensure the tool remains user-friendly and doesn't overwhelm the trader, it includes several management logics:

  • Alert Intervals: You can set a minimum time gap between alerts. This prevents the script from triggering multiple sounds or windows for the same price movement in rapid succession.
  • Automatic Text Cleanup: The on-screen text labels are programmed to automatically disappear after a specific amount of time, keeping your chart clean and uncluttered.
  • Status Indicators: The tool provides a small status comment on the chart to let you know whether your sound alerts are currently enabled or disabled.
Miscellaneous
It plays sound alerts
7 Views
0 Downloads
0 Favorites
qsxyj
//+------------------------------------------------------------------+
//|                                                         qsxyj.mq4 |
//|                       Copyright ?2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "WYF - Trendline break alert"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window

extern bool AllowSound=1;  
extern bool AllowAlertWindow=0;
extern int AlertInterval_Minute=15;
extern int KeepText_Minute=10;

extern string linename="Tr"; 


int PrevAlertTime = 0; 
int Prevtext=0;

int init()
  {
   return(0);
  }
  
int deinit()
  {
   Comment(" ");
   if(ObjectFind("tpl")==0) ObjectDelete("tpl");   
   return(0);
  }                            
//+------------------------------------------------------------------+
int start()
  { 
   int    j,yjx=0;
   double price1,dh,dl,price0;
   string name1;
   
        
   if(AllowSound) Comment("WYF - Trendline break alert: Sound On");
     else Comment("WYF - Trendline break alert: Sound Off")  ;   


//------------find all trendlines and alert----------------------------------------------------------------------
   for (j=0; j<ObjectsTotal(); j++)
    {if(StringSubstr(ObjectName(j),0,2)==linename && ObjectType(ObjectName(j))==OBJ_TREND) 
       { 
         yjx=1; 
         price1=NormalizeDouble(ObjectGetValueByShift(ObjectName(j),1),
                 MarketInfo(Symbol(),MODE_DIGITS)); 
         price0=NormalizeDouble(ObjectGetValueByShift(ObjectName(j),0),
                 MarketInfo(Symbol(),MODE_DIGITS));        
                 
         if (TimeCurrent()-PrevAlertTime>AlertInterval_Minute*60)
           {
            if (Close[1]<=price1 && Close[0]>price0) 
              {
                if(AllowSound) PlaySound("alert.wav"); 
                if(AllowAlertWindow) Alert(Symbol(),"--- UP");   
              //  Print(Symbol(),"--- UP");
                PrevAlertTime = TimeCurrent();     

                ObjectCreate("tpl",OBJ_LABEL,0,0,0);
                ObjectSet("tpl", OBJPROP_XDISTANCE,10);
                ObjectSet("tpl", OBJPROP_YDISTANCE,20); 
                ObjectSet("tpl", OBJPROP_CORNER,3);                        
                ObjectSetText("tpl","This Currency Breaks UP ",16,"Times New Roman",Red);
              }
            if (Close[1]>=price1 && Close[0]<price0) 
              { 
                if(AllowSound) PlaySound("alert.wav");
                if(AllowAlertWindow) Alert(Symbol(),"--- DOWN");
               // Print(Symbol(),"--- D"); 
                PrevAlertTime = TimeCurrent();
                
                ObjectCreate("tpl",OBJ_LABEL,0,0,0);
                ObjectSet("tpl", OBJPROP_XDISTANCE,10);
                ObjectSet("tpl", OBJPROP_YDISTANCE,20); 
                ObjectSet("tpl", OBJPROP_CORNER,2);                        
                ObjectSetText("tpl","This Currency Breaks DOWN ",16,"Times New Roman",Red);                
                
              }
            WindowRedraw();  
           }
         if (TimeCurrent()-Prevtext>KeepText_Minute*60)  
           {
              if(ObjectFind("tpl")==0) ObjectDelete("tpl");
              Prevtext = TimeCurrent();
           }
                  
           
       }
     }      

  return(0);
}

Comments