Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price at current bar for trend Line

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

    Price at current bar for trend Line

    Hi,

    I am trying to get price at the current bar by below:

    private bool getTLYByX(ChartAnchor start, ChartAnchor end, Bars bars, DateTime t0, double x0,
    ChartPanel panel, ChartControl chartControl, ChartScale chartScale, bool useEndPointX,
    ref Point startPoint, ref Point endPoint, ref Point extPoint, ref double priceT0)
    {
    if ((start == null) || (end == null) || (bars == null) || (panel == null) || (chartControl == null) || (chartScale == null))
    {
    return false;
    }

    try
    {
    double startIdx = chartControl.GetSlotIndexByTime(start.Time);
    double endIdx = chartControl.GetSlotIndexByTime(end.Time);

    double price0 = start.Price;
    double price1 = end.Price;
    DateTime time0 = start.Time;
    DateTime time1 = end.Time;

    // Get price at t0
    double startBar = bars.GetBar(start.Time);
    double endBar = bars.GetBar(end.Time);
    double curBar = bars.GetBar(t0);
    priceT0 = price0 + (price1 - price0) * (curBar - startBar) / (endBar - startBar);

    but when I am printing priceT0, it prints different value than the acutal TL end point drawn on the chart.

    I am trying to pin point where the trend line on the current bar to capture when price crosses above or below that point.

    I think, I am making some mistake here, any suggestion will be highly apprecited.
    Last edited by asmmbillah; 04-16-2020, 01:02 PM.

    #2
    Hi asmmbillah, thank you for your question.

    I am unable to tell what could be wrong from the snippet. Print statements would need to be used to trace back the cause of the bug by printing out all of the computations/conditions that lead to priceT0 being set e.g. making sure that all variables in this formula are all correct for the current bar: price0 + (price1 - price0) * (curBar - startBar) / (endBar - startBar);

    To provide some kind of related example, I made this indicator that reads the price of a horizontal line wherever the line is on the chart and renders the price:

    https://ninjatraderecosystem.com/use...izontal-lines/

    Kind regards.

    Disclaimer:
    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Last edited by NinjaTrader_ChrisL; 04-16-2020, 03:01 PM. Reason: Added disclaimer for NinjaTrader Ecosystem website.

    Comment


      #3
      thanks for the example, I will explore it.

      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
      369 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
      572 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