simple code help

 
Hi, I am not sure if the code below is correct. please help to correct it. thanks
it suppose to fire an alarm when I have an inside bar once the current bar is finished.

#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

#property indicator_chart_window
extern int inside=1;//1 once inside, 2 twice inside, else unArmed.

int inside_once_fired = 0;
int snooze = 0;
string inside_once_alarm = "insideOnce.wav";

int init() { return(0); }

int deinit() { return(0); }

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;
for(i = shift; i > 0; i--)
{
if( inside==1 && Low[1]>=Low[2] && High[1]<=High[2] && inside_once_fired < snooze) {PlaySound(inside_once_alarm); inside_once_fired++;}
}
return(0);
}
 
what I am trying to do is to fire the code only once after the current bar finishes drawing.
 
after setting snooze = 5;
the following only fires the alarm once, but I want it 5 times, how can I do this. i.e how can I fire the while block inside the start() before the start() fires again when a new tick is received?

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
if(shift == 2){
for(i = shift; i > 1; i--)
{
if( inside==1 && Low[1]>=Low[2] && High[1]<=High[2] ){
while( inside_once_fired < snooze ){
PlaySound(inside_once_alarm);
inside_once_fired++;
Sleep(1000);
}
}
}
}
//----
return(0);
}
 

Sleep() does not work in an Indicator, only Script or EA...

PlaySound()   repeatedly, without a delay, does not work well and may SEEM to only play once.

Replace

   ...
   Sleep(1000);
   ...

with

   ...
   int tickCount = GetTickCount();
   while(GetTickCount() < tickCount + 1000) {}
   ...