Announcement

Collapse
No announcement yet.

getValue() questions...

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

  • getValue() questions...

    I have the following in an EFS file:

    function preMain() {
    setPriceStudy(true);
    _init = true;
    }

    var _init = true;

    function main() {
    if(_init)
    {
    _init = false;

    var sym = "IBM,D";
    debugPrintln(sym);
    //var openP = getValue("Open", 0, -21, sym);
    //var openP = getValue("Open", 0, -2, sym);
    //var openP = getValue("Open", 0, -1, sym);
    //var openP = getValue("Open", 0, 21, sym);
    debugPrintln("got here");
    }
    }

    And I have the following questions:

    The "got here" debugPrintln() will only be reached when the last 2 getValue() lines are uncommented

    AND

    If the chart is a daily IBM chart.

    "got here" will never be displayed if the chart is anything but IBM daily also "got here" will not be displayed for the first 2 getValue() statements.

    [I uncomment each one in turn to test this.]

    I was under the impression that the syntax for getValue() was correct for the first getValue() line above?

    I also though that you could retrieve the value of any symbol from any chart?

    Is anybody else getting the same results that I'm getting here? Can anybody see what I'm doing wrong?

    Thanks
    Standing on the shoulders of giants.

  • #2
    Hello wildfiction,

    The proper way to write this type of process is to set your _init variable to false after your init routine has properly executed. Try the code below.

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("test");
        
    _init true;
        
    debugClear();
    }

    function 
    main() {
        if(
    _init) {        
            var 
    sym "IBM,D";
            
    debugPrintln(sym);
            
    //var openP = getValue("Open", 0, -21, sym);
            //var openP = getValue("Open", 0, -2, sym);
            //var openP = getValue("Open", 0, -1, sym);
            //var openP = getValue("Open", 0, 21, sym);
            
    debugPrintln(getCurrentBarIndex() + " got here " /*+ openP*/);
            
    _init false;
        }

    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


    • #3
      Hi Jason,

      The reason that the "got here" statement prints in your example is because the _init is not set to false until all the code in the conditional section has executed successfully.

      This means that if the getValue() function causes the if() condition to "bomb out" then it will be re-entered on the next call to the main() function and so on until the getValue() function finally succeeds.

      I'm trying to ascertain why the getValue() function is causing the execution of the code to terminate and not allow subsequent statements to be executed...?
      Standing on the shoulders of giants.

      Comment


      • #4
        Hello wildfiction,

        It's because at the beginning of the initialization of the formula, the data that you're requesting with getValue is not accessible to the function at that instance. There are some failsafes put in place to prevent a crash and allow the formula to continue to initialize and execute on the next bar. Is the solution I provided going to work for you?
        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


        • #5
          Hi Jason,

          Many thanks for the solution. Yes, I've tested it and I can use that solution to work around this particular problem.

          Many thanks for your help as always.
          Standing on the shoulders of giants.

          Comment

          Working...
          X