Bollinger Bands Formula in C#, VB

Posted on 2007-10-16
Last Modified: 2013-12-17
Does anyone know of any sample code in either or C# for a bollinger band formula/calculation as described in this link :
Question by:andreasmanske
    LVL 37

    Expert Comment

    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?



    Author Comment

    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
    LVL 37

    Accepted Solution

    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)
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now