Adding Alert

To add comments, please log in or register
Mohammad Rizal Bin Rahmat
616
Mohammad Rizal Bin Rahmat  

Hi Mentors,

Would greatly appreciate if anyone could help me to add alert to my indicator


//----------------------------------------------------------------------------------------
input string __________1__________="xxxxxxxxxxxxxxxxxxxxx";
input string __________2__________="=ARROW CODE=";//ARROW DETAILS
input string __________3__________="xxxxxxxxxxxxxxxxxxxxx";
input int ARROWUP =217;//ARROW CODE
input int ARROWDN =218;//ARROW CODE
input color ARROWUPc=clrWhite;//Arrow Up Color
input color ARROWDNc=clrWhite;//Arrow Dn Color
//----------------------------------------------------------------------------------------
//--- indicator buffers
double         ArrUpBuffer[];
double         ArrDnBuffer[];
//---
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorBuffers(2);
   SetIndexBuffer(0,ArrUpBuffer);SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,2,ARROWUPc);SetIndexArrow(0,ARROWUP);
   SetIndexBuffer(1,ArrDnBuffer);SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,2,ARROWDNc);SetIndexArrow(1,ARROWDN);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int i,limit;
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)limit=limit+2;
   for(i=limit-2;i>=0;i--)
     {
      if(
         iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_LOW,i+1)<iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)
         )
        {ArrUpBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)-35*pix_y();}
        
      if(
         iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_HIGH,i+1)>iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)
         )  
        {ArrDnBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)+35*pix_y();}
     }
//---------------
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double pix_y()
  {
   return((ChartGetDouble(0,CHART_PRICE_MAX,0)-ChartGetDouble(0,CHART_PRICE_MIN,0))/ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


This Part will Give alert for "BUY"

      if(
         iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_LOW,i+1)<iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)
         )
        {ArrUpBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)-35*pix_y();}


and this part will give alert for "SELL"

      if(
         iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_HIGH,i+1)>iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)
         )  
        {ArrDnBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)+35*pix_y();}


Thank you so much.....

Atila Ribeiro
422
Atila Ribeiro  
//----------------------------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrWhite
#property indicator_color2 clrWhite
#property indicator_width1 1
#property indicator_width2 1
//----------------------------------------------------------------------------------------
input string __________1__________="xxxxxxxxxxxxxxxxxxxxx";
input string __________2__________="=ARROW CODE=";//ARROW DETAILS
input string __________3__________="xxxxxxxxxxxxxxxxxxxxx";
input int ARROWUP =217;//ARROW CODE
input int ARROWDN =218;//ARROW CODE
input color ARROWUPc=clrWhite;//Arrow Up Color
input color ARROWDNc=clrWhite;//Arrow Dn Color
input bool AlertON=false;
//----------------------------------------------------------------------------------------
datetime TIME=0;
//----------------------------------------------------------------------------------------
//--- indicator buffers
double         ArrUpBuffer[];
double         ArrDnBuffer[];
//---
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorBuffers(2);
   SetIndexBuffer(0,ArrUpBuffer);SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,2,ARROWUPc);SetIndexArrow(0,ARROWUP);
   SetIndexBuffer(1,ArrDnBuffer);SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,2,ARROWDNc);SetIndexArrow(1,ARROWDN);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int i,limit;
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)limit=limit+2;
   for(i=limit-2;i>=0;i--){
      if(iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_LOW,i+1)<iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)){
         ArrUpBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)-35*pix_y();
         if(i==0 && TIME!=Time[0] && AlertON){
            Alert(Symbol(),"  M",Period(),"  BUY");
            TIME=Time[0];
         }            
      } 
      if(iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_HIGH,i+1)>iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)){
         ArrDnBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)+35*pix_y();
         if(i==0 && TIME!=Time[0] && AlertON){
            Alert(Symbol(),"  M",Period(),"  SELL");
            TIME=Time[0];
         }
      }
   }
//---------------
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double pix_y()
  {
   return((ChartGetDouble(0,CHART_PRICE_MAX,0)-ChartGetDouble(0,CHART_PRICE_MIN,0))/ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
Mohammad Rizal Bin Rahmat
616
Mohammad Rizal Bin Rahmat  
Atila Ribeiro:

Thank you!! it works perfectly....

dompetku
22
dompetku  
Atila Ribeiro:

Hello mentors,

Please help me to add push/ mobile notifications on this attache indicator

thank you

Files:
Marco vd Heijden
Moderator
8163
Marco vd Heijden  
dompetku:

Hello mentors,

Please help me to add push/ mobile notifications on this attache indicator

thank you

dompetku
22
dompetku  
Marco vd Heijden:
Thank you very much Sir
Mohammad Rizal Bin Rahmat
616
Mohammad Rizal Bin Rahmat  
Atila Ribeiro:

Hi Sir, 

I did some adjustment to the notification. I try adding SendNotitification but it doesn't work

input bool AlertON=false;
input bool NotificationON=false;


 if(i==0 && TIME!=Time[0] && AlertON){
            Alert(Symbol(),"  M",Period(),"  BUY");
            TIME=Time[0];
         }         
if(i==0 && TIME!=Time[0] && NotificationON){
            SendNotification(Symbol(),"  M",Period(),"  BUY");
            TIME=Time[0];
         }      
Mohammad Rizal Bin Rahmat
616
Mohammad Rizal Bin Rahmat  
Atila Ribeiro:

Hi Sir,

Is the below code the way it should be?

if(iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_LOW,i+1)<iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)){
         ArrUpBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_LOWER,i+1)-35*pix_y();
         if(i==0 && TIME!=Time[0] && AlertON){
            Alert(Symbol(),"  M",Period(),"  BUY");
	}
	 if(i==0 && TIME!=Time[0] && NotificationON){
	    SendNotification(Symbol(),"  M",Period(),"  BUY");
	}
            TIME=Time[0];          
      } 
      if(iMA(_Symbol,_Period,5,0,MODE_LWMA,PRICE_HIGH,i+1)>iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)){
         ArrDnBuffer[i+1]=iBands(_Symbol,_Period,20,2.0,0,PRICE_CLOSE,MODE_UPPER,i+1)+35*pix_y();
         if(i==0 && TIME!=Time[0] && AlertON){
            Alert(Symbol(),"  M",Period(),"  SELL");
         }
	 if(i==0 && TIME!=Time[0] && NotificationON){
	    SendNotification(Symbol(),"  M",Period(),"  BUY")
	 }
	    TIME=Time[0];
      }
To add comments, please log in or register