ZZ_MTF_XO2 with Alerts





//+------------------------------------------------------------------+ 
//|                                        ZZ MultiTimeFrame X0      |
//|                                   Copyright © 2008 Tim Hyder     |
//|                                                                  |
//| V1.   Completed by AHGDP ????                                    |
//| V2.   Completed by Tim Hyder 2008                                |
//|               a)   Added Audio, Visual and eMail alerts          | 
//|                                                                  |
//|   Copyright © 2008, Tim Hyder aka Hiachiever                     |
//|                                                                  |
//|   PO BOX 768, Hillarys, Western Australia, Australia, 6923       |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|   All my indicators should be considered donationware. That is   |
//|   you are free to use them for your personal use, and are        |
//|   under no obligation to pay for them. However, if you do find   |
//|   this or any of my other indicators help you with your trading  |
//|   then any Gift or Donation as a show of appreciation is         |
//|   gratefully accepted.                                           |
//|                                                                  |
//|   Gifts or Donations also keep me motivated in producing more    |
//|   great free indicators. :-)                                     |
//|                                                                  |
//|   PayPal - hiachiever@gmail.com                                  |  
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2007, Tim Hyder."
#property link      "http://www.the4xtrader.com"

#define vers    "11Feb.2008"
#define major   2
#define minor   0

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Teal 
#property indicator_color2 Orange
#property indicator_color3 Lime
#property indicator_color4 Red

#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 3

#property indicator_maximum 2.5                     
#property indicator_minimum -2.5

extern string NOTESETTINGS = " - - - INDICATOR SETTINGS - - - ";
extern double KirPER1=4.5;
extern double KirPER2=6.5;
extern int TF1= 240 ;  
extern string NOTEALERTS = " - - - -  ALERTS  - - - - ";
extern bool StrongAlertsOnly = false;
extern bool MsgAlerts = true;
extern bool SoundAlerts = true;
extern string SoundAlertFile = "alert3.wav";
extern bool eMailAlerts = false;
                    
extern int   LastAlertBar, LastDirection, LineSize1=3;
extern int CountBars=500;

double xoup1 , xodn1 ;
double xoup2 , xodn2 ;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,LineSize1);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,LineSize1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,LineSize1);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,LineSize1);
   SetIndexBuffer(3,ExtMapBuffer4);

      string  ThisName = "ZZ_MTF_XO_2";
       string Text=ThisName;
        Text=Text+"  ("+TF1;
 
        Text=Text+")";
        Text=Text+"(";
        Text=Text+" "+DoubleToStr(KirPER1,1);
        Text=Text+", "+DoubleToStr(KirPER2,1);
        
        Text=Text+")  ";
      IndicatorShortName(Text);
     LastAlertBar = Bars-1;
  }
//----
   return(0);
 
//+------------------------------------------------------------------+
//| MTF Parabolic Sar                                         |
//+------------------------------------------------------------------+
int start()
  {
   int    i,limit,y=0,counted_bars=IndicatorCounted();
   string base, Subj, Msg;
   
   limit=Bars-counted_bars;
   limit=Bars-counted_bars;
   limit=Bars-counted_bars;
   limit=Bars-counted_bars;
   
   if(counted_bars>0) limit++; else if (limit>100) limit=CountBars;  
     SetIndexDrawBegin(0,Bars-CountBars);
     SetIndexDrawBegin(1,Bars-CountBars);
     SetIndexDrawBegin(2,Bars-CountBars);
     SetIndexDrawBegin(3,Bars-CountBars);
   
   int lastp15=0, lastp30=0, lastp60=0;
   for(i=0,y=0;i<limit;i++)
   {
      int p1;
      
      p1 = iBarShift( NULL, TF1, Time[i], false );

//========================================================================================  

     double xo1a  = iCustom(NULL,TF1,"XO",KirPER1,0,p1);
     double xo1b  = iCustom(NULL,TF1,"XO",KirPER1,1,p1);              
          if ((xo1a > 0)){ xoup1 = 1; xodn1 = 0; }
          if ((xo1b < 0)){ xoup1 = 0; xodn1 = 1; }  
          
     double xo2a  = iCustom(NULL,TF1,"XO",KirPER2,0,p1);
     double xo2b  = iCustom(NULL,TF1,"XO",KirPER2,1,p1);                 
          if ((xo2a > 0)){ xoup2 = 1; xodn2 = 0; }
          if ((xo2b < 0)){ xoup2 = 0; xodn2 = 1; }   
//========================================================================================  
      double TF1Up = 0.0;
      double TF1Down = 0.0;
      double TF2Up = 0.0;
      double TF2Down = 0.0;


     if  ( (xoup1 + xoup2 ) == 2 )   TF1Up   =   2 ;
     if  ( (xodn1 + xodn2 ) == 2 )   TF1Down = - 2 ;

     if ( TF1Up == 2 || TF1Down == - 2 )
          {
            ExtMapBuffer3[i] = TF1Up;
            ExtMapBuffer4[i] = TF1Down;   
            if (LastDirection != 2 && Bars>LastAlertBar)  
            {
               base = Symbol()+ ", TF: " + TF2Str(TF1);
               Subj = base + ".  Strong Up Alert";
               if (TF1Down == - 2) Subj = base + ".  Strong Down Alert";
         
               Msg = Subj + " @ " + TimeToStr(TimeLocal(),TIME_SECONDS);
               DoAlerts(Msg,Subj);
               LastAlertBar = Bars; 
               LastDirection = 2;
            }
         }
//=========================================================================================     

    if  ( ( xoup2) ==  1 )   TF2Up   =   1 ;
    if  ( ( xodn2) ==  1 )   TF2Down = - 1 ;

    
   if ( TF2Up == 1 || TF2Down == - 1 )
        {
           ExtMapBuffer1[i] = TF2Up;
           ExtMapBuffer2[i] = TF2Down;     
           if (LastDirection != 1 && Bars>LastAlertBar)  
           {
               base = Symbol()+ ", TF: " + TF2Str(TF1);
               Subj = base + ".  Weak Up Alert";
               if (TF2Down == - 1) Subj = base + ".  Weak Down Alert";
         
               Msg = Subj + " @ " + TimeToStr(TimeLocal(),TIME_SECONDS);
               if (!StrongAlertsOnly) DoAlerts(Msg,Subj);
               LastAlertBar = Bars; 
               LastDirection = 1;
           }
       }

//================================================================== 
   }  
 
   return(0);
  }
//+------------------------------------------------------------------+

void DoAlerts(string msgText,string eMailSub)
{
   if (MsgAlerts) Alert(msgText);
   if (SoundAlerts)  PlaySound(SoundAlertFile);
   if (eMailAlerts) SendMail(eMailSub, msgText);
}

string TF2Str(int period) 
{
  switch (period) 
  {
    case PERIOD_M1: return("M1");
    case PERIOD_M5: return("M5");
    case PERIOD_M15: return("M15");
    case PERIOD_M30: return("M30");
    case PERIOD_H1: return("H1");
    case PERIOD_H4: return("H4");
    case PERIOD_D1: return("D1");
    case PERIOD_W1: return("W1");
    case PERIOD_MN1: return("MN");
  }
  return (Period());
} 



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_HISTOGRAM


Indicators Used:




Custom Indicators Used:
XO

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen
It plays sound alerts
It sends emails