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


Using external historical data as indicator values

  • Filter
  • Time
  • Show
Clear All
new posts

    Using external historical data as indicator values

    I'm calculating some outside independent values that I'd like to use in strategy development. I'd like to use it as an indicator though, so I'll be able to show it on the charts, and use it as I do some of the other indicators for the strategy. Thus I have created an outside program to create an appropriate data format to import into Ninja using the Import -> Historical Data methods.

    It appears that the default setting is for Instrument to be a STOCK.

    My question is this, how do I best get this new information into my indicator. I am trying to write a custom indicator for this purpose, which will just call:


    I have looked at the data on a daily chart, and the values are what I put in the file. But when I try to use it with a daily future I seem to have issues with when the data is called with respect to the BarUpdates being out of order. Sometimes it even appears that the custom bar is not called on BarClose (specifically with the last datapoint in the custom series).

    I have played around with the Instrument settings for the Custom Series by changing the Trading Hours to match or just offset the ES futures. I've also looked at it against a regular stock like AAPL, and I still don't see the last data point. In the output screen, it appears that it's not calling that specific bar.

    This may not be enough information to debug I realize, but wondering if this is a good approach in general or if there's another suggestion to approach the problem: basically I have an externally calculated indicator (daily in this case) that I'd like to have available as an indicator. Perhaps just loading the data from the custom indicator itself (and avoiding the Historical import) would be better?

    Open to ideas & suggestions. Thanks.

    Hi mohawkTrader, thanks for posting.

    It's not conventional to use the Import function like this, but it should work as long as the data follows the correct formats here:

    This would need to be tested thoroughly since the data is not conventional instrument data. The best way of doing this would be to gather the information in an indicator in State.DataLoaded or State.Configure into a List or a data structure of your choosing or load it into a Series<T> object that does a lot of the organizational work for you:

    Best regards,
    Chris L.NinjaTrader Customer Service


      Thanks ChrisL.

      The date format is correct, as I can import the custom indicator into a chart without problem. I'll look into it further, but I'm thinking it may have something to do with the Trading Hours or similar. Is there any scenario where the OnBarClose will not be called for a particular bar for a particular data series that is added? For instance, if ExitSession or something similar is called?

      I do think using the import would be the simplest because then in theory the data is organized for me.

      If using the Series<T> object directly, and populating it, do you have examples that match up dates? Since you'll have to back calculate how many bars ago for a particular point. This is fragile when one or the other data series may be missing a point (holiday, missing data, etc) and so they won't necessarily match up without cross checking both dates. Do you have a recommendation for performing this cross check using the Series objects? That is, the data being operated on, the primary series and then the new custom series being created?

      From the guide:
      Setting Values

      You can set the value for the current bar being evaluated by choosing a "barsAgo" value of "0" or, for historical bars, by choosing a "barsAgo" value that represents the number of bars ago that you want the value to be stored at.



        Hi mohawkTrader, thanks for your reply.

        I do not have an example demonstrating this specifically. One important factor of the Series<T> object is that it will always have the same amount of bars as the BarsArray[] that you pass to it, so it makes it easy to store a custom data point for every bar on the chart. The best way of importing the data into an indicator would be to use a StreamReader or System.IO to read from a .txt file. Here are some examples:

        Kind regards,
        Chris L.NinjaTrader Customer Service


        Latest Posts


        Topics Statistics Last Post
        Started by Gerik, Today, 01:02 AM
        0 responses
        Last Post Gerik
        by Gerik
        Started by Shai Samuel, Yesterday, 11:29 PM
        0 responses
        Last Post Shai Samuel  
        Started by futurestrader0000, Yesterday, 09:27 PM
        0 responses
        Last Post futurestrader0000  
        Started by AdeptistJune, Yesterday, 09:19 PM
        0 responses
        Last Post AdeptistJune  
        Started by Johnny90, 05-14-2022, 04:17 AM
        4 responses
        Last Post jeronymite