Announcement

Collapse
No announcement yet.

Difference for efsInternal vs just calling the internal function

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

  • Difference for efsInternal vs just calling the internal function

    I found I can call an internal function two ways but I am unsure as to what the difference might be.

    I can call an internal function by:

    var myVar3 = 3.4572894
    function main(){
    myVar = efsInternal( "rnd", myVar3, 2 );
    //or
    myVar1 = rnd(myVar3, 2);
    debugPrintln(myVar, "myVar- ");
    debugPrintln(myVar1, "myVar1- ");
    }

    function rnd(value, N) { //N = round to N # of digits
    var n;
    var mult=1;
    for(n=0;n<N;n++) mult*=10;
    value*=mult;
    return Math.round( value,N)/mult;
    }


    Is the only difference that using efsInternal returns a series and
    myVar = rnd(myVar3, 2); just returns the current value?

    Thanks in advance.

  • #2
    Re: Difference for efsInternal vs just calling the internal function

    waynecd
    That is one difference between calling a function directly or through efsInternal(). The other is that by passing inv() or sym() as the last parameter you can control the context in which a function is running ie you can base its calculations on an external interval and/or symbol
    Alex


    Originally posted by waynecd
    I found I can call an internal function two ways but I am unsure as to what the difference might be.

    I can call an internal function by:

    var myVar3 = 3.4572894
    function main(){
    myVar = efsInternal( "rnd", myVar3, 2 );
    //or
    myVar1 = rnd(myVar3, 2);
    debugPrintln(myVar, "myVar- ");
    debugPrintln(myVar1, "myVar1- ");
    }

    function rnd(value, N) { //N = round to N # of digits
    var n;
    var mult=1;
    for(n=0;n<N;n++) mult*=10;
    value*=mult;
    return Math.round( value,N)/mult;
    }


    Is the only difference that using efsInternal returns a series and
    myVar = rnd(myVar3, 2); just returns the current value?

    Thanks in advance.

    Comment


    • #3
      wayncd,

      Do not use the efsInternal command to simply call a function, just call it as you did in your second example.

      efsInternal creates, in effect, a new global chart environment, using the efs engine to syncronize the two timeframes. A huge waste of resources if not needed, as is the case with your example.

      Comment


      • #4
        Thanks stevehare2003, your info will save alot of resources.

        I tried both ways to get the slope of the 34 ema into the "function main".
        as indicated below, Test 1 - "Returns "null" to output window and freezes eSignal"

        and Test 2 "Returns "NaN" to output window and doesn't display 34 ema"

        How do I code this?

        I intend to use it for several moving avgs so I would like it as a post function. I got it to work if I code it for one mov avg in the "function main".

        Thanks in advance.

        //**********************Start of Code

        var bInit = false;

        function preMain() {
        setPriceStudy(true);
        setStudyTitle("34 EMA Slope");
        }
        var myStudy3 = null;
        var Multi = 10

        function main(Multi) {

        var myVar3;
        if ( bInit == false ) {
        myStudy3 = ema( 34 );
        bInit = true;
        }
        myVar3 = myStudy3.getValue(0);
        myVar3a = myStudy3.getValue(-1);
        /* 1 **************************************///Below returns "null" to output window and freezes eSignal
        //vSlope34ema = efsInternal( "_Slope", myVar3,myVar3a,Multi )
        //debugPrintln(vSlope34ema.getValue(-1));
        /* 1 **************************************///end 1

        /* 2 **************************************///Below returns "NaN" to output window and doesn't display 34 ema
        vSlope34ema = _Slope(myVar3,myVar3a,Multi)
        debugPrintln(vSlope34ema);

        /* 2 **************************************///end 2


        return new Array( getSeries(myStudy3) );

        }

        function _Slope(_Point1,_Point2,_Multi){
        Slope1 = ((_Point1/_Point2)-1)* _Multi;
        angle1 = (Math.atan(Slope1)/(Math.PI/180 ));
        // sDisplayPrice1 = Math.round(angle1);
        // vCursorSlope1 = " " + Math.round(Slope1);*/
        return Slope1;
        }
        //**********************End of Code

        Comment


        • #5
          waynecd,

          I made some changes to you code (and commented the changes. It now plots.

          Garth

          var bInit = false;

          function preMain() {
          // setPriceStudy(true); I don't think you want this to be a price study....
          setStudyTitle("34 EMA Slope");
          }
          var myStudy3 = null;
          var Multi = 10

          function main() { // Having main (Multi) overroad your Multi definition above

          var myVar3;
          if ( bInit == false ) {
          myStudy3 = ema( 34 );
          bInit = true;
          }

          myVar3 = myStudy3.getValue(0);
          myVar3a = myStudy3.getValue(-1);
          /* 1 **************************************///Below returns "null" to output window and freezes eSignal
          //vSlope34ema = efsInternal( "_Slope", myVar3,myVar3a,Multi )
          //debugPrintln(vSlope34ema.getValue(-1));
          /* 1 **************************************///end 1

          /* 2 **************************************///Below returns "NaN" to output window and doesn't display 34 ema
          vSlope34ema = _Slope(myVar3,myVar3a,Multi)

          /* 2 **************************************///end 2


          return ( vSlope34ema ); // You don't need to use getValue if you call the function diretly...also don't define the return as an array if it is a single valiable

          }

          function _Slope(_Point1,_Point2,_Multi){
          Slope1 = ((_Point1/_Point2)-1)* _Multi;
          angle1 = (Math.atan(Slope1)/(Math.PI/180 ));
          // sDisplayPrice1 = Math.round(angle1);
          // vCursorSlope1 = " " + Math.round(Slope1);*/
          return Slope1;
          Garth

          Comment


          • #6
            ///////////////////////////////////////////////////////////////
            vSlope34ema = _Slope(myVar3,myVar3a,Multi)
            function _Slope(_Point1,_Point2,_Multi){
            ///////////////////////////////////////////////////////
            Programming question: Why use the underscores ( _ ) in the function call? _Point1,_Point2,_Multi
            Thanks, Ken

            Comment


            • #7
              Hi Ken,

              From what I have seen, an underscore generally is used to identify a private variable, method or function. Reference this style guide, but it could just as easily be a person's particular style or preference as it is a legal JavaScript identifier.

              Originally posted by kenz987
              ///////////////////////////////////////////////////////////////
              vSlope34ema = _Slope(myVar3,myVar3a,Multi)
              function _Slope(_Point1,_Point2,_Multi){
              ///////////////////////////////////////////////////////
              Programming question: Why use the underscores ( _ ) in the function call? _Point1,_Point2,_Multi
              Thanks, Ken

              Comment

              Working...
              X