Announcement

Collapse
No announcement yet.

FirstXminsHL.efs

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

  • FirstXminsHL.efs

    How can I add more horizontal lines to this study which would be x ticks above/below the H & L lines. The purpose is to show the A & C lines of the ACD system? Was unable to open the study with the Wizard. Thanks, Andrew.

  • #2
    Andrew
    In lines 83 and 88 of the following image you can see what you need to insert in the formula to draw two more lines one above the High line and one below the Low line.
    In those commands replace every instance of your_value with the point value which needs to be added/subtracted.



    If you want the values to show in the Cursor Window you will also need to modify the return statement as shown in the following image.
    Also in this case replace your_value with the desired point value



    Note that you will not be able to modufy this formula using the Formula Wizard as that tool can only read formulas that were written using the Formula Wizard which this efs is not.
    Alex

    Comment


    • #3
      Get syntax error line 97 nTicksA not defined

      .
      PHP Code:
      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("ACD System");
          
      setCursorLabelName("30m H"0);
          
      setCursorLabelName("30m L"1);
          
      setDefaultBarFgColor(Color.blue0);
          
      setDefaultBarFgColor(Color.blue1);
          
      setDefaultBarThickness(10);
          
      setDefaultBarThickness(11);
          
      setPlotType(PLOTTYPE_FLATLINES0);
          
      setPlotType(PLOTTYPE_FLATLINES1);
          
          var 
      fp1 = new FunctionParameter("nMin"FunctionParameter.NUMBER);
          
      fp1.setName("Number of Minutes");
          
      fp1.setLowerLimit(1);
          
      fp1.setDefault(60);

          var 
      fp2 = new FunctionParameter("nThickness"FunctionParameter.NUMBER);
          
      fp2.setName("Line Thickness");
          
      fp2.setLowerLimit(1);
          
      fp2.setDefault(1);

          var 
      fp3 = new FunctionParameter("cColorH"FunctionParameter.COLOR);
          
      fp3.setName("High Color");
          
      fp3.setDefault(Color.blue);

          var 
      fp4 = new FunctionParameter("cColorL"FunctionParameter.COLOR);
          
      fp4.setName("Low Color");
          
      fp4.setDefault(Color.red);

          var 
      fp5 = new FunctionParameter("nTicksA"FunctionParameter.NUMBER);
          
      fp5.setName("Ticks for A");
          
      fp5.setLowerLimit(1);
          
      fp5.setDefault(1)

          var 
      fp6 = new FunctionParameter("nTicksC"FunctionParameter.NUMBER);
          
      fp6.setName("Ticks for C");
          
      fp6.setLowerLimit(1);
          
      fp6.setDefault(1)
      }

      var 
      bEdit true;
      var 
      bActive true;
      var 
      nDayCntr 0;

      var 
      vStartTime null;
      var 
      vHigh null;
      var 
      vLow null;
      var 
      FirstBar null;

      function 
      main(nMinnThicknesscColorHcColorL) {
          if (
      nMin == nullnMin 60;
          if (
      bEdit == true) {
              
      nMin Math.round(nMin);
              
      setCursorLabelName(nMin "min H"0);
              
      setCursorLabelName(nMin "min L"1);
              
      setDefaultBarThickness(nThickness0);
              
      setDefaultBarThickness(nThickness0);
              
      setDefaultBarFgColor(cColorH0);
              
      setDefaultBarFgColor(cColorL1);
              
      bEdit false;
          }
          
          if (
      getDay() != getDay(-1) || vHigh == null || vLow == null) {
              
      bActive true;
              
      nDayCntr += 1;
              
      vStartTime getValue("Time");
              
      vHigh high();
              
      vLow low();
          }
          
      FirstBar getFirstBarIndexOfDay(vStartTime);
          var 
      vTime getValue("Time");

          
      // 3,600,000 milliseconds = 1 hour
          //    60,000 milliseconds = 1 minute
          
      if ((vTime vStartTime)/60000 nMin) {
              
      vHigh Math.max(high(), vHigh);
              
      vLow Math.min(low(), vLow);
          } else {
              
      bActive false;
          }

          if (
      FirstBar != null) {
              
      drawLineRelativeFirstBarvHigh0vHighPS_SOLIDnThickness,
                  
      cColorH"Hline");
              
      drawLineRelativeFirstBarvHigh+nTicksA0,vHigh+nTicksAPS_SOLIDnThicknesscColor"Hline2");
              
      drawLineRelativeFirstBarvHigh+nTicksA0,vHigh+nTicksCPS_SOLIDnThicknesscColor"Hline3");
              
      drawTextRelative2vHighvHigh.toFixed(2), cColorHnull
                  
      Text.VCENTER|Text.BOLDnull10"High");
              
      drawLineRelativeFirstBarvLow0vLowPS_SOLIDnThickness,
                  
      cColorL"Lline")
              
      drawLineRelativeFirstBarvLow+nTicksA0,vLow-nTicksAPS_SOLIDnThicknesscColor"Lline2");    
              
      drawLineRelativeFirstBarvLow+nTicksA0,vLow-nTicksAPS_SOLIDnThicknesscColor"Lline3");
              
      drawTextRelative2vLowvLow.toFixed(2), cColorLnull
                  
      Text.VCENTER|Text.BOLDnull10"Low");
          }

          if (
      bActive == false) {
              return new Array((
      vHigh+nTicksA).toFixed(2),(vHigh+nTicksC).toFixed(2),vHigh.toFixed(2), vLow.toFixed(2),(vLow-nTicksA).toFixed(2),(vLow-nTicksC).toFixed(2));
          }
          return 
      null

      Comment


      • #4
        astanton
        You need to include in the main definition the names of the FunctionParameters you added (see example below)
        Alex

        PHP Code:
        function main(nMinnThicknesscColorHcColorLnTicksAetc) { 

        Comment


        • #5
          FirstXminsHL.efs

          I added the two new functions to that line but still have the same error. Should there be "setdefault" entries in that section as well?

          Comment


          • #6
            astanton
            If you added the definitions I doubt the error message is going to be the same.
            What does the error message say?
            Alex

            Comment


            • #7
              Exact message when I try to run in chart

              Downloads\ACD System.efs, line 97:
              ReferenceError: cColor is not defined
              Downloads\ACD System.efs, line 97:
              ReferenceError: cColor is not defined
              No Syntax Errors
              Downloads\ACD System.efs, line 97:
              ReferenceError: nTicksA is not defined
              No Syntax Errors
              Downloads\ACD System.efs, line 97:
              ReferenceError: nTicksA is not defined
              No Syntax Errors
              No Syntax Errors
              No Syntax Errors
              Downloads\ACD System.efs, line 97:
              ReferenceError: nTicksA is not defined
              No Syntax Errors
              No SyntaxErrors
              Downloads\ACD System.efs, line 97:
              ReferenceError: nTicksA is not defined
              No Syntax Errors
              Downloads\ACD System.efs, line 97:
              ReferenceError: nTicksA is not defined
              No Syntax Errors
              No Syntax Errors
              No Syntax Errors

              Comment


              • #8
                astanton
                Although it refers to the same line the message is actually different as it is telling you that cColor is not defined..
                You replaced the original cColor FunctionParameter with two new FunctionParameters ie cColorH and cColorL.
                You now need to replace every instance of cColor with either cColorH or cColorL
                Alex

                Comment


                • #9
                  Syntax check

                  When I hit the Syntax Check on the menu in the EFS Editor nothing happens. I only get the error messages when I try to run the file in a chart. Do I have to do anything to get the Editor to work?

                  Comment


                  • #10
                    Last hurdle

                    Thanks for all your help. The following does exactly what I want with one small problem that I cannot resolve. In the cursor window the H value shows up as CUp, L as AUp, CUp as L, and AUp as H. Your help is greatly appreciated, Andrew.

                    function preMain() {
                    setPriceStudy(true);
                    setStudyTitle("ACD System");
                    setCursorLabelName("30m H", 0);
                    setCursorLabelName("30m L", 1);
                    setCursorLabelName("CUp", 2);
                    setCursorLabelName("AUp", 3);
                    setCursorLabelName("ADown", 4);
                    setCursorLabelName("CDown", 5);
                    setDefaultBarFgColor(Color.blue, 0);
                    setDefaultBarFgColor(Color.blue, 1);
                    setDefaultBarFgColor(Color.blue, 2);
                    setDefaultBarFgColor(Color.blue, 3);
                    setDefaultBarFgColor(Color.blue, 4);
                    setDefaultBarFgColor(Color.blue, 5);
                    setDefaultBarThickness(1, 0);
                    setDefaultBarThickness(1, 1);
                    setDefaultBarThickness(1, 2);
                    setDefaultBarThickness(1, 3);
                    setDefaultBarThickness(1, 4);
                    setDefaultBarThickness(1, 5);
                    setPlotType(PLOTTYPE_FLATLINES, 0);
                    setPlotType(PLOTTYPE_FLATLINES, 1);
                    setPlotType(PLOTTYPE_FLATLINES, 2);
                    setPlotType(PLOTTYPE_FLATLINES, 3);
                    setPlotType(PLOTTYPE_FLATLINES, 4);
                    setPlotType(PLOTTYPE_FLATLINES, 5);

                    var fp1 = new FunctionParameter("nMin", FunctionParameter.NUMBER);
                    fp1.setName("Number of Minutes");
                    fp1.setLowerLimit(1);
                    fp1.setDefault(60);

                    var fp2 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);
                    fp2.setName("Line Thickness");
                    fp2.setLowerLimit(1);
                    fp2.setDefault(1);

                    var fp3 = new FunctionParameter("cColorH", FunctionParameter.COLOR);
                    fp3.setName("High Color");
                    fp3.setDefault(Color.blue);

                    var fp4 = new FunctionParameter("cColorL", FunctionParameter.COLOR);
                    fp4.setName("Low Color");
                    fp4.setDefault(Color.red);

                    var fp5 = new FunctionParameter("nTicksA", FunctionParameter.NUMBER);
                    fp5.setName("Ticks for A");
                    fp5.setLowerLimit(.01);
                    fp5.setDefault(1)

                    var fp6 = new FunctionParameter("nTicksC", FunctionParameter.NUMBER);
                    fp6.setName("Ticks for C");
                    fp6.setLowerLimit(.01);
                    fp6.setDefault(1)

                    var fp7 = new FunctionParameter("cColorCUp", FunctionParameter.COLOR);
                    fp7.setName("C Up Color");
                    fp7.setDefault(Color.blue);

                    var fp8 = new FunctionParameter("cColorAUp", FunctionParameter.COLOR);
                    fp8.setName("A Up Color");
                    fp8.setDefault(Color.blue);

                    var fp9 = new FunctionParameter("cColorADown", FunctionParameter.COLOR);
                    fp9.setName("A Down Color");
                    fp9.setDefault(Color.red);

                    var fp10 = new FunctionParameter("cColorCDown", FunctionParameter.COLOR);
                    fp10.setName("C Down Color");
                    fp10.setDefault(Color.red);
                    }

                    var bEdit = true;
                    var bActive = true;
                    var nDayCntr = 0;

                    var vStartTime = null;
                    var vHigh = null;
                    var vLow = null;
                    var FirstBar = null;

                    function main(nMin, nThickness, cColorH, cColorL, cColorCUp, cColorAUp, cColorADown, cColorCDown, nTicksA, nTicksC) {
                    if (nMin == null) nMin = 60;
                    if (bEdit == true) {
                    nMin = Math.round(nMin);
                    setCursorLabelName(nMin + "min H", 0);
                    setCursorLabelName(nMin + "min L", 1);
                    setDefaultBarThickness(nThickness, 0);
                    setDefaultBarThickness(nThickness, 0);
                    setDefaultBarFgColor(cColorH, 0);
                    setDefaultBarFgColor(cColorL, 1);
                    setDefaultBarFgColor(cColorCUp, 2);
                    setDefaultBarFgColor(cColorAUp, 3);
                    setDefaultBarFgColor(cColorADown, 4);
                    setDefaultBarFgColor(cColorCDown, 5);
                    bEdit = false;
                    }

                    if (getDay() != getDay(-1) || vHigh == null || vLow == null) {
                    bActive = true;
                    nDayCntr += 1;
                    vStartTime = getValue("Time");
                    vHigh = high();
                    vLow = low();
                    }
                    FirstBar = getFirstBarIndexOfDay(vStartTime);
                    var vTime = getValue("Time");

                    // 3,600,000 milliseconds = 1 hour
                    // 60,000 milliseconds = 1 minute
                    if ((vTime - vStartTime)/60000 < nMin) {
                    vHigh = Math.max(high(), vHigh);
                    vLow = Math.min(low(), vLow);
                    } else {
                    bActive = false;
                    }

                    if (FirstBar != null) {
                    drawLineRelative( FirstBar, vHigh, 0, vHigh, PS_SOLID, nThickness,cColorH, "Hline");
                    drawLineRelative( FirstBar, vHigh+nTicksC, 0,vHigh+nTicksC, PS_SOLID, nThickness, cColorCUp, "CUp");
                    drawLineRelative( FirstBar, vHigh+nTicksA, 0,vHigh+nTicksA, PS_SOLID, nThickness, cColorAUp, "AUp");
                    drawTextRelative( 2, vHigh, vHigh.toFixed(2), cColorH, null, Text.VCENTER|Text.BOLD, null, 10, "High");
                    drawLineRelative( FirstBar, vLow, 0, vLow, PS_SOLID, nThickness, cColorL, "Lline")
                    drawLineRelative( FirstBar, vLow-nTicksA, 0,vLow-nTicksA, PS_SOLID, nThickness, cColorADown, "ADown");
                    drawLineRelative( FirstBar, vLow-nTicksC, 0,vLow-nTicksC, PS_SOLID, nThickness, cColorCDown, "CDown");
                    drawTextRelative( 2, vLow, vLow.toFixed(2), cColorL, null, Text.VCENTER|Text.BOLD, null, 10, "Low");
                    }

                    if (bActive == false) {
                    return new Array((vHigh+nTicksA).toFixed(2),(vHigh+nTicksC).t oFixed(2),vHigh.toFixed(2), vLow.toFixed(2),
                    (vLow-nTicksA).toFixed(2),(vLow-nTicksC).toFixed(2));
                    }
                    return null;
                    }

                    Comment


                    • #11
                      Andrew
                      You may need to rearrange the elements in the return statement ie return new Array((vHigh+nTicksA).toFixed(2),etc etc_ to match the order of the cursor labels. 0 is the first element, 1 the second, etc
                      Alex

                      Comment

                      Working...
                      X