Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I limit the length of an horizontal line?

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

    How do I limit the length of an horizontal line?

    The code below draws the horizontal line across the entire chart. However, i would like to limit the length to the last 20bars. Is there a way to do this.

    if (UseExtendedLine)
    {
    // Draw.HorizontalLine(this, "Currprice", false, SLTPLineC, LineColor, LineStyle, LineWidth);
    Draw.HorizontalLine(this, "Currprice1", false, Close[0]+SLTPLine1, LineColor1, LineStyle1, LineWidth1);
    Draw.HorizontalLine(this, "Currprice2", false, Close[0]-SLTPLine1, LineColor1, LineStyle1, LineWidth1);
    Draw.HorizontalLine(this, "Currprice3", false, Close[0]+SLTPLine2, LineColor2, LineStyle2, LineWidth2);
    Draw.HorizontalLine(this, "Currprice4", false, Close[0]-SLTPLine2, LineColor2, LineStyle2, LineWidth2);
    Draw.HorizontalLine(this, "Currprice5", false, Close[0]+SLTPLine3, LineColor3, LineStyle3, LineWidth3);
    Draw.HorizontalLine(this, "Currprice6", false, Close[0]-SLTPLine3, LineColor3, LineStyle3, LineWidth3);

    }

    I tried using the draw.line code below, but it wasn't drawing the line on the chart.

    Draw.Line(this, "CurrPrice7", false, 20, Close[0]+SLTPLine1, 0, Close[0]+SLTPLine1, LineColor1, LineStyle1, LineWidth1)

    What am I doing wrong?

    #2
    Hello cryfgg,

    Thanks for your post.

    Draw.HorizontalLine does not allow you to specify the number of bars back that you would like the line to start.

    Instead, Draw.Line would need to be used if you want to specify the number of bars back that the line starts.

    See the attached example script which demonstrates using Draw.Line to draw a line starting 20 bars ago.

    Also, see this help guide page for more information: https://ninjatrader.com/support/help.../draw_line.htm

    Let us know if we may further assist.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    92 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    48 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    75 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    72 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    60 views
    0 likes
    Last Post CarlTrading  
    Working...
    X