Get Alerts on Any Indicator with Simple Steps - Best Ideas for MetaTrader

Alert in the indicator. How do you insert Alert and Arrow into your indicator?

Working with Telegram in MetaTrader. Telegram channels and bot
 My Autolot Secrets. Dynamic Lot or Autolot.
Working with Telegram in MetaTrader. Telegram channels and bot
 My Autolot Secrets. Dynamic Lot or Autolot.

Description

The most frequent queries in the search engine and the topics of different forums are the phrases:

  • “Alert indicator”;
  • “How do you add a sound signal to the indicator?”
  • “Help me insert a sound signal into the indicator”;
  • “How to insert Alert and Arrows”;
  • “How to send a message to the mail or phone when the signal from the indicator? “.

In this article, I will try to describe in as much detail as possible the easy way to add Alert Mail Push Arrow to any indicator from  the additional code www.expforex.com

  

Foreword 

In order to start the correct installation of Alerts in your indicator, you must have the open-source code of your indicator. 

The decompiled code is undesirable because, for the beginner, the decompiled code represents the minimum amount of information. It’s hard to figure it out. 

You may also have problems with compilation after editing. 

Beginning of work

   First, you need to find out which indicator buffers give this or that signal, the purpose of creating an alert, and the conditions for determining the signal on the indicator. 

Important: Only external buffers defined at the beginning of the variable code can be shown in indicators: 

#property indicator_buffers 1

But the indicator can also contain hidden buffers, which are set in the init() function and declared as a variable:

IndicatorBuffers(7): We only need the first buffers. 

If, for example, you have 1 external buffer, then look at the variable: 

SetIndexBuffer( 0 ,SarBuffer);
  • 0 is the first buffer
  • 1 is the second buffer………   

These buffers, or their name, can be obtained by hovering over a specific line of the indicator on the chart

Value1 -This is the first buffer Or 0 in the number system in the code  

SetIndexBuffer( 0,SarBuffer); //The name of the buffer we need  

is SarBuffer, then we will use it

Further, it is a matter of technology = to determine how the signal will arrive;

for example, if this is the intersection of the 0 line from the top (bottom) down (up), then it will look like this:

SarBuffer[shift+1]>=0 && SarBuffer[shift]<0

Indicator crossing the current price or a bar, a bar breakdown by the indicator, and so on:

SarBuffer[shift+1]>=Close[shift] && SarBuffer[shift]<Close[shift]

If This is the intersection of unique levels, indicators such as stochastics:

SarBuffer[shift+1]<=75 && SarBuffer[shift]>75;

SarBuffer[shift+1]>=25 && SarBuffer[shift]<25;

If there are already arrows in your indicator, then the following type of signal is also possible:

DnTrend[1]!=EMPTY_VALUE && DnTrend[1]!=0&& UpTrend[2]!=EMPTY_VALUE

In any case, you need to show logic and creativity in order to record the signal correctly. If you have any difficulties, write to this thread, only attach the indicator, show the lines on the chart, and describe in detail what you can’t do. Throwing a message like “you need to insert an alert into the indicator” without explaining what goes where, and actually without the indicator itself – is not necessary. 

Code from www.expforex.com

The next step of adding our alert to your indicator consists of several points:

STEP 1

Insert the following code at the beginning of the Expert Advisor before the OnCalculate ()  (start) unction:

//+==+//+ www.expforex.com edit AlertArrow +//+==+
extern string Alerts="Alerts and arrows from www.expforex.com";
extern bool AlerT=true; // Issue an alert to the screen
extern bool Mail=true; // Send message
extern bool Push=true; // Send PUSH to phone
extern bool Arrow=true; // Put arrows on signals
extern int shift=1; // On which bar to count the signal 0 - on the current one 1 - on the closed  int timeee;
// Internal variable
string nameInd;
void SetArrow(int cd, color cl,              string nm="", datetime t1=0, double p1=0, int sz=3)
  {
   if(nm=="")
      nm=DoubleToStr(Time[0], 0);
   if(t1<=0)
      t1=Time[0];
   if(p1<=0)
      p1=Bid;
   nameInd=WindowExpertName();
   int wind=WindowFind(nameInd);
   wind=0;
   if(ObjectFind(nm)<0)
      ObjectCreate(nm, OBJ_ARROW, wind, 0,0);
   ObjectSet(nm, OBJPROP_TIME1, t1);
   ObjectSet(nm, OBJPROP_PRICE1, p1);
   ObjectSet(nm, OBJPROP_ARROWCODE, cd);
   ObjectSet(nm, OBJPROP_COLOR, cl);
   ObjectSet(nm, OBJPROP_WIDTH, sz);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Expforex_AlertArrow(string text="",int arrowdir=0,bool history=false,int i=0)
  {
   nameInd=WindowExpertName();
   int wind=WindowFind(nameInd);
   if(wind==-1)
      wind=0;
   ObjectCreate("Originalalert",OBJ_LABEL,wind,0,0);
   ObjectSetText("Originalalert","Модификация AlertArrow www.expforex.com",10,"Arial Bold",Red);
   ObjectSet("Originalalert",OBJPROP_CORNER,2);
   ObjectSet("Originalalert",OBJPROP_XDISTANCE,200);
   ObjectSet("Originalalert",OBJPROP_YDISTANCE,10);
   if(!history)
     {
      if(AlerT)
         Alert(text);
      if(Arrow)
         if(arrowdir==1)
            SetArrow(241,Blue,nameInd+DoubleToStr(Time[shift],0),Time[shift],Low[shift]);
      if(Arrow)
         if(arrowdir==2)
            SetArrow(242,Red,nameInd+DoubleToStr(Time[shift],0),Time[shift],High[shift]);
      if(!IsTesting())
         if(Mail)
            SendMail(text,text);
      if(!IsTesting())
         if(Push)
            SendNotification(text);
     }
   if(history)
     {
      if(Arrow)
         if(arrowdir==1)
            SetArrow(241,Blue,nameInd+DoubleToStr(Time[shift+i],0),Time[shift+i],Low[shift+i]);
      if(Arrow)
         if(arrowdir==2)
            SetArrow(242,Red,nameInd+DoubleToStr(Time[shift+i],0),Time[shift+i],High[shift+i]);

     }

  }//+==+//+ www.expforex.com edit AlertArrow +//+==+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   for(int i=ObjectsTotal(); i>=0; i--)
     {
      if(StringFind(ObjectName(i),nameInd)!=-1)
         ObjectDelete(ObjectName(i));

     }

  }
//+------------------------------------------------------------------+

STEP 2

 Before closing the start()( OnCalculate ) function inside the function before  

return(rates_total);  }

Paste the following code:

//+==+//+ www.expforex.com edit AlertArrow +//+==+

nameInd=WindowExpertName();

if(timeee!=Time[0] && SarBuffer[shift+1]<=75 && SarBuffer[shift]>75)
  {
   Expforex_AlertArrow(Symbol()+" "+Period()+nameInd+" UP",1);
   timeee=Time[0];
  }
if(timeee!=Time[0] && SarBuffer[shift+1]>=25 && SarBuffer[shift]<25)
  {
   Expforex_AlertArrow(Symbol()+" "+Period()+nameInd+" DN",2);
   timeee=Time[0];
  }//+==+//+ www.expforex.com edit AlertArrow +//+==+
//+------------------------------------------------------------------+

STEP 3

This code will serve as our signal.

Naturally, you need to replace some code with your own. 

The following code serves as a signal for an alert:

1. Intersection of the 0 lines from the top (bottom) down (up), then it will look like this:

SarBuffer[shift+1]>=0 && SarBuffer[shift]<0

2. Indicator crossing the current price or a bar, a bar breakdown by the indicator, and so on:

SarBuffer[shift+1]>=Close[shift] && SarBuffer[shift]<Close[shift]

3. If this is the intersection of unique levels, indicators such as stochastics:

SarBuffer[shift+1]<=75 && SarBuffer[shift]>75

SarBuffer[vshift+1]>=25 && SarBuffer[shift]<25

 

After use

To use a sound signal to the indicator, you can follow these steps:

  • 1. Open the indicator’s settings.
  • 2. Look for the “Alert” or “Arrows” section.
  • 3. Select the option to add a sound alert.
  • 4. Choose the sound file you want to use as the alert.
  • 5. Save the changes.

By inserting a sound signal into the indicator, you can receive an audible notification when certain conditions are met, which can help you make better trading decisions.

If you need arrows on history, then you need to do this:

After the above code, add another one:

//+==+//+ www.expforex.com edit AlertArrow +//+==+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
if(counted_bars>0)
   counted_bars--;
int limit2=Bars-counted_bars;
for(int i2=0; i2<limit2; i2++)
  {
   nameInd=WindowExpertName();
   if(SarBuffer[shift+1+i2]<=75 && SarBuffer[shift+i2]>75)
     {
      Expforex_AlertArrow(Symbol()+" "+Period()+nameInd+" UP"+i2,1,true,i2);
     }
   if(SarBuffer[shift+1+i2]>=25 && SarBuffer[shift+i2]<25)
     {
      Expforex_AlertArrow(Symbol()+" "+Period()+nameInd+" DN"+i2,2,true,i2);
     }
  }//+==+//+ www.expforex.com edit AlertArrow +//+==+

Examples

These examples are taken from the corresponding branch of our forum. I modified the indicators according to the principle described above. 

Conclusions

In this article, I explained the process of creating signals for the indicator in the most detailed and understandable way.

 The above code can be used without restrictions on any indicator. It is important not to change the author’s name when adding code to the indicator. 

If you liked this article and found this method of inserting signals useful, please leave your comments and rate the topics. 

Signal Bar, This is important to know:

Questions?

If you have any questions, please ask them. We do not sell the pig in a poke.

And each of our products can be checked before the purchase.

We appreciate your attitude and wishes for our products and try to keep the quality standard high.

Thank you for being with us!

Do you have a question?

Leave a Reply

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


    This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.
    Read more