Announcement

Collapse
No announcement yet.

How many times is sym(xx) passed when main passes it to an efsInt that calls another

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

  • How many times is sym(xx) passed when main passes it to an efsInt that calls another

    Hi,

    Does an internal function [function bb()] called by another internal function [function aa()] inherit the sym() passed by main()?
    And does a series calculation based on the called internal function (bb) also inherit the sym() passed by main()?

    Hopefully the questions are clearer when commented in the sample script below.


    PHP Code:
    var Study null;
    var 
    bInit false;

    function 
    main(){

        if(!
    bInit){
             
    Symbol getSymbol();
             
    Interval getInterval();
             var 
    xSymbol Symbol+","+Interval;
             
    study efsInternal("aa",sym(xSymbol));
             
    bInit=true;       
        }
    ...
    }

    function 
    aa(){
        
    xTR efsInternal("bb");//Does "function aa()" pass "sym(xSymbol)" to "function bb()"?
        
    xAvgTR ema(MALengthxTR);//is "xAvgTR" calculated based on "sym(xSymbol) since "xAvgTR is based on "function bb()"?
    }
    function 
    bb(){//if "sym(xSymbol)" is not passed how do I make sure the whole script is based on the desired symbol and interval?
        
    return (high(0)-low(0));

    I don't know how to test for this andn othing I've tried so far clears this up for me.

    Thanks in advance.

    Wayne
    Last edited by waynecd; 06-04-2010, 02:55 AM.

  • #2
    Re: How many times is sym(xx) passed when main passes it to an efsInt that calls another

    Hi Wayne,

    I rewrote the efs and marked it up such that it can be used as a reference. Alex has a great tutorial thread on internal series and efsInternal which is much better than I could put together.

    The modified efs I enclosed is more a tutorial to demonstrate efsinternal execution flow in addition to demonstrating several related concepts. I also saved the efs to my Functions fileShare here.


    I hope this helps.



    Originally posted by waynecd
    Hi,

    Does an internal function [function bb()] called by another internal function [function aa()] inherit the sym() passed by main()?
    And does a series calculation based on the called internal function (bb) also inherit the sym() passed by main()?

    Hopefully the questions are clearer when commented in the sample script below.


    PHP Code:
    var Study null;
    var 
    bInit false;

    function 
    main(){

        if(!
    bInit){
             
    Symbol getSymbol();
             
    Interval getInterval();
             var 
    xSymbol Symbol+","+Interval;
             
    study efsInternal("aa",sym(xSymbol));
             
    bInit=true;       
        }
    ...
    }

    function 
    aa(){
        
    xTR efsInternal("bb");//Does "function aa()" pass "sym(xSymbol)" to "function bb()"?
        
    xAvgTR ema(MALengthxTR);//is "xAvgTR" calculated based on "sym(xSymbol) since "xAvgTR is based on "function bb()"?
    }
    function 
    bb(){//if "sym(xSymbol)" is not passed how do I make sure the whole script is based on the desired symbol and interval?
        
    return (high(0)-low(0));

    I don't know how to test for this andn othing I've tried so far clears this up for me.

    Thanks in advance.

    Wayne


    PHP Code:
    //~ DEMO CONCEPTS EFS ==>> EFSINTERNAL EXECUTION FLOW
    //~ The efs returns an exponential moving average of the price range ((high(0) - low(0)) and has extensive debug output
    //~ Written by Steve Hare 6/4/2010

    //~ NOTE:  much of the code and the majority of the concepts in this efs are discussed and demonstrated  quite thoroughly in the following 
    //~ thread ==>> 'http://forum.esignalcentral.com/showthread.php?s=&threadid=12752' 

    //~ This efs was written in response to a question in this thread ==>>  'http://forum.esignalcentral.com/showthread.php?s=&threadid=33639'
    //~ I didn't address the timeframe and symbol questions because they are discussed in the first referenced thread (12752)
    //~ However, I did show how to determine the timeframe and symbols in every function and potential timeframe
    //~ I saved a copy in this folder ==>> 'http://share.esignal.com/groupcontents.jsp?folder=Demo%20Concepts&groupid=339'

    //~ I identified via comments several concepts in the efs.  They are described as best I can below:
    //~ ********************************************* 

    //~ CONCEPT 1:
    //~ - 'http://www.wait-till-i.com/2007/11/27/javascript-shortcut-notations-that-shouldnt-be-black-magic-to-the-average-developer/'
    //~ - 'http://dev.opera.com/articles/view/javascript-best-practices/'

    //~ CONCEPT 2: Simple technique using setGlobalValue() and getGlobalValue() to keep track of efs function execution calls and their flow 

    //~ CONCEPT 3: Another technique that can be used anywhere to determine timeframe and symbol

    //~ CONCEPT 4: getSeries() must be used to expose external series 
    //~ - 'http://forum.esignalcentral.com/showthread.php?s=&threadid=12752' 
    //~ - 'http://forum.esignalcentral.com/showthread.php?s=&threadid=29145'
    //~ I recommend uncommented and re-commenting the steps marked with CONCEPT 4, note the first uncommented return statement skips the rest

    //~ CONCEPT 5: using efsInternal() creates a new copy of all global objects and keeps them private
    //~ - 'http://forum.esignalcentral.com/showthread.php?s=&postid=72994#post72994'

    //~ CONCEPT 6: The use of this conditional was used it to keep track of efs function execution and limit debug output to once

    //~ CONCEPT 7: 
    //~ I used this debugPrintln statement for troubleshooting.  I left it there so it can be un-commented .
    //~ More often than not, code does not work as expected the first time through (quite an understatement for some of my code)
    //~ I recommend that anyone using this efs to uncommented it and re-comment to understand the sequencing
    //~ Also note how I constructed the debugPrintln statements, using function identifiers and numerical references, this works well for me and am passing it along 
    //~ debugPrintln output goes to a file in the eSignal folder ==>> \eSignal\formulaoutput.log  I have a shortcut to the file on my desktop and highly recommend it

    //~ CONCEPT 8: The postMain() function is called when you close or reload the efs.  I used it to reset the global variable used in CONCEPT 2:

    //~ ********************************************* 

    //~ Finally, check out the links in my user signature block .  There are links to a number of excellent efs2 tutorial threads in addition to other handy efs references.
    //~ There is also a copy of these links in my FileShare. as well. ==>> 'http://share.esignal.com/groupcontents.jsp?groupid=339'

    //~ a copy of the debug output is listed below the efs

    var nHL null;
    var 
    xAvgTR=null;
    var 
    bInit false;

    var 
    wCount=getGlobalValue("wCount")||0//~ if null or zero, set to 0  //~ CONCEPT 1
    setGlobalValue("wCount",wCount);  //~ CONCEPT 2
    debugPrintln("");
    var 
    wCount=getGlobalValue("wCount");   debugPrintln("global.1: step executed, global.bInit ==>> "+bInit+", wCount = "+wCount);  //~ CONCEPT 2
    debugPrintln("global.2: getSymbol() = "+getSymbol()+", getInterval() = "+getInterval()+", wCount = "+wCount); //~ CONCEPT 3
    debugPrintln("");

    function 
    preMain() {
     
    //~ setPriceStudy(true);
     
    setPriceStudy(false);
     
    setShowCursorLabel(true);
     
    setStudyTitle("efsInternal execution flow");
     }

    function 
    main(MALength) {
      if (!
    bInit) {
      
    MALength=MALength||10//~ if null, undefined false or zero, set to 10  //~ CONCEPT 1
      
    var wCount=getGlobalValue("wCount");   debugPrintln("mn.1: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount+", MALength = "+MALength);  //~ CONCEPT 2
      
    wCount++;    debugPrintln("mn.2: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount);  // ~CONCEPT 2
      
    setGlobalValue("wCount",wCount);    debugPrintln("mn.3: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount);  // ~ CONCEPT 2
      
    debugPrintln("mn.4: getSymbol() = "+getSymbol()+", getInterval() = "+getInterval()); //~ CONCEPT 3
        
    nHL efsInternal("range");    debugPrintln("mn.6: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount);  // ~ 
      //~ nHL=getSeries(nHL);  //~ CONCEPT 4 
        
    if(nHL==null){return null;}
      
    xAvgTR ema(MALength,nHL); debugPrintln("mn.7: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount);  // ~ 
      //~ xAvgTR=getSeries(xAvgTR);    debugPrintln("mn.8: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount);  // ~   //~ CONCEPT 4 
      
    if(xAvgTR==null){return null;}
      
    bInit true;    debugPrintln("mn.9: step executed, mn.bInit ==>> "+bInit+", wCount = "+wCount);  
      
    debugPrintln("");
      }
     return 
    xAvgTR.getValue(0); //~ CONCEPT 4 
     //~ return xAvgTR;  //~ CONCEPT 4 
     //~ return nHL;  //~ CONCEPT 4 
    }
     
    function 
    range() { //~ [url]http://forum.esignalcentral.com/showthread.php?s=&threadid=12752[/url] 
     
    if (!bInit) {//~ CONCEPT 5 ~  //~ CONCEPT 6 
      
    var wCount=getGlobalValue("wCount");    debugPrintln("range.1: step executed, range.bInit ==>> "+bInit+", wCount = "+wCount);  //~ CONCEPT 2
      
    wCount++;    debugPrintln("range.2: step executed, range.bInit ==>> "+bInit+", wCount = "+wCount);  //~ CONCEPT 2
      
    setGlobalValue("wCount",wCount);    debugPrintln("range.3: step executed, range.bInit ==>> "+bInit+", wCount = "+wCount);  //~ CONCEPT 2
      
    debugPrintln("range.4: getSymbol() = "+getSymbol()+", getInterval() = "+getInterval());  //~ CONCEPT 3
      
    bInit true;     debugPrintln("range.5: step executed, range.bInit ==>> "+bInit+", wCount = "+wCount);   //~ CONCEPT 5 
      
    debugPrintln("");
      }
     
    //~ debugPrintln("range.6:  (high(0) - low(0)) ==>> "+(high(0) - low(0)));   //~ CONCEPT 7 
     
    return (high(0) - low(0));
    }

    function 
    postMain(){
     
    setGlobalValue("wCount",null); //~  set to null if reloaded  //~ CONCEPT 8 
    }

    //~ DEBUG OUTPUT FROM THIS EFS, COPIED FROM THIS FILE IN THE ESIGNAL FOLDER ==>> \ESIGNAL\FORMULAOUTPUT.LOG 

    //~ global.1: step executed, global.bInit ==>> false, wCount = 0
    //~ global.2: getSymbol() = ES #F, getInterval() = 5, wCount = 0

    //~ mn.1: step executed, mn.bInit ==>> false, wCount = 0, MALength = 10
    //~ mn.2: step executed, mn.bInit ==>> false, wCount = 1
    //~ mn.3: step executed, mn.bInit ==>> false, wCount = 1
    //~ mn.4: getSymbol() = ES #F, getInterval() = 5

    //~ global.1: step executed, global.bInit ==>> false, wCount = 1
    //~ global.2: getSymbol() = ES #F, getInterval() = 5, wCount = 1

    //~ range.1: step executed, range.bInit ==>> false, wCount = 1
    //~ range.2: step executed, range.bInit ==>> false, wCount = 2
    //~ range.3: step executed, range.bInit ==>> false, wCount = 2
    //~ range.4: getSymbol() = ES #F, getInterval() = 5
    //~ range.5: step executed, range.bInit ==>> true, wCount = 2

    //~ mn.1: step executed, mn.bInit ==>> false, wCount = 2, MALength = 10
    //~ mn.2: step executed, mn.bInit ==>> false, wCount = 3
    //~ mn.3: step executed, mn.bInit ==>> false, wCount = 3
    //~ mn.4: getSymbol() = ES #F, getInterval() = 5
    //~ mn.6: step executed, mn.bInit ==>> false, wCount = 3
    //~ mn.7: step executed, mn.bInit ==>> false, wCount = 3
    //~ mn.9: step executed, mn.bInit ==>> true, wCount = 3 
    Attached Files

    Comment


    • #3
      Hi Steve,

      In addition to the code, your comments, concepts, and links were also extremely useful.

      I also appreciate the way you explain the use of global variables for tracking code execution.

      //~ More often than not, code does not work as expected the first time through (quite an understatement for some of my code)
      Ref: quote - you have no idea how true that statement is for me as well.

      A million thanks to you and Alex.

      Wayne
      Last edited by waynecd; 06-05-2010, 06:41 AM.

      Comment


      • #4
        Hi Wayne,

        Your most welcome, appreciate the nice note.

        Steve

        Comment

        Working...
        X