RSI Sound Alert Loop -- need it to stop after 'x' times

 

Hi!

Thanks for your help. I know this is probably super simple but I'm stumped.

I would like to modify the RSI Sound Alert with loop below to add a counter, whereby after 'x' times the alert will stop. I would like the 'x' to be a user input. I took a stab at it but am getting an error ("i" variable already defined).

I added:

extern int Count = 50;

and

for(int i=Count();i>=0;i--)

Could you please help me to modify my code?

Thank you kindly,

Leftcoaster


extern bool UseSound = True;
extern int rsiPeriod = 14;
extern int OverBought = 70;
extern int OverSold = 30;
double RSI;
double Condition;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

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

RSI= iRSI(Symbol(),0,rsiPeriod,PRICE_CLOSE,0);
Condition = 0;

if (RSI>=OverBought)Condition = 1;
if (RSI<=OverSold)Condition = -1;
if (Condition == 1)
{
if (UseSound == true)Alert (Symbol()+ " RSI Over Bought @ "+RSI);
if (UseSound == true)PlaySound ("Alert2.wav");
}
if (Condition == -1)
{
if (UseSound == true)Alert (Symbol()+ " RSI Over Sold @ "+RSI);
if (UseSound == true)PlaySound ("Alert2.wav");
}

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

 
int start()
{
int 
   Local_Count = Count;
static int 
   User_Notified;
//----
   RSI= iRSI(Symbol(),0,rsiPeriod,PRICE_CLOSE,0);
   if (RSI>=OverBought){
      Condition = 1
      if(User_Notified!=Condition){
         User_Notified=Condition;
         if (UseSound == true){
            Alert (Symbol()+ " RSI Over Bought @ "+RSI);
            While(Local_Count>=0){
               PlaySound ("Alert2.wav");
               Local_Count--;
            }
         }
      }
   }
   if (RSI<=OverSold){
      Condition = -1
      if(User_Notified!=Condition){
         User_Notified=Condition;
         if (UseSound == true){
            Alert (Symbol()+ " RSI Over Bought @ "+RSI);
            While(Local_Count>=0){
               PlaySound ("Alert2.wav");
               Local_Count--;
            }
         }
      }
   }
//----
return(0);
}
//+------------------------------------------------------------------+
Added the User_Notified to prevent this giving you a constant warning. This way it should only give the warning(50 times!!) once when the condition changes.