3MA_Cross_w_Alert_v2GS2





//+--------------------------------------------------------------------------+
//| 3 MA Cross w_Alert v2.mq4                                                |
//| Copyright © 2005, Jason Robinson (jnrtrading)                            |
//| http://www.jnrtading.co.uk                                               |
//| 3 ma conversion and Alert , David Honeywell , transport.david@gmail.com  |
//| http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ |
//+--------------------------------------------------------------------------+

/*
  +-------------------------------------------------------------------------------+
  | Allows you to enter 3 ma periods and it will then show you and alert you at   |
  | which point the 2 faster ma's "OPEN" are both above or below the Slowest ma . |
  +-------------------------------------------------------------------------------+
*/   
//  mod. 2008fxtsd eachMAShift taken off; 1GeneralShift 4 all MAs &Sigs; signals after bar close only// ki
//  3MA_Cross_w_Alert_v2GS2 displacement shift for lines and signals; actual cross MAshift = 0!



#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link      "http://www.jnrtrading.co.uk"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Aquamarine
#property indicator_color2 Magenta
#property indicator_color3 RoyalBlue
#property indicator_color4 Red
#property indicator_color5 Yellow

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1

extern int FastMA       =    5;
extern int FastMAMode   =    1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
//extern int FasterShift =   0;
extern int MediumMA      =   13;
extern int MediumMAMode  =   1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
//extern int MediumShift =    -3;
extern int SlowMA        =   21;
extern int  SlowMAMode   =   1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
//extern int SlowerShift =   -1;
extern int FastMADisplacement   =  0;  // 4 display only // calculated shift = 0! 
extern int MediumMADisplacement =  0;
extern int SlowMADisplacement   =  0;
//extern int  GeneralShift =   0;
extern int  SignalDisplacement   =  0;
extern bool MADisplacementON        =  true;
extern bool SignalDisplacementON    =  true;
extern string   note_Displacement   = "calculated MAshift = 0!";

extern bool Drawlines           =  true;
extern bool SoundAlertON        =  true;
extern string   note_MA_Mode    = "SMA0 EMA1 SMMA2 LWMA3";

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

double CrossUp[];
double CrossDown[];
double prevtime;
double Range, AvgRange;
double fastMAnow, fastMAprevious, fastMAafter;
double mediumMAnow, mediumMAprevious, mediumMAafter;
double slowMAnow, slowMAprevious, slowMAafter;
double alertTag;
double control=2147483647;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 233);//221
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 234);//222
   SetIndexBuffer(1, CrossDown);

if (SignalDisplacementON)
   {
   SetIndexShift(0,SignalDisplacement);   
   SetIndexShift(1,SignalDisplacement);   
   }
 else 
   {
   SetIndexShift(0,0);   
   SetIndexShift(1,0);   
   }
 
   //---- indicators
  
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer1);

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer2);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);

if (MADisplacementON)
   {
   SetIndexShift(4,FastMADisplacement);   
   SetIndexShift(3,MediumMADisplacement);
   SetIndexShift(2,SlowMADisplacement);
   }
 else 
   {
   SetIndexShift(4,0);   
   SetIndexShift(3,0);   
   SetIndexShift(2,0);   
   }


   SetIndexLabel(0,"3MA("+FastMA+","+MediumMA+","+SlowMA+")xUp");      
   SetIndexLabel(1,"3MA("+FastMA+","+MediumMA+","+SlowMA+")xDn");      
   SetIndexLabel(2,"3MAxFast("+FastMA+","+MediumMA+","+SlowMA+")");      
   SetIndexLabel(3,"3MAxMid("+FastMA+","+MediumMA+","+SlowMA+")");      
   SetIndexLabel(4,"3MAxSlow("+FastMA+","+MediumMA+","+SlowMA+")");      


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
 {
   
   int limit, i, counter;
   
   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;
       
      fastMAnow      = iMA(NULL, 0, FastMA, 0, FastMAMode, PRICE_CLOSE, i+1);
      fastMAprevious = iMA(NULL, 0, FastMA, 0, FastMAMode, PRICE_CLOSE, i+2);
      fastMAafter    = iMA(NULL, 0, FastMA, 0, FastMAMode, PRICE_OPEN,  i);
      
      mediumMAnow      = iMA(NULL, 0, MediumMA, 0, MediumMAMode, PRICE_CLOSE, i+1);
      mediumMAprevious = iMA(NULL, 0, MediumMA, 0, MediumMAMode, PRICE_CLOSE, i+2);
      mediumMAafter    = iMA(NULL, 0, MediumMA, 0, MediumMAMode, PRICE_OPEN,  i);
      
      slowMAnow      = iMA(NULL, 0, SlowMA, 0, SlowMAMode, PRICE_CLOSE, i+1);
      slowMAprevious = iMA(NULL, 0, SlowMA, 0, SlowMAMode, PRICE_CLOSE, i+2);
      slowMAafter    = iMA(NULL, 0, SlowMA, 0, SlowMAMode, PRICE_OPEN,  i);
 
      if ((fastMAnow      > slowMAnow       &&
           fastMAprevious <= slowMAprevious  &&
           fastMAafter    > fastMAprevious     &&   
           mediumMAnow    > slowMAnow     )            // fast x slow up; med>slow            
           ||
          (fastMAnow        > slowMAnow      &&
           mediumMAnow      > slowMAnow       &&
           mediumMAprevious <= slowMAprevious  &&
           mediumMAafter    > mediumMAprevious   ))        //    med x sl up; fast >slow   
           {
          CrossUp[i] = Low[i] - Range*0.5;
           }
       
 
      if ((fastMAnow      < slowMAnow       &&
           fastMAprevious >= slowMAprevious  &&
           fastMAafter    < fastMAprevious    &&
           mediumMAnow    < slowMAnow      )        // fast x slow dn; mid<slow
           ||
          (fastMAnow        < slowMAnow       &&
           mediumMAnow      < slowMAnow        &&
           mediumMAprevious >= slowMAprevious  &&
           mediumMAafter    < mediumMAprevious    ))        // mid x slow dn; fast<slow
           {
          CrossDown[i] = High[i] + Range*0.5;
           }
      
    
   
      if (SoundAlertON==true && i==1 && CrossUp[i] > CrossDown[i] && alertTag!=Time[0])
        {
       Alert("3MACross2GS going Down on ",Symbol()," M",Period(),"  @ ",Bid);
        alertTag = Time[0];
        }
        if (SoundAlertON==true && i==1 && CrossUp[i] < CrossDown[i] && alertTag!=Time[0])
        {
       Alert("3MACross2GS going Up on ",Symbol()," M",Period(),"  @ ",Bid);
        alertTag = Time[0];
        } 
   
   //Comment("  CrossUp[0]  ",CrossUp[0]," ,  CrossDown[0]  ",CrossDown[0]," ,  prevtime  ",prevtime);
   //Comment("");
 
      if (Drawlines)
        {
         ExtMapBuffer1[i]= iMA(NULL,0,FastMA,  0, FastMAMode,  PRICE_CLOSE,i);

         ExtMapBuffer2[i]= iMA(NULL,0,MediumMA,0, MediumMAMode,PRICE_CLOSE,i);

         ExtMapBuffer3[i]= iMA(NULL,0,SlowMA,  0, SlowMAMode,  PRICE_CLOSE,i);
        }
 
 
     }
   return(0);
 }





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_ARROW

Implements a curve of type DRAW_LINE

Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen