Bollinger Bands Formula in C#, VB

Does anyone know of any sample code in either or C# for a bollinger band formula/calculation as described in this link :
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

gregoryyoungConnect With a Mentor Commented:
ok so to get your set for a bollinger band at a point you need to get the N samples prior to that point.

N can be defined as duration in minutes/5 (5 minute samples). An easy way to get this data would be to issue a query where time >= currentpoint - duration and time <= currentpoint

Once you have the set it is quite easy to do the calculation on it.

Your middle point is simply the average of all of the items in your set. The upper point is the mean raised by N standard deviations and the low point is the mean lowered by N standard deviations.

 to calculate ... you iterate through the set again calculating

foreach(Item in Set) {
    x = Item.Price - Average;
    sumxx += x * x;

this is the inner part the have given you (note you could also use stdev and avg in sql to do this).

we then take std = sumxx / n (n = number of items in the set)

Now we just add and subtract std from our middle line respectively (we can use a multiplier if we want it is represented by D in those equations)
bollinger bands are really simple to implement once you have a "moving" set ... do you currently have a moving set and if so can you place your code up?


andreasmanskeAuthor Commented:
I have a table, which i can turn into a dataset or datareader or some kind of array, which has the values in individual rows which are seperated by a span of 5 minutes as illustrated below
RowID=1  Euro=1.410  08/10/07 8:10:00PM
RowID=2  Euro=1.412  08/10/07 8:15:00PM
RowID=3  Euro=1.409  08/10/07 8:20:00PM
Forced accept.

EE Admin
All Courses

From novice to tech pro — start learning today.