Announcement

Collapse
No announcement yet.

Can't access: call and callFunction by Matt Gundersen

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

  • Can't access: call and callFunction by Matt Gundersen

    Alex

    Related reading material: call and callFunction by Matt Gundersen

    When I click on the link, "call and callFunction" I can't access it.

    Please help.

    THANKING YOU IN ADVANCE.

  • #2
    buzzhorton
    The link pointed to a forum that has since been archived.
    Enclosed below are the contents of that article
    Alex

    Originally posted by mattgundersen
    call(sFunctionName, args);
    Call the "main(args)" function in another file within the formula root.

    Call the moving average formula, passing 50 for the moving average length.

    call("ma.txt", 50);


    callFunction("Filename.EFS", "FunctionName", [Parameters…]);

    Here's how to call formulas using the "call" function. Let's set up a few parameters first. The symbol is MSFT, 1 minute bars, and there are 600 bars in memory.

    1) Let's talk about a regular formula first. When a formula is "run," it is iterated for every bar on the chart. As the formula iterates, you might have variables or arrays defined outside main that maintain some kind of state or current values. You might also use the "ref(...)" function to access previously returned values. Because the formula remains live until the chart is closed or the symbol changes, states are maintained, you can use ref, etc...

    2) Now let's talk about a formula calling a formula. You have an entrypoint function MajorMA that calls MinorMA. When MajorMA calls MinorMA, MinorMA is iterated for all 600 bars, and the return values are stored in memory. Now, as MajorMA is being iterated and it calls MinorMA, we simply do a value lookup in memory.

    The primary reason for building all the bars in MinorMA when it is called by a parent formula is because of the issues raised in #1. If we simply allowed MajorMA to call MinorMA on a bar-by-bar basis without letting MinorMA run and maintain the appropriate states, MinorMA might not return the values you are expecting.

    Things get a little tricky when we allow parameter passing. Suppose MinorMA has an input parameter nInputLength that determines the length of a moving average.

    Then, in MajorMA you have:

    PHP Code:
    Function main() {
    Call("MinorMA.efs"10);
    Call("MinorMA.efs"50); 

    Now what you've done (but probably didn't know) is created two versions of MinorMA. When MajorMA called MinorMA(10), we ran one instance of MinorMA and passed the "10" parameter. When MajorMA(50) is called, we create a second instance of MinorMA and pass the 50 parameter.

    So, what happens is...

    MajorMA starts, MinorMA(10) is instantiated and iterated for 600 bars, then MinorMA(50) is iterated for 600 bars. Then, we can resume iterating MajorMA for its 600 bars. Note: Once MinorMA has been instantiated and iterated, it won't be re-iterated. It will, however, be called as ticks come in.

    Why we are creating new instances based off input parameters? Because input parameters can affect computational output, and we don't know what your input parameters are doing, we assume any difference in input parameter values means a new instantiation of a called formula.

    Thus, henceforth, to whit, and in conclusion:

    PHP Code:
    For(1100n++) {
    Call("yadayada.efs"n);

    Loops around calls and passing the loop variable can make for a very busy cpu.
    To allow for reuse of code and to allow you to call functions without the overhead of "call", we've added a "callFunction" function to EFS. This is much like doing a "#include" or a macro.

    "callFunction" allows you to call any function directly in any EFS without all the overhead discussed above. HOWEVER, this also means that, if the function you are calling relies on built-ins like "ref", you may get inconsistent results

    Comment

    Working...
    X