Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Chris L.NinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      11 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      16 views
      0 likes
      Last Post AaronKoRn  
      Working...
      X