Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Edit a previous line instead of drawing a new line on each bar

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

    Edit a previous line instead of drawing a new line on each bar

    Hi all,

    I am having a performance issue on my indicator.

    My indicator is supposed to draw trendlines based on certain conditions. On each bar update the last trendline is updated as long as it is "alive". (based on the original conditions). The problem I am facing is that the graph performance is greatly reduced when I add the indicator.

    I'm guessing that what my code is doing is adding one new line on each bar update which is causing the issue. I'm wondering how can I edit just the last line instead of adding a new one.

    Code:
    Draw.Line(this,"TrendLineCont " + CurrentBar, CurrentBar - SwingHigh1Bar, High[CurrentBar - SwingHigh1Bar], 0, yn, Brushes.Magenta);
    Additional Note: I've also tried drawing dots instead but drawing lines it better for what I want to accomplish.

    Thanks.

    #2
    Hello Danilod,

    Thanks for your post.

    Since you are adding CurrentBar to the tag parameter of Draw.Line(), a new line will be drawn on the chart for each new bar update when the condition is true. To have a currently drawn line update without drawing a new line, you would need to exclude CurrentBar from your tag parameter so that it reads "TrendLineCont " instead of "TrendLineCont " + CurrentBar.

    See the attached example script demonstrating how to draw a line and have the line update its position with each new bar.

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

    Let us know if we may assist further.
    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


      #3
      Brandon,
      I appreciate your help. The issue with the solution you suggested is that each line is replaced. What I need is to keep all the previous lines as they are and update (replace) just the last one.
      I though about adding a counter but I couldn't figure out how to code it properly.

      Thanks agian.

      Comment


        #4
        Hello Danilod,

        Thanks for your note.

        It seems that the performance problem is caused by drawing a line from a start point to the current bar, and then on the next update, the script is drawing a new line that lays on top of the previous line.

        You could consider reusing the same tag name for your drawing object until a new swing is found. For example, see below. Note that the tag name could be a counter if you want.

        Code:
        if (new swing found)
        {
            create new tag name
            Draw new line
        }
        else
        {
            Draw same line with same tag name but to the new CurrentBar
        }
        Let us know if we may assist further.
        <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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X