EA generates too many alerts

 

hi all, i just finished writing an EA. the EA works just fine, only that it generates many alerts. every time after the conditions have been met(crossovers) if there is a movement in the 5th digit there is an alert. Isn't the shift field used to take values from "x" bars relative to the current one? if so, then what may be the possible reasons for multiple alerts.

PS:i am using icustom function and the shift value is 1.

 

Because your code dictates that an alert is sent every tick.

Only send an alert when conditions are met and only when a new bar opens

 

You could try something like this

static datetime newbar;

if(newbar!= Time[0])
  {
  //code to check conditions
  //send alert if conditions met
  newbar=Time[0]
  }
 
@gumrai: well first of all thanks for guiding me there. i have incorporated the check new bar thing into my code. however there is another problem. my EA works on crossovers. every time a new bar is formed, it sends the alert. but after the crossover one of the output parameter(x1) stays above the other parameter(x2) until another crossover occurs. and since my EA checks if (x1>x2) every time a new bar is formed and x1>x2 there is an alert. could you please guide me how do i restrict the EA to give only one alert per cross over.
 
cryptex:
@gumrai: well first of all thanks for guiding me there. i have incorporated the check new bar thing into my code. however there is another problem. my EA works on crossovers. every time a new bar is formed, it sends the alert. but after the crossover one of the output parameter(x1) stays above the other parameter(x2) until another crossover occurs. and since my EA checks if (x1>x2) every time a new bar is formed and x1>x2 there is an alert. could you please guide me how do i restrict the EA to give only one alert per cross over.


You need to check the previous bar as well

ie.

if (x1 > x2  &&  x2 < x3 ) 
 
had thought of that condition(albeit with a less than equal to inequality). pardon me for my ignorance, but wouldn't it cause me trouble every time i open the terminal or reloaded the EA?
 
cryptex:
had thought of that condition(albeit with a less than equal to inequality). pardon me for my ignorance, but wouldn't it cause me trouble every time i open the terminal or reloaded the EA?

Sorry, it was not clear, probably better to use x and y
if (x1 > y1  &&  x2 < y2 )
 
cryptex: since my EA checks if (x1>x2) every time a new bar is formed
x1 > x2 is not a check for a cross, you need 4 values. Use descriptive names not x1
double slow_curr = ... 1),
       slow_prev = ... 2),
       fast_curr = ... 1),
       fast_prev = ... 2);
bool  isAbove = fast_curr > slow_curr,
     wasAbove = fast_prev > slow_prev;
if(isAbove != wasAbove){ // has crossed
 

WHRoeder:
x1 > x2 is not a check for a cross, you need 4 values. Use descriptive names not x1

double slow_curr = ... 1),
       slow_prev = ... 2),
       fast_curr = ... 1),
       fast_prev = ... 2);
bool  isAbove = fast_curr > slow_curr,
     wasAbove = fast_prev > slow_prev;
if(isAbove != wasAbove){ // has crossed

This is way beyond my comprehension.

How can a double =...1) ?

I'm not disputing, just don't understand.

 
GumRai:

This is way beyond my comprehension.

How can a double =...1) ?

I'm not disputing, just don't understand.

. . . ., 1) represents the iCustom() call
 
iCustom(..., 1) iMA(..., 1) whatever your lines come from.
Reason: