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

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 wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        193 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,235 views
        0 likes
        Last Post xiinteractive  
        Working...
        X