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

Not receiving all historical data bars at State.DataLoaded or State.Transition

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

    Not receiving all historical data bars at State.DataLoaded or State.Transition

    I'm attempting to create multi-time frame indicator.

    In addition to the primary bars, I've added an additional data series when processing reaches State.Configure.

    From the documentation, it looks like I should be able to access this data when processing reaches State.DataLoaded. But if I attempt to access the bar, barArry or any of the derivative arrays (Closes, etc.) at that time, they are null.

    If I step through the code, it looks like the object transitions to State.Historical after State.DataLoaded and starts processing bars and adding them to the series data (it's calling OnBarUpdate during this time). After some number of bars, the object transitions to State.Transition and then State.Realtime. After it enters State.Realtime, no further bar updates occur (this behavior is expected since the chart is set for daily data, so realtime bar updates would not occur intraday).

    If I look at the bar series for both the primary and secondary bars at the time processing enters State.Transition, it's much less than the number of bars I asked for. For example, when I asked for 50 bars (BarsToLoad == 50), at the time the processing entered State.Transition, the series data had a count of 18. I checked the date range, and that's accurate for the number of bars that I requested.

    Can someone clarify 1) Whether all data is actually available at the time State.DataLoaded is processed, and if so, how do I access it? 2) Anything that I might have missed? 3) How I should be coding this to receive all the bars of data that I'm requesting?

    The following snippet demonstrates the issue I'm seeing. I set a breakpoints on the CurrentValue assignments in the State.DataLoaded and State.Transition clauses to explore the data available for the object.

    Code:
    protected override void OnStateChange()
    {
        if (State == State.SetDefaults)
        {
            Description = @"Testing.";
            Name = "Testing";
            Calculate = Calculate.OnBarClose;
            MarketSymbol = @"SPY";
        }
        else if (State == State.Configure)
        {
            // Apply the same bar period to the market symbol as the primary
            // data series.
            BarsPeriod barsPeriod = new BarsPeriod() {
                BarsPeriodType = BarsPeriod.BarsPeriodType,
                Value = BarsPeriod.Value,
            };
    
            BarsRequiredToPlot = BarsToLoad;
    
            // Get the market symbol as daily data. Index = 1
            AddDataSeries(MarketSymbol, barsPeriod);
        }
        else if(State == State.DataLoaded)
        {
            CurrentValue = 0.0;
        }
        else if(State == State.Transition)
        {
            // Transition from historical data to realtime data.
            CurrentValue = 0.0;
        }
    }
    Last edited by Rincewind; 06-02-2020, 11:47 AM.

    #2
    Hello Rincewind ,

    Thanks for your post.

    The historical data for all added data series will be available in State.DataLoaded. This will be before the script starts processing the data, so the data would not be accessed with regular PriceSeries references with BarsAgo indexing. You could access those values with BarsArray[i].GetClose(j) where i is the BarsInProgress index of the data series and j is the bar index (not to be confused with the BarsAgo index) on that data series.

    Some example code for referencing this data in State.DataLoaded (before the data begins to be processed by the script) is included below.

    Code:
    else if (State == State.Configure)
    {
        AddDataSeries("CL 07-20");
        AddDataSeries("ES 06-20");
    }
    else if (State == State.DataLoaded)
    {
        for (int i = 0; i < BarsArray.Length; i++)
        {
            for (int j = 0; j < BarsArray[i].Count; j++)
                Print(String.Format("BarsArray[{0}].GetClose({1}): {2} ", i, j, BarsArray[i].GetClose(j)));
        }
    }
    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      Thanks for your response.
      I inserted your State.DataLoaded code as-is and it does work.

      But I'm still not receiving as many bars of data as I'm expecting. I'm setting the days back input parameter to 50, but I'm only getting back 18 bars of data. I would expect about 46 or 45 bars back from this request to account for weekends and holidays. Can you tell me why I wouldn't see the number of bars I requested being loaded?

      Comment


        #4
        Hi Rincewind thanks for your reply.

        In the Data Series menu do you have the proper amount of bars/days loaded? Also, are you loading tick data? Depending on your data provider they could be limiting the amount of historical tick data you can request during the session (you could try requesting the tick data when the session is over and they might allow more).

        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,

          So I think I misspoke in my initial post, I'm writing a MarketAnalyzerColumn indicator, not a chart indicator. When I configure the column, I have a Data Series and a Time frame.

          The configured values for these two parameter groups are:

          Data Series
          • Input series = Close
          • Price based on = Last
          • Type = Day
          • Value = 1
          Time frame
          • Load data based on = Days
          • Days back = 50
          • Trading hours = US Equities ETH
          • Break at EOD = true

          I'm trying to configure the indicator to receive 50 bars of daily data. I'm interpreting the Value parameter in the data series as the number of days per bar. I'm assuming that the days back field will request 50 days of whatever data series I've configured.

          Have I misinterpreted how these fields should be configured?

          Thanks for your continued support.
          Last edited by Rincewind; 06-02-2020, 02:13 PM.

          Comment


            #6
            Hi Rincewind, thanks for your reply.

            The MarketAnalyzerColumn class does not have a BarsArray object by default, so you are making an indicator that can be applied to a chart or superDOM right? I was able to get 50 days of data with this contrived script (the plot assignment is just to make sure the indicator does something.):

            Code:
                public class TestSuperDOMIndicator : Indicator
                {
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Calculate                                    = Calculate.OnBarClose;
                            IsOverlay                                    = true;
            
                        }
                        else if (State == State.Configure)
                        {
                            AddPlot(Brushes.Red, "MyPlot");
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
                        Print(Time[0]);
                        Values[0][0] = Math.PI;
            
                    }
                }
            I tested this using Kinetick. Any data provider should provide 50 bars of daily data. Did you try the Kinetick EOD connection?

            I look forward to hearing from you.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,

              I'm actually trying to build a MarketAnalyzerColumn Indicator.

              I tried disconnecting my TDAmeritrade data feed and connecting to Kinetick and received back all of the data I was expecting. I then reconnected TDAmeritrade and reran the indicator and received all the data I was expecting as well.

              I don't know why it was returning half the requested data previously. I do have the data feed connect automatically, though. Possibly there was some conflict between the saved layout and the datafeed that was resolved by the disconnect? I don't really know.

              Thanks for all your help.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Austiner87, Today, 03:42 PM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by cshox, Today, 11:11 AM
              2 responses
              15 views
              0 likes
              Last Post cshox
              by cshox
               
              Started by algospoke, Today, 06:53 PM
              0 responses
              9 views
              0 likes
              Last Post algospoke  
              Started by mlprice12, 12-21-2021, 04:55 PM
              3 responses
              297 views
              0 likes
              Last Post paypachaysa  
              Started by lorem, 04-25-2024, 09:18 AM
              20 responses
              86 views
              0 likes
              Last Post lorem
              by lorem
               
              Working...
              X