Announcement

Collapse
No announcement yet.

current bar horz lines

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

  • current bar horz lines

    Hi-
    I have no experience writing efs scripts so
    I'm trying to alter an existing one to do what I want but I cannot get it to work. I trade the es and I want to draw 2 horizontal lines, one to plot +1.25 points above current bar low and one to plot -.25 points below current bar low. With the ability to update as the bar is forming in real time.
    If it can be done without a full horizontal bar and instead short bars (attached image) that extend to the right off current bar with price, that would work even better. The attached link shows what I'm trying to accomplish.
    Thanks so much for any help.

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("Lines");
    setCursorLabelName("Line1",0);
    setCursorLabelName("Line1",1);

    var fp3 = new FunctionParameter("Lower1", FunctionParameter.NUMBER);
    fp3.setLowerLimit(0);
    fp3.setDefault(0.25);

    var fp4 = new FunctionParameter("Upper2", FunctionParameter.NUMBER);
    fp4.setLowerLimit(0);
    fp4.setDefault(1.25);
    }

    function main(Lower1,Lower2) {

    clearLineTool(LineTool.HORZ);

    var L1 = low()-Lower1;
    var L2 = low()+Lower2;

    addLineTool(LineTool.HORZ, L1, 1, Color.red, "Lo1");
    addLineTool(LineTool.HORZ, L2, 1, Color.red, "Up2");

    return new Array (formatPriceNumber(L1),formatPriceNumber(L2):
    }
    Attached Files

  • #2
    function main() {
    return new Array ( low(0) - 0.25, high(0) + 1.25);
    }

    might be all you need

    Comment


    • #3
      dido
      Enclosed is the corrected script with comments
      For the description and syntax of the drawLineRelative() function I used in your script as a replacement of the horizontal line see this article in the EFS KnowledgeBase
      Alex

      PHP Code:
      function preMain() {

          
      setPriceStudy(true);
          
      setStudyTitle("Lines");
          
      setCursorLabelName("Line1",0);
          
      setCursorLabelName("Line1",1);

          var 
      fp3 = new FunctionParameter("Lower1"FunctionParameter.NUMBER);
          
      fp3.setLowerLimit(0); 
          
      fp3.setDefault(0.25);

          var 
      fp4 = new FunctionParameter("Upper2"FunctionParameter.NUMBER);
          
      fp4.setLowerLimit(0); 
          
      fp4.setDefault(1.25); 
      }

      function 
      main(Lower1,Upper2) {//replaced invalid parameter Lower2 with Upper2

          //clearLineTool(LineTool.HORZ);//ACM removed 

          
      var L1 low(0)-Lower1;//ACM added 0 in low()
          
      var L2 low(0)+Upper2;//as above and replaced invalid Lower2 with Upper2

          //addLineTool(LineTool.HORZ, L1, 1, Color.red, "Lo1");//ACM removed 
          //addLineTool(LineTool.HORZ, L2, 1, Color.red, "Up2");//ACM removed 

          
      drawLineRelative(0,L1,10,L1,PS_SOLID,1,Color.blue,"line1");//ACM added
          
      drawLineRelative(0,L2,10,L2,PS_SOLID,1,Color.blue,"line2");//as above

          
      return new Array (formatPriceNumber(L1),formatPriceNumber(L2));//missing close parenthesis - also replaced 
                                                                     //incorrect colon with semicolon




      Originally posted by dido
      Hi-
      I have no experience writing efs scripts so
      I'm trying to alter an existing one to do what I want but I cannot get it to work. I trade the es and I want to draw 2 horizontal lines, one to plot +1.25 points above current bar low and one to plot -.25 points below current bar low. With the ability to update as the bar is forming in real time.
      If it can be done without a full horizontal bar and instead short bars (attached image) that extend to the right off current bar with price, that would work even better. The attached link shows what I'm trying to accomplish.
      Thanks so much for any help.

      function preMain() {

      setPriceStudy(true);
      setStudyTitle("Lines");
      setCursorLabelName("Line1",0);
      setCursorLabelName("Line1",1);

      var fp3 = new FunctionParameter("Lower1", FunctionParameter.NUMBER);
      fp3.setLowerLimit(0);
      fp3.setDefault(0.25);

      var fp4 = new FunctionParameter("Upper2", FunctionParameter.NUMBER);
      fp4.setLowerLimit(0);
      fp4.setDefault(1.25);
      }

      function main(Lower1,Lower2) {

      clearLineTool(LineTool.HORZ);

      var L1 = low()-Lower1;
      var L2 = low()+Lower2;

      addLineTool(LineTool.HORZ, L1, 1, Color.red, "Lo1");
      addLineTool(LineTool.HORZ, L2, 1, Color.red, "Up2");

      return new Array (formatPriceNumber(L1),formatPriceNumber(L2):
      }

      Comment


      • #4
        dido
        If you then want to add some text labels to the lines you would use the drawTextRelative() function to do that (see the link for the description and syntax required by the function).
        Enclosed below is a revsion of the script with the labels added and some comments
        Alex

        PHP Code:
        function preMain() {

            
        setPriceStudy(true);
            
        setStudyTitle("Lines");
            
        setCursorLabelName("Line1",0);
            
        setCursorLabelName("Line1",1);

            var 
        fp3 = new FunctionParameter("Lower1"FunctionParameter.NUMBER);
            
        fp3.setLowerLimit(0); 
            
        fp3.setDefault(0.25);

            var 
        fp4 = new FunctionParameter("Upper2"FunctionParameter.NUMBER);
            
        fp4.setLowerLimit(0); 
            
        fp4.setDefault(1.25); 
        }

        function 
        main(Lower1,Upper2) {//replaced invalid parameter Lower2 with Upper2

            //clearLineTool(LineTool.HORZ);//ACM removed 

            
        var L1 low(0)-Lower1;//ACM added 0 in low()
            
        var L2 low(0)+Upper2;//as above and replaced invalid Lower2 with Upper2

            //addLineTool(LineTool.HORZ, L1, 1, Color.red, "Lo1");//ACM removed 
            //addLineTool(LineTool.HORZ, L2, 1, Color.red, "Up2");//ACM removed 

            
        drawLineRelative(0,L1,10,L1,PS_SOLID,1,Color.blue,"line1");//ACM added
            
        drawLineRelative(0,L2,10,L2,PS_SOLID,1,Color.blue,"line2");//as above
            //because the line ends 10 bars to the right of the last bar we add the text on the 11th bar
            //then we align the text to the left of that bar and center it vertically to the calculated
            //prices of L1 and L2
            
        drawTextRelative(11L1formatPriceNumber(L1), Color.bluenullText.LEFT|Text.VCENTER"Arial"10"text1");
            
        drawTextRelative(11L2formatPriceNumber(L2), Color.bluenullText.LEFT|Text.VCENTER"Arial"10"text2");

            return new Array (
        formatPriceNumber(L1),formatPriceNumber(L2));//missing close parenthesis - also replaced 
                                                                       //incorrect colon with semicolon

        Comment


        • #5
          Thanks

          Thanks so much Alex, that's perfect. I appreciate it and the notes were very helpful also

          Comment


          • #6
            dido
            You are most welcome. Glad to hear that you found the notes useful
            Alex

            Comment

            Working...
            X