Announcement

Collapse
No announcement yet.

drawLineAbsolute, drawLineRelative

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

  • drawLineAbsolute, drawLineRelative

    If I call drawLineAbsolute or drawLineRelative from main(), it seems to only draw the lines once - from the last time main() is executed.

    So, in this example, it does color all the price bars green & red, and it also draws a line thru all the closes, so it does know which bar it's on each time main is called. But it only draws the high & low lines once, at the right end of the plot.
    /************************************************** *****************************
    Tests drawLineRelative.

    Date Major Changes
    12mar2009 Created.
    12mar2009
    ************************************************** *****************************/

    g = {};
    g.nBar = 0;

    function preMain()
    {
    setStudyTitle ("Test of drawLineRelative");
    setCursorLabelName ("Test1");

    setPriceStudy (true);
    }

    function main(p_nPeriods, p_nBuy, p_nSell)
    {
    g.nBar += 1;

    drawLineAbsolute (-1, high(-1), 0, high(), PS_SOLID, 1, Color.blue, "highs");
    drawLineRelative (-1, low(-1), 0, low(), PS_SOLID, 1, Color.red, "lows");

    if (g.nBar % 2)
    {setPriceBarColor (Color.green, Color.green);
    }
    else
    {setPriceBarColor (Color.red, Color.red);
    }

    return close(0);
    }
    How do I get it to draw for each bar?

  • #2
    Re: drawLineAbsolute, drawLineRelative

    jennifersimonds
    That is happening because the tagID parameter you are using in the drawLineXxx() commands is the same for all the graphic objects being drawn and since there can only be one graphic object per tagID only the last one remains on the chart [the other ones are removed]. You need to use a tagID that will be unique to each graphic object you want to draw eg
    PHP Code:
    drawLineAbsolute( - 1high( - 1), 0high(), PS_SOLID1Color.blue"highs"+rawtime(0));
    drawLineRelative( - 1low( - 1), 0low(), PS_SOLID1Color.red"lows"+rawtime(0)); 
    In this case I am adding rawtime(0) which is unique to each bar to the strings used as tagIDs but you can use any counter you prefer
    Alex


    Originally posted by jennifersimonds
    If I call drawLineAbsolute or drawLineRelative from main(), it seems to only draw the lines once - from the last time main() is executed.

    So, in this example, it does color all the price bars green & red, and it also draws a line thru all the closes, so it does know which bar it's on each time main is called. But it only draws the high & low lines once, at the right end of the plot.


    How do I get it to draw for each bar?

    Comment


    • #3
      Re: Re: drawLineAbsolute, drawLineRelative

      Originally posted by Alexis C. Montenegro

      That is happening because the tagID parameter you are using in the drawLineXxx() commands is the same for all the graphic objects being drawn and since there can only be one graphic object per tagID only the last one remains on the chart [the other ones are removed]. You need to use a tagID that will be unique to each graphic object you want to draw eg
      Ah, that worked, thanks!

      In my case, since I'm drawing two lines in the same call to main(), I had to make their tagIDs even further unique, since rawtime(0) is going to be the same for each call to main. (Oh, that does make sense, since rawtime(0) returns the Unix timestamp for that bar. Duh.) Anyway, this worked for me:
      drawLineAbsolute (-1, high(-1), 0, high(), PS_SOLID, 1, Color.blue, rawtime(0)+"a");
      drawLineRelative (-1, low(-1), 0, low(), PS_SOLID, 1, Color.red, rawtime(0)+"b");
      Last edited by jennifersimonds; 03-13-2009, 06:53 PM.

      Comment


      • #4
        Re: Re: Re: drawLineAbsolute, drawLineRelative

        jennifersimonds
        You are most welcome.
        That is why in my example I used "highs"+rawtime(0) and "lows"+rawtime(0) as the tagIDs
        Alex


        Originally posted by jennifersimonds
        Ah, that worked, thanks!

        In my case, since I'm drawing two lines in the same call to main(), I had to make their tagIDs even further unique, since rawtime(0) is going to be the same for each call to main. (Oh, that does make sense, since rawtime(0) returns the Unix timestamp for that bar. Duh.) Anyway, this worked for me:
        Code:
        drawLineAbsolute (-1, high(-1), 0, high(), PS_SOLID, 1, Color.blue, rawtime(0)+"a");
        drawLineRelative (-1, low(-1), 0, low(), PS_SOLID, 1, Color.red, rawtime(0)+"b");

        Comment


        • #5
          Re: Re: Re: Re: drawLineAbsolute, drawLineRelative

          Oops, didn't notice that.

          Comment

          Working...
          X