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

CurrentBars[1] = -1 after AddDataSeries in a multi-time frame script, same instrument

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

    CurrentBars[1] = -1 after AddDataSeries in a multi-time frame script, same instrument

    Hi,
    what are the possible reasons for CurrentBars[1] of the secondary (added) data series to be: -1 all the time?
    It seems that he following addDataSeries failed to load any data?

    else if (State == State.Configure)
    {
    ClearOutputWindow();

    // add minute data series to watch for EOD
    AddDataSeries("ES", BarsPeriodType.Minute, 15);
    ...
    Print("State: Configured done");
    }
    else if (State == State.DataLoaded)
    {
    ...
    Print(Times[0][0].ToShortTimeString() + " DEBUG => current bars[1]:" + CurrentBars[1].ToString());
    }

    Note: access to this time-frame data from my provider was tested by loading it into a chart, as a primary data series

    Here is a debug-output from the script (primary data BarPeriod = 60min)

    State: Configured
    7:00 PM DEBUG => current bars[1]:-1
    State: Data Loaded
    OnBarUpdate():
    7:00 PM DEBUG 0 => current bars[0]:0
    7:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate():
    8:00 PM DEBUG 0 => current bars[0]:1
    8:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate():
    9:00 PM DEBUG 0 => current bars[0]:2
    9:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate():
    10:00 PM DEBUG 0 => current bars[0]:3
    10:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate():
    11:00 PM DEBUG 0 => current bars[0]:4
    11:00 PM DEBUG 1 => current bars[1]:-1
    Sate: defaults set
    Sate: defaults set
    Sate: defaults set

    #2
    Ok, after some more debugging - the second data series does not seem to call OnBarUpdate,
    note how OnBarUpdate is called only on he primary series: OnBarUpdate(0):

    State: Configured
    7:00 PM DEBUG => current bars[1]:-1
    State: Data Loaded
    OnBarUpdate(0):
    7:00 PM DEBUG 0 => current bars[0]:0
    7:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate(0):
    8:00 PM DEBUG 0 => current bars[0]:1
    8:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate(0):
    9:00 PM DEBUG 0 => current bars[0]:2
    9:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate(0):
    10:00 PM DEBUG 0 => current bars[0]:3
    10:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate(0):
    11:00 PM DEBUG 0 => current bars[0]:4
    11:00 PM DEBUG 1 => current bars[1]:-1
    OnBarUpdate(0):
    12:00 AM DEBUG 0 => current bars[0]:5
    12:00 AM DEBUG 1 => current bars[1]:-1
    Sate: defaults set
    Sate: defaults set

    What could be wrong? Any suggestions? (note: this is run in Analyzer / for back-testing)

    Comment


      #3
      Originally posted by momchi View Post
      Ok, after some more debugging - the second data series does not seem to call OnBarUpdate,
      note how OnBarUpdate is called only on he primary series: OnBarUpdate(0):

      State: Configured
      7:00 PM DEBUG => current bars[1]:-1
      State: Data Loaded
      OnBarUpdate(0):
      7:00 PM DEBUG 0 => current bars[0]:0
      7:00 PM DEBUG 1 => current bars[1]:-1
      OnBarUpdate(0):
      8:00 PM DEBUG 0 => current bars[0]:1
      8:00 PM DEBUG 1 => current bars[1]:-1
      OnBarUpdate(0):
      9:00 PM DEBUG 0 => current bars[0]:2
      9:00 PM DEBUG 1 => current bars[1]:-1
      OnBarUpdate(0):
      10:00 PM DEBUG 0 => current bars[0]:3
      10:00 PM DEBUG 1 => current bars[1]:-1
      OnBarUpdate(0):
      11:00 PM DEBUG 0 => current bars[0]:4
      11:00 PM DEBUG 1 => current bars[1]:-1
      OnBarUpdate(0):
      12:00 AM DEBUG 0 => current bars[0]:5
      12:00 AM DEBUG 1 => current bars[1]:-1
      Sate: defaults set
      Sate: defaults set

      What could be wrong? Any suggestions? (note: this is run in Analyzer / for back-testing)
      ref: https://ninjatrader.com/support/help...nstruments.htm

      About half-way down the page, in the section called "Using Bars Objects as Input to Indicator Methods" is this statement:
      Note: By default, the CurrentBars starting value will be -1 until all series have processed the first bar.

      Comment


        #4
        Hi momchi,

        Please make sure you have enough bars on the chart before accessing the secondary series.

        e.g. if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return; //if your accessing further back than 1, replace 1 with X.

        If you need to most recent from month for the ES, do AddDataSeries("@ES", BarsPeriodType.Minute, 15);
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by koganam View Post

          ref: https://ninjatrader.com/support/help...nstruments.htm

          About half-way down the page, in the section called "Using Bars Objects as Input to Indicator Methods" is this statement:
          Thank you, Koganam, for the default value note.

          Comment


            #6
            Originally posted by NinjaTrader_ChrisL View Post
            Hi momchi,

            Please make sure you have enough bars on the chart before accessing the secondary series.

            e.g. if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return; //if your accessing further back than 1, replace 1 with X.

            If you need to most recent from month for the ES, do AddDataSeries("@ES", BarsPeriodType.Minute, 15);
            Chris - many thanks as always: I did have the above check, however I had silly debug statements right before that which were trying to acces Times series like that:
            Print(Times[0][0].ToShortTimeString() + " DEBUG 0 => current bars[0]:" + CurrentBars[0].ToString());
            Print(Times[1][0].ToShortTimeString() + " DEBUG 1 => current bars[1]:" + CurrentBars[1].ToString());

            So the first of which was trying to get the times of the bars of the primary series before the first bar of that was closed when OnBarUpdate was called from the secondary (minute time-frame) series, and was the direct source of the error. Thank you for you guiding me in that direction!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jpapa, Today, 07:22 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by kevinenergy, 02-17-2023, 12:42 PM
            116 responses
            2,758 views
            1 like
            Last Post kevinenergy  
            Started by franatas, 12-04-2023, 03:43 AM
            7 responses
            106 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Jltarrau, Today, 05:57 AM
            3 responses
            9 views
            0 likes
            Last Post Jltarrau  
            Started by f.saeidi, Today, 05:56 AM
            2 responses
            9 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X