Download MetaTrader 5

Indicators: AlertLine

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
182588
MetaQuotes Software Corp. 2010.12.20 08:08 

AlertLine:

The indicator shows a messsage then the price crosses the lines, titled the "Support" and "Rezistans" on the chart.

Author: Vladimir Khlystov

marc weedbrook
119
marc weedbrook 2010.12.20 15:50  

Hi cmillion

Brooky here,

Thanks for this free code but I found a few areas that did not work for me.

They were primarily

a) An alert issues every tick the price is not crossing but above or below respective lines. That a lot of alerts.

b) I prefer to leave the line where it is before moving to see if is retested, so moving it to a new position is not practical just to stop the alert sounding.

c) The message displayed for Support or Resistance was the same.

I was writing something similar for another indicator I am making so I thought I might attach the following code as an enhancement (IMHO)

to this one. All credits to you.

The modified code now was modified to

a) Alert only once per bar ( by that wonderful bit of code by codersguru )

b) Alert only on the crossing of the Support and Resistance

c) Be appropriately descriptive in the comments.

d) Allow comments to be turned on or off.

e) Allow the trend line to stay in place to check for retests without constant alerts.

Once again thank you.

Code below.

Cheers Brooky

//|                               Copyright © 2010, Vladimir Hlystov |
//|                                         http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Vladimir Hlystov"
#property link      "http://cmillion.narod.ru"
#property indicator_chart_window
extern string Instructions_1 = " Draw 2 Trendlines ";
extern string Instructions_2 = " Name 1) Support ";
extern string Instructions_3 = " Name 2) Resistance  ";
extern bool see_comment = true;
//+------------------------------------------------------------------+
//--Modified by  Brooky at WWW.Brooky-Indicators.com
int deinit() 
{
    Comment("");
    return( 0 );
}
//int start()
//{
//--Brooky Added Code
  int start()
    {
     int limit;
     int counted_bars=IndicatorCounted();
  //---- check for possible errors
     if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
  //---- main loop
     for(int i=0; i<limit; i++)
       {
//----------------+
         datetime sigtime = iTime(NULL,0,i); 
         int sighr = TimeHour(sigtime);
         int sigmin = TimeMinute(sigtime);
         int sigday = TimeDay(sigtime);
         int sigmth = TimeMonth(sigtime);
         int sigyr = TimeYear(sigtime); 
         string tdisplay = sigday+"/"+sigmth+"/"+sigyr+": "+sighr+":"+sigmin;
         
         
         string tf = "Tf:"+Period();
         if(Period()==1)tf = "M1";
         if(Period()==5)tf = "M5";
         if(Period()==15)tf = "M15";
         if(Period()==30)tf = "M30";
         if(Period()==60)tf = "H1";
         if(Period()==240)tf = "H4";
         if(Period()==1440)tf = "Daily";
         if(Period()==10080)tf = "Weekly";
         if(Period()==43200)tf = "Monthly";
         
         string symtdisplay = "( "+Symbol()+" )"+tf+"( "+tdisplay+" )";
       
   double Support,Resistance;
   string txt;
   if (ObjectFind("Support")==-1) txt="No line <Support>\n";
   else 
   {
      Support = ObjectGetValueByShift("Support", 0);
      //if (Bid<Support)
      //--Brooky Added Code
      if(iHigh(NULL,0,i)>Support && iLow(NULL,0,i)<Support)
      {
         //--Brooky Added Code
               int alertname = 1;
               string mymessage1 = symtdisplay+" Price Crossing the support line ";
               AlertOnce (mymessage1,alertname);
               txt=StringConcatenate(txt,"( Price bar on the support line ) \n");
         //-----+
         //Alert("Price below the support line ");
         if (Bid<Support)txt=StringConcatenate(txt," Price below the support line \n")
         ;
      }
      else txt=StringConcatenate(txt," Distance to the line of support ",DoubleToStr((Bid-Support)/Point,0),"\n");
   }
   if (ObjectFind("Resistance")==-1) txt=StringConcatenate(txt,"No line <Resistance>\n");
   else 
   {
      Resistance = ObjectGetValueByShift("Resistance", 0);
      //if (Ask>Resistance)
      //--Brooky Added Code
      if(iHigh(NULL,0,i)>Resistance && iLow(NULL,0,i)<Resistance)
      {
         //--Brooky Added Code
               int alertname2 = 2;
               string mymessage2 = symtdisplay+" Price Crossing the Resistance line ";
               AlertOnce (mymessage2,alertname2);
               txt=StringConcatenate(txt,"( Price bar on the Resistance line )\n");
         //-----+
         //Alert("Price above the Resistanceance line");
         if (Ask>Resistance) txt=StringConcatenate(txt," Price above the Resistance line");
      }
      else txt=StringConcatenate(txt," Distance to the line of Resistance ",DoubleToStr((Resistance-Ask)/Point,0));
   }
   if(see_comment)Comment(txt);
   
   
   return(0);
}
       }
  //---- done
     return(0);
    //}
//+------------------------------------------------------------------+
   bool AlertOnce(string alert_msg, int ref)
   {  
   int barcheck = Bars;
   static int LastAlert_1 = 0;
   static int LastAlert_2 = 0;
      
   switch(ref)
   {
      case 1:
         if( LastAlert_1 == 0 || LastAlert_1 < barcheck )
         {
            Alert(alert_msg);
            LastAlert_1 = barcheck;
            return (1);
         }
      break;
      case 2:
         if( LastAlert_2 == 0 || LastAlert_2 < barcheck )
         {
            Alert(alert_msg);
            LastAlert_2 = barcheck;
            return (1);
         }
      break;
   }
   }
Vladimir Khlystov
11820
Vladimir Khlystov 2010.12.20 18:12  
brooky29:

Hi cmillion

Brooky here,

Thanks for this free code but I found a few areas that did not work for me.

/////

More expanded version was published earlier: http://codebase.mql4.com/en/code/9302
To add comments, please log in or register