MACD Crossover Arrows & Alert

MACD Crossover Arrows & Alert
Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
MACD Crossover Arrows & Alert
//+------------------------------------------------------------------+
//|                   MACD Crossover Arrows & Alert                  |
//|              Copyright © 2006 Written by PussyGalore             |
//+------------------------------------------------------------------+


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_width1 3
#property indicator_color2 Magenta
#property indicator_width2 3

extern int MACD_Fast = 12;
extern int MACD_Slow = 26;
extern int MACD_Slowing = 9; 
extern int Bars_Count= 20000;

extern string note1 = "Arrow Type";
extern string note2 = "0=Thick, 1=Thin, 2=Hollow, 3=Round";
extern string note3 = "4=Fractal, 5=Diagonal Thin";
extern string note4 = "6=Diagonal Thick, 7=Diagonal Hollow";
extern string note5 = "8=Thumb, 9=Finger";
extern int ArrowType=2;
extern string note6 = "--------------------------------------------";
extern string note7 = "turn on Alert = true; turn off = false";
extern bool AlertOn = true;
extern string note8 = "--------------------------------------------";
extern string note9 = "send Email Alert = true; turn off = false";
extern bool SendAnEmail=false;

double CrossUp[];
double CrossDown[];
string AlertPrefix, MA1short_name, MA2short_name;
string GetTimeFrameStr() {
   switch(Period())
   {
      case 1 : string TimeFrameStr="M1"; break;
      case 5 : TimeFrameStr="M5"; break;
      case 15 : TimeFrameStr="M15"; break;
      case 30 : TimeFrameStr="M30"; break;
      case 60 : TimeFrameStr="H1"; break;
      case 240 : TimeFrameStr="H4"; break;
      case 1440 : TimeFrameStr="D1"; break;
      case 10080 : TimeFrameStr="W1"; break;
      case 43200 : TimeFrameStr="MN1"; break;
      default : TimeFrameStr=Period();
   } 
   return (TimeFrameStr);
   }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if (ArrowType == 0) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 233);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 234);
   }
   else if (ArrowType == 1) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 225);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 226);
   }
   else if (ArrowType == 2) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 241);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 242);
   }
   else if (ArrowType == 3) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 221);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 222);
   }
   else if (ArrowType == 4) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 217);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 218);
   }
   else if (ArrowType == 5) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 228);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 230);
   }
   else if (ArrowType == 6) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 236);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 238);
   }
   else if (ArrowType == 7) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 246);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 248);
   }
   else if (ArrowType == 8) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 67);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 68);
   }
   else if (ArrowType == 9) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 71);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 72);
   }

   SetIndexBuffer(0, CrossUp);
   SetIndexBuffer(1, CrossDown);


   AlertPrefix=Symbol()+" ("+GetTimeFrameStr()+"):  ";
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
bool NewBar()
{
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
}   
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   
   double macdnow, macd_signow, macdprevious, macd_sigprevious, macdafter, macd_sigafter;
   double Range, AvgRange;
   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++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      macdnow = iMACD(Symbol(), Period(), MACD_Fast, MACD_Slow, MACD_Slowing, PRICE_CLOSE, MODE_MAIN, i);
      macdprevious = iMACD(Symbol(), Period(), MACD_Fast, MACD_Slow, MACD_Slowing, PRICE_CLOSE, MODE_MAIN, i+1);
      macdafter = iMACD(Symbol(), Period(), MACD_Fast, MACD_Slow, MACD_Slowing, PRICE_CLOSE, MODE_MAIN, i-1);
      

      macd_signow = iMACD(Symbol(), Period(), MACD_Fast, MACD_Slow, MACD_Slowing, PRICE_CLOSE, MODE_SIGNAL, i);
      macd_sigprevious = iMACD(Symbol(), Period(), MACD_Fast, MACD_Slow, MACD_Slowing, PRICE_CLOSE, MODE_SIGNAL, i+1);
      macd_sigafter = iMACD(Symbol(), Period(), MACD_Fast, MACD_Slow, MACD_Slowing, PRICE_CLOSE, MODE_SIGNAL, i-1);
      
            
      if ((macdnow > macd_signow) && (macdprevious < macd_sigprevious) && (macdafter > macd_sigafter)) {
                   CrossUp[i] = Low[i] - Range*1.5;
                   if (AlertOn && NewBar()) {
                      Alert(AlertPrefix + "MACD ("+MACD_Fast+","+MACD_Slow+","+MACD_Slowing+") crosses UP");
                   }   
              	    if (SendAnEmail && NewBar()) {
                      SendMail(AlertPrefix, "MACD ("+MACD_Fast+","+MACD_Slow+","+MACD_Slowing+") crosses UP");
              	    }
      }
      else if ((macdnow < macd_signow) && (macdprevious > macd_sigprevious) && (macdafter < macd_sigafter)) {
                   CrossDown[i] = High[i] + Range*1.5;
                   if (AlertOn && NewBar()) {
                      Alert(AlertPrefix + "MACD ("+MACD_Fast+","+MACD_Slow+","+MACD_Slowing+") crosses DOWN");
                   }   
              	    if (SendAnEmail && NewBar()) {
                      SendMail(AlertPrefix, "MACD ("+MACD_Fast+","+MACD_Slow+","+MACD_Slowing+") crosses DOWN");
              	    }
      }
   }
   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 ---