Announcement

Collapse
No announcement yet.

Initializing EFS Variables

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

  • Initializing EFS Variables

    could someone please check this for me ...

    var v1 = false;

    function main() {

    if (v1 == false) { v1 = true; debugPrint(v1); }

    return null;

    }

    when the study is loaded into the chart, all is well and debug prints "true".

    if the chart is scrolled to the left to dynamically load more data, v1 remains "true" and debug doesn't print.
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

  • #2
    Not sure that I would classify that as a bug. When you scroll to the left in a chart with a dynamic time template, it is not performing a complete script refresh when those new bars are called... rather it simply sets the BARSTATE_ALLBARS state flag. So any variables external to main() and preMain() will retain their current value (it is essentially the equivalent of calling the reloadEFS function). If you need to perform some action if/when the user scrolls to the left and pulls in more data, you would need to use BARSTATE_ALLBARS as the trigger for that event.

    Chris

    Comment


    • #3
      thanks ckryza. probably worth pointing out for others ...

      var v1 = false;

      function re_initialize() {

      v1 = false;

      }

      function main() {

      if (getBarState() == BARSTATE_ALLBARS) re_initialize();

      if (v1 == false) { v1 = true; debugPrint(v1); }

      return null;

      }
      Paul Williams
      Strategy & Applications
      www.futurenets.co.uk

      Comment


      • #4
        more information on ALLBARS if available would be very welcome ... e.g. when in this state

        1. what's actually happening in the back of eSignal regarding the efs study and the price bars?

        2. re-initializing large qty's of variables (in case additional bars are dynamically added) appears to incurr significantly more loading time?

        3. do studies e.g. MAStudy(...) need to be re-initialized as bars are dynamically added?

        4. anyone else .....

        Thanks in advance
        Paul Williams
        Strategy & Applications
        www.futurenets.co.uk

        Comment


        • #5
          Hello Paul,

          1. When new data is requested in the advanced chart dynamically, the formula reloads and processes once for each historical bar. Global variables will not be re-initialized. Checking for the BARSTATE_ALLBARS event as Chris pointed out can be used to reset any global variables.

          2. In regards to re-initialization time, there will be some processing time required. This should be expected. However, the time is more dependant on the interval of the chart and the amount of new data being requested, not variables in your formula. If you request data in two charts using the same symbol/interval/time template where one has your formula and the other does not, you shouldn't see much difference in request time.

          It's possible that there are some routines in your code causing a problem, but without seeing any code it's difficult to say. Generally, as long as the code doesn't trigger massive looping routines or something of that nature at ALLBARS, formulas shouldn't be much of a factor in refresh time of the chart.

          3. No.
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            does this mean that when bars are added dynamically, any re-initialization required at the start of the updated chart, get repeated for each bar on the chart? isn't that inefficient?
            Paul Williams
            Strategy & Applications
            www.futurenets.co.uk

            Comment


            • #7
              Hello Paul,

              Not if you put the re-initialization routine inside a check for BARSTATE_ALLBARS. This event only happens once on the oldest bar in the chart. It will not occur for each bar while the chart is loading.

              If you want to limit the number of historical bars where your main() function processes its code, you could add an additional check for the bar index and simply end the execution of main with a return statement.

              PHP Code:
              function main() {
                if (
              getBarState() == BARSTATE_ALLBARSre_initialize();
                if (
              getCurrentBarIndex() < -100) return;
                ...

              This would only allow your formula to process your formula code once it sees bar index of -100 to 0.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment


              • #8
                thanks Jason thats the answer I needed. will re-try.
                Paul Williams
                Strategy & Applications
                www.futurenets.co.uk

                Comment

                Working...
                X