Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to identify the last OnBarUpdate() call from history bars?

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

    How to identify the last OnBarUpdate() call from history bars?

    I have a third party DLL which calculates an new moving average. The Dll function interface is "int GMA(double[] ArrayPrice,double[] ArrayGMA,int BarCount,int Period)". For now, there are 10000 history bars and "CalculateOnBarClose = true". When starting the indicator, i get 10000 times OnBarUpdate() call. Whenever getting OnBarUpdate() call, my code will call Dll interface which means the system will call Dll interface 10000 times when starting the indicator. It's very slow.

    To avoid calling Dll interface 10000 times at starting time, my current code have to change as following:

    protected override void OnBarUpdate()
    {
    if (Historical)
    return;
    //Call Dll Interface, and plot
    }

    But after filtering out Historical OnBarUpdate() call, my program will only show the indicator drawing after real-time new bar incoming. If opening the chart window after market time, the indicator will not draw anything because there is no real-time new bar incoming after market time. So how to get OnBarUpdate() call just one time for history bars? Or is there any property or method which tells it's the last OnBarUpdate() call from the last historical bar? Thanks.

    #2
    Hello 51friend,

    For historical indicator values, there will need to be an OnBarUpdate() call for each bar.

    You may need to look at how the dll is coded to improve efficiency here. One suggestion is that the dll should be coded so that you pass in a series as input.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Problem solved perfectly. Which broker use Ninja as platform?

      The problem is solved perfectly by reading Ninja documents. Write the following code to avoid calling DLL API many time at start time.

      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      bPainted = false;
      //other initial logic
      }

      protected override void OnBarUpdate()
      {
      if(CurrentBar<Count-2)
      return;
      if(!bPainted)
      {
      PlotAllBar();
      bPainted=true;
      }
      else
      PlotOneBar();
      }

      NinjaTrader is a great developing tool. Which stock broker is using NinjaTrader as their stock trading platform? For now, i only see there are many futures brokers, but not a stock broker. Thanks.

      Comment


        #4
        51friend,

        Glad you were able to get it sorted. Thanks for sharing your solution. See the link below to find out which of our supported brokers offers stock (Equities) trading.

        Click here to view more information on Historical Data
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        597 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 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
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X