making the code wait "sleep"

 
Hi
I have the alert code below, I am expecting it to fire 5 times and then stop, I tried different version and played around with different blocks of code, but it is sounding once with the block 1 and twice with the block 2 as indicated in the code below. that is if I un_commnets the block 1, it sounds once, but if I un_commnets the block 2 and comment out block 1, it sounds twice.

thanks for helping

the code

//****************************************************
//+------------------------------------------------------------------+
//| alerts.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_chart_window
//---- input parameters
extern int inside=1;//1 once inside, 2 twice inside, else unArmed.
extern int out_direction=2; //1 out_up, -1 out_down, 0 either, else unArmed.
int snooze = 5;
int sleep_condition = 0;

int inside_once_fired = 0;
string inside_once_alarm = "insideOnce.wav";
int inside_twice_fired = 0;
string inside_twice_alarm = "insideTwice.wav";
string out_up_alert = "outUp.wav";
int out_up_fired = 0;
string out_down_alert = "outDown.wav";
int out_down_fired = 0;
string out_bar = "outBar.wav";
int out_fired = 0;
string stoch_buy_fired = "stochBuy.wav";
int stoch_buy = 0;
string stoch_sell_fired = "stochBuy.wav";
int stoch_sell = 0;
int tick_count;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
tick_count = GetTickCount();
// Comment(tick_count);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{


int counted_bars = IndicatorCounted();
if(counted_bars < 0) return (-1);
if(counted_bars > 0) counted_bars--; //last bar recounted
int i;
int shift = Bars - counted_bars - 1; // initially 2408, then 1, once closed it becomes 2, once a tick is received it turns 1
//Comment(inside_once_fired+" "+shift);
if(shift >= 2){
for(i = shift; i > 1; i--)
{
if( inside==1 && Low[1]>=Low[2] && High[1]<=High[2] ){


/*************BLOCK 1************************
while( inside_once_fired < snooze ){
PlaySound(inside_once_alarm);
while(GetTickCount() < tick_count + 5000) {}
inside_once_fired++;
}
*******************************************/


/*******************BLOCK 2******************
while( inside_once_fired < snooze && sleep_condition < 1){
sleep_condition = GetTickCount();
if( sleep_condition + 5000 > GetTickCount() ){
PlaySound(inside_once_alarm);
inside_once_fired++;
} else {
sleep_condition = 0;
}
}
*******************************************/
//inside = 0; //reset
}
else if( inside==2 && Low[1]>=Low[2] && High[1]<=High[2] && Low[2]>=Low[3] && High[2]<=High[3] ){while( inside_twice_fired < snooze ){ PlaySound(inside_twice_alarm); inside_twice_fired++; while(GetTickCount() < tick_count + 1000) {}} }
}
}
else if(shift == 1){
if(out_direction == 1 && Low[0] < Low[1] && Bid > High[1])while( out_up_fired < snooze ){PlaySound(out_up_alert);out_up_fired++; while(GetTickCount() < tick_count + 1000) {}}
else if( out_direction == -1 && High[0] < High[1] && Bid < Low[1]) while( out_down_fired < snooze ){PlaySound(out_down_alert);out_down_fired++; while(GetTickCount() < tick_count + 1000) {}}
else if( out_direction == 0 && ( (Low[0] < Low[1] && Bid > High[1])|| (High[0] > High[1] && Bid < Low[1]))) while( out_fired < snooze ){PlaySound(out_bar);out_fired++; while(GetTickCount() < tick_count + 1000) {}}

}
//----

return(0);
}
//+------------------------------------------------------------------+




//****************************************************
Reason: