Announcement

Collapse
No announcement yet.

Iterating Line Identifier

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

  • Iterating Line Identifier

    Hi,

    I'm trying to draw horizontal lines based on major highs and lows. I would like like to draw both major and minor divisions set up from a defined array. I can almost get it to work. I don't know how to increment the line identifier for the minor division during the embedded iteration.

    Perhaps a guru can once again rescue me.

    Humbly Yours !, Glenn


    function preMain() {
    setComputeOnClose();
    setPriceStudy(true);

    Top = 1000 ;
    Base = 0;

    Ls = -40 ; // Line Start
    Le = 0 ; // Line End

    T1 = Le + 10 ; // Text Position
    Tp1 = T1 + 17 ; // Text Percentage Position

    Div = new Array( 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1 );

    }


    function main() {


    MajorRange = Top - Base ;

    for (i=0; i<10; i++) {

    MajorDiv = Div[i]; // For the initial iteration

    yVal = Base + ( MajorDiv * MajorRange) ;
    drawLineRelative( Ls, yVal, Le, yVal, PS_SOLID, 2, Color.RGB(250,250,0), (i+"A"));


    NextDiv = Div[i+1]; // NextDiv is the divider to use for the next iteration, to set up minor Range
    NextBase = Base + ( NextDiv * MajorRange) ; // yVal of next divider

    MinorRange = NextBase - yVal ;
    MinorRange = Math.round(MinorRange) ;

    for (j=1; j<11; j++) {

    MinorDiv = Div[j]; // Divider to use this minor iteration
    MinorBase = yVal ; // base to add the iterations to

    yValj = MinorBase + ( MinorDiv * MinorRange) ;
    drawLineRelative( Ls, yValj, Le, yValj, PS_SOLID, 1, Color.RGB(200,200,0), (j+"D")); // This is where I'm stuck.
    // How do I get the line identifier to increment so I can get all the minor lines
    // to draw, not just the last set ?
    }
    }

    }

  • #2
    Glenn
    Change (j+"D”) to (j+"D"+i)
    Alex


    Originally posted by fastflyer View Post
    Hi,

    I'm trying to draw horizontal lines based on major highs and lows. I would like like to draw both major and minor divisions set up from a defined array. I can almost get it to work. I don't know how to increment the line identifier for the minor division during the embedded iteration.

    Perhaps a guru can once again rescue me.

    Humbly Yours !, Glenn


    function preMain() {
    setComputeOnClose();
    setPriceStudy(true);

    Top = 1000 ;
    Base = 0;

    Ls = -40 ; // Line Start
    Le = 0 ; // Line End

    T1 = Le + 10 ; // Text Position
    Tp1 = T1 + 17 ; // Text Percentage Position

    Div = new Array( 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1 );

    }


    function main() {


    MajorRange = Top - Base ;

    for (i=0; i<10; i++) {

    MajorDiv = Div[i]; // For the initial iteration

    yVal = Base + ( MajorDiv * MajorRange) ;
    drawLineRelative( Ls, yVal, Le, yVal, PS_SOLID, 2, Color.RGB(250,250,0), (i+"A"));


    NextDiv = Div[i+1]; // NextDiv is the divider to use for the next iteration, to set up minor Range
    NextBase = Base + ( NextDiv * MajorRange) ; // yVal of next divider

    MinorRange = NextBase - yVal ;
    MinorRange = Math.round(MinorRange) ;

    for (j=1; j<11; j++) {

    MinorDiv = Div[j]; // Divider to use this minor iteration
    MinorBase = yVal ; // base to add the iterations to

    yValj = MinorBase + ( MinorDiv * MinorRange) ;
    drawLineRelative( Ls, yValj, Le, yValj, PS_SOLID, 1, Color.RGB(200,200,0), (j+"D")); // This is where I'm stuck.
    // How do I get the line identifier to increment so I can get all the minor lines
    // to draw, not just the last set ?
    }
    }

    }

    Comment


    • #3
      Thank You Once Again Alexis , for the elegant method.

      Glenn

      Comment


      • #4
        Glenn
        You are most welcome
        Alex


        Originally posted by fastflyer View Post
        Thank You Once Again Alexis , for the elegant method.

        Glenn

        Comment

        Working...
        X