How to prevent alert from firing more than once?

 

Hi all, I have this code below that is meant to fire an alert whenever a new S/R level is created. The problem I am having is that the alert fires over and over again, and I would like for it to only fire once. I figure the easiest way to solve this issue would be to take the value of the S/R level being created and add it to an array. The alert function could then check to see if the S/R level already exists in the array before firing.

Am I on the right track or is there another way to do this? Any help would be greatly appreciated.

void UpcomingTradeAlert(int tp_0, int tp_4) {

double newLevel = tro_211[tp_0][tp_4];

// need to add the value of newLevel to an array

if ( // array needs to be checked to see if value of newLevel has already been added before launching alert ) {

Alert("New S/R Level Created");

}

}

 
hyperseer:

Hi all, I have this code below that is meant to fire an alert whenever a new S/R level is created. The problem I am having is that the alert fires over and over again, and I would like for it to only fire once. I figure the easiest way to solve this issue would be to take the value of the S/R level being created and add it to an array. The alert function could then check to see if the S/R level already exists in the array before firing.

Am I on the right track or is there another way to do this? Any help would be greatly appreciated.

void UpcomingTradeAlert(int tp_0, int tp_4) {

double newLevel = tro_211[tp_0][tp_4];

// need to add the value of newLevel to an array

if ( // array needs to be checked to see if value of newLevel has already been added before launching alert ) {

Alert("New S/R Level Created");

}

}


Place a counting in your indicator

 
Thanks for the response, but that won't work because there can be multiple S/R levels on a chart - it needs to fire once, but for each S/R level. So instead of a counter, I need to store the actual value somewhere so I can test if the alert has already gone off for that value.
 
Use an Array, one entry for each level, and use a value for each level to tell you if it has been Alerted or not.
 
RaptorUK:
Use an Array, one entry for each level, and use a value for each level to tell you if it has been Alerted or not.

Thanks RaptorUK - that's what I figured. But I am a total newbie when it comes to MQL4 so I'm not really sure how to code that.
Reason: