EMA-alert and email alert

Author: Copyright � 2007, MetaQuotes Software Corp.
EMA-alert and email alert
Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screenIt plays sound alertsIt sends emails
0 Views
0 Downloads
0 Favorites
EMA-alert and email alert
//+------------------------------------------------------------------+
//|                                                   EMA-alert.mq4  |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1

//---- input parameters
extern int ema_period = 34;
//---- buffers
double ExtMapBuffer1[];
extern bool Box_Alert=true;
extern bool Sound_Alert=true;
extern bool Email_Alert=false;
extern int pip_distance = 10;
datetime lastimealert;
//----
double ema_value;
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  
    SetIndexBuffer(0, ExtMapBuffer1);

//---- name for DataWindow and indicator subwindow label
  
//----
   
    return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int limit;
    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(int i = 0; i < limit; i++)
      {
       ema_value= iMA(NULL,0,ema_period,0,MODE_EMA,PRICE_CLOSE,i);
        //----
        ExtMapBuffer1[i] = ema_value-Ask ;
        if(MathAbs(ema_value-Bid)<=pip_distance*Point&& lastimealert!= Time[0] )
            {
            
            if(Box_Alert) Alert("Price is within ",pip_distance," pips of ",ema_period," period EMA");
            if(Sound_Alert) PlaySound("alert.wav");
            if(Email_Alert) SendMail("Price Alert on "+Symbol(),"Price is within "+pip_distance+" pips of "+ema_period+" period EMA");
            lastimealert= 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 ---