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

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:
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    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:
                  Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                  ObaTest.zip

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by rdtdale, Today, 01:02 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post rdtdale
                  by rdtdale
                   
                  Started by alifarahani, Today, 09:40 AM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by RookieTrader, Today, 09:37 AM
                  4 responses
                  18 views
                  0 likes
                  Last Post RookieTrader  
                  Started by PaulMohn, Today, 12:36 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post PaulMohn  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  41 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X