• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Wrong data

  • Filter
  • Time
  • Show
Clear All
new posts

    Wrong data


    I am running a simple strategy on 100 Range chart using Market Replay.
    I output the data from Lows, Highs and Times and it seems that the data is 3 bars late.
    for example, when i output Lows[0][0] i get the data from the fourth bar and not the first.

    Please help


    This shouldn't be the case, but I would need to see more code. Could you possible post more of your code here?
    Adam P.NinjaTrader Customer Service


      Thank you for your reply.
      I attached code+print screen.
      Attached Files



        I'll have to test on my end here, however I can see what you are pointing at.

        This is market replay correct? Do you download this data from the market replay servers or record it from your data provider?
        Adam P.NinjaTrader Customer Service



          I downloaded the data for the market replay. My data provider ad broker is MBTrading.

          I now tried it on live (demo) and same error accord only this time more than 3 bars difference.
          When i connected today, NT downloaded missing data. I think (and it's just an idea) that the script recognize the first bar BEFORE the new data download as the first bar in the chart (although new bars are now shown after the download).
          Last edited by kiss987; 09-06-2012, 03:48 AM.


            I did some more testing and the problem still remain, but i dont think it has to do with my connection time.

            Also i added the following line:
            Print(DateTime.Now.ToString() + " " + Time.ToString());
            which gave:
            9/6/2012 15:28:46 9/5/2012 0:03:22
            9/6/2012 15:28:46 is the correct local date and time (I live in Israel).
            i don't know why Time.ToString is printing 9/5/2012 0:03:22.

            when i changed the output to 1 minute bars i got:
            i= 0 LowsBid= 1.25637 9/5/2012 0:03:00
            i= 1 LowsBid= 1.25641 9/5/2012 0:02:00
            i= 2 LowsBid= 1.25631 9/4/2012 23:59:00
            i= 3 LowsBid= 1.25638 9/4/2012 23:58:00
            i= 4 LowsBid= 1.25638 9/4/2012 23:57:00

            Maybe it's something with local time and server time...
            i changed my session from UTC-06 to UTC+2 but it didnt change much...
            btw, i trade forex if it changes anything.
            i also deleted my db cache data but no luck.
            Last edited by kiss987; 09-06-2012, 05:45 AM.


              Where did you add this new print statement? Was this OnStartUp()?

              If you change the number of "Days to load", does it output different date/time?
              MatthewNinjaTrader Product Management


                Yes, OnStartUp.
                "Days to load" on the chart? i changed it but it doesn't help. i dont execute the strategy from a chart, but from the strategies tab->new srtategy


                  Does the value change if you change the number of bars to load from the strategy tab then?
                  MatthewNinjaTrader Product Management


                    no, it doesnt...
                    I just ran the script on a different computer and the problem happens on it as well.
                    were u able to restore the problem?
                    Last edited by kiss987; 09-06-2012, 12:47 PM.



                      OnStartUp is only ran on the first bar on the chart. So when you're printing DateTime.Now and Time[0], you're getting the current time, and the time of the first bar of the chart.

                      You're also going to have to move the for loop to OnBarUpdate() in order to start on the most current bar on the chart

                      		protected override void OnBarUpdate()
                      			Print("Time : " + Time.ToString());
                      			for(int i = 0; i < 10 ; i++)
                      				Print("i= " + i + " LowsBid= " + Lows[0][i] + " " + Times[0][i]);
                      When I run this, I get the correct lows:

                      Time : 9/6/2012 3:29:00 PM
                      i= 0 LowsBid= 1432.75 9/6/2012 3:29:00 PM
                      i= 1 LowsBid= 1432.25 9/6/2012 3:28:00 PM
                      i= 2 LowsBid= 1432.25 9/6/2012 3:27:00 PM
                      i= 3 LowsBid= 1432.25 9/6/2012 3:26:00 PM
                      i= 4 LowsBid= 1432.25 9/6/2012 3:25:00 PM
                      i= 5 LowsBid= 1432.25 9/6/2012 3:24:00 PM
                      i= 6 LowsBid= 1432.25 9/6/2012 3:23:00 PM
                      i= 7 LowsBid= 1432.5 9/6/2012 3:22:00 PM
                      i= 8 LowsBid= 1432.5 9/6/2012 3:21:00 PM
                      i= 9 LowsBid= 1432.5 9/6/2012 3:20:00 PM
                      Please let me know if that does not produce the results or behavior you're seeking.
                      MatthewNinjaTrader Product Management


                        Thank you for your relpy,

                        I tried your new code and what happened is that the log wrote data of thousands bars ago until the current bar (most right). it seems the OnBarUpdate is called not only for the most right bar but starting with many bars ago until the right bar.

                        I changed the code to the following:

                        if(Count-CurrentBar > 5)return;

                        Print("Time : " + Time.ToString() + " DateTime : " + DateTime.Now.ToString());

                        for(int i = 0; i < 3 ; i++)
                        Print("Count= " + Count + " CurrentBar= " + CurrentBar + " i= " + i + " LowsBid= " + Lows[0][i] + " " + Times[0][i]);
                        This code got me the data from the last few bars only which is what i wanted.

                        My new question is: Is this the correct behavior? does the OnBarUpdate should refer to historical bars and not just new ticks from after the strategy start?


                          OnBarUpdate will run on each bar on historical data first starting on bar 0, and then will continue to update on the current bar, depending on your COBC settings - when set to True, it will update when each new bar closes, and when set to false it will update with each incoming tick.
                          MatthewNinjaTrader Product Management


                          Latest Posts


                          Topics Statistics Last Post
                          Started by Simon Investimens, Today, 03:26 AM
                          1 response
                          Last Post NinjaTrader_Marco  
                          Started by fx.practic, Today, 05:15 AM
                          0 responses
                          Last Post fx.practic  
                          Started by guidoisot, Today, 05:03 AM
                          0 responses
                          Last Post guidoisot  
                          Started by EnveousColnago, Yesterday, 06:58 AM
                          1 response
                          Last Post NinjaTrader_ChrisSch  
                          Started by owreivmatot, Today, 01:38 AM
                          0 responses
                          1 view
                          Last Post owreivmatot