i need help in this code....very importnant

 
hi guys ;

iam new in this mql4 i want a code prevent appearing the repeated signal

if my indicator gave buy signal i find lots of buy signals i just want one signal buy and when the indicator

gives sell sungnal i want one signal ;;; i know i can make it crossing the lines but i want the code

to use it in any indicators in future

 
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
//---- input parameters
extern int FasterEMA = 4;
extern int SlowerEMA = 8;
extern bool   enableAlert = true;
//---- buffers
double buySignal[];
double sellSignal[];
double ExtMapBuffer[];
static datetime lastAlertTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
 
   SetIndexBuffer(0, buySignal);
   SetIndexBuffer(1, sellSignal);
 
   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
   
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
   
   ArraySetAsSeries(ExtMapBuffer, true);
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   for (int i = Bars - IndicatorCounted(); i >= 0; i--)
   {
      double ali1 =    iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE,i);
      double ali2 =   iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE,i+1);
      
      
      
      double displacement = GetArrowDisplacement(i);
   
      if (ali1>ali2 )
      {
         buySignal[i] = Low[i+1] - displacement;
         if (enableAlert == true && i == 0)
            SignalAlert("Buy signal On: ");
      }
      
      if (ali1<ali2 )
      {
         sellSignal[i] = High[i+1] + displacement;
         if (enableAlert == true && i == 0)
            SignalAlert("Sell signal On: ");
      }      
 
   }
 
   return(0);
}
//+------------------------------------------------------------------+
void SignalAlert(string message)
{
   if (Time[0] != lastAlertTime)
   {
      Alert(message, Symbol(), ", ", Period(), " Minutes chart");
      lastAlertTime = Time[0];
   }
}
//+------------------------------------------------------------------+
double GetArrowDisplacement(int i)
{
   double high = iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_HIGH, i);
   double low = iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_LOW, i);
   
   return ((high - low) / 2);
}
//+------------------------------------------------------------------+
 
I don't know where did you get this indicator but this one is a poor modification of 5/8 EMA Crossover indicator. Look for the original in forexfactory.com in Trading System forum and compare it with yours. You'll know how to get rid of all those redundant arrows.
 

Use a flag:


      static int direction = 0; // 1 = buy signal active, -1 = sell signal active
 
      if (ali1>ali2  && direction != 1)
      {
         direction = 1;
         buySignal[i] = Low[i+1] - displacement;
         if (enableAlert == true && i == 0)
            SignalAlert("Buy signal On: ");
      }
      
      if (ali1<ali2  && direction != -1)
      {
         direction = -1;
         sellSignal[i] = High[i+1] + displacement;
         if (enableAlert == true && i == 0)
            SignalAlert("Sell signal On: ");
      }
 
phy:

Use a flag:


      static int direction = 0; // 1 = buy signal active, -1 = sell signal active
 
      if (ali1>ali2  && direction != 1)
      {
         direction = 1;
         buySignal[i] = Low[i+1] - displacement;
         if (enableAlert == true && i == 0)
            SignalAlert("Buy signal On: ");
      }
      
      if (ali1<ali2  && direction != -1)
      {
         direction = -1;
         sellSignal[i] = High[i+1] + displacement;
         if (enableAlert == true && i == 0)
            SignalAlert("Sell signal On: ");
      }
it works................thanksssssssssssssssssssss
 

Yup.

Reason: