Announcement

Collapse
No announcement yet.

Storing series results in an array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Storing series results in an array

    I'd like to calculate several series and store them in an array. See below. I don't get an error message with this but the debugPrintln command for xAverage doesn't work. It only returns "[object series]." So, I don't know how to reference individual values within this array. Any help will be appreciated. Thanks.

    var bInit = false;
    var xSymbol = new Array();
    var xAverage = new Array();
    var xList = new Array ("XOM","INTC","ORCL","IBM","MMM");

    function main() {
    if (getBarState() == BARSTATE_NEWBAR) {
    for (var i=0;i<5;i++) {
    xSymbol[i] = xList[i]+","+getInterval();
    xAverage[i] = ema(5,close(sym(xSymbol)));
    }
    }

    // Calculate some index with all these series
    debugPrintln(xSymbol[1]);
    debugPrintln(xAverage[1]);
    return; //calculated index (one number)
    }

  • #2
    Re: Storing series results in an array

    AssetHound
    There are a couple of errors in the following line of your code
    [i]xAverage = ema(5,close(sym(xSymbol)));
    1. You are always only passing the first symbol of the xSymbol array. You need to modify xSymbol to [i]xSymbol
    2. You are not assigning to [i]xAverage the value of the series but the series itself hence the [object series] returned to the Formula Output window by the efs engine. To accomplish what you want you need to also pass the bar index parameter to retrieve the value at the specific bar ie ema(5, close(sym(...)),0)
    See this thread for a complete set of examples on retrieving values directly (ie without using the getValue() method)
    Alex


    Originally posted by AssetHound
    I'd like to calculate several series and store them in an array. See below. I don't get an error message with this but the debugPrintln command for xAverage doesn't work. It only returns "[object series]." So, I don't know how to reference individual values within this array. Any help will be appreciated. Thanks.

    var bInit = false;
    var xSymbol = new Array();
    var xAverage = new Array();
    var xList = new Array ("XOM","INTC","ORCL","IBM","MMM");

    function main() {
    if (getBarState() == BARSTATE_NEWBAR) {
    for (var i=0;i<5;i++) {
    xSymbol[i] = xList[i]+","+getInterval();
    xAverage[i] = ema(5,close(sym(xSymbol)));
    }
    }

    // Calculate some index with all these series
    debugPrintln(xSymbol[1]);
    debugPrintln(xAverage[1]);
    return; //calculated index (one number)
    }

    Comment


    • #3
      Re: Re: Storing series results in an array

      Alexis -- Thanks very much. -- Bob

      Comment


      • #4
        Bob
        You are most welcome
        Alex


        Originally posted by AssetHound
        Alexis -- Thanks very much. -- Bob

        Comment

        Working...
        X