Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Brandon H.NinjaTrader Customer Service

    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.
        Brandon H.NinjaTrader Customer Service

        Comment


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

          Kay Wai

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by millonperez, Today, 07:01 AM
          0 responses
          3 views
          0 likes
          Last Post millonperez  
          Started by Richozzy38, Yesterday, 01:06 PM
          4 responses
          21 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by KonAdams, 05-07-2024, 10:53 PM
          2 responses
          17 views
          0 likes
          Last Post KonAdams  
          Started by Patlpp, 08-16-2021, 03:10 PM
          11 responses
          507 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by DawnTreader, Yesterday, 05:58 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X