Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to have line rendered using OnBarUpdate calculated values

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

    How to have line rendered using OnBarUpdate calculated values

    Hello,

    I am having some trouble understanding how to correctly have a line rendered on the chart using values that are calculated on OnBarUpdate. Below I have attached a picture that shows two lines. The blue line is rendered in OnRender, and the purple line is a line drawn using DrawLine() in OnBarUpdate. The blue line needs to be rendered where the purple line is. I will provide a quick snippet of what I have written to make this happen.

    Code:
    if (State == State.SetDefaults)
    {
    Calculate = Calculate.OnBarClose;
    DefaultBrush2 = System.Windows.Media.Brushes.DodgerBlue;
    }
    
    OnBarUpdate()
    {
    if (!TrendSwitchUp)
    {
    CreateUpLineOne = true;
    
    //DrawLine
    UpTrendLines = Draw.Line(this, "UpTrendLine" + CurrentBar.ToString(), false, TrendsLastBarsAgo, LastLow, 1, High[1], Brushes.DodgerBlue, DashStyleHelper.Solid, 4);
    }
    }
    
    OnRender()
    {
    if (!IsInHitTest)
    {
    //UpLine Render Targets
    SharpDX.Vector2 upStartPoint = new SharpDX.Vector2(ChartPanel.X, ChartPanel.Y);
    SharpDX.Vector2 upEndPoint = new SharpDX.Vector2(ChartPanel.X + ChartPanel.W, ChartPanel.Y + ChartPanel.H);
    
    //SharpDX Brush Resource
    SharpDX.Direct2D1.Brush defaultBrush2Dx;
    
    defaultBrush2Dx = DefaultBrush2.ToDxBrush(RenderTarget);
    
    if (CreateUpLineOne)
    {
    //RenderLine
    RenderTarget.DrawLine(upStartPoint, upEndPoint, defaultBrush2Dx, 2);​
    }
    defaultBrush2Dx.Dispose();
    }
    }
    In the picture provided, the purple line is drawn after bar 1 has finished printing. On the DrawLine() method, "TrendsLastBarsAgo" = current session's first bar number (0) - Bars.BarsSinceNewTradingDay, "LastLow" = Low[TrendsLastBarsAgo], and the rest of the coordinates are pretty obvious.

    The render targets for the blue line are just copied from the 'SampleCustomRender" indicator that Ninjatrader Provides, I did this to just get something on screen since it is my first time using SharpDx tools. It will be greatly appreciated if I can have a bit of guidance on how to get these render targets working correctly to mimic what the DrawLine() is doing.
    Attached Files

    #2
    You need to use chartScale.GetYByValue() and chartControl.GetXByBarIndex() to get the coordinates to draw the line. Your line code does not look like it is related to the bars at all. In the help it describes how these functions work.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello Don22Trader1,

      Thank you for your post.

      There is an overview of SharpDX Vectors and Charting Coordinates in the help guide here:


      For example, to get X and Y coordinates you could take advantage of the following methods:Please let us know if we may be of further assistance.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      368 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      571 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