I'm trying to create a bar timer that will play a WAV file 30seconds before the bar completes. This is to get my attention.
I have tried the following code but it does not work correctly. The idea is that it plays once at 30 seconds and again at 10 seconds.
Looking at the two flags FirstAlarmPlayed and SecondAlarmPlayed with the Print statement, they are getting set an cleared at the correct times but the Playsound is not doing anything.
If I remove the checking of the flags in the IF statement, it does play the sound multiple times until a new bar is created.
By the way, I'm using 5 min bars.
Code: Select all
{
Type - Indicator
Name - NWT Bar Timer
Desc - This indicator plays sounds to indicate an alarm prior to a new bar being displayed
Written by Neil Wrightson
Version Date Reason
1 08/02/2011 Start
}
Inputs: En_FirstAlarm(1),FirstAlarm(30),FirstAlarm_WAV_File("C:\Sounds\Alert4.WAV");
Inputs: En_SecondAlarm(1),SecondAlarm(10),SecondAlarm_WAV_File("C:\Sounds\Alert2.WAV");
Variables : FirstAlarmPlayed(0),SecondAlarmPlayed(0);
Variables : L_AlarmTime(0),L_Currenttime(0);
L_Currenttime = el_timetodatetime_s(currenttime_s) ;
L_AlarmTime = (el_timetodatetime_s(time_s) - el_timetodatetime_s(FirstAlarm)) ;
if (L_Currenttime > L_AlarmTime) AND (FirstAlarmPlayed=0) then
begin
PlaySound(FirstAlarm_WAV_File);
FirstAlarmPlayed = FirstAlarmPlayed + 1 ;
end;
if el_timetodatetime_s(currenttime_s) < (el_timetodatetime_s(time_s) - el_timetodatetime_s(FirstAlarm)) then
FirstAlarmPlayed = 0;
if (el_timetodatetime_s(currenttime_s) > (el_timetodatetime_s(time_s) - el_timetodatetime_s(SecondAlarm))) AND (SecondAlarmPlayed=0) then
begin
PlaySound(SecondAlarm_WAV_File);
SecondAlarmPlayed = SecondAlarmPlayed + 1 ;
end;
if el_timetodatetime_s(currenttime_s) < (el_timetodatetime_s(time_s) - el_timetodatetime_s(SecondAlarm)) then
SecondAlarmPlayed = 0;
print(currenttime_s,FirstAlarmPlayed,SecondAlarmPlayed," ",L_AlarmTime:1:10," ",L_Currenttime:1:10) ;