RSI_Cross50_Alert

Author: Copyright � 2007, Robert Hill
RSI_Cross50_Alert
Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1It plays sound alertsIt issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
RSI_Cross50_Alert
//+------------------------------------------------------------------+
//|                                     RSI-Cross50_Alert.mq4 |
//|         Copyright © 2006, Robert Hill                            |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Robert Hill"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 1

extern int RSI_Period=14;

double rsi[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
   SetIndexBuffer(0, rsi);
   SetIndexLabel (0, "RSI" + "("+RSI_Period+")");
   SetLevelStyle(STYLE_DASH, 1, Silver);
   SetLevelValue(0, 50);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit, i;
   double RSInow, RSIprevious;
   datetime alertTag;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++)
    {
   
     RSInow = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
     RSIprevious = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i+1);
      
      rsi[i] = RSInow;
      if (RSInow > 50 && RSIprevious < 50.0)
      {
         if ( alertTag!=Time[0])
         {
          PlaySound("news.wav");// buy wav
          Alert(Symbol(),"  M",Period()," RSI cross above 50");
         }
          alertTag = Time[0];
          
      }
      else if (RSInow < 50.0 && RSIprevious > 50.0)
      {
         if ( alertTag!=Time[0])
         {
          PlaySound("news.wav"); //sell wav
           Alert(Symbol(),"  M",Period()," RSI cross below 50");
         }
          alertTag = Time[0];
      }
   }
   return(0);
}


Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---