Announcement

Collapse
No announcement yet.

Works in 10.6, why not 11?

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

  • Works in 10.6, why not 11?

    In my code, I have defined a function to assign a number to each bar as they occur.

    In the main function I have these two instructions:

    var nState=getBarState();
    if(nState==BARSTATE_NEWBAR) BarIndx = efsInternal("IndxBars");

    I also defined the function IndxBars:

    function IndxBars(){
    fBarIndx = fBarIndx + 1;
    return fBarIndx;
    }

    Back in main I use this call to get the index number:
    flag=BarIndx.getValue();

    This code runs fine in ver10.6, but the "flag=BarIndx.getValue();" call fails in ver11. The code won't run and returns an error saying "Undefined function call"

    How do I fix this?

    Thanks,

    Perry

  • #2
    Re: Works in 10.6, why not 11?

    Perry
    You may want to post the entire code as it is working in 10.6 so that anyone trying to help you does not have to guess as to what the rest of the code is.
    That aside assuming that I understood correctly what you are trying to do you could just use the getCurrentBarCount() function which returns the bar count starting from the first [ie oldest] bar on the chart
    Alex


    Originally posted by perrydolia
    In my code, I have defined a function to assign a number to each bar as they occur.

    In the main function I have these two instructions:

    var nState=getBarState();
    if(nState==BARSTATE_NEWBAR) BarIndx = efsInternal("IndxBars");

    I also defined the function IndxBars:

    function IndxBars(){
    fBarIndx = fBarIndx + 1;
    return fBarIndx;
    }

    Back in main I use this call to get the index number:
    flag=BarIndx.getValue();

    This code runs fine in ver10.6, but the "flag=BarIndx.getValue();" call fails in ver11. The code won't run and returns an error saying "Undefined function call"

    How do I fix this?

    Thanks,

    Perry

    Comment


    • #3
      OK. Here you go, the whole code follows.

      It fails near the end, on the line:
      var p5Offset=p5Indx - BarIndx.getValue();
      since this was the first time the BarIndx.getValue(); instruction was run.

      If fails with an "undefined function call"



      /* This code draws a zig zag line to define
      the most recent two M or W waves */

      var hL=0; var lL=0;
      var hH=0; var lH=0;
      var upsw=0;
      var p1=0; var p2=0; var p3=0; var p4=0; var p5=0;
      var v1=0; var v2=0; var v3=0; var v4=0; var v5=0;
      var p1Indx=0; var p2Indx=0; var p3Indx=0; var p4Indx=0; var p5Indx=0;
      var v1Indx=0; var v2Indx=0; var v3Indx=0; var v4Indx=0; var v5Indx=0;
      var BarIndx=0; var fBarIndx=0; var NewIndx=0;

      function preMain() { //****************************************

      setStudyTitle("2MW waves");
      setPriceStudy(true);
      }

      function main() { //********************************************

      if(hL==0){ //set initial values for hL and lH
      lH=high();
      hH=high();
      hL=low();
      lL=low();
      }

      /* the instr for drawing lines requires a -x lookback number
      from the last bar to define the line end points,
      this BarIndex provides that relative reference for positioning the lines */
      var nState=getBarState(); //if starting a new bar...
      if(nState==BARSTATE_NEWBAR) BarIndx = efsInternal("IndxBars"); //give this bar an index number

      if(upsw==1) { //on an up swing

      if(low()>hL) hL=low(); //update the highest low as it moves up
      if(high()>hH){ //update and index the highest high of the swing
      hH=high();
      NewIndx=BarIndx.getValue();
      }

      if(high()<hL && low()<low(-1)) { //swing turns to down if high clears dn and not an inside bar

      //we just made an new peak, revise prev peaks values
      p5=p4;
      p4=p3;
      p3=p2;
      p2=p1;
      p1=hH;
      //and, revise index locations of prev peaks
      p5Indx=p4Indx;
      p4Indx=p3Indx;
      p3Indx=p2Indx;
      p2Indx=p1Indx;
      p1Indx=NewIndx;
      //change swing direction
      upsw=0;
      lH=high(); //set new lowest high
      lL=low(); //set new lowest low
      NewIndx=BarIndx.getValue(); //index location of new lowest low
      }
      }

      if(upsw==0) { //on a down swing

      if(high()<lH) lH=high(); //update the lowest high as is moves down
      if(low()<lL){ //update and index the lowest low as it moves down
      lL=low();
      NewIndx=BarIndx.getValue();
      }

      if(low()>lH && high()>high(-1)) { //swing turns to up if low clears up and not an inside day

      //we just made a new valley, revise prev valley values
      v5=v4;
      v4=v3;
      v3=v2;
      v2=v1;
      v1=lL;
      //and, revise index locations of prev valleys
      v5Indx=v4Indx;
      v4Indx=v3Indx;
      v3Indx=v2Indx;
      v2Indx=v1Indx;
      v1Indx=NewIndx;
      //change to up swing
      upsw=1;
      hL=low(); //set new highest low
      hH=high(); //set new highest high
      NewIndx=BarIndx.getValue(); //index location of new highest high
      }
      }

      if(upsw==1){ //output previous two M waves

      //calculate offsets, offsets are required to specify the location (-x) from last bar
      var p5Offset=p5Indx - BarIndx.getValue();
      var p4Offset=p4Indx - BarIndx.getValue();
      var p3Offset=p3Indx - BarIndx.getValue();
      var p2Offset=p2Indx - BarIndx.getValue();
      var p1Offset=p1Indx - BarIndx.getValue();
      var v5Offset=v5Indx - BarIndx.getValue();
      var v4Offset=v4Indx - BarIndx.getValue();
      var v3Offset=v3Indx - BarIndx.getValue();
      var v2Offset=v2Indx - BarIndx.getValue();
      var v1Offset=v1Indx - BarIndx.getValue();

      //draw previous M wave
      drawLineRelative( v5Offset, v5, p4Offset, p4, PS_SOLID, 2, Color.black, 1 );
      drawLineRelative( p4Offset, p4, v4Offset, v4, PS_SOLID, 2, Color.black, 2 );
      drawLineRelative( v4Offset, v4, p3Offset, p3, PS_SOLID, 2, Color.black, 3 );
      drawLineRelative( p3Offset, p3, v3Offset, v3, PS_SOLID, 2, Color.black, 4 );
      //draw recent M wave
      drawLineRelative( v3Offset, v3, p2Offset, p2, PS_SOLID, 2, Color.blue, 5 );
      drawLineRelative( p2Offset, p2, v2Offset, v2, PS_SOLID, 2, Color.blue, 6 );
      drawLineRelative( v2Offset, v2, p1Offset, p1, PS_SOLID, 2, Color.blue, 7 );
      drawLineRelative( p1Offset, p1, v1Offset, v1, PS_SOLID, 2, Color.blue, 8 );
      }

      if(upsw==0) { //output previous two W waves

      //calculate offsets, offsets are required to specify the location (-x) from last bar
      var p5Offset=p5Indx - BarIndx.getValue();
      var p4Offset=p4Indx - BarIndx.getValue();
      var p3Offset=p3Indx - BarIndx.getValue();
      var p2Offset=p2Indx - BarIndx.getValue();
      var p1Offset=p1Indx - BarIndx.getValue();
      var v5Offset=v5Indx - BarIndx.getValue();
      var v4Offset=v4Indx - BarIndx.getValue();
      var v3Offset=v3Indx - BarIndx.getValue();
      var v2Offset=v2Indx - BarIndx.getValue();
      var v1Offset=v1Indx - BarIndx.getValue();

      //draw previous W wave
      drawLineRelative( p5Offset, p5, v4Offset, v4, PS_SOLID, 2, Color.black, 1 );
      drawLineRelative( v4Offset, v4, p4Offset, p4, PS_SOLID, 2, Color.black, 2 );
      drawLineRelative( p4Offset, p4, v3Offset, v3, PS_SOLID, 2, Color.black, 3 );
      drawLineRelative( v3Offset, v3, p3Offset, p3, PS_SOLID, 2, Color.black, 4 );
      //draw recent W wave
      drawLineRelative( p3Offset, p3, v2Offset, v2, PS_SOLID, 2, Color.blue, 5 );
      drawLineRelative( v2Offset, v2, p2Offset, p2, PS_SOLID, 2, Color.blue, 6 );
      drawLineRelative( p2Offset, p2, v1Offset, v1, PS_SOLID, 2, Color.blue, 7 );
      drawLineRelative( v1Offset, v1, p1Offset, p1, PS_SOLID, 2, Color.blue, 8 );
      }
      }

      function IndxBars(){ //*************************************************
      fBarIndx = fBarIndx + 1;
      return fBarIndx;
      }

      Comment


      • #4
        Perry
        The first problem is that you are using the getValue() method of the series object without passing a bar index [ie myVar.getValue() instead of myVar.getValue(0)]. While 10.6 will allow it this is actually an incorrect behavior that version 11 fixes
        The second problem is that the efsInternal() function is not initialized on the first bar as the getBarState() function does not return BARSTATE_NEWBAR on that bar. While 10.6 allows it version 11 will throw an error if you call an undefined function [I believe this is due to the newer JavaScript engine used in version 11].
        Once you have corrected the problem related to the proper usage of the getValue() method you have a number of solutions to fix the error generated for the undefined function.
        One is to OR a check for BARSTATE_ALLBARS in the same conditional statement in which you check for BARSTATE_NEWBAR. This will allow the efsInternal() function to be initialized also on the first bar on the chart
        Alternatively at the very top of main run a check on the bar count [using getCurrentBarCount()] and if it is less than 2 interrupt the execution of the script. This will prevent the rest of the script from running on the first bar
        As I suggested in my previous reply you could instead simply use the getCurrentBarCount() function to obtain the same result that you are getting by using the IndxBars function called by the efsInternal() function
        To do this assign the getCurrentBarCount() to the BarIndx variable [in lieu of calling the IndxBars function through efsInternal()] then replace all instances of BarIndex.getValue(0) with BarIndx and remove the IndxBars function altogether. The result will be the same and the script should be more efficient.
        Alex


        Originally posted by perrydolia
        OK. Here you go, the whole code follows.

        It fails near the end, on the line:
        var p5Offset=p5Indx - BarIndx.getValue();
        since this was the first time the BarIndx.getValue(); instruction was run.

        If fails with an "undefined function call"



        /* This code draws a zig zag line to define
        the most recent two M or W waves */

        var hL=0; var lL=0;
        var hH=0; var lH=0;
        var upsw=0;
        var p1=0; var p2=0; var p3=0; var p4=0; var p5=0;
        var v1=0; var v2=0; var v3=0; var v4=0; var v5=0;
        var p1Indx=0; var p2Indx=0; var p3Indx=0; var p4Indx=0; var p5Indx=0;
        var v1Indx=0; var v2Indx=0; var v3Indx=0; var v4Indx=0; var v5Indx=0;
        var BarIndx=0; var fBarIndx=0; var NewIndx=0;

        function preMain() { //****************************************

        setStudyTitle("2MW waves");
        setPriceStudy(true);
        }

        function main() { //********************************************

        if(hL==0){ //set initial values for hL and lH
        lH=high();
        hH=high();
        hL=low();
        lL=low();
        }

        /* the instr for drawing lines requires a -x lookback number
        from the last bar to define the line end points,
        this BarIndex provides that relative reference for positioning the lines */
        var nState=getBarState(); //if starting a new bar...
        if(nState==BARSTATE_NEWBAR) BarIndx = efsInternal("IndxBars"); //give this bar an index number

        if(upsw==1) { //on an up swing

        if(low()>hL) hL=low(); //update the highest low as it moves up
        if(high()>hH){ //update and index the highest high of the swing
        hH=high();
        NewIndx=BarIndx.getValue();
        }

        if(high()<hL && low()<low(-1)) { //swing turns to down if high clears dn and not an inside bar

        //we just made an new peak, revise prev peaks values
        p5=p4;
        p4=p3;
        p3=p2;
        p2=p1;
        p1=hH;
        //and, revise index locations of prev peaks
        p5Indx=p4Indx;
        p4Indx=p3Indx;
        p3Indx=p2Indx;
        p2Indx=p1Indx;
        p1Indx=NewIndx;
        //change swing direction
        upsw=0;
        lH=high(); //set new lowest high
        lL=low(); //set new lowest low
        NewIndx=BarIndx.getValue(); //index location of new lowest low
        }
        }

        if(upsw==0) { //on a down swing

        if(high()<lH) lH=high(); //update the lowest high as is moves down
        if(low()<lL){ //update and index the lowest low as it moves down
        lL=low();
        NewIndx=BarIndx.getValue();
        }

        if(low()>lH && high()>high(-1)) { //swing turns to up if low clears up and not an inside day

        //we just made a new valley, revise prev valley values
        v5=v4;
        v4=v3;
        v3=v2;
        v2=v1;
        v1=lL;
        //and, revise index locations of prev valleys
        v5Indx=v4Indx;
        v4Indx=v3Indx;
        v3Indx=v2Indx;
        v2Indx=v1Indx;
        v1Indx=NewIndx;
        //change to up swing
        upsw=1;
        hL=low(); //set new highest low
        hH=high(); //set new highest high
        NewIndx=BarIndx.getValue(); //index location of new highest high
        }
        }

        if(upsw==1){ //output previous two M waves

        //calculate offsets, offsets are required to specify the location (-x) from last bar
        var p5Offset=p5Indx - BarIndx.getValue();
        var p4Offset=p4Indx - BarIndx.getValue();
        var p3Offset=p3Indx - BarIndx.getValue();
        var p2Offset=p2Indx - BarIndx.getValue();
        var p1Offset=p1Indx - BarIndx.getValue();
        var v5Offset=v5Indx - BarIndx.getValue();
        var v4Offset=v4Indx - BarIndx.getValue();
        var v3Offset=v3Indx - BarIndx.getValue();
        var v2Offset=v2Indx - BarIndx.getValue();
        var v1Offset=v1Indx - BarIndx.getValue();

        //draw previous M wave
        drawLineRelative( v5Offset, v5, p4Offset, p4, PS_SOLID, 2, Color.black, 1 );
        drawLineRelative( p4Offset, p4, v4Offset, v4, PS_SOLID, 2, Color.black, 2 );
        drawLineRelative( v4Offset, v4, p3Offset, p3, PS_SOLID, 2, Color.black, 3 );
        drawLineRelative( p3Offset, p3, v3Offset, v3, PS_SOLID, 2, Color.black, 4 );
        //draw recent M wave
        drawLineRelative( v3Offset, v3, p2Offset, p2, PS_SOLID, 2, Color.blue, 5 );
        drawLineRelative( p2Offset, p2, v2Offset, v2, PS_SOLID, 2, Color.blue, 6 );
        drawLineRelative( v2Offset, v2, p1Offset, p1, PS_SOLID, 2, Color.blue, 7 );
        drawLineRelative( p1Offset, p1, v1Offset, v1, PS_SOLID, 2, Color.blue, 8 );
        }

        if(upsw==0) { //output previous two W waves

        //calculate offsets, offsets are required to specify the location (-x) from last bar
        var p5Offset=p5Indx - BarIndx.getValue();
        var p4Offset=p4Indx - BarIndx.getValue();
        var p3Offset=p3Indx - BarIndx.getValue();
        var p2Offset=p2Indx - BarIndx.getValue();
        var p1Offset=p1Indx - BarIndx.getValue();
        var v5Offset=v5Indx - BarIndx.getValue();
        var v4Offset=v4Indx - BarIndx.getValue();
        var v3Offset=v3Indx - BarIndx.getValue();
        var v2Offset=v2Indx - BarIndx.getValue();
        var v1Offset=v1Indx - BarIndx.getValue();

        //draw previous W wave
        drawLineRelative( p5Offset, p5, v4Offset, v4, PS_SOLID, 2, Color.black, 1 );
        drawLineRelative( v4Offset, v4, p4Offset, p4, PS_SOLID, 2, Color.black, 2 );
        drawLineRelative( p4Offset, p4, v3Offset, v3, PS_SOLID, 2, Color.black, 3 );
        drawLineRelative( v3Offset, v3, p3Offset, p3, PS_SOLID, 2, Color.black, 4 );
        //draw recent W wave
        drawLineRelative( p3Offset, p3, v2Offset, v2, PS_SOLID, 2, Color.blue, 5 );
        drawLineRelative( v2Offset, v2, p2Offset, p2, PS_SOLID, 2, Color.blue, 6 );
        drawLineRelative( p2Offset, p2, v1Offset, v1, PS_SOLID, 2, Color.blue, 7 );
        drawLineRelative( v1Offset, v1, p1Offset, p1, PS_SOLID, 2, Color.blue, 8 );
        }
        }

        function IndxBars(){ //*************************************************
        fBarIndx = fBarIndx + 1;
        return fBarIndx;
        }

        Comment


        • #5
          Alexis,

          Thank you for your help and clarification. I will implement the necessary changes.

          Perry

          Comment


          • #6
            Perry
            You are welcome
            Alex


            Originally posted by perrydolia
            Alexis,

            Thank you for your help and clarification. I will implement the necessary changes.

            Perry

            Comment

            Working...
            X