Announcement

Collapse
No announcement yet.

drawLineRelative

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

  • drawLineRelative

    In the following code, why is it that the High/Low lines are drawn only once for the last bar? It seems that it would do it for every bar. (It does what I want but I don't understand). Thanks.

    function preMain() {
    setPriceStudy(true);
    }

    var vtime
    var vHigh;
    var vLow;
    var BarCntr = 0;
    function main() {


    if (getBarState() == BARSTATE_NEWBAR) {
    BarCntr +=1;

    vHigh = high();
    vLow = low();
    debugPrint("Bar=" + BarCntr + " Max=" + vHigh + " Min=" + vLow + "\n");

    for (i = 0; i < 20; ++i) {
    vHigh = Math.max(high(-i), vHigh);
    vLow = Math.min(low(-i), vLow);
    }

    drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High");
    drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low");
    }

    }

  • #2
    try this

    drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High",bar);
    bar=+1
    drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low"bar);

    Comment


    • #3
      invalid number of arguments

      i get "invalid number of arguments". what was it supposed to do?

      code:
      var bar;
      ...
      drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High", bar);
      bar=+1
      drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low", bar);
      ...

      Comment


      • #4
        The problem you are seeing is due to the fact that the label is supposed to be unique for each line. If it isn't, then only the last line with that label will be seen.

        Try this:

        var bar=0;

        drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High", "H" + bar);
        drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low", "L" + bar);
        bar++;
        Garth

        Comment


        • #5
          Actually,
          drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High", "H" + bar);
          drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low", "L" + bar);

          was still causing "Invalid number of parameters" error. So I changed it to:

          drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "H" + bar);
          drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "L" + bar);

          figuring that the last parameter must be the "Label" you are talking about.

          The "invalid number of parameters" error is gone but it remains that the high/low bars are printed only once for the last bar. I'd like to understand this so that in case I do want to draw multiple bars, I can. Thanks.

          Comment


          • #6


            says

            drawLineRelative(x1, y1, x2, y2, style, thickness, color);
            drawLineAbsolute(x1, y1, x2, y2, style, thickness, color);

            Style
            PS_SOLID
            PS_DASH
            PS_DOT
            PS_DASHDOT
            PS_DASHDOTDOT

            Thickness
            Thickness of line. Minimum of 1.

            Color

            Color.RGB or Color.colorname

            Is it possible this is leaving out some of the parameters?

            Comment


            • #7
              Hello philtong,

              Welcome to the Boards. Here's a link to the current specs for this function.

              Drawing Images, Shapes, and Text with EFS
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment


              • #8
                Originally posted by philtong
                Actually,
                drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High", "H" + bar);
                drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low", "L" + bar);

                was still causing "Invalid number of parameters" error. So I changed it to:

                drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "H" + bar);
                drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "L" + bar);
                Yes, sorry I wrote that really quickly before heading out on my adventures. That is the correct way.

                I'd like to understand this so that in case I do want to draw multiple bars, I can. Thanks.
                Again my fault. Move bar to be defined outside both main() and preMain() so it's value is maintained through each iteration of main()

                preMain(){
                }

                var bar = 0;

                main(){

                .
                .
                .
                }

                As long as you increment bar (bar++) after the drawline commands you should be fine.
                Garth

                Comment

                Working...
                X