Visokio website     Downloads     Video tutorials     KnowledgeBase  
Formulae: Moving Average on the previous row's result? - Visokio Forums
Formulae: Moving Average on the previous row's result?
  • Oke369 April 23, 2014 11:11AM
    Good day
    Please can you assist, basically I have attached 3 files, Automation Excel, I am trying to replicate this formula on Omniscope. if you look at k17 the formula is a moving average, then in cell k18 the formula changes by referencing cell k17 and then Adding a few variables.

    In stock I've added a few of my failed attempts at the formula, I would just like clarity on where I'm going wrong. I manage to get the first 3 results. correct but then it seems to loop?
    Please let me know if you need anything else.
    thank you, Stephen
  • 3 Comments
  •     paola April 23, 2014 11:57AM
    Moving average calculation is relying on order for reference, and for this purpose you can use Currentrow() or Rank another field, such as [Date].

    Previous Close = SUBSET_SUM([Close], Subset([Row],[Row]-1,"="))
    # establishing the previous value, with [Row] reference

    Quick formula for n=14:
    SUBSET_SUM([Close],
    Subset2([Row],[Row],[Row],[Row]-13,"<=",">=")
    )/14

    It is better to include a safeguard IF function and Intersection function
    IF([Row]<14,
    null,
    SUBSET_SUM([Close],
    INTERSECTION(SUBSET([Row],[Row],"<="),SUBSET([Row],[Row]-13,">=")))
    /14
    )

    Here is a link for the Subset functions: http://www.visokio.com/kb/subset-functions
    There are several other forum posts offering examples how to calculate moving averages:
    http://forums.visokio.com/discussion/comment/6201/#Comment_6201
    http://forums.visokio.com/discussion/1522
    http://forums.visokio.com/discussion/comment/4522/#Comment_4522
  • Oke369 April 23, 2014 2:30PM
    HI Paola,
    Thank you, However I'm struggling with the next bit of logic, the K18 formula. i.e. it's to Take ((K17*13)+gain)/14. I see that for row 17, 18 works but not further than that.
  •     paola May 8, 2014 6:42AM
    That is a self-referencing formula, where result of each cell is product of result in the cell above (same field). It is possible to achieve this using a scripting formula:
    SCRIPT(`
    var a0 = formula("CELL([A0],"+currentrow+")");
    var n = formula("CELL([i],"+currentrow+")");
    var val;
    var str;
    if (a0==null || n==null) {
    val = 0;
    str = "";
    } else {
    var val = Math.pow(13/14, n)*a0;
    var str = "13/14^"+n+"*"+a0;
    for (var row = 1; row <= allrecordcount; row++) {
    var iRow = formula("CELL([I],"+row+")");
    var gRow = formula("CELL([G],"+row+")");
    if (iRow!=null && iRow <= n) {
    val += Math.pow((13/14), n-iRow)*gRow/14;
    str += " + (1/14)^"+(n-iRow+1)+"*"+gRow;
    }
    }
    }
    val;
    `, "currentrow", CURRENTROW(), "allrecordcount", ALLRECORDCOUNT())

    [AO] is the first value, [I] is row number field and [G] is gain.
    File is attached.

Welcome!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership