Help about Bollinger Bandwidth and %B

 

Hi everyone, I need a help to write a funcion that give back the BBW value, so I have few question:

- to calculate correctly BBW i can use the formula (BBU-BBL)/BBM, upper-lower/medium value. Now the question is: to calculate those values is necessary to use a buffer isn't it?

- if I use a buffer the value needed is the last one? so I put the last one in the formula over there and that gives me back the BBW referred to the specific period?

- for the %b I have to do the same changing only the formula to calculate it?

I asked about that cause i've tried to do with


   BBU=0;
   BBU=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
   // Print("value BBU: ",BBU);
   BBL=0;
   BBL=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
   // Print("value BBL: ",BBL);
   BBM=0;
   BBM=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0);
   // Print("value BBM: ",BBM);
   BBW=0;
   BBW=((BBU-BBL)/BBM)*MathPow(10,Digits);

   Print("value BBW: ",BBW);

  // second mode to calculate

   BBWdirect=0;
   BBWdirect=((iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0)-iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0))/iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0))*MathPow(10,Digits);
   Print("value BBWdirect: ",BBWdirect);
  

but the risult is not that I've expected, so mine was a concept error?

Thank's to all