// LindencourtFX Signal
// modified by San May 31, 2010

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
double dva[];
double tri[];

string SignalText;

extern bool       RepeatSignals        = false;
extern int        CountBars            = 5000;
extern bool       AlertON              = true;
int Alert_Count = 0;
datetime    Prior_Time;

int init() {
  SetIndexStyle(0, DRAW_ARROW, 3);
  SetIndexArrow(0, 233);
  SetIndexBuffer(0, CrossUp);
  SetIndexStyle(1, DRAW_ARROW, 3);
  SetIndexArrow(1, 234);
  SetIndexBuffer(1, CrossDown);      
  SetIndexBuffer(2, dva);      
  SetIndexBuffer(3, tri);    
    
   return (0);
}

int deinit() {
   return (0);
}

int g_last_bar_time = 0;

int start() {
  if (g_last_bar_time == Time[0]) {return(0);} else {g_last_bar_time = Time[0];} //

   int counted_bars=IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
 
   if (iTime(Symbol(),Period(),1) != Prior_Time)
    {
     Prior_Time = iTime(Symbol(),Period(),1);
     Alert_Count = 0;
    }
   else
    {
     return;
    }   
   
   int limit = MathMin(Bars-counted_bars,CountBars);
   
   for (int i=limit; i>=0; i--)
   {
   
      double formula00 = iCustom(NULL,0,"BandsRSI",8,30,3,i); 
      double formula01 = iCustom(NULL,0,"BandsRSI",8,30,3,i+1);
      double formula02 = iCustom(NULL,0,"BandsRSI",8,30,3,i+2);      
      double formula10 = iCustom(NULL,0,"BandsRSI",8,30,1,i); 
      double formula11 = iCustom(NULL,0,"BandsRSI",8,30,1,i+1);      
      double formula20 = iCustom(NULL,0,"BandsRSI",8,30,2,i); 
      double formula21 = iCustom(NULL,0,"BandsRSI",8,30,2,i+1);   
      double ssrc = iCustom(NULL,0,"SSRC",3,21,2.0,6,0,i);      
      double ssrc1 = iCustom(NULL,0,"SSRC",3,21,2.0,6,0,i+1);                      
                             
      if(formula00>formula20 && formula01<formula21 && ssrc<-0.75 && (formula00<30 || formula01<30 || formula02<30)) { // long conditions
         if(RepeatSignals){
            CrossUp[i]=Low[i]-25 * Point;
            if (i<=1) {
            if (AlertON == 1 && Alert_Count == 0) Alert("BUY Signal: " + Symbol());}
            }
         else if(CrossUp[i+1] == EMPTY_VALUE){
            CrossUp[i]=Low[i]-25 * Point;
            if (i<=1) {
            if (AlertON == 1 && Alert_Count == 0) Alert("BUY Signal: " + Symbol());}
            }
      }
      else if(formula00<formula10 && formula01>formula11 && ssrc>0.75 && (formula00>70 || formula01>70 || formula02>70)) { // short conditions
         if(RepeatSignals){
            CrossDown[i]=High[i]+25 * Point;
            if (i<=1) {
            if (AlertON == 1 && Alert_Count == 0) Alert("SELL Signal: " + Symbol());}
            }
         else if(CrossUp[i+1] == EMPTY_VALUE){
            CrossDown[i]=High[i]+25 * Point;
            if (i<=1) {
            if (AlertON == 1 && Alert_Count == 0) Alert("SELL Signal: " + Symbol());}
            }
      }
   }
   return (0);
}

