Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Line with (double startY) set to chart.Control

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

    Draw.Line with (double startY) set to chart.Control

    Hi,

    Is it possible in code to start plotting a line on the left side of the chart?
    Also, will the plot start move as you scroll on chart?

    example
    Draw.Line(this,"Settlement",true, chartControl.CanvasLeft, SM, -100, SM, Brushes.Gray, DashStyleHelper.Solid, 2);

    Thanks, Woody

    #2
    Hello woodyfox,

    It is possible to create a line that is attached to left side of a chart, but you would not want to use ChartControl.CanvasLeft for this. You would want to call ChartControl.GetTimeByX(ChartPanel.X) to get the appropriate input to attach the line to the edge of a chart. You will also want to call this line within OnRender() to have its position update as you scroll a chart.

    Please consider the follow as an example:

    Code:
    private DateTime MyTime;
    private double ClosePrice;
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    	if(ChartControl != null)
    		Draw.Line(this,"Settlement",true, ChartControl.GetTimeByX(ChartPanel.X), ClosePrice, MyTime, ClosePrice, Brushes.Gray, DashStyleHelper.Solid, 2);
    }
    I am using two variables to hold the current time and the current price to use as input with the line. You may update these variables within OnBarUpdate(), because you will not be able to access the normal price and time series' directly from OnRender().

    You may reference the following documentation:

    Draw.Line() - https://ninjatrader.com/support/help...?draw_line.htm

    OnRender() - https://ninjatrader.com/support/help.../?onrender.htm

    GetTimeByX() - https://ninjatrader.com/support/help...gettimebyx.htm

    Please let me know if I may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    82 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    43 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Working...
    X