Get 1 notification per 2 consecutive bars (30 mins for timeframe 15 min)

To add comments, please log in or register
TienGrT
43
TienGrT  

Kindly help me this issue.

Below is MA cross alert, but I got too many messages per 1 same notification.

I just wanna get 1 notification per 2 consecutive bars, it means number of bars is 2 to skip before next alert.

How can I do, kindly help me. Thank you so much



//+------------------------------------------------------------------+

//|                MA Cross Arrows.mq4                               |

//|                Copyright © 2006  Scorpion@fxfisherman.com        |

//+------------------------------------------------------------------+

#property copyright "FxFisherman.com"

#property link      "http://www.fxfisherman.com"



#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 Blue

#property indicator_color2 White

#property indicator_color3 Red



extern int Crossed_Pips = 0;

extern int MA_Period = 21;

extern int MA_Type = MODE_SMA;

extern int Shift_Bars=0;

extern int Bars_Count= 1000;

int state;

  

//---- buffers

double v1[];

double v2[];

double v3[];

  





int start()

 {

  double ma;

  int previous;

  int i;

  int shift;

  bool crossed_up, crossed_down;

  int totalBars = Bars - (MA_Period * 2);

  

  if (Bars_Count > 0 && Bars_Count <= totalBars)

  {

    i = Bars_Count;

  }else if(totalBars <= 0 ) {

    return(0);

  }else{

    i = totalBars;

  }

  

  while(i>=0)

   {

    shift = i + Shift_Bars;

    ma = iMA(Symbol(), Period(), MA_Period, 0, MA_Type, PRICE_CLOSE, shift);

    crossed_up = High[shift] >= (ma + (Crossed_Pips * Point));

    crossed_down = Low[shift] <= (ma - (Crossed_Pips * Point));



    v1[i] = NULL;

    v2[i] = NULL;    

    v3[i] = ma;

    if (crossed_up && previous != 1) {

      v1[i] = ma + (Crossed_Pips * Point);

      previous = 1;

    }else if(crossed_down && previous != 2){

      v2[i] = ma - (Crossed_Pips * Point);

      previous = 2;

    }

 

    i--;

   }

   

   ma = iMA(Symbol(), Period(), MA_Period, 0, MA_Type, PRICE_CLOSE, 0);

   if (Close[0] >= ma + (Crossed_Pips * Point) && state != 1) { 

      state = 1;

      SendNotification(Symbol() + "M"+_Period + " Price crossed UP EMA21.");

   }else if (Close[0] <= ma - (Crossed_Pips * Point) && state != -1) {

      state = -1;

      SendNotification(Symbol() + "M"+_Period + " Price cross DOWN the EMA21.");

   }



   return(0);

 }
To add comments, please log in or register