Announcement

Collapse
No announcement yet.

continue statement

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

  • continue statement

    I'm trying to use "continue label" statement in my script, but when I apply study on chart I have a syntax error at line 36.
    I can't find the error.
    Please, someone more expert than me, can help me?
    Thanks in advance.
    Massimo

    var vEx=null;
    function main() {
    debugPrintln("Start ");
    if (vEx==null) vEx=Pivot(high(), 20, 3, 3, 1, 1);
    debugPrintln("Prova "+vEx.getValue(0));
    }

    // PIVOT Function ------------------------------------------------------------------------
    var bPivot_Init=false;
    function Pivot(xPriceValue, xLen, xLeftStrength, xRightStrength, xInstance, xHiLo) {
    if (bPivot_Init==false) {
    var vPriceValue=xPriceValue;
    var vLen=-xLen;
    var vLeftStrength=-xLeftStrength;
    var vRightStrength=-xRightStrength;
    var vInstance=xInstance;
    var vHiLo=xHiLo;
    var vCount_Instance=0;
    var vX=0;
    var vY=0;
    var bPivot_Flag=false;
    var vReturnPivot=-1, vReturnPivotPriceValue=-1, vReturnPivotBar=-1;
    var vCounter=0;
    bPivot_Init=true;
    }
    vX=vRightStrength; //Our first bar index
    maxlabel1 :
    while (bPivot_Flag==false && vX>vLen) { //we start scanning bars
    debugPrintln("Counter "+vCounter++);
    vY=vX+1; //Index of the bar to compare with
    while ((vX-vY)>=vRightStrength) { // check dx
    if ((vHiLo==1 && vPriceValue.getValue(vX)>vPriceValue.getValue(vY)) || (vHiLo==-1 && vPriceValue.getValue(vX)<vPriceValue.getValue(vY)) ) {
    vY=vY+1;
    } else { // dx check ko
    vX=vX-1;
    continue maxlabel1;
    }
    }
    vY=vX-1; // dx ok, now sx
    while ((vY-vX)>=vLeftStrength) { // check sx
    if ((vHiLo==1 && vPriceValue.getValue(vX)>=vPriceValue.getValue(vY) ) || (vHiLo==-1 && vPriceValue.getValue(vX)<=vPriceValue.getValue(vY) )) {
    vY--;
    } else { // sx check ko
    vX--;
    continue maxlabel1;
    }
    }
    vCount_Instance++; // here pivot ok & vCount_Instance++
    if (vCount_Instance==Instance) {
    bPivot_Flag=true;
    } else { // go to next vCount_Instance
    vX--;
    continue maxlabel1;
    }
    }
    if (bPivot_Flag==true) {
    vReturnPivot=1;
    vReturnPivotPriceValue=vPriceValue.getValue(vX);
    vReturnPivotBar=vX;
    drawImageRelative(vReturnPivotBar, vReturnPivotPriceValue, "SystemHappyFace", null, Image.ONTOP, "TagName");
    } else {
    vReturnPivot=-1;
    vReturnPivotPriceValue=-1;
    vReturnPivotBar=-1;
    }
    return new Array (vReturnPivot, vReturnPivotPriceValue, vReturnPivotBar);
    }

  • #2
    In a while loop, you just put:

    continue;

    There is no label to jump to. It's all implied that you're going to continue back up to the top of the while loop for the next condition test.

    In other words, delete "maxlabel1:" next to your while statement and replace every occurrence of "continue maxlabel1;" with "continue;"

    Comment


    • #3
      Hi Steve,
      I read of labels in KB at this link:



      Thanks a lot, I will rewrite my code.
      Regards
      Massimo

      Comment


      • #4
        Hi Steve,
        maybe the link does not work.
        I read EFS KnowledgeBase, Core JavaScript Guide 1.5,
        Chapter 5: Statements.
        It talks about labels.
        What a strange thing ?
        Thanks again.
        Massimo

        Comment


        • #5
          I see what you're saying. I'd advise against using that feature. All it does is promote bad programming habits.

          The simple usage of break and continue with no label after either one should do exactly what you want 99.9% of the time. Otherwise, the code probably has way too many "true/false" flag variables in it or bad if() statement structuring.

          Comment


          • #6
            Ok Steve,
            I will treasure your advice !
            Merry Christmas to all forum members.
            Massimo

            Comment

            Working...
            X