Playsound from Indicator

 
How do you set an alert/playsound to go off when an indicator hits it's extremes? I've tried to insert:

//---- PlaySound
if(k<0.01) PlaySound("sample.wav");
if(k>99.99) PlaySound("sample.wav");
return(0);
}

at then end of my Stochastic.mq4 file but it does not seem to work.
 
k is just a loop counter. insert function in a proper place.
 
irusoh1:
k is just a loop counter. insert function in a proper place.
Thanks for the reply. OK, Compiler says OK, but it still does not work. Here is the end of my Stochastic.mq4 file.


//---- %K line
i=Bars-draw_begin1;
if(counted_bars>draw_begin1) i=Bars-counted_bars-1;
while(i>=0)
{
double sumlow=0.0;
double sumhigh=0.0;
for(k=(i+Slowing-1);k>=i;k--)
{
sumlow+=Close[k]-LowesBuffer[k];
sumhigh+=HighesBuffer[k]-LowesBuffer[k];
}
if(sumhigh==0.0) MainBuffer[i]=100.0;
else MainBuffer[i]=sumlow/sumhigh*100;
i--;
}
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//---- signal line is simple movimg average
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MainBuffer,Bars,DPeriod, 0, MODE_SMA, i);
//---- PlaySound
if(MainBuffer[i]<20.00) PlaySound("sound.wav");
if(MainBuffer[i]>80.00) PlaySound("sound.wav");
return(0);
}
 
maybe you should change i to 0 then it will play on last bar
 
irusoh1:
maybe you should change i to 0 then it will play on last bar
Thanks irusoh1 for your help. I got it to work with MainBuffer[0], and saving it in my custom indicators folder. It works by playing the "sound.wav" at each price change whenever the Stochastic exceeds my set limits. Simple task, but it took me a long time to get it to work. I think it would be a nice feature to add more functionality to the Alert Editor in the terminal so as to include indicators too. Thanks again.
Reason: