Announcement

Collapse
No announcement yet.

Fundamental question on execution of EFS Formula and getting historic bar values into

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

  • Fundamental question on execution of EFS Formula and getting historic bar values into

    Hello - Fundamental question on execution of EFS Formula and getting historic bar values into (my own) fixed value array (and not Series Object) :

    When I apply a formula to an advanced chart, it executes (I think) the bars from left to right, from oldest to newest sequentially, and then switches in Real time mode.

    Now I would like to get into my own array say all highs of each (historic) bar; I think it is nonsense to create ex post a formula within main such as: For bar = -1 to -1000 do... , as this would be executed every single time main is called (a new tick), doing thousands of times the same thing, whereas the historic values do not change.
    Hence I would like to get the values while the historic bars are scanned (initially), or whenever they are reevaluated, when changing for instance the chart timewindow. How would I do that, any suggestion?

  • #2
    Re: Fundamental question on execution of EFS Formula and getting historic bar values into

    WaldMeister
    Assuming I understood you correctly a simple method would be to create an array as a global variable eg
    PHP Code:
    var myArray = new Array() 
    then populate it as the efs runs through historical bars and update its most recent element in real time eg
    PHP Code:
    //...
    if(getBarState()==BARSTATE_NEWBAR){
        
    myArray.unshift(high(0));
    }else{
        
    myArray[0]=high(0);
    }
    debugPrintln("oldest High is "+myArray[myArray.length -1]+" most recent High is "+myArray[0]);
    //... 
    For a description of the methods and properties of the Array Object you may want to review this article in the EFS KnowledgeBase
    Alex


    Originally posted by WaldMeister
    Hello - Fundamental question on execution of EFS Formula and getting historic bar values into (my own) fixed value array (and not Series Object) :

    When I apply a formula to an advanced chart, it executes (I think) the bars from left to right, from oldest to newest sequentially, and then switches in Real time mode.

    Now I would like to get into my own array say all highs of each (historic) bar; I think it is nonsense to create ex post a formula within main such as: For bar = -1 to -1000 do... , as this would be executed every single time main is called (a new tick), doing thousands of times the same thing, whereas the historic values do not change.
    Hence I would like to get the values while the historic bars are scanned (initially), or whenever they are reevaluated, when changing for instance the chart timewindow. How would I do that, any suggestion?

    Comment


    • #3
      For completeness, you'll need to handle BARSTATE_ALLBARS as well. Otherwise, anytime the chart is refreshed or the total number of bars changes (by decreasing bar spacing, increasing the width of the chart, or dragging the chart to look at past bars off to the left) your array will grow, and grow, and grow - affecting performance.

      Adding to the code Alex posted:

      PHP Code:
      var myArray;

      function 
      main () {
          var 
      barState getBarState();

          if(
      barState == BARSTATE_ALLBARS){
              
      // Start of chart or got a chart refresh...
              // All bars will be "resent" to the EFS, so start with a new Array.
              
      myArray = new Array;
              
      myArray.unshift(high(0));
          } else if (
      barState == BARSTATE_NEWBAR){
              
      myArray.unshift(high(0));
          } else {    
      // BARSTATE_CURRENTBAR
              
      myArray[0]=high(0);
          }

          
      debugPrintln("oldest High is "+myArray[myArray.length -1]+" most recent High is "+myArray[0]);

          
      //...


      Last edited by shortandlong; 02-19-2010, 06:50 AM.

      Comment


      • #4
        Many Thanks!

        Many Thanks!

        Comment

        Working...
        X