Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Different BarTypes and BarsArray Processing

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

    Different BarTypes and BarsArray Processing

    I have a question if I did this properly. It produces the correct results now, but I think I might be "hacking" to get it. My goal was to get the opening, 30 min, 60 min and high low of the current day and the high and low of the chart range. I thought I had it done, but when I tried bar types other than min, it produced wrong results. So then I did AddDataSeries(Data.BarsPeriodType.Minute, 1); in the State.Configure section and created a function that is called from OnBarUpdate() to calculate the numbers. I had to create a for loop starting at the beginning index of the data series above in the function to loop through the whole series to get the values, which would be processor intensive for every bar update. To increase it's performance I created a class variable called LastBarProcessed and update it on every call to my function so it only processes one bar at a time after the initial processing of all catchup bars when the indicator is first loaded. I put parts of the code below here:

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }

    In OnBarUpdate()
    {
    // other code
    // Get Levels
    GetLevels();
    RenderTextInfo();

    }

    protected void GetLevels()
    {
    double close, high, low;

    for (int i = LastBarProcessed; i < BarsArray[1].Count; i++)
    {
    WorkingDate = BarsArray[1].GetTime(i);
    int currentTime = ToTime(WorkingDate);

    close = BarsArray[1].GetClose(i);
    high = BarsArray[1].GetHigh(i);
    low = BarsArray[1].GetLow(i);
    if (currentTime == RTHStart) DayOpenPrice = close;
    if (currentTime == Day30MinTime) Day30MinPrice = close;
    if (currentTime == Day60MinTime) Day60MinPrice = close;

    if (CompareDates(WorkingDate, LastDate))
    {
    // Code to set levels
    }
    else
    {
    // Initialize New Calendar Date Levels
    // Code to initialize levels
    }
    }
    // Additional Processing Code here
    LastBarProcessed = BarsArray[1].Count;
    }

    #2
    Hi jalley,

    If you are going to add a one minute bar series in the program, do all your calculations on that. Now It will work the same no matter what chart you put it on. Daily high and low are the same on all charts, use the one minute. Use bar time stamp features to determine market open and day change.Use the one minute. You are making this way harder than it has to be.

    RJay
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      Hello jalley,

      Thank you for your post.

      RJay's on the money here - you're already getting all your values from the secondary data series from what I can see here, so I would expect that this would work fine. Using a secondary 1 minute data series would be what I'd recommend so it's standardized regardless of the primary series. Doesn't look "hack"-y to me.

      Please let us know if we may be of further assistance to you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      585 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      340 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X