Announcement

Collapse
No announcement yet.

Clarification on efs calls

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

  • Clarification on efs calls

    When you call efsExternal, does it call main inside that script?
    Or is that a efs() call that I saw somewhere?
    Can it call an active efs script currently loaded within a chart and access the current state of that script?

    ie, if I loaded efs1 into chart1 and loaded efs2 into chart2, can efs2 call efs("efs1") to call main() of efs1, which will be the current state of efs1 with access to all variables declared outside of main in that script?

    Or is that call loading a separate copy of efs1, and if so, does premain get called before main is called?

    Also, if I have defined vars inside a script which are declared outside of main (so they are global to that script), and I then call efsInternal, does the invoked function have access to those vars?
    An example I have is say I have three different sym/intervals defined outside of main (say var1 = close("A, 3), var2 = high("B, 5") and var3 = something else). Then I call an internal function. Can it access those vars?

    Thanks

  • #2
    Re: Clarification on efs calls

    Hello crazytiger,

    Originally posted by crazytiger
    When you call efsExternal, does it call main inside that script?
    Or is that a efs() call that I saw somewhere?
    Can it call an active efs script currently loaded within a chart and access the current state of that script?

    ie, if I loaded efs1 into chart1 and loaded efs2 into chart2, can efs2 call efs("efs1") to call main() of efs1, which will be the current state of efs1 with access to all variables declared outside of main in that script?

    Or is that call loading a separate copy of efs1, and if so, does premain get called before main is called?
    Yes, main() is called. The efsExternal() function creates a Series Object from the called efs's return array. Do not use efs(), that is the old function name for what is now efsExternal().

    efsExternal() does not refer to or call a formula instance that is currently active in the chart. It creates it's own instance for the calling efs. The called efs will run in the context of the calling efs's chart symbol and interval unless you pass sym() or inv() to the called efs. In this case the called efs needs to have formula parameters setup to accept the sym() or inv() and incorporate them into it's internally declared series.

    Another way to force the called efs to run on a specified sym() or inv() is to pass the sym/inv as the last parameter to efsInternal() inside your calling efs. Then within the efsInternal() function you would call efsExternal(). That might seem a little confusing at first. If you need help setting this up, post your code example and we'll go from there.

    The preMain() function does get executed by efsExternal() by default, but it has no affect on the chart.

    Also, if I have defined vars inside a script which are declared outside of main (so they are global to that script), and I then call efsInternal, does the invoked function have access to those vars?
    An example I have is say I have three different sym/intervals defined outside of main (say var1 = close("A, 3), var2 = high("B, 5") and var3 = something else). Then I call an internal function. Can it access those vars?

    Thanks
    Yes, the called function gets it's own instance of those global vars. If you change the value of a global var in main() to one value and you use the same global var inside an efsInternal() function, you essentially now have two unique instances of this global var. Try the following code. You will see two lines plotted at 1 and 2.

    PHP Code:
    var xStudy null;
    var 
    nNum null;

    function 
    main() {
        if (
    xStudy == nullxStudy efsInternal("temp1");
        
        if (
    nNum == nullnNum 2;
        
        return new Array(
    xStudy.getValue(0), nNum);
    }


    function 
    temp1() {
        if (
    nNum == nullnNum 1
        
    return nNum;

    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

    Working...
    X