Squeeze function

 

Hi, i want to calculate the average of bb bands difference (Bandhigh-BandLow) for a variable set of bars. If last band difference (0) is < than the average, we have a squeeze.

I have done the following code but I have errors:

int IsSqueeze(){
   double lastvalue=0,sum=0,bbaverage=0;
   int i,temp;
   temp=0
   for(i=1;i<SqueezeFilterBars;i++)
   {
      sum+=iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_UPPER,i)
          -iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_CLOSE,i);
        }
        bbaverage=sum/SqueezeFilterBars;   
   lastvalue=iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_UPPER,0)
         -iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_CLOSE,0);
   if (lastvalue<bbaverage) 
      temp= 1;
   if (lastvalue>bbaverage) 
      temp= 0;
   if (lastvalue==bbaverage)
      temp= 2;              
   return temp;   
}
 

This is an MQL4 topic. MODE_CLOSE is not supported on iBands, only MODE_MAIN, MODE_UPPER or MODE_LOWER.

And you didn't tell anything about these errors.

 
Have u a code for help to detech squeeze? thx for your attention.
 
lippmaje:

This is an MQL4 topic. MODE_CLOSE is not supported on iBands, only MODE_MAIN, MODE_UPPER or MODE_LOWER.

And you didn't tell anything about these errors.

it is an error...

int IsSqueeze(){
   double lastvalue=0,sum=0,bbaverage=0;
   int i,temp;
   temp=0
   for(i=1;i<SqueezeFilterBars;i++)
   {
      sum+=iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_UPPER,i)
          -iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_LOWER,i);
        }
        bbaverage=sum/SqueezeFilterBars;   
   lastvalue=iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_UPPER,0)
         -iBands(Symbol(),0,BandsPeriod,BandsDeviation,BandsShift,PRICE_CLOSE,MODE_LOWER,0);
   if (lastvalue<bbaverage) 
      temp= 1;
   if (lastvalue>bbaverage) 
      temp= 0;
   if (lastvalue==bbaverage)
      temp= 2;              
   return temp;   
}
 
error in for....semicolon expected, but I don't understand where...I see semicolons...
 
code looks good to go... just put the semicolon to the line preceeding the for
 
andy60:

Hi, i want to calculate the average of bb bands difference (Bandhigh-BandLow) for a variable set of bars. If last band difference (0) is < than the average, we have a squeeze.

I have done the following code but I have errors:

Why don't you simply use standard deviation instead (since that is what you are going to get in the end)?
 
Mladen Rakic:
Why don't you simply use standard deviation instead (since that is what you are going to get in the end)?

I am a newbee...I will try..thx

Reason: