Keltner_ChannelsAlert

Author: Copyright � 2005, MetaQuotes Software Corp.
Keltner_ChannelsAlert
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alertsIt sends emails
0 Views
0 Downloads
0 Favorites
Keltner_ChannelsAlert
//+------------------------------------------------------------------+
//|                                             Keltner Channels.mq4 |
//|                                                  Coded by Gilani |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White


double upper[], middle[], lower[];
extern int period = 10;

extern int SoundAlert  =    1; // 0 = disabled
extern int PopUpAlert = 1;
extern string BuySoundFile = "alert.wav";
extern string SellSoundFile = "alert2.wav";
extern int EmailAlert  =    1;
datetime prevtime = 0;


int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,0);
   SetIndexDrawBegin(0,0);
   SetIndexBuffer(0,upper);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(1,0);
   SetIndexDrawBegin(1,0);
   SetIndexBuffer(1,middle);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexShift(2,0);
   SetIndexDrawBegin(2,0);
   SetIndexBuffer(2,lower);
    
return(0);
}
int deinit(){return(0);}
int start() {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   double avg;
   
   for(int x=0; x<limit; x++) {
      middle[x] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_CLOSE, x);
      avg  = findAvg(period, x);
      upper[x] = middle[x] + avg;
      lower[x] = middle[x] - avg;
   }
      if ((Bid >= lower[0]) && (Bid <= upper[0])) { prevtime = 0; }
      
      if ((Bid > upper[0]) && (prevtime != Time[0]))
       {
         prevtime = Time[0];
         if (SoundAlert != 0)PlaySound(BuySoundFile);
         if (EmailAlert != 0) SendMail("Keltner breakout above Alert for " + Symbol(), " @  Hour " + Hour() + "  Minute " + Minute());
         if (PopUpAlert != 0)Alert(Symbol(),"Keltner breakout above @  Hour ",Hour(),"  Minute ",Minute());
       }
      
      if ((Bid < lower[0]) && (prevtime != Time[0]))
       {
         prevtime = Time[0];
         if (SoundAlert != 0)PlaySound(SellSoundFile);
         if (EmailAlert != 0) SendMail("Keltner breakout below Alert for " + Symbol(), " @  Hour " + Hour() + "  Minute " + Minute());
         if (PopUpAlert != 0)Alert(Symbol(),"Keltner breakout below @  Hour ",Hour(),"  Minute ",Minute());
       }
   return(0);
  }
//+------------------------------------------------------------------+


   double findAvg(int period, int shift) {
      double sum=0;
      for (int x=shift;x<(shift+period);x++) {     
         sum += High[x]-Low[x];
      }
      sum = sum/period;
      return (sum);
   }

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 ---