Announcement

Collapse
No announcement yet.

retreiving variables efficiently

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

  • retreiving variables efficiently

    Hello,
    If I want to use only the current values of the variables vADV and vDECL in a calculation, is Case 1 below just as efficient (in terms of computer resources) as Case 2 for getting those values? Would Case 1 be even more efficient for any reason?

    I understand that case 2 retreives each series, so would Case 2 only be needed if I also needed the ___.getValue(-1) values for my calculation as well?

    Thanks
    shaeffer

    PHP Code:
    //--- CASE 1 --------------------------------------------------
    function main() {

    var 
    vADV;
    var 
    vDECL;

        
    vADV  close(0sym("$ADV")); 
        
    vDECL close(0sym("$DECL"));

    //--- CASE 2 ----------------------------------------------------------- 

    var xADV  null;
    var 
    xDECL null;
    var 
    bInit false;

    function 
    main(){

    var 
    vADV;
    var 
    vDECL;

        if(
    bInit == false){
            
    xADV  close(sym("$ADV"));
            
    xDECL close(sym("$DECL"));
            
    bInit true;
        }

    vADV  =  xADV.getValue(0)
    vDECL =  xDECL.getValue(0)

    //--------------------------------------------------------------- 

  • #2
    Re: retreiving variables efficiently

    shaeffer
    Case 2 of your examples is more efficient because while you are creating a series in either case in the first one the efs engine has to check on each iteration if that series already exists so as not to create another instance of it. By using the bInit [or similar] routine you preempt the efs engine from having to perform those checks thereby increasing the efficiency of execution of the script
    Alex


    Originally posted by shaeffer
    Hello,
    If I want to use only the current values of the variables vADV and vDECL in a calculation, is Case 1 below just as efficient (in terms of computer resources) as Case 2 for getting those values? Would Case 1 be even more efficient for any reason?

    I understand that case 2 retreives each series, so would Case 2 only be needed if I also needed the ___.getValue(-1) values for my calculation as well?

    Thanks
    shaeffer

    PHP Code:
    //--- CASE 1 --------------------------------------------------
    function main() {

    var 
    vADV;
    var 
    vDECL;

        
    vADV  close(0sym("$ADV")); 
        
    vDECL close(0sym("$DECL"));

    //--- CASE 2 ----------------------------------------------------------- 

    var xADV  null;
    var 
    xDECL null;
    var 
    bInit false;

    function 
    main(){

    var 
    vADV;
    var 
    vDECL;

        if(
    bInit == false){
            
    xADV  close(sym("$ADV"));
            
    xDECL close(sym("$DECL"));
            
    bInit true;
        }

    vADV  =  xADV.getValue(0)
    vDECL =  xDECL.getValue(0)

    //--------------------------------------------------------------- 

    Comment


    • #3
      Re: Re: retreiving variables efficiently

      Originally posted by Alexis C. Montenegro
      shaeffer
      Case 2 of your examples is more efficient because while you are creating a series in either case in the first one the efs engine has to check on each iteration if that series already exists so as not to create another instance of it. By using the bInit [or similar] routine you preempt the efs engine from having to perform those checks thereby increasing the efficiency of execution of the script
      Alex
      Thanks Alex,
      I did not realize that Case 1 was also creating a series (as apposed to simply getting the latest value). I'll fix up my efs's accordingly.
      Regards
      shaeffer

      Comment


      • #4
        Re: Re: Re: retreiving variables efficiently

        shaeffer
        You are welcome.
        FWIW if you search the forums you will find several threads on this topic as it has been discussed at length before
        Alex


        Originally posted by shaeffer
        Thanks Alex,
        I did not realize that Case 1 was also creating a series (as apposed to simply getting the latest value). I'll fix up my efs's accordingly.
        Regards
        shaeffer

        Comment


        • #5
          Re: Re: retreiving variables efficiently

          Originally posted by Alexis C. Montenegro
          shaeffer
          ..... By using the bInit [or similar] ......
          Alex
          Hello Alex,
          I've fixed up a few of my efs's per your earlier reply, but then arrived at this one used for plotting daily moving averages on intraday charts.

          It looks to me like line 86 is acheving the same as the bInit in Case 2 below, or does this still need an efficiency tune-up?

          Regards
          shaeffer
          Attached Files

          Comment


          • #6
            Re: Re: Re: retreiving variables efficiently

            shaeffer
            It is essentially the same
            Alex


            Originally posted by shaeffer
            Hello Alex,
            I've fixed up a few of my efs's per your earlier reply, but then arrived at this one used for plotting daily moving averages on intraday charts.

            It looks to me like line 86 is acheving the same as the bInit in Case 2 below, or does this still need an efficiency tune-up?

            Regards
            shaeffer

            Comment

            Working...
            X