Why is my IF statement not working? Help please ....

 
#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 10
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_color3 DodgerBlue
//---- input parameters
extern int       BB_Period=20;
extern double    BB_Var=2;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    ExtCountedBars=IndicatorCounted();
   int BuySig[],SellSig[];
   int i,limit;
   double Ratio;
   // basic checks
   if (ExtCountedBars<0) return(-1);
   //---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   if(Bars<100)
      {
         Print("bars less than 100");
         return(0);
      }
   limit=Bars-ExtCountedBars-1;

   for (i=0; i<=limit; i++)
      {  
         //----Calculate Buy and Sell signals on 5-min timeframe
            Ratio=iClose(NULL,PERIOD_M5,i+1)/iBands(NULL,PERIOD_M5,BB_Period,BB_Var,0,PRICE_CLOSE,MODE_LOWER,i+1);
            if ((iClose(NULL,PERIOD_M5,i+1)/iBands(NULL,PERIOD_M5,BB_Period,BB_Var,0,PRICE_CLOSE,MODE_LOWER,i+1))<1)
               {
                  BuySig[i]=1;
                  Print("Ratio="+iClose(NULL,PERIOD_M5,i+1)/iBands(NULL,PERIOD_M5,BB_Period,BB_Var,0,PRICE_CLOSE,MODE_LOWER,i+1)+" BuySig["+i+"]="+BuySig[i]);
               }
            if (iClose(NULL,PERIOD_M5,i+1)/iBands(NULL,PERIOD_M5,BB_Period,BB_Var,0,PRICE_CLOSE,MODE_UPPER,i+1)>1)
               {
                  SellSig[i]=1;
               }
//----End Signal Calculations
         ExtMapBuffer1[i]=BuySig[i];
         ExtMapBuffer2[i]=SellSig[i];
         ExtMapBuffer3[i]=BuySig[i]-SellSig[i];
      }
   return(0);
  }
//+------------------------------------------------------------------+

Dear All,

I feel a little stupid here, but am stumped as to why my IF statement is not working...any help is appreciated.

 
What exactly is not working in the if statement? As of now both if statements are run, are you looking for if...else if?
 

I think you have error - devide zero.

Try to change a little:

double band=iBands(NULL,PERIOD_M5,BB_Period,BB_Var,0,PRICE_CLOSE,MODE_LOWER,i+1);
if(band!=0) Ratio=iClose(NULL,PERIOD_M5,i+1)/band;

 
jmca wrote >>
What exactly is not working in the if statement? As of now both if statements are run, are you looking for if...else if?

Roger
wrote
>>

I think you have error - devide zero.

Try to change a little:

double band=iBands(NULL,PERIOD_M5,BB_Period,BB_Var,0,PRICE_CLOSE,MODE_LOWER,i+1);
if(band!=0) Ratio=iClose(NULL,PERIOD_M5,i+1)/band;

Dear Roger and jmca,

Thanks for your quick responses...I did add the zero divide check...but here is what was wrong on top of that zero divide...

1. I was not looping to correct bar value

=> Changed limit=Bars-ExtCountedBars-1; to limit=Bars-ExtCountedBars-2;

2. I was using SellSig/BuySig as arrays and then assigning their values to buffer arrays

=> Changed int BuySig[],SellSig[]; to int BuySig,SellSig;

Now, the code works correctly and shows the buffers mapped on the chart...

Thanks once again for your help!

best,

Maratha