Announcement

Collapse
No announcement yet.

drawLineRelative

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

  • drawLineRelative

    I am coming up short in using the drawLineRelative parameters in my code. Any help would be appreciated. I believe I am confused with the nBarCounter as I would like to be able to have the lines stay on the chart permanently each time the condition is met, but currently, they only show on a most recent event and then drop off the next time it occurs. Here is what I have so far:

    if(getBarState() == BARSTATE_NEWBAR) {


    nBarCounter = 0;

    if //my conditions
    {
    drawLineRelative(0, low(0)-.5,8,low(0)
    -.5,PS_SOLID,2,Color.red,"Entry"+nBarCounter);
    }


    Thank you.

  • #2
    Re: drawLineRelative

    turbotrade
    This is not apparent from the snippet of code you posted anyhow nBarCounter needs to be a global variable [ie declared outside of the main function]
    Then inside the getBarState() conditional statement you need to increment nBarCounter by 1 at each iteration whereas you are resetting it to 0 eg
    if(getBarState() == BARSTATE_NEWBAR) {
    nBarCounter ++;

    alternatively you can also write the latter as
    nBarCounter +=1;
    This way nBarCounter will have a different value on each bar
    Alex


    Originally posted by turbotrade
    I am coming up short in using the drawLineRelative parameters in my code. Any help would be appreciated. I believe I am confused with the nBarCounter as I would like to be able to have the lines stay on the chart permanently each time the condition is met, but currently, they only show on a most recent event and then drop off the next time it occurs. Here is what I have so far:

    if(getBarState() == BARSTATE_NEWBAR) {


    nBarCounter = 0;

    if //my conditions
    {
    drawLineRelative(0, low(0)-.5,8,low(0)
    -.5,PS_SOLID,2,Color.red,"Entry"+nBarCounter);
    }


    Thank you.

    Comment


    • #3
      Hi Alex,
      That worked perfectly...thank you again. I apologize for not posting my entire code - still can't get anything with my vB code to post.

      As you suggested, I set up the global variable outside of preMain and Main as:
      var nBarCounter = 0;

      and used nBarCounter ++;


      Jody

      Comment


      • #4
        Jody
        You are most welcome
        Alex


        Originally posted by turbotrade
        Hi Alex,
        That worked perfectly...thank you again. I apologize for not posting my entire code - still can't get anything with my vB code to post.

        As you suggested, I set up the global variable outside of preMain and Main as:
        var nBarCounter = 0;

        and used nBarCounter ++;


        Jody

        Comment

        Working...
        X