Avoid alert when chart is updating

 

Hi everyone,

I would like to know if there is a way or if one of you has an idea on how to solve my issue.

I have an indicator which produce an alert when some criteras are met. Everything is working fine but when I closed my plateform and open it again later, the indicator is producing an alert at the same time the chart is updating as if it was real ticks.

How can I avoid this? Is there a function to delay the indicator as long as the chart is not updated? 

 Thanks a lot. 

 
fftremblay:

How can I avoid this? Is there a function to delay the indicator as long as the chart is not updated? 

You could try testing for error 4066

ERR_HISTORY_WILL_UPDATED4066Requested history data in updating state.
 
fftremblay: How can I avoid this? Is there a function to delay the indicator as long as the chart is not updated? 
  1. Fix the indicator. It should not generate an alert except on the first of bar 0 or 1
  2. Indicators can not wait.
 

Thanks for your replies. I tried to test it for the error 4066 at the beginning of the start function but the same problem happened. I Tried to delay the execution by saving TimeCurrent() into a variable during the initialization and testing the variable against TimeCurrent() + 5 at the beginning of the start function but it doesn't seem to work either.

 This is the code for the indicator. The indicator is showing an arrow, playing a sound and popping up an alert everytime we have a serie of "iBars" bearish or bullish candles

 Thanks for your help. 


#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red


extern int iBars = 3;

double tUpArrow[], tDownArrow[];

int iLastBar = 0;

int iDate;

bool bFirst;


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

//| Custom indicator initialization function                         |

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

int init()

  {

  IndicatorBuffers(2);

  SetIndexStyle(0, DRAW_ARROW);

  SetIndexStyle(1, DRAW_ARROW);

  SetIndexArrow(0, 241);

  SetIndexArrow(1, 242);

  SetIndexBuffer(0, tUpArrow);

  SetIndexBuffer(1, tDownArrow);   

  IndicatorDigits(Digits); 

  iDate = StrToTime(sDate);

  iLastBar = Time[0]; 

  bFirst = True;

  return(0);

  }

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

//| Custom indicator deinitialization function                       |

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

int deinit()

  {

  Comment("");  

  return(0);

  }

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

//| Custom indicator iteration function                              |

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

int start()

  {

  int i, y, iLimit; 

  int iCnt;

  int iCountedBars = IndicatorCounted();

  

  if(iCountedBars == 0)

    {

    for(i = Bars-1; i >= 0; i--)

      {

      tUpArrow[i] = EMPTY_VALUE;

      tDownArrow[i] = EMPTY_VALUE;

      }

    }   

    

  iLimit = Bars - iCountedBars - 1;   

   

  for(i = iLimit; i >= 0; i--)

    {

    y = i + 1;

    if(Close[y] < Open[y])

      {

      iCnt = 1;

      y++;

      while(True)

        {

        if(Close[y] > Open[y]) 

          break;

        iCnt++;

        if(iCnt == iBars 

          break;

        y++;

        if(y >= Bars - 1) 

          break;         

        }

      if(iCnt == iBars )

        {

        tDownArrow[i+1] = High[i+1] + 0.5 * iATR(NULL, 0, 21, i+1);   

        if(Time[i+1] != iLastBar && bFirst == False)

          {

          iLastBar = Time[i+1];

          Alert(iBars , " bearish candles on ", Symbol(), " at ", TimeHour(Time[0]), ":", TimeMinute(Time[0]), "!");    

          PlaySound("Alert.wav");

          }

        }

      }

    else

      {

      iCnt = 1;

      y++;

      while(True)

        {

        if(Close[y] < Open[y]) 

          break;

        iCnt++;

        if(iCnt == iBars) 

          break;

        y++;

        if(y >= Bars - 1) 

          break;         

        }

      if(iCnt == iBars)

        {

        tUpArrow[i+1] = Low[i+1] - 0.5 * iATR(NULL, 0, 21, i+1);

        if(Time[i+1] != iLastBar && bFirst == False)

          {

          iLastBar = Time[i+1];

          Alert(iBars , " bullish candles on ", Symbol(), " at ", TimeHour(Time[0]), ":", TimeMinute(Time[0]), "!");    

          PlaySound("Alert.wav");

          }

        }

      }     

    }

  bFirst = False;

  return(0);

  }

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

Reason: