Download MetaTrader 5

IS THERE AN INDICATOR send alarm or message when price reach to a trend line?

To add comments, please log in or register
Learn operation principles of Trading Signals for MetaTrader.
Mehrdad Shiri
4481
Mehrdad Shiri 2013.02.05 22:27 

IS THERE AN INDICATOR send alarm or message when price reach to a trend line?

in picture below :


how can do such that: ( or is there a similar indicator do like this? ; i can use it as a sample .)

when price reach to the line ; send alarm or message .

can you please help?

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2011, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
/*
//----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ 
//Version: Final, November 01, 2008                                  |
Editing:   Nikolay Kositsin  farria@mail.redcom.ru                   |
//----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ 
This variant  of  the ZigZag indicator is  recalculated at  each  tick 
only  at the bars that were not calculated yet and, therefore, it does 
not overload CPU at all which is different from the standard indicator.
Besides, in this indicator drawing of a line is executed exactly in the
ZIGZAG style and, therefore,  the  indicator  correctly  simultaneously
displays two of its extreme points (High and Low) at the same bar!
Nikolay Kositsin
//----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
Depth is a minimum number of bars without the second maximum (minimum)
which is Deviation pips less (more) than the previous one, i.e. ZigZag
always can diverge but it may converge (or dislocate entirely) for the
value more than Deviation only after the Depth number of bars. Backstep
is a minimum number of bars between maximums (minimums).
//----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
Zigzag  indicator  is a number of  trendlines  that  unite considerable
tops and bottoms on a price chart. The parameter concerning the minimum
prices  changes determines the per cent value where the price must move
to  generate  a new "Zig"  or  "Zag"  line.  This indicator filters the 
changes on an analyzed chart that are less than the set value. Therefore,
Zigzag reflects only considerable amedments.  Zigzag is used mainly for
the  simplified  visualization  of  charts,  as  it shows only the most 
important  changes  and  reverses.  Also,  it can be used to reveal the
Elliott Waves and different chart figures. It is necessary to  remember
that the last indicator segment can change depending on the changes of
the  analyzed  data.  It  is  one of the few indicators that can change
their previous value, in case of an asset price change. Such an ability
to  correct  its  values according to the further price changings makes
Zigzag an excellent tool for the already formed price changes. Therefore,
there is no point in creating a trading system based on Zigzag as it is
most suitable for the analysis of historical data not forecasting.
 Copyright © 2005, MetaQuotes Software Corp.
 */
//+------------------------------------------------------------------+ 
//|                                                    ZigZag_NK.mq5 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+ 
//---- author of the indicator
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
//---- link to the website of the author
#property link      "http://www.metaquotes.net/"
//---- indicator version
#property version   "1.00"
#property description "ZigZag"
//*************************************************************************
//*************************************************************************
//*************************************************************************
//***************  I ADD THIS   *********
int NODE_ZigZag=3000;      //  
double ZigZag_Extermum[3001]; //  
datetime TIME_Extermum[3001]; //  
double UP_ZigZag[1501];       //  
double DOWN_ZigZag[1501];     //  
datetime UP_TIME[1501];       //  
datetime DOWN_TIME[1501];     //  
double ZigZag_Extermum_Temp;
datetime TIME_Extermum_Temp;
int z;
//*************************************************************************
//*************************************************************************
//*************************************************************************
//+----------------------------------------------+ 
//|  Indicator drawing parameters                |
//+----------------------------------------------+ 
//---- drawing the indicator in the main window
#property indicator_chart_window 
//---- 2 buffers are used for calculation of drawing of the indicator
#property indicator_buffers 4
//---- only 1 plot is used
#property indicator_plots   3
//---- ZIGZAG is used for the indicator
#property indicator_type1   DRAW_ZIGZAG
//---- displaying the indicator label
#property indicator_label1  "ZigZag_NK"
//---- use blue violet color for the indicator line
#property indicator_color1 BlueViolet
//---- the indicator line is a long dashed line
#property indicator_style1  STYLE_DASH
//---- indicator line width is equal to 1
#property indicator_width1  1
//---
#property indicator_type2   DRAW_SECTION
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//---
#property indicator_type3   DRAW_SECTION
#property indicator_color3  clrRed
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//+----------------------------------------------+ 
//|  Indicator input parameters                  |
//+----------------------------------------------+ 
input int ExtDepth=12;
input int ExtDeviation=5;
input int ExtBackstep =3;
//---- declaration of dynamic arrays that 
// will be used as indicator buffers
double HighestBuffer[];
double LowestBuffer[];
double TOP_BOUND_Buffer[];
double BOTTOM_BOUND_Buffer[];
//---- declaration of memory variables for recalculation of the indiator only at the previously not calculated bars
int LASTlowpos,LASThighpos;
double LASTlow0,LASTlow1,LASThigh0,LASThigh1;
//---- Declaration of the integer variables for the start of data calculation
int StartBars;
datetime time_saved;
double WL_1_PRICE;
datetime WL_1_TIME;
double WL_2_PRICE;
datetime WL_2_TIME;
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+ 
void OnInit()
  {
//---- initialization of variables of the start of data calculation
   StartBars=ExtDepth+ExtBackstep;
//---- set dynamic arrays as indicator buffers
   SetIndexBuffer(0,LowestBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,HighestBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,TOP_BOUND_Buffer,INDICATOR_DATA);
   SetIndexBuffer(3,BOTTOM_BOUND_Buffer,INDICATOR_DATA);
//---- restriction to draw empty values for the indicator
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0);

//---- create labels to display in Data Window
   PlotIndexSetString(0,PLOT_LABEL,"ZigZag Lowest");
   //PlotIndexSetString(1,PLOT_LABEL,"ZigZag Highest");
   PlotIndexSetString(1,PLOT_LABEL,"ZigZag Top");
   PlotIndexSetString(2,PLOT_LABEL,"ZigZag Bottom");

//---- indexing the elements in buffers as timeseries   
   ArraySetAsSeries(LowestBuffer,true);
   ArraySetAsSeries(HighestBuffer,true);
   ArraySetAsSeries(TOP_BOUND_Buffer,true);
   ArraySetAsSeries(BOTTOM_BOUND_Buffer,true);

//---- set the position, from which the Bollinger Bands drawing starts
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBars);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,StartBars);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,StartBars);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,StartBars);

//---- Setting the format of accuracy of displaying the indicator
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- name for the data window and the label for sub-windows
   string shortname;
   StringConcatenate(shortname,"ZigZag (ExtDepth=",
                     ExtDepth,"ExtDeviation = ",ExtDeviation,"ExtBackstep = ",ExtBackstep,")");
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//----   
  }
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+ 
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---- checking the number of bars to be enough for the calculation
   if(rates_total<StartBars) return(0);

//---- declarations of local variables 
   int limit,bar,back,lasthighpos,lastlowpos;
   double curlow,curhigh,lasthigh0=0.0,lastlow0=0.0,lasthigh1,lastlow1,val,res;

//---- calculate the limit starting number for loop of bars recalculation and start initialization of variables
   if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of the indicator calculation
     {
      limit=rates_total-StartBars; // starting index for calculation of all bars

      lastlow1=-1;
      lasthigh1=-1;
      lastlowpos=-1;
      lasthighpos=-1;
     }
   else
     {
      limit=rates_total-prev_calculated; // starting index for calculation of new bars

      //---- restore values of the variables
      lastlow0=LASTlow0;
      lasthigh0=LASThigh0;

      lastlow1=LASTlow1;
      lasthigh1=LASThigh1;

      lastlowpos=LASTlowpos+limit;
      lasthighpos=LASThighpos+limit;
     }

//---- indexing elements in arrays as timeseries  
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(time,true);
//---- first big indicator calculation loop
   for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      //---- store values of the variables before running at the current bar
      if(rates_total!=prev_calculated && bar==0)
        {
         LASTlow0=lastlow0;
         LASThigh0=lasthigh0;
        }

      //---- low
      val=low[ArrayMinimum(low,bar,ExtDepth)];
      if(val==lastlow0) val=0.0;
      else
        {
         lastlow0=val;
         if((low[bar]-val)>(ExtDeviation*_Point))val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=LowestBuffer[bar+back];
               if((res!=0) && (res>val))LowestBuffer[bar+back]=0.0;
              }
           }
        }
      LowestBuffer[bar]=val;

      //---- high
      val=high[ArrayMaximum(high,bar,ExtDepth)];
      if(val==lasthigh0) val=0.0;
      else
        {
         lasthigh0=val;
         if((val-high[bar])>(ExtDeviation*_Point))val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=HighestBuffer[bar+back];
               if((res!=0) && (res<val))HighestBuffer[bar+back]=0.0;
              }
           }
        }
      HighestBuffer[bar]=val;

     }

//---- the second big indicator calculation loop
   for(bar=limit; bar>=0; bar--)
     {

      TOP_BOUND_Buffer[bar]   = HighestBuffer[bar];
      BOTTOM_BOUND_Buffer[bar]= LowestBuffer[bar];


      //---- store values of the variables before running at the current bar
      if(rates_total!=prev_calculated && bar==0)
        {
         LASTlow1=lastlow1;
         LASThigh1=lasthigh1;

         LASTlowpos=lastlowpos;
         LASThighpos=lasthighpos;
        }

      curlow=LowestBuffer[bar];
      curhigh=HighestBuffer[bar];
      //----
      if((curlow==0) && (curhigh==0))continue;
      //----
      if(curhigh!=0)
        {
         if(lasthigh1>0)
           {
            if(lasthigh1<curhigh)HighestBuffer[lasthighpos]=0;
            else HighestBuffer[bar]=0;
           }
         //----
         if(lasthigh1<curhigh || lasthigh1<0)
           {
            lasthigh1=curhigh;
            lasthighpos=bar;
           }
         lastlow1=-1;
        }
      //----
      if(curlow!=0)
        {
         if(lastlow1>0)
           {
            if(lastlow1>curlow) LowestBuffer[lastlowpos]=0;
            else LowestBuffer[bar]=0;
           }
         //----
         if((curlow<lastlow1) || (lastlow1<0))
           {
            lastlow1=curlow;
            lastlowpos=bar;
           }
         lasthigh1=-1;
        }
     }
/*
//********************************************************************** 
*/
   if(time[0]!=time_saved)
     {
      int up=0; int down=0;
      for(int i=0; i<rates_total;i++)
        {
         if(LowestBuffer[i]>0.0)
           {
            ZigZag_Extermum[up+down]=LowestBuffer[i];
            TIME_Extermum[up+down]=time[i];
            DOWN_ZigZag[down]=LowestBuffer[i];
            DOWN_TIME[down]=time[i];
            down++;
           }

         if(HighestBuffer[i]>0.0)
           {
            ZigZag_Extermum[up+down]=HighestBuffer[i];
            TIME_Extermum[up+down]=time[i];
            UP_ZigZag[up]=HighestBuffer[i];
            UP_TIME[up]=time[i];
            up++;
           }
         if((up+down)>NODE_ZigZag)break;
        }
        
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+      
          WL_1_PRICE=UP_ZigZag[0];
          WL_1_TIME=UP_TIME[0]; 
          WL_2_PRICE=UP_ZigZag[1];
          WL_2_TIME=UP_TIME[1];       
   //  CreateTline(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text);
   SetWLline(0,"WL1",0,WL_1_TIME,WL_1_PRICE,WL_2_TIME,WL_2_PRICE,WL_Color,STYLE_SOLID,6,"WL1");             
        
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+        

      Comment(""
              /*
          ,"\nZigZag_Extermum[0] = " ,ZigZag_Extermum[0]
    
          ,"\n"     
*/
              ,"\n                        UP_ZigZag[0] = ",UP_ZigZag[0],"   UP_TIME[0] = ",UP_TIME[0]
              ,"\n                        UP_ZigZag[1] = ",UP_ZigZag[1],"   UP_TIME[1] = ",UP_TIME[1]
     /*         
              ,"\n                        UP_ZigZag[2] = ",UP_ZigZag[2],"   UP_TIME[2] = ",UP_TIME[2]
            [12] = " ,DOWN_TIME[12]
          ,"\n                        DOWN_ZigZag[13] = " ,DOWN_ZigZag[13],"   DOWN_TIME[13] = " ,DOWN_TIME[13]
*/);
      time_saved=time[0];
     }
//----          
   return(rates_total);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//********************************************************************************************************************
//+------------------------------------------------------------------+
//|  L creation  "  L Line "                                     |
//+------------------------------------------------------------------+
void CreateWLline(long     chart_id,  // chart ID
                  string   name,      // object name
                  int      nwin,      // window index
                  datetime time1,     // price level time 1
                  double   price1,    // price level 1
                  datetime time2,     // price level time 2
                  double   price2,    // price level 2
                  color    Color,     // line color
                  int      style,     // line style
                  int      width,     // line width
                  string   text)      // text
  {
   ObjectCreate(chart_id,name,OBJ_TREND,nwin,time1,price1,time2,price2);
   ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,true);
   ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);
   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);
   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);
  }
//+------------------------------------------------------------------+
//|  Trend line reinstallation   "  Trigger Line "                   |
//+------------------------------------------------------------------+
void SetWLline(long     chart_id,  // chart ID
              string   name,      // object name
              int      nwin,      // window index
              datetime time1,     // price level time 1
              double   price1,    // price level 1
              datetime time2,     // price level time 2
              double   price2,    // price level 2
              color    Color,     // line color
              int      style,     // line style
              int      width,     // line width
              string   text)      // text
  {
   if(ObjectFind(chart_id,name)==-1) CreateWLline(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text);
   else
     {
      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
      ObjectMove(chart_id,name,0,time1,price1);
      ObjectMove(chart_id,name,1,time2,price2);
     }
  }
input color WL_Color=White;
//+------------------------------------------------------------------+
//********************************************************************************************************************
Ahmed Soliman
15714
Ahmed Soliman 2013.02.06 05:46  

Hi,

I created for you this indicator. Place it with your indicator.

CG

Files:
Mehrdad Shiri
4481
Mehrdad Shiri 2013.02.06 06:45  
codersguru:

Hi,

I created for you this indicator. Place it with your indicator.

hi, codersguru ;


& tank you .

khai hoan nguyen
242
khai hoan nguyen 2013.02.06 07:51  

thanks codersquru . you are kindly
Ahmed Soliman
15714
Ahmed Soliman 2013.02.06 17:46  
You're welcome!
Please tell me the results when you test it.
Mehrdad Shiri
4481
Mehrdad Shiri 2013.02.07 03:47  
codersguru:
You're welcome!
Please tell me the results when you test it.

ok.

thanks again.

To add comments, please log in or register