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

BarsRequiredToPlot Question

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

    BarsRequiredToPlot Question

    Hi, I am trying to add a daily ATR to an intraday chart and I have a problem with the amount of data required for the indicator to work. The code below works but instead of requiring 14 days of daily data to be loaded it requires 28 days. From the output window I have noticed that I have to load 28 days of data to get it to start working (processes the second block of code) and it starts counting at currentbars[1] = -1 and finishes counting at current bars[1] = 17 even though I'm loading 28 days. It's very confusing can you shed any light on this please?

    public class DailyATR2 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Add a Daily bars object and calculate ATR";
    Name = "Daily ATR2";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;

    IsSuspendedWhileInactive = true;
    BarsRequiredToPlot = 14;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Day, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot) //(CurrentBars[1] < 14)//

    {
    Print("The current daily bar is " + CurrentBars[1]);
    Print("The Time is " + Time[0]);
    }
    else
    {
    var dailyATR = ATR(BarsArray[1], 14)[0];
    Print("The current daily bar is " + CurrentBars[1]);
    Print("The time is " + Time[0]);
    Print("The Daily ATR is " + dailyATR);
    }
    // This is working but it requires far more bars than expected in order to work. Investigate tomorrow.

    }

    region Properties

    #endregion

    }

    As can be seen in the output windows below the indicator starts on the 01/12/2022 and ends on the 30th (28 and a bit days of data) but the bar count if only 18? and the barscount starts at -1?

    Click image for larger version

Name:	image.png
Views:	160
Size:	12.4 KB
ID:	1229408
    Click image for larger version

Name:	image.png
Views:	51
Size:	15.3 KB
ID:	1229409

    Thankyou​​​

    #2
    Hi sjmuk1, thanks for posting. I am testing the same thing and I am getting some unexpected behavior when I try to load daily bars in a secondary series. I will need to check with my colleagues to see if there is an issue here in requesting the correct amount of data. Ill update this thread as soon as I have more information.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi, I came back to test this and I do get the requested amount of Daily bars here. I attached my test script to try it on your installation.

      Attached Files
      Chris L.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,603 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      12 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X