Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw line object at an angle

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

    Draw line object at an angle

    Hello,

    Is there any sample coding that will automatically draw a line from a specified price point at a specific angle?

    Thanks

    #2
    Hello MisterGee,

    Thanks for your question.

    Small snippets of sample code for using Drawing methods can be found in the Help Guide.

    Drawing - https://ninjatrader.com/support/help...t8/drawing.htm

    When drawing a line, we need to provide an X coordinate (a time or a certain number of bars ago from when we draw the line) and a Y coordinate (price level.) Visually, this will not reflect the same angle, because as we adjust the scale of the chart, the angle of the line will change. However, since the line is drawing from the same X and Y coordinates, the slope of that line is the same in relativity to Rise/Run.

    If you would like to have code generated that draws a line from 2 different points and are unfamiliar writing the C# code, I suggest using the Strategy Builder to generate syntax to draw a line.

    Drawing on a chart - https://ninjatrader.com/support/help...ToDrawOnAChart

    For example, the Strategy Builder can be used to generate syntax like the following:

    Code:
    if (CurrentBars[0] < 10)
        return;
    
    Draw.Line(this, @"MyCustomStrategy7 Line_1", true, 10, High[10], 0, High[0], Brushes.CornflowerBlue, DashStyleHelper.Solid, 2);
    If you want to draw a line at an angle that is not relative to the chart scale, this requires custom rendering with SharpDX.

    To get more acquainted with SharpDX rendering, please see the Help Guide article below, and please see the SampleCustomRender indicator that comes with NinjaTrader.

    https://ninjatrader.com/support/help..._rendering.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you. What might actually be more helpful to me is knowing, what is the distance between bars on a standard bar width/spacing chart.

      I would like to plot points along an angled line below the price/bars but without knowing the x coordinate (how far along the x axis price (each bar) moves) I am unable to find the y coordinate on the line. What is the unit of measure between each bar?

      Comment


        #4
        Hello MisterGee,

        ChartControl.Properties.BarDistance can get the distance in pixels between the left/right edge of a bar and ChartControl.GetBarPaintWidth can be used to get the width of each bar in pixels.

        ChartControl.Properties - https://ninjatrader.com/support/help...properties.htm

        ChartControl.GetBarPaintWidth() - https://ninjatrader.com/support/help...paintwidth.htm

        Let us know if there is anything else we can do to help.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks for your reply Jim,

          I have attempted to integrate your information into my code however being novice has made this difficult! Would you be able to provide a sample code for setting a variable to the X coordinate of the left edge the current bar (most recently painted)?

          Thanks

          Comment


            #6
            Hello MisterGee,

            Attached is an example that can draw to the left edge of the current bar. Please see the OnRender method and the DrawLine method there in where the coordinates are supplied. The example uses some helper methods for SharpDX rendering that could be re-used in other scripts.

            Please note that bar coordinates can be retrieved with ChartControl.GetXByBarIndex and ChartScale.GetYByValue.

            GetXByBarIndex - https://ninjatrader.com/support/help...bybarindex.htm

            GetYByValue - https://ninjatrader.com/support/help...etybyvalue.htm

            We look forward to assisting.
            Attached Files
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by maybeimnotrader, Yesterday, 05:46 PM
            1 response
            18 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Perr0Grande, Yesterday, 08:16 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by f.saeidi, Yesterday, 08:12 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by algospoke, Yesterday, 06:40 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by quantismo, Yesterday, 05:13 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X