Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding values for bars that don't have one

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

    Adding values for bars that don't have one

    I've used AddDataSeries() to add an additional instrument to my chart. If that additional instrument is missing a bar that the primary instrument has, how can I use the previous value of close? Here is my code:

    Code:
            protected override void OnBarUpdate() 
            { 
    
    
                if (BarsInProgress == 0) 
                {
    
                } 
                else if (BarsInProgress == 1)  
                {
                     Value[0] = Close[0];
                }
    
            }
    When the second bars object is missing a bar, I get a blank space in my indicator like this screenshot:
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    How can I check if there is not a value for the bar and if true, use Close[1]?

    #2
    Hello swcooke,
    Thanks for your post.

    What data series have you added?

    Can I see your OnStateChange() method?

    What data provider are you connected to?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      I am using IQFeed. I've added the following in State.Configure:
      Code:
      AddDataSeries("XLRE",BarsPeriodType.Minute,BarsPeriod.Value);

      Comment


        #4
        What you have to do is Record the BarsInProgress ==1 value and print that information in the BarsInProgress == 0; Your indicator primary is BarsInProgress ==0;

        // Global variable
        double dMyValue ;



        if(BarsinProgress ==0)
        Value[0] = dMyValue;

        if(BarsInProgress == 1)
        dMyValue = Value[0];


        Last edited by ballboy11; 10-15-2018, 09:29 AM.

        Comment


          #5
          Thanks ballboy11,

          Unfortunately, I cannot see how this solves the issue in my screenshot however I went through to motions of creating a separate script (see attached) with your syntax in hopes it would shed some light on what seems to be a simple issue. Can you provide an example script I could import that does not show the blank space I showed in my screenshot?

          This one uses your syntax and does not work:
          ObaTest1.zip
          Attached Files

          Comment


            #6
            If you right-click inside your chart>>Reload all historical data does that fix the issue?
            I believe this is a historical data issue and not a programming issue.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              No, it does not..

              Comment


                #8
                I have tested on my end and also see a gap in historical data on the XLRE at that time and have reported the missing data. You can confirm this by comparing the time stamps on the surrounding bars. I do not believe you need to change your logic because this is not something that I would regularly expect to happen.

                One thing you could do is use IsValidDataPoint() to check make sure there is valid data there before accessing it.

                Josh G.NinjaTrader Customer Service

                Comment


                  #9
                  Absolutely. I have attached it. Here is a screenshot of what I am seeing on my side:
                  World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


                  ObaTest.zip

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  612 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  355 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  561 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  564 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X