My Alert msg is sending too many Alerts, need help stopping it with one Alert.

 

The problem is that it's sending too many Alerts because the conditions are true for a long time. How can I get it to only send me one alert when it finds the conditions are true? Below is my code:


total = OrdersTotal(); if(total < 1) { if(cnt_buy ==2) { PlaySound("Alert.wav"); Alert("ALERT! Buy Now!! " + Symbol()); } if(cnt_sell == 2) { PlaySound("Alert.wav"); Alert("ALERT: Sell now!!! " + Symbol()); } } //---- return(0); }

 

//USE A GLOBAL VARIABLE


bool alert_buy_made=false;

bool alert_sell_made=false;


int start()


{

....

....


total = OrdersTotal();
if(total < 1)
{
if(cnt_buy ==2 && !
alert_buy_made)
{

PlaySound("Alert.wav");
Alert("ALERT! Buy Now!! " + Symbol());

alert_buy_made =true;

}

if(cnt_sell == 2 && !
alert_sell_made)
{
PlaySound("Alert.wav");
Alert("ALERT: Sell now!!! " + Symbol());

alert_sell_made=true;

}
}

//----

// this might have to be put other place.

alert_buy_made = (cnt_buy==2); // reset flag;

alert_sell_made = (cnt_sell==2); // reset flag;

return(0);
}

}

 
abstract_mind:

}

Ok, so I put in your modification and I'm getting 3-4 repeats from time to time but it's alot better than constant :) Here's what I have in now:


total = OrdersTotal();

if(total < 1)

{

if(cnt_buy ==2 && !alert_buy_made )

{

{

PlaySound("Alert.wav");

Alert("ALERT! Buy Now!! " + Symbol());

alert_buy_made =true;

}

alert1++;

}

if(cnt_sell == 2 && !alert_sell_made)

{

// Print("PRINT: Sell now...the conditions have been met");

PlaySound("Alert.wav");

Alert("ALERT: Sell now!!! " + Symbol());

alert_sell_made=true;

}

alert_buy_made = (cnt_buy==2); // reset flag;

alert_sell_made = (cnt_sell==2); // reset flag;

}

//----

return(0);

 

Probably other parts of the code may be modifying the values of cnt_buy and cnt_sell. If they are changed to a not 2 number, flags are set to false, enabling the alerts to fire, when the control variables are again assigned with value 2.

 
abstract_mind:

Probably other parts of the code may be modifying the values of cnt_buy and cnt_sell. If they are changed to a not 2 number, flags are set to false, enabling the alerts to fire, when the control variables are again assigned with value 2.

Well...cnt_buy and cnt_sell will vary between =0, 1, and 2.


The count changes based on the following code. Depending on what's going on...the "ADX(5) +DI" may be true so it will add 1 to the cnt_buy. If it's false it will be 0...and when it's true and SAR_DIRECTION= BOTTOM then it adds 1 to the counter and we end up with a buy scenario. So yes, it is changing above from 0 to 1 to 2 depending on the two indicators that I'm using.

int cnt_buy = 0;

int cnt_sell = 0;

if (

ADX5_DI_Plus_1Day < 11

) // good

cnt_buy++;

else

if (

ADX5_DI_Minus_1hr < 11 // good

)

cnt_sell++;

// And this too.....

if (SAR_DIRECTION == "BOTTOM")

cnt_buy++; // should = 5 by now...all conditions have been met

else

if (SAR_DIRECTION == "TOP")

cnt_sell++; //should = 2

 
rortiz77:

Well...cnt_buy and cnt_sell will vary between =0, 1, and 2.


The count changes based on the following code. Depending on what's going on...the "ADX(5) +DI" may be true so it will add 1 to the cnt_buy. If it's false it will be 0...and when it's true and SAR_DIRECTION= BOTTOM then it adds 1 to the counter and we end up with a buy scenario. So yes, it is changing above from 0 to 1 to 2 depending on the two indicators that I'm using.

int cnt_buy = 0;

int cnt_sell = 0;

if (

ADX5_DI_Plus_1Day < 11

) // good

cnt_buy++;

else

if (

ADX5_DI_Minus_1hr < 11 // good

)

cnt_sell++;

// And this too.....

if (SAR_DIRECTION == "BOTTOM")

cnt_buy++; // should = 5 by now...all conditions have been met

else

if (SAR_DIRECTION == "TOP")

cnt_sell++; //should = 2

Yeah I just verified that it's not giving me true alerts :(

An alert poped up telling me to buy and yet the counter was "0". Conditions were'nt met...but it still sent the alert.

 

//DELETE THESE LINES

alert_buy_made = (cnt_buy==2); // reset flag;

alert_sell_made = (cnt_sell==2); // reset flag;



// You might have a buy/sell section in your EA, so adjust the code to something like this:


...

if(now_performing_buy)

{

OrderSend(.....); // make the trade

alert_buy_made = false; // enable more alerts;


}

....

if(now_performing_sell)

{

OrderSend(.....); // make the trade

alert_buy_made = false; // enable more alerts;

}


In relation to not giving true results, you must realize that code works deterministically. That is, if you have the statement "if(cnt_buy ==2 && !alert_buy_made ){.... }", it only makes the alert IF AND ONLY IF cnt_buy=2 and alert_buy_made=false, and no chance to fire in other situation.

I can help you more if take a look to your complete code.

If you dont mind post it here, or send it to abstract.mind@hotmail.com



to the Moderator:

Hi Rosh, is it ok to post my email?

Reason: