How to code alerts for RSi?

 
Newbie here, 

Can anyone please tell me how to code your own alerts for RSI indicator? Thanks!
 
Matthew Amoroso:
Newbie here, 

Can anyone please tell me how to code your own alerts for RSI indicator? Thanks!

Hello,

you should create an alert with ::Alert() function.

 
Andrey Barinov:

Hello,

you should create an alert with ::Alert() function.

Thanks for responding Andrey! But can you please give me an example? This is my first time coding my own ea and im really having a hard time writing it. I just want rsi to send alerts as soon as it touches ob/os levels... I have downloaded a free rsi alert custom indicator but it sends signals after rsi MA pulls back from ob/os levels. Please help me out... Thanks! :-))
 
Matthew Amoroso:
Thanks for responding Andrey! But can you please give me an example? This is my first time coding my own ea and im really having a hard time writing it. I just want rsi to send alerts as soon as it touches ob/os levels... I have downloaded a free rsi alert custom indicator but it sends signals after rsi MA pulls back from ob/os levels. Please help me out... Thanks! :-))

I hope this helps you :)

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_minimum 0
#property indicator_maximum 100

extern int  RSI_Period       = 14;   
extern int  Applied_Price    = 0;
extern int  Overbought_level = 70;
extern int  Oversold_level   = 30;
extern bool Alert_Mode       = true;

double RSIBuffer[];
double OverboughtBuffer[];
double OversoldBuffer[];

int init()
{
   string short_name = "RSI Alert("+RSI_Period+")";
   IndicatorShortName(short_name);
   
   SetIndexBuffer(0,RSIBuffer);
   SetIndexBuffer(1,OverboughtBuffer);
   SetIndexBuffer(2,OversoldBuffer);
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"OverBought");
   SetIndexLabel(2,"OverSold");

   SetIndexDrawBegin(0,RSI_Period);

   return(0);
}

int start()
{
   int i;
   int counted_bars = IndicatorCounted();

   if(Bars <= RSI_Period) 
     return(0);

   i = Bars - RSI_Period - 1;
   if(counted_bars >= RSI_Period) 
     i=Bars-counted_bars-1;
     
   while(i >= 0)
   {
      RSIBuffer[i] = iRSI(NULL, 0, RSI_Period, Applied_Price, i);
      OverboughtBuffer[i] = Overbought_level;
      OversoldBuffer[i]   = Oversold_level;
      i--;
   }
   
   if(Alert_Mode)
   {
      if(RSIBuffer[1] < Overbought_level && RSIBuffer[0] >= Overbought_level)
         Alert(Symbol(), " ", Period(), "  RSI("+RSI_Period+") over "+Overbought_level+"");
         
      else if(RSIBuffer[1] > Oversold_level && RSIBuffer[0] <= Oversold_level)
         Alert(Symbol(), " ", Period(), "  RSI("+RSI_Period+") under "+Oversold_level+"");
   }

   return(0);
}

JustForTest