Announcement

Collapse
No announcement yet.

Am I using valid array logic?

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

  • Am I using valid array logic?

    P.P.S. This is a 2nd edit.
    The code shown below boils down to the question "are the following 4 statements in the code shown below valid for storing and retrieving array elements"?
    MyArray[DAY_NUM,1] = day_date;
    MyArray[DAY_NUM,2] = open(0);
    array_element = MyArray[x,1];
    array_element = MyArray[x,2];




    P.S. This is an edit: I think maybe I should have submitted this to the EFS studies forum. Sorry about that.

    /* Am I using valid array logic?
    I am trying to access MyArray by row number and column number
    so I tried the following test which did not work (i.e) the element
    values retrieved in the "display array values" loop are unchanged
    and are the last day values repeated over and over again for the
    entire loop.
    The elements displayed in the Formula Output window are (for all 54 days)
    row54,column1 = 5/2/2008
    row54,column2 = 49.19
    */
    MyArray = new Array();
    var x;
    var array_element;
    var DAY_NUM=0;
    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("SHORT DEBUG TEST")
    setCursorLabelName("open", 0);
    }
    function main()
    {
    if (getBarState() == BARSTATE_NEWBAR) DAY_NUM=DAY_NUM+1;
    var day_date=month(0)+"/"+day(0)+"/"+year(0);
    MyArray[DAY_NUM,1] = day_date;
    MyArray[DAY_NUM,2] = open(0);
    if(DAY_NUM==54) //display array values
    //if(isLastBarOnChart)
    {
    for (x=0; x<=DAY_NUM; x++)
    {
    array_element = MyArray[x,1];
    debugPrint("row"+DAY_NUM+",column1 = "+array_element+"\n");
    array_element = MyArray[x,2];
    debugPrint("row"+DAY_NUM+",column2 = "+array_element.toFixed(2)+"\n");
    }
    }
    return open(0);
    }
    Last edited by jcm21; 05-04-2008, 06:44 PM.

  • #2
    Re: Am I using valid array logic?

    jcm21
    If you are trying to create a multidimensional array then that is not the correct syntax. You may want to reference the examples for multidimensional arrays provided by Jason and Jay in this thread. Also if you run a search using the keyword multidimension* you should find an extensive write-up on arrays (complete with sample scripts) that was compiled by Steve Hare
    Alex


    Originally posted by jcm21
    P.P.S. This is a 2nd edit.
    The code shown below boils down to the question "are the following 4 statements in the code shown below valid for storing and retrieving array elements"?
    MyArray[DAY_NUM,1] = day_date;
    MyArray[DAY_NUM,2] = open(0);
    array_element = MyArray[x,1];
    array_element = MyArray[x,2];




    P.S. This is an edit: I think maybe I should have submitted this to the EFS studies forum. Sorry about that.

    /* Am I using valid array logic?
    I am trying to access MyArray by row number and column number
    so I tried the following test which did not work (i.e) the element
    values retrieved in the "display array values" loop are unchanged
    and are the last day values repeated over and over again for the
    entire loop.
    The elements displayed in the Formula Output window are (for all 54 days)
    row54,column1 = 5/2/2008
    row54,column2 = 49.19
    */
    MyArray = new Array();
    var x;
    var array_element;
    var DAY_NUM=0;
    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("SHORT DEBUG TEST")
    setCursorLabelName("open", 0);
    }
    function main()
    {
    if (getBarState() == BARSTATE_NEWBAR) DAY_NUM=DAY_NUM+1;
    var day_date=month(0)+"/"+day(0)+"/"+year(0);
    MyArray[DAY_NUM,1] = day_date;
    MyArray[DAY_NUM,2] = open(0);
    if(DAY_NUM==54) //display array values
    //if(isLastBarOnChart)
    {
    for (x=0; x<=DAY_NUM; x++)
    {
    array_element = MyArray[x,1];
    debugPrint("row"+DAY_NUM+",column1 = "+array_element+"\n");
    array_element = MyArray[x,2];
    debugPrint("row"+DAY_NUM+",column2 = "+array_element.toFixed(2)+"\n");
    }
    }
    return open(0);
    }

    Comment


    • #3
      Thanks Alex.
      The results of my searchs in the last couple of days indicated to me that it all seemed so unnecessarily complicated that I decided to just create a one dimensional array for each column in an otherwise multi-dimensional array. Works fine for me [ie] it is simple & non-cumbersome.
      Why can't an array simply just be defined as multi-dimensional in one statement and that would be that [eg] my_array(10,10) ? That has worked wonderfully in other languages for half a century.
      However I am plenty happy with the editor and the language syntax.
      Thanks again.

      Comment

      Working...
      X