Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw line object at an angle

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

  • NinjaTrader_Jim
    replied
    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

    Leave a comment:


  • MisterGee
    replied
    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

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • MisterGee
    replied
    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?

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • MisterGee
    started a topic Draw line object at an angle

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by funk10101, Today, 12:02 AM
1 response
11 views
0 likes
Last Post NinjaTrader_LuisH  
Started by GLFX005, Today, 03:23 AM
1 response
6 views
0 likes
Last Post NinjaTrader_Erick  
Started by nandhumca, Yesterday, 03:41 PM
1 response
13 views
0 likes
Last Post NinjaTrader_Gaby  
Started by The_Sec, Yesterday, 03:37 PM
1 response
11 views
0 likes
Last Post NinjaTrader_Gaby  
Started by vecnopus, Today, 06:15 AM
0 responses
1 view
0 likes
Last Post vecnopus  
Working...
X