Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Lines within a bar

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

    Draw Lines within a bar

    Hi,

    I'd like to Draw Horizontal lines within a bar. Currently, using the Draw.Line function, the line is drawn from the middle of the current bar to the middle of the future bar.

    I've attached an example of what I'm trying to do. I'm referring to the Red and Blue lines in the attachment (file: Capure. I've also attached an example of what I'm getting now (File: SPY (Daily) 2022_02_12 (4_20_22 PM)).

    Is there any way I can achieve my desired result?

    Regards
    Kay Wai
    Attached Files
    Last edited by kaywai; 02-15-2022, 02:21 AM.

    #2
    Hello kaywai,

    Thanks for your post.

    You could consider using Median[0] or (High[0] + Low[0]) /2 for the Y coordinates when calling the drawing method.

    See the help guide documentation below for more information.
    Draw.Line: https://ninjatrader.com/support/help.../draw_line.htm
    PriceSeries<double>: https://ninjatrader.com/support/help...riceseries.htm

    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


      #3
      Hi BrandonH,

      Thank you for you reply but that isn't what i'm looking for.

      What i would like is for the horizontal line to be drawn across the width of the current bar or candle. Currently when i use the draw.line function, it is drawing the horizontal from the second half of the current bar or the current candle to the space that will be taken up by first half of the future bar of candle.

      The capture file is not from a NT8 chart but I would like to achieve a similar result. The second chart is what i'm getting from NT8 right now which isn't what I really want. On the X-axis of Draw.Line, I'm using 0 for the startBarsAgo and 1 for the endBarsAgo.

      Regards

      Kay Wai

      Comment


        #4
        Hello kaywai,

        Thanks for your note.

        I understand that you would like to have a horizontal line drawn across the width of a bar similar to the first image you shared in your initial post.

        To accomplish this, you would need to use custom rendering with SharpDX in OnRender() instead of Drawing objects such as Draw.Line().

        Drawing objects will snap to the anchor which is in the center of the bar. Custom rendering with SharpDX in OnRender() would allow you to calculate the exact location you want your line placed on a chart.

        See the SampleCustomRender indicator that comes default with NinjaTrader for examples of custom rendering with SharpDX. To view the SampleCustomRender indicator code, open a New > NinjaScript Editor window, open the Indicators folder in the Editor, and select the SampleCustomRender script.

        Also, see the help guide documentation below.

        Using SharpDX: https://ninjatrader.com/support/help..._rendering.htm
        RenderTarget.DrawLine: https://ninjatrader.com/support/help...t_drawline.htm

        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


          #5
          Thank you BrandonH. Let me read up on that.

          Kay Wai

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          646 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          367 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X