Navigation:Home > Content >

rsi_with_rsi_Alert(1).mq4

Time: 2015-10-27 | Download file:rsi_with_rsi_Alert(1).mq4

//+------------------------------------------------------------------+
//|                                                 rsi with rsi.mq4 |
//|                                                                  |
//| TASC January 2011 Peter Konne article "Combining Rsi With Rsi"   |
//+------------------------------------------------------------------+
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1  DeepSkyBlue
#property indicator_color2  PaleVioletRed
#property indicator_color3  DeepSkyBlue
#property indicator_color4  PaleVioletRed
#property indicator_width1  4
#property indicator_width2  4
#property indicator_width3  1
#property indicator_width4  1
#define SIGNAL_BAR 1
//
//
//
//
//

extern int    RsiShort      = 5;
extern int    RsiLong       = 17;
extern int    RsiPrice      = PRICE_CLOSE;
extern double RsiLevelUp    = 60;
extern double RsiLevelDown  = 40;
extern int    MaShortPeriod = 10;
extern int    MaLongPeriod  = 40;
extern int    MaPrice       = PRICE_CLOSE;
extern bool UseSound=true;
extern bool AlertSound=true;
extern bool UseSoundСross=true;
extern bool AlertSoundСross=true;

extern string SoundFileBuy ="tada.wav";
extern string SoundFileSell="email.wav";
extern bool SendMailPossible = false;
bool SoundBuy  = False;
bool SoundSell = False;
bool SoundBuyСross  = False;
bool SoundSellСross = False;


//
//
//
//
//

double signallUp[];
double signallDn[];
double signalsUp[];
double signalsDn[];
double trend1[];
double trend2[];
bool  hl;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(6);
      SetIndexBuffer(0,signallUp); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,159);
      SetIndexBuffer(1,signallDn); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,159);
      SetIndexBuffer(2,signalsUp); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,251);
      SetIndexBuffer(3,signalsDn); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,251);
      SetIndexBuffer(4,trend1);
      SetIndexBuffer(5,trend2);
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

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

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit=MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //

   for(i=limit; i>=0; i--)
   {
      double range    = iATR(NULL,0,10,i)/2.0;
      double rsiShort = iRSI(NULL,0,RsiShort,RsiPrice,i);
      double rsiLong  = iRSI(NULL,0,RsiLong ,RsiPrice,i);
      double maLong   = iMA(NULL,0,MaLongPeriod ,0,MODE_SMA,MaPrice,i);
      double maShort  = iMA(NULL,0,MaShortPeriod,0,MODE_SMA,MaPrice,i);
      double price    = iMA(NULL,0,1            ,0,MODE_SMA,MaPrice,i);
      
      //
      //
      //
      //
      //
      
         trend1[i] = trend1[i+1]; 
            if (rsiShort>RsiLevelUp)   trend1[i] =  1;
            if (rsiShortRsiLevelUp)    trend2[i] =  1;
            if (rsiLong maShort && trend2[i] == -1) signalsUp[i] = Low[i]  - range;  
         if (trend2[i]!=trend2[i+1] && trend2[i]== 1 && price > maLong)                     signallUp[i] = Low[i]  - range*2.0;
         if (trend1[i]!=trend1[i+1] && trend1[i]==-1 && price < maShort && trend2[i] ==  1) signalsDn[i] = High[i] + range;
         if (trend2[i]!=trend2[i+1] && trend2[i]==-1 && price < maLong)                     signallDn[i] = High[i] + range*2.0;
   } 
//+------------------------------------------------------------------+         
        if (signallUp[SIGNAL_BAR] != EMPTY_VALUE && signallUp[SIGNAL_BAR] != 0 && SoundBuy)
         {
         SoundBuy = False;
            if (UseSound) PlaySound (SoundFileBuy);
               if(AlertSound){         
               Alert("rsi with rsi (", Symbol(), ", ", Period(), ")  -  BUY!!!");                             
               if (SendMailPossible) SendMail(Symbol()+ " M"+ Period()+ " rsi with rsi -  BUY!", ""); 
            }              
         } 
      if (!SoundBuy && (signallUp[SIGNAL_BAR] == EMPTY_VALUE || signallUp[SIGNAL_BAR] == 0)) SoundBuy = True;  
            
  
     if (signallDn[SIGNAL_BAR] != EMPTY_VALUE && signallDn[SIGNAL_BAR] != 0 && SoundSell)
         {
         SoundSell = False;
            if (UseSound) PlaySound (SoundFileSell); 
             if(AlertSound){                    
             Alert("rsi with rsi (", Symbol(), ", ", Period(), ")  -  SELL!!!");             
             if (SendMailPossible) SendMail(Symbol()+ " M"+ Period()+ " rsi with rsi -  SELL!!!", ""); 
             }            
         } 
      if (!SoundSell && (signallDn[SIGNAL_BAR] == EMPTY_VALUE || signallDn[SIGNAL_BAR] == 0)) SoundSell = True; 
      
       //+------------------------------------------------------------------+ 
              
  if (signalsUp[SIGNAL_BAR] != EMPTY_VALUE && signalsUp[SIGNAL_BAR] != 0 && SoundBuyСross)
         {
         SoundBuyСross = False;
            if (UseSoundСross) PlaySound (SoundFileBuy);
               if(AlertSoundСross){         
               Alert("rsi with rsi (", Symbol(), ", ", Period(), ")  -   BUY!!!");                             
               if (SendMailPossible) SendMail(Symbol()+ " M"+ Period()+ " rsi with rsi - BUY!", ""); 
            }              
         } 
      if (!SoundBuyСross && (signalsUp[SIGNAL_BAR] == EMPTY_VALUE || signalsUp[SIGNAL_BAR] == 0)) SoundBuyСross = True;  
            
  
     if (signalsDn[SIGNAL_BAR] != EMPTY_VALUE && signalsDn[SIGNAL_BAR] != 0 && SoundSellСross)
         {
         SoundSellСross = False;
            if (UseSoundСross) PlaySound (SoundFileSell); 
             if(AlertSoundСross){                    
             Alert("rsi with rsi (", Symbol(), ", ", Period(), ")  - SELL!!!");             
             if (SendMailPossible) SendMail(Symbol()+ " M"+ Period()+ " rsi with rsi - SELL!!!", ""); 
             }            
         } 
      if (!SoundSellСross && (signalsDn[SIGNAL_BAR] == EMPTY_VALUE || signalsDn[SIGNAL_BAR] == 0)) SoundSellСross = True; 
      
       //+------------------------------------------------------------------+        
   return(0);
}

Recommend