Announcement

Collapse
No announcement yet.

Is this code to save historical values valid?

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

  • Is this code to save historical values valid?

    Is the following logic valid for retaining computed historical values? [the chart is a daily bar chart].
    Define my_historical_array.
    Define an array pointer.
    Then in Main, increment the array pointer, store some computed value in the array and set a variable equal to some historical value.
    When I try it the eSignal program freezes up [ie] becomes non-responsive?

    //Sample skeleton code is as follows:
    ...
    ...
    var my_historical_array=new Array;
    var array_ptr=0;
    ...
    ...
    function preMain()
    {
    ...
    ...
    }
    function main()
    {
    ...
    ...
    array_ptr=array_ptr+1;
    ...
    ...
    my_historical_array(array_ptr)=some_computed_value ;
    output1=my_historical_array(array_ptr-2);
    ...
    ...
    return output1;
    }
    Last edited by jcm21; 12-26-2007, 10:13 PM.

  • #2
    Here is an update

    I am working to find my coding error - but so far no luck.

    Here is an update:

    I included a logic to check on BARSTATE_NEWBAR even though I wonder if the check is necessary because it is a daily bar chart:
    if(getBarState()==BARSTATE_NEWBAR)
    {output1_dm1=output1;} //<-- dm1 means "day minus 1"

    I verified that output1_dm1 is declared globally.

    Then I verified that a new value for output1 is computed AFTER output1_dm1 is updated from output1.

    debugPrintln() then shows that the new value for output1 is as expected ....... BUT OUTPUT1 IS ALWAYS ZERO????


    after

    Comment


    • #3
      jcm21
      Make sure that also output1 is declared globally
      As to the value of output1 being always 0 you need to post your code for someone to be able to assist you
      With regards to the code you posted in the previous message there are various errors in the use of the array
      In creating the array you omitted to include the () in the constructor ie.
      var my_historical_array=new Array; should be var my_historical_array=new Array();
      When referencing the elements of an array you used parenthesis () instead of square brackets [] ie
      my_historical_array(array_ptr) should be my_historical_array[array_ptr]
      For information on the Array Object see this article in the Core JavaScript Guide and this article in the Function Reference
      Alex


      Originally posted by jcm21
      I am working to find my coding error - but so far no luck.

      Here is an update:

      I included a logic to check on BARSTATE_NEWBAR even though I wonder if the check is necessary because it is a daily bar chart:
      if(getBarState()==BARSTATE_NEWBAR)
      {output1_dm1=output1;} //<-- dm1 means "day minus 1"

      I verified that output1_dm1 is declared globally.

      Then I verified that a new value for output1 is computed AFTER output1_dm1 is updated from output1.

      debugPrintln() then shows that the new value for output1 is as expected ....... BUT OUTPUT1 IS ALWAYS ZERO????


      after

      Comment


      • #4
        to Alex, a valuable resource

        Thanks,

        You hit the nail right on the head. Once again you have saved the day. In this case [ ] vs. ( ) was the main lesson.

        Comment


        • #5
          jcm21
          You are most welcome and I am glad to have been of help
          Alex


          Originally posted by jcm21
          Thanks,

          You hit the nail right on the head. Once again you have saved the day. In this case [ ] vs. ( ) was the main lesson.

          Comment

          Working...
          X